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

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: Moved the order of open and close function Created 5 years, 5 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 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after
2275 if (!isHTMLDocument()) 2275 if (!isHTMLDocument())
2276 return false; 2276 return false;
2277 return isHTMLFrameSetElement(body()); 2277 return isHTMLFrameSetElement(body());
2278 } 2278 }
2279 2279
2280 ScriptableDocumentParser* Document::scriptableDocumentParser() const 2280 ScriptableDocumentParser* Document::scriptableDocumentParser() const
2281 { 2281 {
2282 return parser() ? parser()->asScriptableDocumentParser() : 0; 2282 return parser() ? parser()->asScriptableDocumentParser() : 0;
2283 } 2283 }
2284 2284
2285 void Document::open(Document* ownerDocument, ExceptionState& exceptionState) 2285 void Document::open()
2286 { 2286 {
2287 if (importLoader()) { 2287 ASSERT(!importLoader());
2288 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support open().");
2289 return;
2290 }
2291
2292 if (ownerDocument) {
2293 setURL(ownerDocument->url());
2294 m_cookieURL = ownerDocument->cookieURL();
2295 setSecurityOrigin(ownerDocument->securityOrigin());
2296 }
2297 2288
2298 if (m_frame) { 2289 if (m_frame) {
2299 if (ScriptableDocumentParser* parser = scriptableDocumentParser()) { 2290 if (ScriptableDocumentParser* parser = scriptableDocumentParser()) {
2300 if (parser->isParsing()) { 2291 if (parser->isParsing()) {
2301 // FIXME: HTML5 doesn't tell us to check this, it might not be c orrect. 2292 // FIXME: HTML5 doesn't tell us to check this, it might not be c orrect.
2302 if (parser->isExecutingScript()) 2293 if (parser->isExecutingScript())
2303 return; 2294 return;
2304 2295
2305 if (!parser->wasCreatedByScript() && parser->hasInsertionPoint() ) 2296 if (!parser->wasCreatedByScript() && parser->hasInsertionPoint() )
2306 return; 2297 return;
2307 } 2298 }
2308 } 2299 }
2309 2300
2310 if (m_frame->loader().provisionalDocumentLoader()) 2301 if (m_frame->loader().provisionalDocumentLoader())
2311 m_frame->loader().stopAllLoaders(); 2302 m_frame->loader().stopAllLoaders();
2312 } 2303 }
2313 2304
2314 removeAllEventListenersRecursively(); 2305 removeAllEventListenersRecursively();
2315 implicitOpen(ForceSynchronousParsing); 2306 implicitOpen(ForceSynchronousParsing);
2316 if (ScriptableDocumentParser* parser = scriptableDocumentParser()) 2307 if (ScriptableDocumentParser* parser = scriptableDocumentParser())
2317 parser->setWasCreatedByScript(true); 2308 parser->setWasCreatedByScript(true);
2318 2309
2319 if (m_frame) 2310 if (m_frame)
2320 m_frame->loader().didExplicitOpen(); 2311 m_frame->loader().didExplicitOpen();
2321 if (m_loadEventProgress != LoadEventInProgress && m_loadEventProgress != Unl oadEventInProgress) 2312 if (m_loadEventProgress != LoadEventInProgress && m_loadEventProgress != Unl oadEventInProgress)
2322 m_loadEventProgress = LoadEventNotRun; 2313 m_loadEventProgress = LoadEventNotRun;
2323 } 2314 }
2324 2315
2316 void Document::close()
2317 {
2318 if (!scriptableDocumentParser() || !scriptableDocumentParser()->wasCreatedBy Script() || !scriptableDocumentParser()->isParsing())
2319 return;
2320
2321 explicitClose();
2322 }
2323
2324 void Document::open(Document* ownerDocument, ExceptionState& exceptionState)
2325 {
2326 if (importLoader()) {
2327 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support open().");
2328 return;
2329 }
2330
2331 if (!isHTMLDocument()) {
2332 exceptionState.throwDOMException(InvalidStateError, "Only HTML documents support open().");
2333 return;
2334 }
2335
2336 if (ownerDocument) {
2337 setURL(ownerDocument->url());
2338 m_cookieURL = ownerDocument->cookieURL();
2339 setSecurityOrigin(ownerDocument->securityOrigin());
2340 }
2341
2342 open();
2343 }
2344
2325 void Document::detachParser() 2345 void Document::detachParser()
2326 { 2346 {
2327 if (!m_parser) 2347 if (!m_parser)
2328 return; 2348 return;
2329 m_parser->detach(); 2349 m_parser->detach();
2330 m_parser.clear(); 2350 m_parser.clear();
2331 } 2351 }
2332 2352
2333 void Document::cancelParsing() 2353 void Document::cancelParsing()
2334 { 2354 {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2448 void Document::close(ExceptionState& exceptionState) 2468 void Document::close(ExceptionState& exceptionState)
2449 { 2469 {
2450 // FIXME: We should follow the specification more closely: 2470 // FIXME: We should follow the specification more closely:
2451 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-cl ose 2471 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-cl ose
2452 2472
2453 if (importLoader()) { 2473 if (importLoader()) {
2454 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support close()."); 2474 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support close().");
2455 return; 2475 return;
2456 } 2476 }
2457 2477
2458 if (!scriptableDocumentParser() || !scriptableDocumentParser()->wasCreatedBy Script() || !scriptableDocumentParser()->isParsing()) 2478 if (!isHTMLDocument()) {
2479 exceptionState.throwDOMException(InvalidStateError, "Only HTML documents support close().");
2459 return; 2480 return;
2481 }
2460 2482
2461 explicitClose(); 2483 close();
2462 } 2484 }
2463 2485
2464 void Document::explicitClose() 2486 void Document::explicitClose()
2465 { 2487 {
2466 if (RefPtrWillBeRawPtr<DocumentParser> parser = m_parser) 2488 if (RefPtrWillBeRawPtr<DocumentParser> parser = m_parser)
2467 parser->finish(); 2489 parser->finish();
2468 2490
2469 if (!m_frame) { 2491 if (!m_frame) {
2470 // Because we have no frame, we don't know if all loading has completed, 2492 // Because we have no frame, we don't know if all loading has completed,
2471 // so we just call implicitClose() immediately. FIXME: This might fire 2493 // so we just call implicitClose() immediately. FIXME: This might fire
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
2694 return static_cast<int>((currentTime() - m_startTime) * 1000); 2716 return static_cast<int>((currentTime() - m_startTime) * 1000);
2695 } 2717 }
2696 2718
2697 void Document::write(const SegmentedString& text, Document* ownerDocument, Excep tionState& exceptionState) 2719 void Document::write(const SegmentedString& text, Document* ownerDocument, Excep tionState& exceptionState)
2698 { 2720 {
2699 if (importLoader()) { 2721 if (importLoader()) {
2700 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support write()."); 2722 exceptionState.throwDOMException(InvalidStateError, "Imported document d oesn't support write().");
2701 return; 2723 return;
2702 } 2724 }
2703 2725
2726 if (!isHTMLDocument()) {
2727 exceptionState.throwDOMException(InvalidStateError, "XML document doesn' t support write().");
philipj_slow 2015/06/29 15:02:38 I think this message should match those for open()
Habib Virji 2015/06/29 15:25:20 Added in the description and correct the message..
2728 return;
2729 }
2730
2704 NestingLevelIncrementer nestingLevelIncrementer(m_writeRecursionDepth); 2731 NestingLevelIncrementer nestingLevelIncrementer(m_writeRecursionDepth);
2705 2732
2706 m_writeRecursionIsTooDeep = (m_writeRecursionDepth > 1) && m_writeRecursionI sTooDeep; 2733 m_writeRecursionIsTooDeep = (m_writeRecursionDepth > 1) && m_writeRecursionI sTooDeep;
2707 m_writeRecursionIsTooDeep = (m_writeRecursionDepth > cMaxWriteRecursionDepth ) || m_writeRecursionIsTooDeep; 2734 m_writeRecursionIsTooDeep = (m_writeRecursionDepth > cMaxWriteRecursionDepth ) || m_writeRecursionIsTooDeep;
2708 2735
2709 if (m_writeRecursionIsTooDeep) 2736 if (m_writeRecursionIsTooDeep)
2710 return; 2737 return;
2711 2738
2712 bool hasInsertionPoint = m_parser && m_parser->hasInsertionPoint(); 2739 bool hasInsertionPoint = m_parser && m_parser->hasInsertionPoint();
2713 2740
2714 if (!hasInsertionPoint && m_ignoreDestructiveWriteCount) { 2741 if (!hasInsertionPoint && m_ignoreDestructiveWriteCount) {
2715 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."))); 2742 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.")));
2716 return; 2743 return;
2717 } 2744 }
2718 2745
2719 if (!hasInsertionPoint) 2746 if (!hasInsertionPoint)
2720 open(ownerDocument); 2747 open(ownerDocument, ASSERT_NO_EXCEPTION);
2721 2748
2722 ASSERT(m_parser); 2749 ASSERT(m_parser);
2723 m_parser->insert(text); 2750 m_parser->insert(text);
2724 } 2751 }
2725 2752
2726 void Document::write(const String& text, Document* ownerDocument, ExceptionState & exceptionState) 2753 void Document::write(const String& text, Document* ownerDocument, ExceptionState & exceptionState)
2727 { 2754 {
2728 write(SegmentedString(text), ownerDocument, exceptionState); 2755 write(SegmentedString(text), ownerDocument, exceptionState);
2729 } 2756 }
2730 2757
2731 void Document::writeln(const String& text, Document* ownerDocument, ExceptionSta te& exceptionState) 2758 void Document::writeln(const String& text, Document* ownerDocument, ExceptionSta te& exceptionState)
2732 { 2759 {
2733 write(text, ownerDocument, exceptionState); 2760 write(text, ownerDocument, exceptionState);
2734 if (exceptionState.hadException()) 2761 if (exceptionState.hadException())
2735 return; 2762 return;
2736 write("\n", ownerDocument); 2763 write("\n", ownerDocument);
2737 } 2764 }
2738 2765
2766 void Document::write(LocalDOMWindow* callingWindow, const Vector<String>& text, ExceptionState& exceptionState)
2767 {
2768 ASSERT(callingWindow);
2769 StringBuilder builder;
2770 for (const String& string : text)
2771 builder.append(string);
2772 write(builder.toString(), callingWindow->document(), exceptionState);
2773 }
2774
2775 void Document::writeln(LocalDOMWindow* callingWindow, const Vector<String>& text , ExceptionState& exceptionState)
2776 {
2777 ASSERT(callingWindow);
2778 StringBuilder builder;
2779 for (const String& string : text)
2780 builder.append(string);
2781 writeln(builder.toString(), callingWindow->document(), exceptionState);
2782 }
2783
2739 const KURL& Document::virtualURL() const 2784 const KURL& Document::virtualURL() const
2740 { 2785 {
2741 return m_url; 2786 return m_url;
2742 } 2787 }
2743 2788
2744 KURL Document::virtualCompleteURL(const String& url) const 2789 KURL Document::virtualCompleteURL(const String& url) const
2745 { 2790 {
2746 return completeURL(url); 2791 return completeURL(url);
2747 } 2792 }
2748 2793
(...skipping 2990 matching lines...) Expand 10 before | Expand all | Expand 10 after
5739 #ifndef NDEBUG 5784 #ifndef NDEBUG
5740 using namespace blink; 5785 using namespace blink;
5741 void showLiveDocumentInstances() 5786 void showLiveDocumentInstances()
5742 { 5787 {
5743 WeakDocumentSet& set = liveDocumentSet(); 5788 WeakDocumentSet& set = liveDocumentSet();
5744 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5789 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5745 for (Document* document : set) 5790 for (Document* document : set)
5746 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data()); 5791 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data());
5747 } 5792 }
5748 #endif 5793 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698