Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: Source/core/dom/Document.cpp

Issue 1176013002: Move attributes and methods from HTMLDocument to Document (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Introduced open and close methods without arguments to handle internal calls. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 2263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2274 if (!isHTMLDocument()) 2274 if (!isHTMLDocument())
2275 return false; 2275 return false;
2276 return isHTMLFrameSetElement(body()); 2276 return isHTMLFrameSetElement(body());
2277 } 2277 }
2278 2278
2279 ScriptableDocumentParser* Document::scriptableDocumentParser() const 2279 ScriptableDocumentParser* Document::scriptableDocumentParser() const
2280 { 2280 {
2281 return parser() ? parser()->asScriptableDocumentParser() : 0; 2281 return parser() ? parser()->asScriptableDocumentParser() : 0;
2282 } 2282 }
2283 2283
2284 void Document::open(Document* ownerDocument, ExceptionState& exceptionState) 2284 void Document::open()
2285 { 2285 {
2286 if (importLoader()) {
2287 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support open().");
2288 return;
2289 }
2290
2291 if (ownerDocument) {
2292 setURL(ownerDocument->url());
2293 m_cookieURL = ownerDocument->cookieURL();
2294 setSecurityOrigin(ownerDocument->securityOrigin());
2295 }
2296
2297 if (m_frame) { 2286 if (m_frame) {
2298 if (ScriptableDocumentParser* parser = scriptableDocumentParser()) { 2287 if (ScriptableDocumentParser* parser = scriptableDocumentParser()) {
2299 if (parser->isParsing()) { 2288 if (parser->isParsing()) {
2300 // FIXME: HTML5 doesn't tell us to check this, it might not be c orrect. 2289 // FIXME: HTML5 doesn't tell us to check this, it might not be c orrect.
2301 if (parser->isExecutingScript()) 2290 if (parser->isExecutingScript())
2302 return; 2291 return;
2303 2292
2304 if (!parser->wasCreatedByScript() && parser->hasInsertionPoint() ) 2293 if (!parser->wasCreatedByScript() && parser->hasInsertionPoint() )
2305 return; 2294 return;
2306 } 2295 }
2307 } 2296 }
2308 2297
2309 if (m_frame->loader().provisionalDocumentLoader()) 2298 if (m_frame->loader().provisionalDocumentLoader())
2310 m_frame->loader().stopAllLoaders(); 2299 m_frame->loader().stopAllLoaders();
2311 } 2300 }
2312 2301
2313 removeAllEventListenersRecursively(); 2302 removeAllEventListenersRecursively();
2314 implicitOpen(ForceSynchronousParsing); 2303 implicitOpen(ForceSynchronousParsing);
2315 if (ScriptableDocumentParser* parser = scriptableDocumentParser()) 2304 if (ScriptableDocumentParser* parser = scriptableDocumentParser())
2316 parser->setWasCreatedByScript(true); 2305 parser->setWasCreatedByScript(true);
2317 2306
2318 if (m_frame) 2307 if (m_frame)
2319 m_frame->loader().didExplicitOpen(); 2308 m_frame->loader().didExplicitOpen();
2320 if (m_loadEventProgress != LoadEventInProgress && m_loadEventProgress != Unl oadEventInProgress) 2309 if (m_loadEventProgress != LoadEventInProgress && m_loadEventProgress != Unl oadEventInProgress)
2321 m_loadEventProgress = LoadEventNotRun; 2310 m_loadEventProgress = LoadEventNotRun;
2322 } 2311 }
2323 2312
2313 void Document::open(Document* ownerDocument, ExceptionState& exceptionState)
2314 {
2315 if (importLoader()) {
2316 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support open().");
philipj_slow 2015/06/24 11:52:19 Is an import document also an HTML document? If no
Habib Virji 2015/06/25 13:09:46 Changed as suggested and it is do important added
philipj_slow 2015/06/27 21:42:56 Can you link to http://w3c.github.io/webcomponents
Habib Virji 2015/06/29 12:17:41 Done.
2317 return;
2318 }
2319
2320 if (isXHTMLDocument()) {
tkent 2015/06/23 23:42:17 Why do you check isXHTMLDocument(), not isXMLDocum
philipj_slow 2015/06/24 11:52:19 The spec says "If the Document object is not flagg
Habib Virji 2015/06/25 13:09:46 I find spec in-consistent. What you mentioned is
philipj_slow 2015/06/27 21:42:56 The note is non-normative, so !isHTMLDocument() is
Habib Virji 2015/06/29 12:17:42 Done.
2321 exceptionState.throwDOMException(InvalidStateError, "XHTML doesn't suppo rt open().");
2322 return;
2323 }
2324
2325 if (ownerDocument) {
2326 setURL(ownerDocument->url());
2327 m_cookieURL = ownerDocument->cookieURL();
2328 setSecurityOrigin(ownerDocument->securityOrigin());
2329 }
2330
2331 open();
2332 }
2333
2324 void Document::detachParser() 2334 void Document::detachParser()
2325 { 2335 {
2326 if (!m_parser) 2336 if (!m_parser)
2327 return; 2337 return;
2328 m_parser->detach(); 2338 m_parser->detach();
2329 m_parser.clear(); 2339 m_parser.clear();
2330 } 2340 }
2331 2341
2332 void Document::cancelParsing() 2342 void Document::cancelParsing()
2333 { 2343 {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2437 if (!rootStyle) { 2447 if (!rootStyle) {
2438 rootStyle = rootElement->computedStyle(); 2448 rootStyle = rootElement->computedStyle();
2439 if (!rootStyle) 2449 if (!rootStyle)
2440 return 0; 2450 return 0;
2441 } 2451 }
2442 if (bodyElement && rootStyle->isOverflowVisible() && isHTMLHtmlElement(*root Element)) 2452 if (bodyElement && rootStyle->isOverflowVisible() && isHTMLHtmlElement(*root Element))
2443 return bodyElement; 2453 return bodyElement;
2444 return rootElement; 2454 return rootElement;
2445 } 2455 }
2446 2456
2457 void Document::close()
2458 {
2459 if (!scriptableDocumentParser() || !scriptableDocumentParser()->wasCreatedBy Script() || !scriptableDocumentParser()->isParsing())
2460 return;
2461
2462 explicitClose();
2463 }
2464
2447 void Document::close(ExceptionState& exceptionState) 2465 void Document::close(ExceptionState& exceptionState)
2448 { 2466 {
2449 // FIXME: We should follow the specification more closely: 2467 // FIXME: We should follow the specification more closely:
2450 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-cl ose 2468 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-cl ose
2451 2469
2452 if (importLoader()) { 2470 if (importLoader()) {
2453 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support close()."); 2471 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support close().");
2454 return; 2472 return;
2455 } 2473 }
2456 2474
2457 if (!scriptableDocumentParser() || !scriptableDocumentParser()->wasCreatedBy Script() || !scriptableDocumentParser()->isParsing()) 2475 if (isXHTMLDocument()) {
philipj_slow 2015/06/24 11:52:19 Spec says "If the Document object is not flagged a
Habib Virji 2015/06/25 13:09:47 Since !isHTMLDocument() != isXMLDocument() (as exp
2476 exceptionState.throwDOMException(InvalidStateError, "XHTML doesn't suppo rt close().");
2458 return; 2477 return;
2478 }
2459 2479
2460 explicitClose(); 2480 close();
2461 } 2481 }
2462 2482
2463 void Document::explicitClose() 2483 void Document::explicitClose()
2464 { 2484 {
2465 if (RefPtrWillBeRawPtr<DocumentParser> parser = m_parser) 2485 if (RefPtrWillBeRawPtr<DocumentParser> parser = m_parser)
2466 parser->finish(); 2486 parser->finish();
2467 2487
2468 if (!m_frame) { 2488 if (!m_frame) {
2469 // Because we have no frame, we don't know if all loading has completed, 2489 // Because we have no frame, we don't know if all loading has completed,
2470 // so we just call implicitClose() immediately. FIXME: This might fire 2490 // so we just call implicitClose() immediately. FIXME: This might fire
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
2693 return static_cast<int>((currentTime() - m_startTime) * 1000); 2713 return static_cast<int>((currentTime() - m_startTime) * 1000);
2694 } 2714 }
2695 2715
2696 void Document::write(const SegmentedString& text, Document* ownerDocument, Excep tionState& exceptionState) 2716 void Document::write(const SegmentedString& text, Document* ownerDocument, Excep tionState& exceptionState)
2697 { 2717 {
2698 if (importLoader()) { 2718 if (importLoader()) {
2699 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support write()."); 2719 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support write().");
2700 return; 2720 return;
2701 } 2721 }
2702 2722
2723 if (isXHTMLDocument()) {
philipj_slow 2015/06/24 11:52:19 Here the spec actually says "If the method was inv
Habib Virji 2015/06/25 13:09:46 isXMLDocument() relies on value of DocumentClass,
philipj_slow 2015/06/27 21:42:56 Does write() need to be supported for Image, Plugi
Habib Virji 2015/06/29 12:17:42 It should not. I agree it should throw for !isHTML
2724 exceptionState.throwDOMException(InvalidStateError, "XHTML doesn't suppo rt write().");
2725 return;
2726 }
2727
2703 NestingLevelIncrementer nestingLevelIncrementer(m_writeRecursionDepth); 2728 NestingLevelIncrementer nestingLevelIncrementer(m_writeRecursionDepth);
2704 2729
2705 m_writeRecursionIsTooDeep = (m_writeRecursionDepth > 1) && m_writeRecursionI sTooDeep; 2730 m_writeRecursionIsTooDeep = (m_writeRecursionDepth > 1) && m_writeRecursionI sTooDeep;
2706 m_writeRecursionIsTooDeep = (m_writeRecursionDepth > cMaxWriteRecursionDepth ) || m_writeRecursionIsTooDeep; 2731 m_writeRecursionIsTooDeep = (m_writeRecursionDepth > cMaxWriteRecursionDepth ) || m_writeRecursionIsTooDeep;
2707 2732
2708 if (m_writeRecursionIsTooDeep) 2733 if (m_writeRecursionIsTooDeep)
2709 return; 2734 return;
2710 2735
2711 bool hasInsertionPoint = m_parser && m_parser->hasInsertionPoint(); 2736 bool hasInsertionPoint = m_parser && m_parser->hasInsertionPoint();
2712 2737
2713 if (!hasInsertionPoint && m_ignoreDestructiveWriteCount) { 2738 if (!hasInsertionPoint && m_ignoreDestructiveWriteCount) {
2714 addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessage Level, ExceptionMessages::failedToExecute("write", "Document", "It isn't possibl e to write into a document from an asynchronously-loaded external script unless it is explicitly opened."))); 2739 addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessage Level, ExceptionMessages::failedToExecute("write", "Document", "It isn't possibl e to write into a document from an asynchronously-loaded external script unless it is explicitly opened.")));
2715 return; 2740 return;
2716 } 2741 }
2717 2742
2718 if (!hasInsertionPoint) 2743 if (!hasInsertionPoint)
2719 open(ownerDocument); 2744 open(ownerDocument, exceptionState);
philipj_slow 2015/06/24 11:52:19 It looks like it's impossible for this to throw an
Habib Virji 2015/06/25 13:09:46 The reason for adding was it relied on ASSERT_NO_E
2720 2745
2721 ASSERT(m_parser); 2746 ASSERT(m_parser);
2722 m_parser->insert(text); 2747 m_parser->insert(text);
2723 } 2748 }
2724 2749
2725 void Document::write(const String& text, Document* ownerDocument, ExceptionState & exceptionState) 2750 void Document::write(const String& text, Document* ownerDocument, ExceptionState & exceptionState)
2726 { 2751 {
2727 write(SegmentedString(text), ownerDocument, exceptionState); 2752 write(SegmentedString(text), ownerDocument, exceptionState);
2728 } 2753 }
2729 2754
2730 void Document::writeln(const String& text, Document* ownerDocument, ExceptionSta te& exceptionState) 2755 void Document::writeln(const String& text, Document* ownerDocument, ExceptionSta te& exceptionState)
2731 { 2756 {
2732 write(text, ownerDocument, exceptionState); 2757 write(text, ownerDocument, exceptionState);
2733 if (exceptionState.hadException()) 2758 if (exceptionState.hadException())
2734 return; 2759 return;
2735 write("\n", ownerDocument); 2760 write("\n", ownerDocument);
2736 } 2761 }
2737 2762
2763 void Document::write(LocalDOMWindow* callingWindow, const Vector<String>& text, ExceptionState& exceptionState)
2764 {
2765 ASSERT(callingWindow);
2766 StringBuilder builder;
2767 for (const String& string : text)
2768 builder.append(string);
2769 write(builder.toString(), callingWindow->document(), exceptionState);
2770 }
2771
2772 void Document::writeln(LocalDOMWindow* callingWindow, const Vector<String>& text , ExceptionState& exceptionState)
2773 {
2774 ASSERT(callingWindow);
2775 StringBuilder builder;
2776 for (const String& string : text)
2777 builder.append(string);
2778 writeln(builder.toString(), callingWindow->document(), exceptionState);
2779 }
2780
2738 const KURL& Document::virtualURL() const 2781 const KURL& Document::virtualURL() const
2739 { 2782 {
2740 return m_url; 2783 return m_url;
2741 } 2784 }
2742 2785
2743 KURL Document::virtualCompleteURL(const String& url) const 2786 KURL Document::virtualCompleteURL(const String& url) const
2744 { 2787 {
2745 return completeURL(url); 2788 return completeURL(url);
2746 } 2789 }
2747 2790
(...skipping 2990 matching lines...) Expand 10 before | Expand all | Expand 10 after
5738 #ifndef NDEBUG 5781 #ifndef NDEBUG
5739 using namespace blink; 5782 using namespace blink;
5740 void showLiveDocumentInstances() 5783 void showLiveDocumentInstances()
5741 { 5784 {
5742 WeakDocumentSet& set = liveDocumentSet(); 5785 WeakDocumentSet& set = liveDocumentSet();
5743 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5786 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5744 for (Document* document : set) 5787 for (Document* document : set)
5745 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data()); 5788 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data());
5746 } 5789 }
5747 #endif 5790 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698