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

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

Issue 69823002: Move ownership of the TextResourceDecoder to DecodedDataDocumentParser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review fixes Created 7 years, 1 month 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
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/DocumentEncodingData.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 // generally keep at least one reference to an Element which would in turn 512 // generally keep at least one reference to an Element which would in turn
513 // has a reference to the Document. If you hit this ASSERT, then that 513 // has a reference to the Document. If you hit this ASSERT, then that
514 // assumption is wrong. DocumentParser::detach() should ensure that even 514 // assumption is wrong. DocumentParser::detach() should ensure that even
515 // if the DocumentParser outlives the Document it won't cause badness. 515 // if the DocumentParser outlives the Document it won't cause badness.
516 ASSERT(!m_parser || m_parser->refCount() == 1); 516 ASSERT(!m_parser || m_parser->refCount() == 1);
517 detachParser(); 517 detachParser();
518 518
519 if (this == topDocument()) 519 if (this == topDocument())
520 clearAXObjectCache(); 520 clearAXObjectCache();
521 521
522 setDecoder(PassRefPtr<TextResourceDecoder>());
523
524 if (m_styleSheetList) 522 if (m_styleSheetList)
525 m_styleSheetList->detachFromDocument(); 523 m_styleSheetList->detachFromDocument();
526 524
527 if (m_import) { 525 if (m_import) {
528 m_import->wasDetachedFromDocument(); 526 m_import->wasDetachedFromDocument();
529 m_import = 0; 527 m_import = 0;
530 } 528 }
531 529
532 m_styleEngine.clear(); 530 m_styleEngine.clear();
533 531
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 bool Document::isLoadCompleted() 1088 bool Document::isLoadCompleted()
1091 { 1089 {
1092 return m_readyState == Complete; 1090 return m_readyState == Complete;
1093 } 1091 }
1094 1092
1095 String Document::encodingName() const 1093 String Document::encodingName() const
1096 { 1094 {
1097 // TextEncoding::name() returns a char*, no need to allocate a new 1095 // TextEncoding::name() returns a char*, no need to allocate a new
1098 // String for it each time. 1096 // String for it each time.
1099 // FIXME: We should fix TextEncoding to speak AtomicString anyway. 1097 // FIXME: We should fix TextEncoding to speak AtomicString anyway.
1100 return AtomicString(m_encoding.name()); 1098 return AtomicString(encoding().name());
1101 } 1099 }
1102 1100
1103 String Document::defaultCharset() const 1101 String Document::defaultCharset() const
1104 { 1102 {
1105 if (Settings* settings = this->settings()) 1103 if (Settings* settings = this->settings())
1106 return settings->defaultTextEncodingName(); 1104 return settings->defaultTextEncodingName();
1107 return String(); 1105 return String();
1108 } 1106 }
1109 1107
1110 void Document::setCharset(const String& charset) 1108 void Document::setCharset(const String& charset)
1111 { 1109 {
1112 if (!decoder()) 1110 if (DocumentLoader* documentLoader = loader())
1111 documentLoader->setUserChosenEncoding(charset);
1112 WTF::TextEncoding encoding(charset);
1113 // In case the encoding didn't exist, we keep the old one (helps some sites specifying invalid encodings).
1114 if (!encoding.isValid())
1113 return; 1115 return;
1114 decoder()->setEncoding(charset, TextResourceDecoder::UserChosenEncoding); 1116 DocumentEncodingData newEncodingData = m_encodingData;
1115 setEncoding(m_decoder->encoding()); 1117 newEncodingData.encoding = encoding;
1118 setEncodingData(newEncodingData);
1116 } 1119 }
1117 1120
1118 void Document::setContentLanguage(const String& language) 1121 void Document::setContentLanguage(const String& language)
1119 { 1122 {
1120 if (m_contentLanguage == language) 1123 if (m_contentLanguage == language)
1121 return; 1124 return;
1122 m_contentLanguage = language; 1125 m_contentLanguage = language;
1123 1126
1124 // Document's style depends on the content language. 1127 // Document's style depends on the content language.
1125 setNeedsStyleRecalc(); 1128 setNeedsStyleRecalc();
(...skipping 2024 matching lines...) Expand 10 before | Expand all | Expand 10 after
3150 { 3153 {
3151 DocumentInit init(url()); 3154 DocumentInit init(url());
3152 if (isXHTMLDocument()) 3155 if (isXHTMLDocument())
3153 return createXHTML(init.withRegistrationContext(registrationContext())); 3156 return createXHTML(init.withRegistrationContext(registrationContext()));
3154 return create(init); 3157 return create(init);
3155 } 3158 }
3156 3159
3157 void Document::cloneDataFromDocument(const Document& other) 3160 void Document::cloneDataFromDocument(const Document& other)
3158 { 3161 {
3159 setCompatibilityMode(other.compatibilityMode()); 3162 setCompatibilityMode(other.compatibilityMode());
3160 setEncoding(other.encoding()); 3163 setEncodingData(other.m_encodingData);
3161 setContextFeatures(other.contextFeatures()); 3164 setContextFeatures(other.contextFeatures());
3162 setSecurityOrigin(other.securityOrigin()->isolatedCopy()); 3165 setSecurityOrigin(other.securityOrigin()->isolatedCopy());
3163 } 3166 }
3164 3167
3165 StyleSheetList* Document::styleSheets() 3168 StyleSheetList* Document::styleSheets()
3166 { 3169 {
3167 if (!m_styleSheetList) 3170 if (!m_styleSheetList)
3168 m_styleSheetList = StyleSheetList::create(this); 3171 m_styleSheetList = StyleSheetList::create(this);
3169 return m_styleSheetList.get(); 3172 return m_styleSheetList.get();
3170 } 3173 }
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
3974 if (!length) { 3977 if (!length) {
3975 es.throwUninformativeAndGenericDOMException(InvalidCharacterError); 3978 es.throwUninformativeAndGenericDOMException(InvalidCharacterError);
3976 return false; 3979 return false;
3977 } 3980 }
3978 3981
3979 if (qualifiedName.is8Bit()) 3982 if (qualifiedName.is8Bit())
3980 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, es); 3983 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, es);
3981 return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16( ), length, prefix, localName, es); 3984 return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16( ), length, prefix, localName, es);
3982 } 3985 }
3983 3986
3984 void Document::setDecoder(PassRefPtr<TextResourceDecoder> decoder) 3987 void Document::setEncodingData(const DocumentEncodingData& newData)
3985 { 3988 {
3986 m_decoder = decoder;
3987 setEncoding(m_decoder ? m_decoder->encoding() : WTF::TextEncoding());
3988 }
3989
3990 void Document::setEncoding(const WTF::TextEncoding& encoding)
3991 {
3992 if (m_encoding == encoding)
3993 return;
3994
3995 // It's possible for the encoding of the document to change while we're deco ding 3989 // It's possible for the encoding of the document to change while we're deco ding
3996 // data. That can only occur while we're processing the <head> portion of th e 3990 // data. That can only occur while we're processing the <head> portion of th e
3997 // document. There isn't much user-visible content in the <head>, but there is 3991 // document. There isn't much user-visible content in the <head>, but there is
3998 // the <title> element. This function detects that situation and re-decodes the 3992 // the <title> element. This function detects that situation and re-decodes the
3999 // document's title so that the user doesn't see an incorrectly decoded titl e 3993 // document's title so that the user doesn't see an incorrectly decoded titl e
4000 // in the title bar. 3994 // in the title bar.
4001 if (m_titleElement 3995 if (m_titleElement
3996 && encoding() != newData.encoding
4002 && !m_titleElement->firstElementChild() 3997 && !m_titleElement->firstElementChild()
4003 && m_encoding == Latin1Encoding() 3998 && encoding() == Latin1Encoding()
4004 && m_titleElement->textContent().containsOnlyLatin1()) { 3999 && m_titleElement->textContent().containsOnlyLatin1()) {
4005 4000
4006 CString originalBytes = m_titleElement->textContent().latin1(); 4001 CString originalBytes = m_titleElement->textContent().latin1();
4007 OwnPtr<TextCodec> codec = newTextCodec(encoding); 4002 OwnPtr<TextCodec> codec = newTextCodec(newData.encoding);
4008 String correctlyDecodedTitle = codec->decode(originalBytes.data(), origi nalBytes.length(), true); 4003 String correctlyDecodedTitle = codec->decode(originalBytes.data(), origi nalBytes.length(), true);
4009 m_titleElement->setTextContent(correctlyDecodedTitle, IGNORE_EXCEPTION); 4004 m_titleElement->setTextContent(correctlyDecodedTitle, IGNORE_EXCEPTION);
4010 } 4005 }
4011 4006
4012 m_encoding = encoding; 4007 m_encodingData = newData;
4013 } 4008 }
4014 4009
4015 KURL Document::completeURL(const String& url, const KURL& baseURLOverride) const 4010 KURL Document::completeURL(const String& url, const KURL& baseURLOverride) const
4016 { 4011 {
4017 // Always return a null URL when passed a null string. 4012 // Always return a null URL when passed a null string.
4018 // FIXME: Should we change the KURL constructor to have this behavior? 4013 // FIXME: Should we change the KURL constructor to have this behavior?
4019 // See also [CSS]StyleSheet::completeURL(const String&) 4014 // See also [CSS]StyleSheet::completeURL(const String&)
4020 if (url.isNull()) 4015 if (url.isNull())
4021 return KURL(); 4016 return KURL();
4022 const KURL& baseURL = ((baseURLOverride.isEmpty() || baseURLOverride == blan kURL()) && parentDocument()) ? parentDocument()->baseURL() : baseURLOverride; 4017 const KURL& baseURL = ((baseURLOverride.isEmpty() || baseURLOverride == blan kURL()) && parentDocument()) ? parentDocument()->baseURL() : baseURLOverride;
4023 if (!m_decoder) 4018 if (!encoding().isValid())
4024 return KURL(baseURL, url); 4019 return KURL(baseURL, url);
4025 return KURL(baseURL, url, m_decoder->encoding()); 4020 return KURL(baseURL, url, encoding());
4026 } 4021 }
4027 4022
4028 KURL Document::completeURL(const String& url) const 4023 KURL Document::completeURL(const String& url) const
4029 { 4024 {
4030 return completeURL(url, m_baseURL); 4025 return completeURL(url, m_baseURL);
4031 } 4026 }
4032 4027
4033 // Support for Javascript execCommand, and related methods 4028 // Support for Javascript execCommand, and related methods
4034 4029
4035 static Editor::Command command(Document* document, const String& commandName, bo ol userInterface = false) 4030 static Editor::Command command(Document* document, const String& commandName, bo ol userInterface = false)
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after
5215 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode) 5210 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode)
5216 { 5211 {
5217 if (!isActive()) 5212 if (!isActive())
5218 return; 5213 return;
5219 5214
5220 styleEngine()->modifiedStyleSheet(sheet); 5215 styleEngine()->modifiedStyleSheet(sheet);
5221 styleResolverChanged(when, updateMode); 5216 styleResolverChanged(when, updateMode);
5222 } 5217 }
5223 5218
5224 } // namespace WebCore 5219 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/DocumentEncodingData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698