| 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 2271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(Document* ownerDocument, ExceptionState& exceptionState) |
| 2286 { | 2286 { |
| 2287 if (importLoader()) { | 2287 if (importLoader()) { |
| 2288 exceptionState.throwDOMException(InvalidStateError, "Imported document d
oesn't support open()."); | 2288 exceptionState.throwDOMException(InvalidStateError, "Imported document d
oesn't support open()."); |
| 2289 return; | 2289 return; |
| 2290 } | 2290 } |
| 2291 | 2291 |
| 2292 if (!isHTMLDocument()) { |
| 2293 exceptionState.throwDOMException(InvalidStateError, "Only HTML documents
support open()."); |
| 2294 return; |
| 2295 } |
| 2296 |
| 2292 if (ownerDocument) { | 2297 if (ownerDocument) { |
| 2293 setURL(ownerDocument->url()); | 2298 setURL(ownerDocument->url()); |
| 2294 m_cookieURL = ownerDocument->cookieURL(); | 2299 m_cookieURL = ownerDocument->cookieURL(); |
| 2295 setSecurityOrigin(ownerDocument->securityOrigin()); | 2300 setSecurityOrigin(ownerDocument->securityOrigin()); |
| 2296 } | 2301 } |
| 2297 | 2302 |
| 2303 open(); |
| 2304 } |
| 2305 |
| 2306 void Document::open() |
| 2307 { |
| 2308 ASSERT(!importLoader()); |
| 2309 |
| 2298 if (m_frame) { | 2310 if (m_frame) { |
| 2299 if (ScriptableDocumentParser* parser = scriptableDocumentParser()) { | 2311 if (ScriptableDocumentParser* parser = scriptableDocumentParser()) { |
| 2300 if (parser->isParsing()) { | 2312 if (parser->isParsing()) { |
| 2301 // FIXME: HTML5 doesn't tell us to check this, it might not be c
orrect. | 2313 // FIXME: HTML5 doesn't tell us to check this, it might not be c
orrect. |
| 2302 if (parser->isExecutingScript()) | 2314 if (parser->isExecutingScript()) |
| 2303 return; | 2315 return; |
| 2304 | 2316 |
| 2305 if (!parser->wasCreatedByScript() && parser->hasInsertionPoint()
) | 2317 if (!parser->wasCreatedByScript() && parser->hasInsertionPoint()
) |
| 2306 return; | 2318 return; |
| 2307 } | 2319 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2448 void Document::close(ExceptionState& exceptionState) | 2460 void Document::close(ExceptionState& exceptionState) |
| 2449 { | 2461 { |
| 2450 // FIXME: We should follow the specification more closely: | 2462 // FIXME: We should follow the specification more closely: |
| 2451 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-cl
ose | 2463 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-cl
ose |
| 2452 | 2464 |
| 2453 if (importLoader()) { | 2465 if (importLoader()) { |
| 2454 exceptionState.throwDOMException(InvalidStateError, "Imported document d
oesn't support close()."); | 2466 exceptionState.throwDOMException(InvalidStateError, "Imported document d
oesn't support close()."); |
| 2455 return; | 2467 return; |
| 2456 } | 2468 } |
| 2457 | 2469 |
| 2470 if (!isHTMLDocument()) { |
| 2471 exceptionState.throwDOMException(InvalidStateError, "Only HTML documents
support close()."); |
| 2472 return; |
| 2473 } |
| 2474 |
| 2475 close(); |
| 2476 } |
| 2477 |
| 2478 void Document::close() |
| 2479 { |
| 2458 if (!scriptableDocumentParser() || !scriptableDocumentParser()->wasCreatedBy
Script() || !scriptableDocumentParser()->isParsing()) | 2480 if (!scriptableDocumentParser() || !scriptableDocumentParser()->wasCreatedBy
Script() || !scriptableDocumentParser()->isParsing()) |
| 2459 return; | 2481 return; |
| 2460 | 2482 |
| 2461 explicitClose(); | 2483 explicitClose(); |
| 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(); |
| (...skipping 226 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 (!isHTMLDocument()) { |
| 2727 exceptionState.throwDOMException(InvalidStateError, "Only HTML documents
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 |
| 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 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 |