OLD | NEW |
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 Loading... |
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::open(Document* ownerDocument, ExceptionState& exceptionState) |
| 2317 { |
| 2318 if (importLoader()) { |
| 2319 exceptionState.throwDOMException(InvalidStateError, "Imported document d
oesn't support open()."); |
| 2320 return; |
| 2321 } |
| 2322 |
| 2323 if (!isHTMLDocument()) { |
| 2324 exceptionState.throwDOMException(InvalidStateError, "Only HTML documents
support open()."); |
| 2325 return; |
| 2326 } |
| 2327 |
| 2328 if (ownerDocument) { |
| 2329 setURL(ownerDocument->url()); |
| 2330 m_cookieURL = ownerDocument->cookieURL(); |
| 2331 setSecurityOrigin(ownerDocument->securityOrigin()); |
| 2332 } |
| 2333 |
| 2334 open(); |
| 2335 } |
| 2336 |
2325 void Document::detachParser() | 2337 void Document::detachParser() |
2326 { | 2338 { |
2327 if (!m_parser) | 2339 if (!m_parser) |
2328 return; | 2340 return; |
2329 m_parser->detach(); | 2341 m_parser->detach(); |
2330 m_parser.clear(); | 2342 m_parser.clear(); |
2331 } | 2343 } |
2332 | 2344 |
2333 void Document::cancelParsing() | 2345 void Document::cancelParsing() |
2334 { | 2346 { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2438 if (!rootStyle) { | 2450 if (!rootStyle) { |
2439 rootStyle = rootElement->computedStyle(); | 2451 rootStyle = rootElement->computedStyle(); |
2440 if (!rootStyle) | 2452 if (!rootStyle) |
2441 return 0; | 2453 return 0; |
2442 } | 2454 } |
2443 if (bodyElement && rootStyle->isOverflowVisible() && isHTMLHtmlElement(*root
Element)) | 2455 if (bodyElement && rootStyle->isOverflowVisible() && isHTMLHtmlElement(*root
Element)) |
2444 return bodyElement; | 2456 return bodyElement; |
2445 return rootElement; | 2457 return rootElement; |
2446 } | 2458 } |
2447 | 2459 |
| 2460 void Document::close() |
| 2461 { |
| 2462 if (!scriptableDocumentParser() || !scriptableDocumentParser()->wasCreatedBy
Script() || !scriptableDocumentParser()->isParsing()) |
| 2463 return; |
| 2464 |
| 2465 explicitClose(); |
| 2466 } |
| 2467 |
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 Loading... |
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 (isXMLDocument()) { |
| 2727 exceptionState.throwDOMException(InvalidStateError, "XML document doesn'
t support write()."); |
| 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 |
(...skipping 15 matching lines...) Expand all Loading... |
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 Loading... |
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 |
OLD | NEW |