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

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: rebased 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/DocumentParser.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 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(m_encoding.domName());
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 setEncoding(data);
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 2817 matching lines...) Expand 10 before | Expand all | Expand 10 after
3946 if (!length) { 3949 if (!length) {
3947 es.throwUninformativeAndGenericDOMException(InvalidCharacterError); 3950 es.throwUninformativeAndGenericDOMException(InvalidCharacterError);
3948 return false; 3951 return false;
3949 } 3952 }
3950 3953
3951 if (qualifiedName.is8Bit()) 3954 if (qualifiedName.is8Bit())
3952 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, es); 3955 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, es);
3953 return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16( ), length, prefix, localName, es); 3956 return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16( ), length, prefix, localName, es);
3954 } 3957 }
3955 3958
3956 void Document::setDecoder(PassRefPtr<TextResourceDecoder> decoder) 3959 Document::DocumentEncodingData::DocumentEncodingData()
3957 { 3960 : wasDetectedHeuristically(false)
3958 m_decoder = decoder; 3961 , sawDecodingError(false)
3959 setEncoding(m_decoder ? m_decoder->encoding() : WTF::TextEncoding());
3960 }
3961
3962 void Document::setEncoding(const WTF::TextEncoding& encoding)
3963 { 3962 {
3964 if (m_encoding == encoding) 3963 if (m_encoding == encoding)
3965 return; 3964 return;
3966 3965
3967 // It's possible for the encoding of the document to change while we're deco ding 3966 // It's possible for the encoding of the document to change while we're deco ding
3968 // data. That can only occur while we're processing the <head> portion of th e 3967 // data. That can only occur while we're processing the <head> portion of th e
3969 // document. There isn't much user-visible content in the <head>, but there is 3968 // document. There isn't much user-visible content in the <head>, but there is
3970 // the <title> element. This function detects that situation and re-decodes the 3969 // the <title> element. This function detects that situation and re-decodes the
3971 // document's title so that the user doesn't see an incorrectly decoded titl e 3970 // document's title so that the user doesn't see an incorrectly decoded titl e
3972 // in the title bar. 3971 // in the title bar.
3973 if (m_titleElement 3972 if (m_titleElement
3974 && !m_titleElement->firstElementChild() 3973 && !m_titleElement->firstElementChild()
3975 && m_encoding == Latin1Encoding() 3974 && m_encoding == Latin1Encoding()
3976 && m_titleElement->textContent().containsOnlyLatin1()) { 3975 && m_titleElement->textContent().containsOnlyLatin1()) {
3977 3976
3978 CString originalBytes = m_titleElement->textContent().latin1(); 3977 CString originalBytes = m_titleElement->textContent().latin1();
3979 OwnPtr<TextCodec> codec = newTextCodec(encoding); 3978 OwnPtr<TextCodec> codec = newTextCodec(encoding);
3980 String correctlyDecodedTitle = codec->decode(originalBytes.data(), origi nalBytes.length(), true); 3979 String correctlyDecodedTitle = codec->decode(originalBytes.data(), origi nalBytes.length(), true);
3981 m_titleElement->setTextContent(correctlyDecodedTitle, IGNORE_EXCEPTION); 3980 m_titleElement->setTextContent(correctlyDecodedTitle, IGNORE_EXCEPTION);
3982 } 3981 }
3983 3982
3984 m_encoding = encoding; 3983 m_encoding = encoding;
3984 m_encodingWasDetectedHeuristically = wasDetectedHeuristically;
3985 m_sawDecodingError = sawDecodingError;
3986 }
3987
3988 void Document::setEncoding(DocumentEncodingData data)
3989 {
3990 m_encodingData = data;
3985 } 3991 }
3986 3992
3987 KURL Document::completeURL(const String& url, const KURL& baseURLOverride) const 3993 KURL Document::completeURL(const String& url, const KURL& baseURLOverride) const
3988 { 3994 {
3989 // Always return a null URL when passed a null string. 3995 // Always return a null URL when passed a null string.
3990 // FIXME: Should we change the KURL constructor to have this behavior? 3996 // FIXME: Should we change the KURL constructor to have this behavior?
3991 // See also [CSS]StyleSheet::completeURL(const String&) 3997 // See also [CSS]StyleSheet::completeURL(const String&)
3992 if (url.isNull()) 3998 if (url.isNull())
3993 return KURL(); 3999 return KURL();
3994 const KURL& baseURL = ((baseURLOverride.isEmpty() || baseURLOverride == blan kURL()) && parentDocument()) ? parentDocument()->baseURL() : baseURLOverride; 4000 const KURL& baseURL = ((baseURLOverride.isEmpty() || baseURLOverride == blan kURL()) && parentDocument()) ? parentDocument()->baseURL() : baseURLOverride;
3995 if (!m_decoder) 4001 if (!encoding().isValid())
3996 return KURL(baseURL, url); 4002 return KURL(baseURL, url);
3997 return KURL(baseURL, url, m_decoder->encoding()); 4003 return KURL(baseURL, url, encoding());
3998 } 4004 }
3999 4005
4000 KURL Document::completeURL(const String& url) const 4006 KURL Document::completeURL(const String& url) const
4001 { 4007 {
4002 return completeURL(url, m_baseURL); 4008 return completeURL(url, m_baseURL);
4003 } 4009 }
4004 4010
4005 // Support for Javascript execCommand, and related methods 4011 // Support for Javascript execCommand, and related methods
4006 4012
4007 static Editor::Command command(Document* document, const String& commandName, bo ol userInterface = false) 4013 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
5235 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode) 5241 void Document::modifiedStyleSheet(StyleSheet* sheet, RecalcStyleTime when, Style ResolverUpdateMode updateMode)
5236 { 5242 {
5237 if (!isActive()) 5243 if (!isActive())
5238 return; 5244 return;
5239 5245
5240 styleEngine()->modifiedStyleSheet(sheet); 5246 styleEngine()->modifiedStyleSheet(sheet);
5241 styleResolverChanged(when, updateMode); 5247 styleResolverChanged(when, updateMode);
5242 } 5248 }
5243 5249
5244 } // namespace WebCore 5250 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/DocumentParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698