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

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

Issue 23455024: Move ownership of the TextResourceDecoder to DecodedDataDocumentParser (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 #include "core/html/parser/NestingLevelIncrementer.h" 124 #include "core/html/parser/NestingLevelIncrementer.h"
125 #include "core/inspector/InspectorCounters.h" 125 #include "core/inspector/InspectorCounters.h"
126 #include "core/inspector/InspectorInstrumentation.h" 126 #include "core/inspector/InspectorInstrumentation.h"
127 #include "core/inspector/ScriptCallStack.h" 127 #include "core/inspector/ScriptCallStack.h"
128 #include "core/loader/CookieJar.h" 128 #include "core/loader/CookieJar.h"
129 #include "core/loader/DocumentLoader.h" 129 #include "core/loader/DocumentLoader.h"
130 #include "core/loader/FrameLoader.h" 130 #include "core/loader/FrameLoader.h"
131 #include "core/loader/FrameLoaderClient.h" 131 #include "core/loader/FrameLoaderClient.h"
132 #include "core/loader/ImageLoader.h" 132 #include "core/loader/ImageLoader.h"
133 #include "core/loader/Prerenderer.h" 133 #include "core/loader/Prerenderer.h"
134 #include "core/loader/TextResourceDecoder.h"
135 #include "core/loader/appcache/ApplicationCacheHost.h" 134 #include "core/loader/appcache/ApplicationCacheHost.h"
136 #include "core/page/Chrome.h" 135 #include "core/page/Chrome.h"
137 #include "core/page/ChromeClient.h" 136 #include "core/page/ChromeClient.h"
138 #include "core/page/ContentSecurityPolicy.h" 137 #include "core/page/ContentSecurityPolicy.h"
139 #include "core/page/DOMSecurityPolicy.h" 138 #include "core/page/DOMSecurityPolicy.h"
140 #include "core/page/DOMWindow.h" 139 #include "core/page/DOMWindow.h"
141 #include "core/page/EventHandler.h" 140 #include "core/page/EventHandler.h"
142 #include "core/page/Frame.h" 141 #include "core/page/Frame.h"
143 #include "core/page/FrameTree.h" 142 #include "core/page/FrameTree.h"
144 #include "core/page/FrameView.h" 143 #include "core/page/FrameView.h"
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 // generally keep at least one reference to an Element which would in turn 529 // generally keep at least one reference to an Element which would in turn
531 // has a reference to the Document. If you hit this ASSERT, then that 530 // has a reference to the Document. If you hit this ASSERT, then that
532 // assumption is wrong. DocumentParser::detach() should ensure that even 531 // assumption is wrong. DocumentParser::detach() should ensure that even
533 // if the DocumentParser outlives the Document it won't cause badness. 532 // if the DocumentParser outlives the Document it won't cause badness.
534 ASSERT(!m_parser || m_parser->refCount() == 1); 533 ASSERT(!m_parser || m_parser->refCount() == 1);
535 detachParser(); 534 detachParser();
536 535
537 if (this == topDocument()) 536 if (this == topDocument())
538 clearAXObjectCache(); 537 clearAXObjectCache();
539 538
540 setDecoder(PassRefPtr<TextResourceDecoder>());
541
542 if (m_styleSheetList) 539 if (m_styleSheetList)
543 m_styleSheetList->detachFromDocument(); 540 m_styleSheetList->detachFromDocument();
544 541
545 if (m_import) { 542 if (m_import) {
546 m_import->wasDetachedFromDocument(); 543 m_import->wasDetachedFromDocument();
547 m_import = 0; 544 m_import = 0;
548 } 545 }
549 546
550 m_styleSheetCollections.clear(); 547 m_styleSheetCollections.clear();
551 548
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 1105
1109 m_readyState = readyState; 1106 m_readyState = readyState;
1110 dispatchEvent(Event::create(eventNames().readystatechangeEvent)); 1107 dispatchEvent(Event::create(eventNames().readystatechangeEvent));
1111 } 1108 }
1112 1109
1113 String Document::encodingName() const 1110 String Document::encodingName() const
1114 { 1111 {
1115 // TextEncoding::domName() returns a char*, no need to allocate a new 1112 // TextEncoding::domName() returns a char*, no need to allocate a new
1116 // String for it each time. 1113 // String for it each time.
1117 // FIXME: We should fix TextEncoding to speak AtomicString anyway. 1114 // FIXME: We should fix TextEncoding to speak AtomicString anyway.
1118 return AtomicString(m_encoding.domName()); 1115 return AtomicString(encoding().domName());
1119 } 1116 }
1120 1117
1121 String Document::defaultCharset() const 1118 String Document::defaultCharset() const
1122 { 1119 {
1123 if (Settings* settings = this->settings()) 1120 if (Settings* settings = this->settings())
1124 return settings->defaultTextEncodingName(); 1121 return settings->defaultTextEncodingName();
1125 return String(); 1122 return String();
1126 } 1123 }
1127 1124
1128 void Document::setCharset(const String& charset) 1125 void Document::setCharset(const String& charset)
1129 { 1126 {
1130 if (!decoder()) 1127 if (DocumentLoader* documentLoader = loader())
1128 documentLoader->setUserChosenEncoding(charset);
1129 WTF::TextEncoding encoding(charset);
1130 // In case the encoding didn't exist, we keep the old one (helps some sites specifying invalid encodings).
1131 if (!encoding.isValid())
1131 return; 1132 return;
1132 decoder()->setEncoding(charset, TextResourceDecoder::UserChosenEncoding); 1133 DocumentEncodingData data;
1133 setEncoding(m_decoder->encoding()); 1134 data.encoding = encoding;
1135 setEncoding(data);
abarth-chromium 2013/08/30 22:50:38 Won't this get spammed over the next time we get a
1134 } 1136 }
1135 1137
1136 void Document::setContentLanguage(const String& language) 1138 void Document::setContentLanguage(const String& language)
1137 { 1139 {
1138 if (m_contentLanguage == language) 1140 if (m_contentLanguage == language)
1139 return; 1141 return;
1140 m_contentLanguage = language; 1142 m_contentLanguage = language;
1141 1143
1142 // Document's style depends on the content language. 1144 // Document's style depends on the content language.
1143 setNeedsStyleRecalc(); 1145 setNeedsStyleRecalc();
(...skipping 2785 matching lines...) Expand 10 before | Expand all | Expand 10 after
3929 if (!length) { 3931 if (!length) {
3930 es.throwDOMException(InvalidCharacterError); 3932 es.throwDOMException(InvalidCharacterError);
3931 return false; 3933 return false;
3932 } 3934 }
3933 3935
3934 if (qualifiedName.is8Bit()) 3936 if (qualifiedName.is8Bit())
3935 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, es); 3937 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, es);
3936 return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16( ), length, prefix, localName, es); 3938 return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16( ), length, prefix, localName, es);
3937 } 3939 }
3938 3940
3939 void Document::setDecoder(PassRefPtr<TextResourceDecoder> decoder) 3941 Document::DocumentEncodingData::DocumentEncodingData()
3942 : wasDetectedHeuristically(false)
3943 , sawDecodingError(false)
3940 { 3944 {
3941 m_decoder = decoder;
3942 setEncoding(m_decoder ? m_decoder->encoding() : WTF::TextEncoding());
3943 } 3945 }
3944 3946
3945 void Document::setEncoding(const WTF::TextEncoding& encoding) 3947 void Document::setEncoding(DocumentEncodingData data)
3946 { 3948 {
3947 m_encoding = encoding; 3949 m_encodingData = data;
3948 } 3950 }
3949 3951
3950 KURL Document::completeURL(const String& url, const KURL& baseURLOverride) const 3952 KURL Document::completeURL(const String& url, const KURL& baseURLOverride) const
3951 { 3953 {
3952 // Always return a null URL when passed a null string. 3954 // Always return a null URL when passed a null string.
3953 // FIXME: Should we change the KURL constructor to have this behavior? 3955 // FIXME: Should we change the KURL constructor to have this behavior?
3954 // See also [CSS]StyleSheet::completeURL(const String&) 3956 // See also [CSS]StyleSheet::completeURL(const String&)
3955 if (url.isNull()) 3957 if (url.isNull())
3956 return KURL(); 3958 return KURL();
3957 const KURL& baseURL = ((baseURLOverride.isEmpty() || baseURLOverride == blan kURL()) && parentDocument()) ? parentDocument()->baseURL() : baseURLOverride; 3959 const KURL& baseURL = ((baseURLOverride.isEmpty() || baseURLOverride == blan kURL()) && parentDocument()) ? parentDocument()->baseURL() : baseURLOverride;
3958 if (!m_decoder) 3960 if (!encoding().isValid())
3959 return KURL(baseURL, url); 3961 return KURL(baseURL, url);
3960 return KURL(baseURL, url, m_decoder->encoding()); 3962 return KURL(baseURL, url, encoding());
3961 } 3963 }
3962 3964
3963 KURL Document::completeURL(const String& url) const 3965 KURL Document::completeURL(const String& url) const
3964 { 3966 {
3965 return completeURL(url, m_baseURL); 3967 return completeURL(url, m_baseURL);
3966 } 3968 }
3967 3969
3968 void Document::documentWillBecomeInactive() 3970 void Document::documentWillBecomeInactive()
3969 { 3971 {
3970 if (renderer()) 3972 if (renderer())
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
4670 } 4672 }
4671 4673
4672 void Document::resumeScriptedAnimationControllerCallbacks() 4674 void Document::resumeScriptedAnimationControllerCallbacks()
4673 { 4675 {
4674 if (m_scriptedAnimationController) 4676 if (m_scriptedAnimationController)
4675 m_scriptedAnimationController->resume(); 4677 m_scriptedAnimationController->resume();
4676 } 4678 }
4677 4679
4678 String Document::displayStringModifiedByEncoding(const String& str) const 4680 String Document::displayStringModifiedByEncoding(const String& str) const
4679 { 4681 {
4680 if (m_decoder) 4682 if (encoding().isValid())
4681 return m_decoder->encoding().displayString(str.impl()); 4683 return encoding().displayString(str.impl());
4682 return str; 4684 return str;
4683 } 4685 }
4684 4686
4685 PassRefPtr<StringImpl> Document::displayStringModifiedByEncoding(PassRefPtr<Stri ngImpl> str) const 4687 PassRefPtr<StringImpl> Document::displayStringModifiedByEncoding(PassRefPtr<Stri ngImpl> str) const
4686 { 4688 {
4687 if (m_decoder) 4689 if (encoding().isValid())
4688 return m_decoder->encoding().displayString(str); 4690 return encoding().displayString(str);
4689 return str; 4691 return str;
4690 } 4692 }
4691 4693
4692 template <typename CharacterType> 4694 template <typename CharacterType>
4693 void Document::displayBufferModifiedByEncodingInternal(CharacterType* buffer, un signed len) const 4695 void Document::displayBufferModifiedByEncodingInternal(CharacterType* buffer, un signed len) const
4694 { 4696 {
4695 if (m_decoder) 4697 if (encoding().isValid())
4696 m_decoder->encoding().displayBuffer(buffer, len); 4698 encoding().displayBuffer(buffer, len);
4697 } 4699 }
4698 4700
4699 // Generate definitions for both character types 4701 // Generate definitions for both character types
4700 template void Document::displayBufferModifiedByEncodingInternal<LChar>(LChar*, u nsigned) const; 4702 template void Document::displayBufferModifiedByEncodingInternal<LChar>(LChar*, u nsigned) const;
4701 template void Document::displayBufferModifiedByEncodingInternal<UChar>(UChar*, u nsigned) const; 4703 template void Document::displayBufferModifiedByEncodingInternal<UChar>(UChar*, u nsigned) const;
4702 4704
4703 void Document::enqueuePageshowEvent(PageshowEventPersistence persisted) 4705 void Document::enqueuePageshowEvent(PageshowEventPersistence persisted)
4704 { 4706 {
4705 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=36334 Pageshow event needs to fire asynchronously. 4707 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=36334 Pageshow event needs to fire asynchronously.
4706 dispatchWindowEvent(PageTransitionEvent::create(eventNames().pageshowEvent, persisted), this); 4708 dispatchWindowEvent(PageTransitionEvent::create(eventNames().pageshowEvent, persisted), this);
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
5254 { 5256 {
5255 return DocumentLifecycleNotifier::create(this); 5257 return DocumentLifecycleNotifier::create(this);
5256 } 5258 }
5257 5259
5258 DocumentLifecycleNotifier* Document::lifecycleNotifier() 5260 DocumentLifecycleNotifier* Document::lifecycleNotifier()
5259 { 5261 {
5260 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier()); 5262 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier());
5261 } 5263 }
5262 5264
5263 } // namespace WebCore 5265 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698