summaryrefslogtreecommitdiffstats
path: root/WebCore/dom/Document.cpp
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2009-12-15 10:12:09 +0000
committerSteve Block <steveblock@google.com>2009-12-17 17:41:10 +0000
commit643ca7872b450ea4efacab6188849e5aac2ba161 (patch)
tree6982576c228bcd1a7efe98afed544d840751094c /WebCore/dom/Document.cpp
parentd026980fde6eb3b01c1fe49441174e89cd1be298 (diff)
downloadexternal_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.zip
external_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.tar.gz
external_webkit-643ca7872b450ea4efacab6188849e5aac2ba161.tar.bz2
Merge webkit.org at r51976 : Initial merge by git.
Change-Id: Ib0e7e2f0fb4bee5a186610272edf3186f0986b43
Diffstat (limited to 'WebCore/dom/Document.cpp')
-rw-r--r--WebCore/dom/Document.cpp158
1 files changed, 116 insertions, 42 deletions
diff --git a/WebCore/dom/Document.cpp b/WebCore/dom/Document.cpp
index 174e58d..ba6dc97 100644
--- a/WebCore/dom/Document.cpp
+++ b/WebCore/dom/Document.cpp
@@ -98,6 +98,7 @@
#include "PageGroup.h"
#include "PageTransitionEvent.h"
#include "PlatformKeyboardEvent.h"
+#include "PopStateEvent.h"
#include "ProcessingInstruction.h"
#include "ProgressEvent.h"
#include "RegisteredEventListener.h"
@@ -386,15 +387,18 @@ Document::Document(Frame* frame, bool isXHTML)
m_ignoreAutofocus = false;
m_frame = frame;
+<<<<<<< HEAD:WebCore/dom/Document.cpp
m_renderArena = 0;
#if !PLATFORM(ANDROID)
+=======
+
+>>>>>>> webkit.org at r51976:WebCore/dom/Document.cpp
m_axObjectCache = 0;
#endif
m_docLoader = new DocLoader(this);
visuallyOrdered = false;
m_bParsing = false;
- m_tokenizer = 0;
m_wellFormed = false;
setParseMode(Strict);
@@ -465,8 +469,7 @@ void Document::removedLastRef()
deleteAllValues(m_markers);
m_markers.clear();
- delete m_tokenizer;
- m_tokenizer = 0;
+ m_tokenizer.clear();
m_cssCanvasElements.clear();
@@ -500,18 +503,15 @@ Document::~Document()
forgetAllDOMNodesForDocument(this);
#endif
- delete m_tokenizer;
+ m_tokenizer.clear();
m_document = 0;
delete m_styleSelector;
- delete m_docLoader;
-
- if (m_renderArena) {
- delete m_renderArena;
- m_renderArena = 0;
- }
+ m_docLoader.clear();
+
+ m_renderArena.clear();
#if ENABLE(XBL)
- delete m_bindingManager;
+ m_bindingManager.clear();
#endif
deleteAllValues(m_markers);
@@ -1264,13 +1264,13 @@ void Document::recalcStyle(StyleChange change)
return; // Guard against re-entrancy. -dwh
#if ENABLE(INSPECTOR)
- InspectorTimelineAgent* timelineAgent = inspectorTimelineAgent();
- if (timelineAgent)
+ if (InspectorTimelineAgent* timelineAgent = inspectorTimelineAgent())
timelineAgent->willRecalculateStyle();
#endif
m_inStyleRecalc = true;
suspendPostAttachCallbacks();
+ RenderWidget::suspendWidgetHierarchyUpdates();
if (view())
view()->pauseScheduledEvents();
@@ -1341,6 +1341,7 @@ bail_out:
if (view())
view()->resumeScheduledEvents();
+ RenderWidget::resumeWidgetHierarchyUpdates();
resumePostAttachCallbacks();
m_inStyleRecalc = false;
@@ -1351,7 +1352,7 @@ bail_out:
}
#if ENABLE(INSPECTOR)
- if (timelineAgent)
+ if (InspectorTimelineAgent* timelineAgent = inspectorTimelineAgent())
timelineAgent->didRecalculateStyle();
#endif
}
@@ -1442,7 +1443,7 @@ void Document::attach()
m_renderArena = new RenderArena();
// Create the rendering tree
- setRenderer(new (m_renderArena) RenderView(this, view()));
+ setRenderer(new (m_renderArena.get()) RenderView(this, view()));
#if USE(ACCELERATED_COMPOSITING)
renderView()->didMoveOnscreen();
#endif
@@ -1514,17 +1515,19 @@ void Document::detach()
if (render)
render->destroy();
+ HashSet<RefPtr<HistoryItem> > associatedHistoryItems;
+ associatedHistoryItems.swap(m_associatedHistoryItems);
+ HashSet<RefPtr<HistoryItem> >::iterator end = associatedHistoryItems.end();
+ for (HashSet<RefPtr<HistoryItem> >::iterator i = associatedHistoryItems.begin(); i != end; ++i)
+ (*i)->documentDetached(this);
+
// This is required, as our Frame might delete itself as soon as it detaches
// us. However, this violates Node::detach() symantics, as it's never
// possible to re-attach. Eventually Document::detach() should be renamed,
// or this setting of the frame to 0 could be made explicit in each of the
// callers of Document::detach().
m_frame = 0;
-
- if (m_renderArena) {
- delete m_renderArena;
- m_renderArena = 0;
- }
+ m_renderArena.clear();
}
void Document::removeAllEventListeners()
@@ -1647,8 +1650,7 @@ void Document::cancelParsing()
// the onload handler when closing as a side effect of a cancel-style
// change, such as opening a new document or closing the window while
// still parsing
- delete m_tokenizer;
- m_tokenizer = 0;
+ m_tokenizer.clear();
close();
}
}
@@ -1657,8 +1659,7 @@ void Document::implicitOpen()
{
cancelParsing();
- delete m_tokenizer;
- m_tokenizer = 0;
+ m_tokenizer.clear();
removeChildren();
@@ -1755,8 +1756,7 @@ void Document::implicitClose()
// We have to clear the tokenizer, in case someone document.write()s from the
// onLoad event handler, as in Radar 3206524.
- delete m_tokenizer;
- m_tokenizer = 0;
+ m_tokenizer.clear();
// Parser should have picked up all preloads by now
m_docLoader->clearPreloads();
@@ -1793,6 +1793,9 @@ void Document::implicitClose()
ImageLoader::dispatchPendingEvents();
dispatchWindowLoadEvent();
dispatchWindowEvent(PageTransitionEvent::create(eventNames().pageshowEvent, false), this);
+ if (m_pendingStateObject)
+ dispatchWindowEvent(PopStateEvent::create(m_pendingStateObject.release()));
+
if (f)
f->loader()->handledOnloadEvents();
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
@@ -2291,8 +2294,10 @@ void Document::processHttpEquiv(const String& equiv, const String& content)
}
} else if (equalIgnoringCase(equiv, "set-cookie")) {
// FIXME: make setCookie work on XML documents too; e.g. in case of <html:meta .....>
- if (isHTMLDocument())
- static_cast<HTMLDocument*>(this)->setCookie(content);
+ if (isHTMLDocument()) {
+ ExceptionCode ec; // Exception (for sandboxed documents) ignored.
+ static_cast<HTMLDocument*>(this)->setCookie(content, ec);
+ }
} else if (equalIgnoringCase(equiv, "content-language"))
setContentLanguage(content);
else if (equalIgnoringCase(equiv, "x-dns-prefetch-control"))
@@ -2608,7 +2613,7 @@ void Document::recalcStyleSelector()
sheet = cssSheet.get();
}
}
- } else if (n->isHTMLElement() && (n->hasTagName(linkTag) || n->hasTagName(styleTag))
+ } else if ((n->isHTMLElement() && (n->hasTagName(linkTag) || n->hasTagName(styleTag)))
#if ENABLE(SVG)
|| (n->isSVGElement() && n->hasTagName(SVGNames::styleTag))
#endif
@@ -2770,14 +2775,14 @@ bool Document::setFocusedNode(PassRefPtr<Node> newFocusedNode)
oldFocusedNode->setActive(false);
oldFocusedNode->setFocus(false);
-
+
// Dispatch a change event for text fields or textareas that have been edited
RenderObject* r = oldFocusedNode->renderer();
- if (r && r->isTextControl() && toRenderTextControl(r)->isEdited()) {
- oldFocusedNode->dispatchEvent(Event::create(eventNames().changeEvent, true, false));
+ if (r && r->isTextControl() && toRenderTextControl(r)->wasChangedSinceLastChangeEvent()) {
+ static_cast<Element*>(oldFocusedNode.get())->dispatchFormControlChangeEvent();
r = oldFocusedNode->renderer();
if (r && r->isTextControl())
- toRenderTextControl(r)->setEdited(false);
+ toRenderTextControl(r)->setChangedSinceLastChangeEvent(false);
}
// Dispatch the blur event and let the node do any other blur related activities (important for text fields)
@@ -2861,6 +2866,8 @@ bool Document::setFocusedNode(PassRefPtr<Node> newFocusedNode)
axObjectCache()->handleFocusedUIElementChanged(oldFocusedRenderer, newFocusedRenderer);
}
#endif
+ if (!focusChangeBlocked)
+ page()->chrome()->focusedNodeChanged(m_focusedNode.get());
SetFocusedNodeDone:
updateStyleIfNeeded();
@@ -3112,11 +3119,20 @@ Element* Document::ownerElement() const
return frame()->ownerElement();
}
-String Document::cookie() const
+String Document::cookie(ExceptionCode& ec) const
{
if (page() && !page()->cookieEnabled())
return String();
+ // FIXME: The HTML5 DOM spec states that this attribute can raise an
+ // INVALID_STATE_ERR exception on getting if the Document has no
+ // browsing context.
+
+ if (securityOrigin()->isSandboxed(SandboxOrigin)) {
+ ec = SECURITY_ERR;
+ return String();
+ }
+
KURL cookieURL = this->cookieURL();
if (cookieURL.isEmpty())
return String();
@@ -3124,11 +3140,20 @@ String Document::cookie() const
return cookies(this, cookieURL);
}
-void Document::setCookie(const String& value)
+void Document::setCookie(const String& value, ExceptionCode& ec)
{
if (page() && !page()->cookieEnabled())
return;
+ // FIXME: The HTML5 DOM spec states that this attribute can raise an
+ // INVALID_STATE_ERR exception on setting if the Document has no
+ // browsing context.
+
+ if (securityOrigin()->isSandboxed(SandboxOrigin)) {
+ ec = SECURITY_ERR;
+ return;
+ }
+
KURL cookieURL = this->cookieURL();
if (cookieURL.isEmpty())
return;
@@ -3855,7 +3880,7 @@ void Document::repaintMarkers(DocumentMarker::MarkerType markerType)
}
}
-void Document::setRenderedRectForMarker(Node* node, DocumentMarker marker, const IntRect& r)
+void Document::setRenderedRectForMarker(Node* node, const DocumentMarker& marker, const IntRect& r)
{
MarkerMapVectorPair* vectorPair = m_markers.get(node);
if (!vectorPair) {
@@ -4377,6 +4402,8 @@ void Document::initSecurityContext()
m_cookieURL = url;
ScriptExecutionContext::setSecurityOrigin(SecurityOrigin::create(url));
+ updateSandboxFlags();
+
if (SecurityOrigin::allowSubstituteDataAccessToLocal()) {
// If this document was loaded with substituteData, then the document can
// load local resources. See https://bugs.webkit.org/show_bug.cgi?id=16756
@@ -4427,6 +4454,46 @@ void Document::setSecurityOrigin(SecurityOrigin* securityOrigin)
initDNSPrefetch();
}
+void Document::updateURLForPushOrReplaceState(const KURL& url)
+{
+ Frame* f = frame();
+ if (!f)
+ return;
+
+ setURL(url);
+ f->loader()->documentLoader()->replaceRequestURLForSameDocumentNavigation(url);
+}
+
+void Document::statePopped(SerializedScriptValue* stateObject)
+{
+ Frame* f = frame();
+ if (!f)
+ return;
+
+ if (f->loader()->isComplete())
+ dispatchWindowEvent(PopStateEvent::create(stateObject));
+ else
+ m_pendingStateObject = stateObject;
+}
+
+void Document::registerHistoryItem(HistoryItem* item)
+{
+ ASSERT(!m_associatedHistoryItems.contains(item));
+ m_associatedHistoryItems.add(item);
+}
+
+void Document::unregisterHistoryItem(HistoryItem* item)
+{
+ ASSERT(m_associatedHistoryItems.contains(item) || m_associatedHistoryItems.isEmpty());
+ m_associatedHistoryItems.remove(item);
+}
+
+void Document::updateSandboxFlags()
+{
+ if (m_frame && securityOrigin())
+ securityOrigin()->setSandboxFlags(m_frame->loader()->sandboxFlags());
+}
+
void Document::updateFocusAppearanceSoon()
{
if (!m_updateFocusAppearanceTimer.isActive())
@@ -4690,7 +4757,7 @@ void Document::scriptImported(unsigned long identifier, const String& sourceStri
class ScriptExecutionContextTaskTimer : public TimerBase {
public:
- ScriptExecutionContextTaskTimer(PassRefPtr<Document> context, PassRefPtr<ScriptExecutionContext::Task> task)
+ ScriptExecutionContextTaskTimer(PassRefPtr<Document> context, PassOwnPtr<ScriptExecutionContext::Task> task)
: m_context(context)
, m_task(task)
{
@@ -4704,18 +4771,18 @@ private:
}
RefPtr<Document> m_context;
- RefPtr<ScriptExecutionContext::Task> m_task;
+ OwnPtr<ScriptExecutionContext::Task> m_task;
};
-struct PerformTaskContext {
- PerformTaskContext(ScriptExecutionContext* scriptExecutionContext, PassRefPtr<ScriptExecutionContext::Task> task)
+struct PerformTaskContext : Noncopyable {
+ PerformTaskContext(ScriptExecutionContext* scriptExecutionContext, PassOwnPtr<ScriptExecutionContext::Task> task)
: scriptExecutionContext(scriptExecutionContext)
, task(task)
{
}
ScriptExecutionContext* scriptExecutionContext; // The context should exist until task execution.
- RefPtr<ScriptExecutionContext::Task> task;
+ OwnPtr<ScriptExecutionContext::Task> task;
};
static void performTask(void* ctx)
@@ -4725,7 +4792,7 @@ static void performTask(void* ctx)
delete ptctx;
}
-void Document::postTask(PassRefPtr<Task> task)
+void Document::postTask(PassOwnPtr<Task> task)
{
if (isMainThread()) {
ScriptExecutionContextTaskTimer* timer = new ScriptExecutionContextTaskTimer(static_cast<Document*>(this), task);
@@ -4790,4 +4857,11 @@ bool Document::isXHTMLMPDocument() const
}
#endif
+#if ENABLE(INSPECTOR)
+InspectorTimelineAgent* Document::inspectorTimelineAgent() const
+{
+ return page() ? page()->inspectorTimelineAgent() : 0;
+}
+#endif
+
} // namespace WebCore