diff options
| author | Simon Hausmann <simon.hausmann@digia.com> | 2012-10-17 16:21:14 +0200 |
|---|---|---|
| committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-10-17 16:21:14 +0200 |
| commit | 8995b83bcbfbb68245f779b64e5517627c6cc6ea (patch) | |
| tree | 17985605dab9263cc2444bd4d45f189e142cca7c /Source/WebCore/dom/Document.cpp | |
| parent | b9c9652036d5e9f1e29c574f40bc73a35c81ace6 (diff) | |
Imported WebKit commit cf4f8fc6f19b0629f51860cb2d4b25e139d07e00 (http://svn.webkit.org/repository/webkit/trunk@131592)
New snapshot that includes the build fixes for Mac OS X 10.6 and earlier as well
as the previously cherry-picked changes
Diffstat (limited to 'Source/WebCore/dom/Document.cpp')
| -rw-r--r-- | Source/WebCore/dom/Document.cpp | 221 |
1 files changed, 128 insertions, 93 deletions
diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp index df2ebeff7..c453cd3cc 100644 --- a/Source/WebCore/dom/Document.cpp +++ b/Source/WebCore/dom/Document.cpp @@ -109,6 +109,7 @@ #include "Language.h" #include "Localizer.h" #include "Logging.h" +#include "MediaCanStartListener.h" #include "MediaQueryList.h" #include "MediaQueryMatcher.h" #include "MouseEventWithHitTestResults.h" @@ -174,6 +175,8 @@ #include <wtf/CurrentTime.h> #include <wtf/HashFunctions.h> #include <wtf/MainThread.h> +#include <wtf/MemoryInstrumentationHashMap.h> +#include <wtf/MemoryInstrumentationHashSet.h> #include <wtf/MemoryInstrumentationVector.h> #include <wtf/PassRefPtr.h> #include <wtf/StdLibExtras.h> @@ -458,9 +461,9 @@ Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML) , m_hasXMLDeclaration(0) , m_savedRenderer(0) , m_designMode(inherit) -#if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION) - , m_hasDashboardRegions(false) - , m_dashboardRegionsDirty(false) +#if ENABLE(DASHBOARD_SUPPORT) || ENABLE(DRAGGABLE_REGION) + , m_hasAnnotatedRegions(false) + , m_annotatedRegionsDirty(false) #endif , m_createRenderers(true) , m_inPageCache(false) @@ -526,7 +529,12 @@ Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML) m_markers = adoptPtr(new DocumentMarkerController); - m_cachedResourceLoader = adoptPtr(new CachedResourceLoader(this)); + if (m_frame) + m_cachedResourceLoader = m_frame->loader()->activeDocumentLoader()->cachedResourceLoader(); + if (!m_cachedResourceLoader) + m_cachedResourceLoader = CachedResourceLoader::create(0); + m_cachedResourceLoader->setDocument(this); + #if ENABLE(LINK_PRERENDER) m_prerenderer = Prerenderer::create(this); #endif @@ -642,14 +650,17 @@ Document::~Document() if (m_elemSheet) m_elemSheet->clearOwnerNode(); - deleteCustomFonts(); - m_weakReference->clear(); if (m_mediaQueryMatcher) m_mediaQueryMatcher->documentDestroyed(); clearStyleResolver(); // We need to destory CSSFontSelector before destroying m_cachedResourceLoader. + + // It's possible for multiple Documents to end up referencing the same CachedResourceLoader (e.g., SVGImages + // load the initial empty document and the SVGDocument with the same DocumentLoader). + if (m_cachedResourceLoader->document() == this) + m_cachedResourceLoader->setDocument(0); m_cachedResourceLoader.clear(); // We must call clearRareData() here since a Document class inherits TreeScope @@ -949,9 +960,7 @@ PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionCo ec = NAMESPACE_ERR; return 0; } - RefPtr<Element> newElement = createElement(oldElement->tagQName(), ec); - if (ec) - return 0; + RefPtr<Element> newElement = createElement(oldElement->tagQName(), false); newElement->cloneDataFromElement(*oldElement); @@ -1041,10 +1050,9 @@ PassRefPtr<Node> Document::adoptNode(PassRefPtr<Node> source, ExceptionCode& ec) return 0; } - // FIXME: What about <frame> and <object>? - if (source->hasTagName(iframeTag)) { - HTMLIFrameElement* iframe = static_cast<HTMLIFrameElement*>(source.get()); - if (frame() && frame()->tree()->isDescendantOf(iframe->contentFrame())) { + if (source->isFrameOwnerElement()) { + HTMLFrameOwnerElement* frameOwnerElement = toFrameOwnerElement(source.get()); + if (frame() && frame()->tree()->isDescendantOf(frameOwnerElement->contentFrame())) { ec = HIERARCHY_REQUEST_ERR; return 0; } @@ -1140,17 +1148,6 @@ bool Document::cssGridLayoutEnabled() const #if ENABLE(CSS_REGIONS) -PassRefPtr<WebKitNamedFlow> Document::webkitGetFlowByName(const String& flowName) -{ - if (!cssRegionsEnabled() || !renderer()) - return 0; - - // It's possible to have pending styles not applied that affect the existing flows. - updateStyleIfNeeded(); - - return namedFlows()->flowByName(flowName); -} - PassRefPtr<DOMNamedFlowCollection> Document::webkitGetNamedFlows() { if (!cssRegionsEnabled() || !renderer()) @@ -1627,10 +1624,10 @@ PageVisibilityState Document::visibilityState() const { // The visibility of the document is inherited from the visibility of the // page. If there is no page associated with the document, we will assume - // that the page is visible i.e. invisibility has to be explicitly - // specified by the embedder. + // that the page is hidden, as specified by the spec: + // http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html#dom-document-hidden if (!m_frame || !m_frame->page()) - return PageVisibilityStateVisible; + return PageVisibilityStateHidden; return m_frame->page()->visibilityState(); } @@ -1773,11 +1770,16 @@ void Document::unscheduleStyleRecalc() m_pendingStyleRecalcShouldForce = false; } -bool Document::isPendingStyleRecalc() const +bool Document::hasPendingStyleRecalc() const { return m_styleRecalcTimer.isActive() && !m_inStyleRecalc; } +bool Document::hasPendingForcedStyleRecalc() const +{ + return m_styleRecalcTimer.isActive() && m_pendingStyleRecalcShouldForce; +} + void Document::styleRecalcTimerFired(Timer<Document>*) { updateStyleIfNeeded(); @@ -1977,20 +1979,6 @@ PassRefPtr<RenderStyle> Document::styleForPage(int pageIndex) return style.release(); } -void Document::registerCustomFont(PassOwnPtr<FontData> fontData) -{ - m_customFonts.append(fontData); -} - -void Document::deleteCustomFonts() -{ - size_t size = m_customFonts.size(); - for (size_t i = 0; i < size; ++i) - GlyphPageTreeNode::pruneTreeCustomFontData(m_customFonts[i].get()); - - m_customFonts.clear(); -} - bool Document::isPageBoxVisible(int pageIndex) { RefPtr<RenderStyle> style = styleForPage(pageIndex); @@ -2684,6 +2672,14 @@ double Document::minimumTimerInterval() const return p->settings()->minDOMTimerInterval(); } +double Document::timerAlignmentInterval() const +{ + Page* p = page(); + if (!p) + return ScriptExecutionContext::timerAlignmentInterval(); + return p->settings()->domTimerAlignmentInterval(); +} + EventTarget* Document::errorEventTarget() { return domWindow(); @@ -3354,16 +3350,16 @@ void Document::activeChainNodeDetached(Node* node) m_activeNode = m_activeNode->parentNode(); } -#if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION) -const Vector<DashboardRegionValue>& Document::dashboardRegions() const +#if ENABLE(DASHBOARD_SUPPORT) || ENABLE(DRAGGABLE_REGION) +const Vector<AnnotatedRegionValue>& Document::annotatedRegions() const { - return m_dashboardRegions; + return m_annotatedRegions; } -void Document::setDashboardRegions(const Vector<DashboardRegionValue>& regions) +void Document::setAnnotatedRegions(const Vector<AnnotatedRegionValue>& regions) { - m_dashboardRegions = regions; - setDashboardRegionsDirty(false); + m_annotatedRegions = regions; + setAnnotatedRegionsDirty(false); } #endif @@ -3710,7 +3706,7 @@ EventListener* Document::getWindowAttributeEventListener(const AtomicString& eve void Document::dispatchWindowEvent(PassRefPtr<Event> event, PassRefPtr<EventTarget> target) { - ASSERT(!eventDispatchForbidden()); + ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); DOMWindow* domWindow = this->domWindow(); if (!domWindow) return; @@ -3719,7 +3715,7 @@ void Document::dispatchWindowEvent(PassRefPtr<Event> event, PassRefPtr<EventTar void Document::dispatchWindowLoadEvent() { - ASSERT(!eventDispatchForbidden()); + ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); DOMWindow* domWindow = this->domWindow(); if (!domWindow) return; @@ -3926,6 +3922,19 @@ String Document::lastModified() const return String::format("%02d/%02d/%04d %02d:%02d:%02d", date.month() + 1, date.monthDay(), date.fullYear(), date.hour(), date.minute(), date.second()); } +static bool isValidNameNonASCII(const LChar* characters, unsigned length) +{ + if (!isValidNameStart(characters[0])) + return false; + + for (unsigned i = 1; i < length; ++i) { + if (!isValidNamePart(characters[i])) + return false; + } + + return true; +} + static bool isValidNameNonASCII(const UChar* characters, unsigned length) { unsigned i = 0; @@ -3966,16 +3975,20 @@ bool Document::isValidName(const String& name) if (!length) return false; - const UChar* characters; if (name.is8Bit()) { - if (isValidNameASCII(name.characters8(), length)) - return true; - characters = name.characters(); - } else { - characters = name.characters16(); + const LChar* characters = name.characters8(); + if (isValidNameASCII(characters, length)) return true; + + return isValidNameNonASCII(characters, length); } + + const UChar* characters = name.characters16(); + + if (isValidNameASCII(characters, length)) + return true; + return isValidNameNonASCII(characters, length); } @@ -4069,14 +4082,25 @@ void Document::setInPageCache(bool flag) m_inPageCache = flag; FrameView* v = view(); + Page* page = this->page(); + if (flag) { ASSERT(!m_savedRenderer); m_savedRenderer = renderer(); if (v) { + // FIXME: There is some scrolling related work that needs to happen whenever a page goes into the + // page cache and similar work that needs to occur when it comes out. This is where we do the work + // that needs to happen when we enter, and the work that needs to happen when we exit is in + // HistoryController::restoreScrollPositionAndViewState(). It can't be here because this function is + // called too early on in the process of a page exiting the cache for that work to be possible in this + // function. It would be nice if there was more symmetry here. + // https://bugs.webkit.org/show_bug.cgi?id=98698 v->cacheCurrentScrollPosition(); - if (page() && page()->mainFrame() == m_frame) + if (page && page->mainFrame() == m_frame) { v->resetScrollbarsAndClearContentsSize(); - else + if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator()) + scrollingCoordinator->clearStateTree(); + } else v->resetScrollbars(); } m_styleRecalcTimer.stop(); @@ -4450,10 +4474,10 @@ PassRefPtr<HTMLCollection> Document::windowNamedItems(const AtomicString& name) { NamedCollectionMap::AddResult result = m_windowNamedItemCollections.add(name, 0); if (!result.isNewEntry) - return result.iterator->second; + return result.iterator->value; RefPtr<HTMLNameCollection> collection = HTMLNameCollection::create(this, WindowNamedItems, name); - result.iterator->second = collection.get(); + result.iterator->value = collection.get(); return collection.release(); } @@ -4461,10 +4485,10 @@ PassRefPtr<HTMLCollection> Document::documentNamedItems(const AtomicString& name { NamedCollectionMap::AddResult result = m_documentNamedItemCollections.add(name, 0); if (!result.isNewEntry) - return result.iterator->second; + return result.iterator->value; RefPtr<HTMLNameCollection> collection = HTMLNameCollection::create(this, DocumentNamedItems, name); - result.iterator->second = collection.get(); + result.iterator->value = collection.get(); return collection.release(); } @@ -4802,7 +4826,7 @@ CanvasRenderingContext* Document::getCSSCanvasContext(const String& type, const HTMLCanvasElement* Document::getCSSCanvasElement(const String& name) { - RefPtr<HTMLCanvasElement>& element = m_cssCanvasElements.add(name, 0).iterator->second; + RefPtr<HTMLCanvasElement>& element = m_cssCanvasElements.add(name, 0).iterator->value; if (!element) element = HTMLCanvasElement::create(this); return element.get(); @@ -5063,9 +5087,17 @@ void Document::requestFullScreenForElement(Element* element, unsigned short flag // There is a previously-established user preference, security risk, or platform limitation. if (!page() || !page()->settings()->fullScreenEnabled()) break; - - if (!page()->chrome()->client()->supportsFullScreenForElement(element, flags & Element::ALLOW_KEYBOARD_INPUT)) - break; + + if (!page()->chrome()->client()->supportsFullScreenForElement(element, flags & Element::ALLOW_KEYBOARD_INPUT)) { + // The new full screen API does not accept a "flags" parameter, so fall back to disallowing + // keyboard input if the chrome client refuses to allow keyboard input. + if (!inLegacyMozillaMode && flags & Element::ALLOW_KEYBOARD_INPUT) { + flags &= ~Element::ALLOW_KEYBOARD_INPUT; + if (!page()->chrome()->client()->supportsFullScreenForElement(element, false)) + break; + } else + break; + } // 2. Let doc be element's node document. (i.e. "this") Document* currentDoc = this; @@ -5525,7 +5557,7 @@ void Document::loadEventDelayTimerFired(Timer<Document>*) } #if ENABLE(REQUEST_ANIMATION_FRAME) -int Document::webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback> callback) +int Document::requestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback> callback) { if (!m_scriptedAnimationController) { #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) @@ -5543,18 +5575,18 @@ int Document::webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallba return m_scriptedAnimationController->registerCallback(callback); } -void Document::webkitCancelAnimationFrame(int id) +void Document::cancelAnimationFrame(int id) { if (!m_scriptedAnimationController) return; m_scriptedAnimationController->cancelCallback(id); } -void Document::serviceScriptedAnimations(DOMTimeStamp time) +void Document::serviceScriptedAnimations(double monotonicAnimationStartTime) { if (!m_scriptedAnimationController) return; - m_scriptedAnimationController->serviceScriptedAnimations(time); + m_scriptedAnimationController->serviceScriptedAnimations(monotonicAnimationStartTime); } #endif @@ -5865,9 +5897,8 @@ void Document::updateHoverActiveState(const HitTestRequest& request, HitTestResu void Document::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const { MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); - info.addMember(m_styleResolver); ContainerNode::reportMemoryUsage(memoryObjectInfo); - info.addMember(m_customFonts); + info.addMember(m_styleResolver); info.addMember(m_url); info.addMember(m_baseURL); info.addMember(m_baseURLOverride); @@ -5876,30 +5907,34 @@ void Document::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const info.addMember(m_firstPartyForCookies); info.addMember(m_documentURI); info.addMember(m_baseTarget); + info.addMember(m_docType); + info.addMember(m_implementation); + info.addMember(m_elemSheet); info.addMember(m_frame); info.addMember(m_cachedResourceLoader); - info.addMember(m_elemSheet); info.addMember(m_styleSheetCollection); - info.addHashSet(m_nodeIterators); - info.addHashSet(m_ranges); + info.addMember(m_styleSheetList); + info.addMember(m_formController); + info.addMember(m_nodeIterators); + info.addMember(m_ranges); info.addMember(m_title.string()); info.addMember(m_rawTitle.string()); info.addMember(m_xmlEncoding); info.addMember(m_xmlVersion); info.addMember(m_contentLanguage); - info.addHashMap(m_documentNamedItemCollections); - info.addHashMap(m_windowNamedItemCollections); -#if ENABLE(DASHBOARD_SUPPORT) - info.addMember(m_dashboardRegions); + info.addMember(m_documentNamedItemCollections); + info.addMember(m_windowNamedItemCollections); +#if ENABLE(DASHBOARD_SUPPORT) || ENABLE(DRAGGABLE_REGION) + info.addMember(m_annotatedRegions); #endif - info.addHashMap(m_cssCanvasElements); + info.addMember(m_cssCanvasElements); info.addMember(m_iconURLs); - info.addHashSet(m_documentSuspensionCallbackElements); - info.addHashSet(m_mediaVolumeCallbackElements); - info.addHashSet(m_privateBrowsingStateChangedElements); - info.addHashMap(m_elementsByAccessKey); + info.addMember(m_documentSuspensionCallbackElements); + info.addMember(m_mediaVolumeCallbackElements); + info.addMember(m_privateBrowsingStateChangedElements); + info.addMember(m_elementsByAccessKey); info.addMember(m_eventQueue); - info.addHashSet(m_mediaCanStartListeners); + info.addMember(m_mediaCanStartListeners); info.addMember(m_pendingTasks); } @@ -5959,19 +5994,19 @@ PassRefPtr<ElementAttributeData> Document::cachedImmutableAttributeData(const El unsigned cacheHash = cacheKey.hash(); ImmutableAttributeDataCache::iterator cacheIterator = m_immutableAttributeDataCache.add(cacheHash, nullptr).iterator; - if (cacheIterator->second && cacheIterator->second->key != cacheKey) + if (cacheIterator->value && cacheIterator->value->key != cacheKey) cacheHash = 0; RefPtr<ElementAttributeData> attributeData; - if (cacheHash && cacheIterator->second) - attributeData = cacheIterator->second->value; + if (cacheHash && cacheIterator->value) + attributeData = cacheIterator->value->value; else attributeData = ElementAttributeData::createImmutable(attributes); - if (!cacheHash || cacheIterator->second) + if (!cacheHash || cacheIterator->value) return attributeData.release(); - cacheIterator->second = adoptPtr(new ImmutableAttributeDataCacheEntry(ImmutableAttributeDataCacheKey(element->tagQName(), attributeData->immutableAttributeArray(), attributeData->length()), attributeData)); + cacheIterator->value = adoptPtr(new ImmutableAttributeDataCacheEntry(ImmutableAttributeDataCacheKey(element->tagQName(), attributeData->immutableAttributeArray(), attributeData->length()), attributeData)); return attributeData.release(); } @@ -5981,15 +6016,15 @@ bool Document::haveStylesheetsLoaded() const return !m_styleSheetCollection->hasPendingSheets() || m_ignorePendingStylesheets; } -Localizer& Document::getLocalizer(const AtomicString& locale) +Localizer& Document::getCachedLocalizer(const AtomicString& locale) { AtomicString localeKey = locale; if (locale.isEmpty() || !RuntimeEnabledFeatures::langAttributeAwareFormControlUIEnabled()) localeKey = defaultLanguage(); LocaleToLocalizerMap::AddResult result = m_localizerCache.add(localeKey, nullptr); if (result.isNewEntry) - result.iterator->second = Localizer::create(localeKey); - return *(result.iterator->second); + result.iterator->value = Localizer::create(localeKey); + return *(result.iterator->value); } } // namespace WebCore |
