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

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: Moved DocumentEncodingData to its own header 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
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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 // generally keep at least one reference to an Element which would in turn 511 // generally keep at least one reference to an Element which would in turn
512 // has a reference to the Document. If you hit this ASSERT, then that 512 // has a reference to the Document. If you hit this ASSERT, then that
513 // assumption is wrong. DocumentParser::detach() should ensure that even 513 // assumption is wrong. DocumentParser::detach() should ensure that even
514 // if the DocumentParser outlives the Document it won't cause badness. 514 // if the DocumentParser outlives the Document it won't cause badness.
515 ASSERT(!m_parser || m_parser->refCount() == 1); 515 ASSERT(!m_parser || m_parser->refCount() == 1);
516 detachParser(); 516 detachParser();
517 517
518 if (this == topDocument()) 518 if (this == topDocument())
519 clearAXObjectCache(); 519 clearAXObjectCache();
520 520
521 setDecoder(PassRefPtr<TextResourceDecoder>());
522
523 if (m_styleSheetList) 521 if (m_styleSheetList)
524 m_styleSheetList->detachFromDocument(); 522 m_styleSheetList->detachFromDocument();
525 523
526 if (m_import) { 524 if (m_import) {
527 m_import->wasDetachedFromDocument(); 525 m_import->wasDetachedFromDocument();
528 m_import = 0; 526 m_import = 0;
529 } 527 }
530 528
531 m_styleEngine.clear(); 529 m_styleEngine.clear();
532 530
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 bool Document::isLoadCompleted() 1091 bool Document::isLoadCompleted()
1094 { 1092 {
1095 return m_readyState == Complete; 1093 return m_readyState == Complete;
1096 } 1094 }
1097 1095
1098 String Document::encodingName() const 1096 String Document::encodingName() const
1099 { 1097 {
1100 // TextEncoding::name() returns a char*, no need to allocate a new 1098 // TextEncoding::name() returns a char*, no need to allocate a new
1101 // String for it each time. 1099 // String for it each time.
1102 // FIXME: We should fix TextEncoding to speak AtomicString anyway. 1100 // FIXME: We should fix TextEncoding to speak AtomicString anyway.
1103 return AtomicString(m_encoding.name()); 1101 return AtomicString(encoding().name());
1104 } 1102 }
1105 1103
1106 String Document::defaultCharset() const 1104 String Document::defaultCharset() const
1107 { 1105 {
1108 if (Settings* settings = this->settings()) 1106 if (Settings* settings = this->settings())
1109 return settings->defaultTextEncodingName(); 1107 return settings->defaultTextEncodingName();
1110 return String(); 1108 return String();
1111 } 1109 }
1112 1110
1113 void Document::setCharset(const String& charset) 1111 void Document::setCharset(const String& charset)
1114 { 1112 {
1115 if (!decoder()) 1113 if (DocumentLoader* documentLoader = loader())
1114 documentLoader->setUserChosenEncoding(charset);
1115 WTF::TextEncoding encoding(charset);
1116 // In case the encoding didn't exist, we keep the old one (helps some sites specifying invalid encodings).
1117 if (!encoding.isValid())
1116 return; 1118 return;
1117 decoder()->setEncoding(charset, TextResourceDecoder::UserChosenEncoding); 1119 DocumentEncodingData data;
1118 setEncoding(m_decoder->encoding()); 1120 data.encoding = encoding;
1121 setEncodingData(data);
abarth-chromium 2013/11/14 07:04:33 It's ok to clobber all the data? We don't want to
oystein (OOO til 10th of July) 2013/11/14 19:02:29 Unsure, maybe jamesr@ knows. I've modified this to
1119 } 1122 }
1120 1123
1121 void Document::setContentLanguage(const String& language) 1124 void Document::setContentLanguage(const String& language)
1122 { 1125 {
1123 if (m_contentLanguage == language) 1126 if (m_contentLanguage == language)
1124 return; 1127 return;
1125 m_contentLanguage = language; 1128 m_contentLanguage = language;
1126 1129
1127 // Document's style depends on the content language. 1130 // Document's style depends on the content language.
1128 setNeedsStyleRecalc(); 1131 setNeedsStyleRecalc();
(...skipping 1972 matching lines...) Expand 10 before | Expand all | Expand 10 after
3101 { 3104 {
3102 DocumentInit init(url()); 3105 DocumentInit init(url());
3103 if (isXHTMLDocument()) 3106 if (isXHTMLDocument())
3104 return createXHTML(init.withRegistrationContext(registrationContext())); 3107 return createXHTML(init.withRegistrationContext(registrationContext()));
3105 return create(init); 3108 return create(init);
3106 } 3109 }
3107 3110
3108 void Document::cloneDataFromDocument(const Document& other) 3111 void Document::cloneDataFromDocument(const Document& other)
3109 { 3112 {
3110 setCompatibilityMode(other.compatibilityMode()); 3113 setCompatibilityMode(other.compatibilityMode());
3111 setEncoding(other.encoding()); 3114 setEncodingData(other.encodingData());
abarth-chromium 2013/11/14 07:04:33 Notice that there's no reason to call encodingData
oystein (OOO til 10th of July) 2013/11/14 19:02:29 Done.
3112 setContextFeatures(other.contextFeatures()); 3115 setContextFeatures(other.contextFeatures());
3113 setSecurityOrigin(other.securityOrigin()->isolatedCopy()); 3116 setSecurityOrigin(other.securityOrigin()->isolatedCopy());
3114 } 3117 }
3115 3118
3116 StyleSheetList* Document::styleSheets() 3119 StyleSheetList* Document::styleSheets()
3117 { 3120 {
3118 if (!m_styleSheetList) 3121 if (!m_styleSheetList)
3119 m_styleSheetList = StyleSheetList::create(this); 3122 m_styleSheetList = StyleSheetList::create(this);
3120 return m_styleSheetList.get(); 3123 return m_styleSheetList.get();
3121 } 3124 }
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
3921 if (!length) { 3924 if (!length) {
3922 es.throwUninformativeAndGenericDOMException(InvalidCharacterError); 3925 es.throwUninformativeAndGenericDOMException(InvalidCharacterError);
3923 return false; 3926 return false;
3924 } 3927 }
3925 3928
3926 if (qualifiedName.is8Bit()) 3929 if (qualifiedName.is8Bit())
3927 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, es); 3930 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, es);
3928 return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16( ), length, prefix, localName, es); 3931 return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16( ), length, prefix, localName, es);
3929 } 3932 }
3930 3933
3931 void Document::setDecoder(PassRefPtr<TextResourceDecoder> decoder) 3934 void Document::setEncodingData(const DocumentEncodingData& newData)
3932 { 3935 {
3933 m_decoder = decoder;
3934 setEncoding(m_decoder ? m_decoder->encoding() : WTF::TextEncoding());
3935 }
3936
3937 void Document::setEncoding(const WTF::TextEncoding& encoding)
3938 {
3939 if (m_encoding == encoding)
3940 return;
3941
3942 // It's possible for the encoding of the document to change while we're deco ding 3936 // It's possible for the encoding of the document to change while we're deco ding
3943 // data. That can only occur while we're processing the <head> portion of th e 3937 // data. That can only occur while we're processing the <head> portion of th e
3944 // document. There isn't much user-visible content in the <head>, but there is 3938 // document. There isn't much user-visible content in the <head>, but there is
3945 // the <title> element. This function detects that situation and re-decodes the 3939 // the <title> element. This function detects that situation and re-decodes the
3946 // document's title so that the user doesn't see an incorrectly decoded titl e 3940 // document's title so that the user doesn't see an incorrectly decoded titl e
3947 // in the title bar. 3941 // in the title bar.
3948 if (m_titleElement 3942 if (m_titleElement
3943 && encoding() != newData.encoding
3949 && !m_titleElement->firstElementChild() 3944 && !m_titleElement->firstElementChild()
3950 && m_encoding == Latin1Encoding() 3945 && encoding() == Latin1Encoding()
3951 && m_titleElement->textContent().containsOnlyLatin1()) { 3946 && m_titleElement->textContent().containsOnlyLatin1()) {
3952 3947
3953 CString originalBytes = m_titleElement->textContent().latin1(); 3948 CString originalBytes = m_titleElement->textContent().latin1();
3954 OwnPtr<TextCodec> codec = newTextCodec(encoding); 3949 OwnPtr<TextCodec> codec = newTextCodec(newData.encoding);
3955 String correctlyDecodedTitle = codec->decode(originalBytes.data(), origi nalBytes.length(), true); 3950 String correctlyDecodedTitle = codec->decode(originalBytes.data(), origi nalBytes.length(), true);
3956 m_titleElement->setTextContent(correctlyDecodedTitle, IGNORE_EXCEPTION); 3951 m_titleElement->setTextContent(correctlyDecodedTitle, IGNORE_EXCEPTION);
3957 } 3952 }
3958 3953
3959 m_encoding = encoding; 3954 m_encodingData = newData;
3960 } 3955 }
3961 3956
3962 KURL Document::completeURL(const String& url, const KURL& baseURLOverride) const 3957 KURL Document::completeURL(const String& url, const KURL& baseURLOverride) const
3963 { 3958 {
3964 // Always return a null URL when passed a null string. 3959 // Always return a null URL when passed a null string.
3965 // FIXME: Should we change the KURL constructor to have this behavior? 3960 // FIXME: Should we change the KURL constructor to have this behavior?
3966 // See also [CSS]StyleSheet::completeURL(const String&) 3961 // See also [CSS]StyleSheet::completeURL(const String&)
3967 if (url.isNull()) 3962 if (url.isNull())
3968 return KURL(); 3963 return KURL();
3969 const KURL& baseURL = ((baseURLOverride.isEmpty() || baseURLOverride == blan kURL()) && parentDocument()) ? parentDocument()->baseURL() : baseURLOverride; 3964 const KURL& baseURL = ((baseURLOverride.isEmpty() || baseURLOverride == blan kURL()) && parentDocument()) ? parentDocument()->baseURL() : baseURLOverride;
3970 if (!m_decoder) 3965 if (!encoding().isValid())
3971 return KURL(baseURL, url); 3966 return KURL(baseURL, url);
3972 return KURL(baseURL, url, m_decoder->encoding()); 3967 return KURL(baseURL, url, encoding());
3973 } 3968 }
3974 3969
3975 KURL Document::completeURL(const String& url) const 3970 KURL Document::completeURL(const String& url) const
3976 { 3971 {
3977 return completeURL(url, m_baseURL); 3972 return completeURL(url, m_baseURL);
3978 } 3973 }
3979 3974
3980 // Support for Javascript execCommand, and related methods 3975 // Support for Javascript execCommand, and related methods
3981 3976
3982 static Editor::Command command(Document* document, const String& commandName, bo ol userInterface = false) 3977 static Editor::Command command(Document* document, const String& commandName, bo ol userInterface = false)
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after
5210 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode) 5205 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode)
5211 { 5206 {
5212 if (!isActive()) 5207 if (!isActive())
5213 return; 5208 return;
5214 5209
5215 styleEngine()->modifiedStyleSheet(sheet); 5210 styleEngine()->modifiedStyleSheet(sheet);
5216 styleResolverChanged(when, updateMode); 5211 styleResolverChanged(when, updateMode);
5217 } 5212 }
5218 5213
5219 } // namespace WebCore 5214 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698