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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSParserContext.cpp

Issue 2616093003: Make CSSParserContext be garbage collected. (Closed)
Patch Set: comments 1 Created 3 years, 11 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/parser/CSSParserContext.h" 5 #include "core/css/parser/CSSParserContext.h"
6 6
7 #include "core/css/CSSStyleSheet.h"
8 #include "core/css/StyleSheetContents.h"
7 #include "core/frame/Settings.h" 9 #include "core/frame/Settings.h"
8 #include "core/frame/csp/ContentSecurityPolicy.h" 10 #include "core/frame/csp/ContentSecurityPolicy.h"
9 #include "core/html/imports/HTMLImportsController.h" 11 #include "core/html/imports/HTMLImportsController.h"
10 12
11 namespace blink { 13 namespace blink {
12 14
13 CSSParserContext::CSSParserContext(CSSParserMode mode, 15 // static
14 UseCounter* useCounter, 16 CSSParserContext* CSSParserContext::create(const CSSParserContext* other,
15 SelectorProfile profile) 17 const CSSStyleSheet* styleSheet) {
18 return new CSSParserContext(other, UseCounter::getFrom(styleSheet));
19 }
20
21 // static
22 CSSParserContext* CSSParserContext::create(
23 const CSSParserContext* other,
24 const StyleSheetContents* styleSheetContents) {
25 return new CSSParserContext(other, UseCounter::getFrom(styleSheetContents));
26 }
27
28 CSSParserContext::CSSParserContext(CSSParserMode mode, SelectorProfile profile)
16 : m_mode(mode), 29 : m_mode(mode),
17 m_matchMode(mode), 30 m_matchMode(mode),
18 m_profile(profile), 31 m_profile(profile),
19 m_isHTMLDocument(false), 32 m_isHTMLDocument(false),
20 m_useLegacyBackgroundSizeShorthandBehavior(false), 33 m_useLegacyBackgroundSizeShorthandBehavior(false),
21 m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy), 34 m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy),
22 m_useCounter(useCounter) {} 35 m_useCounter(nullptr) {}
23 36
24 CSSParserContext::CSSParserContext(const Document& document, 37 CSSParserContext::CSSParserContext(const Document& document,
25 UseCounter* useCounter,
26 const KURL& baseURL, 38 const KURL& baseURL,
27 const String& charset, 39 const String& charset,
28 SelectorProfile profile) 40 SelectorProfile profile)
29 : m_baseURL(baseURL.isNull() ? document.baseURL() : baseURL), 41 : m_baseURL(baseURL.isNull() ? document.baseURL() : baseURL),
30 m_charset(charset), 42 m_charset(charset),
31 m_mode(document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode), 43 m_mode(document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode),
32 m_profile(profile), 44 m_profile(profile),
33 m_referrer(m_baseURL.strippedForUseAsReferrer(), 45 m_referrer(m_baseURL.strippedForUseAsReferrer(),
34 document.getReferrerPolicy()), 46 document.getReferrerPolicy()),
35 m_isHTMLDocument(document.isHTMLDocument()), 47 m_isHTMLDocument(document.isHTMLDocument()),
36 m_useLegacyBackgroundSizeShorthandBehavior( 48 m_useLegacyBackgroundSizeShorthandBehavior(
37 document.settings() 49 document.settings()
38 ? document.settings() 50 ? document.settings()
39 ->getUseLegacyBackgroundSizeShorthandBehavior() 51 ->getUseLegacyBackgroundSizeShorthandBehavior()
40 : false), 52 : false),
41 m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy), 53 m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy),
42 m_useCounter(useCounter) { 54 m_useCounter(nullptr) {
43 if (ContentSecurityPolicy::shouldBypassMainWorld(&document)) 55 if (ContentSecurityPolicy::shouldBypassMainWorld(&document))
44 m_shouldCheckContentSecurityPolicy = DoNotCheckContentSecurityPolicy; 56 m_shouldCheckContentSecurityPolicy = DoNotCheckContentSecurityPolicy;
45 else 57 else
46 m_shouldCheckContentSecurityPolicy = CheckContentSecurityPolicy; 58 m_shouldCheckContentSecurityPolicy = CheckContentSecurityPolicy;
47 59
48 if (HTMLImportsController* importsController = document.importsController()) { 60 if (HTMLImportsController* importsController = document.importsController()) {
49 m_matchMode = importsController->master()->inQuirksMode() 61 m_matchMode = importsController->master()->inQuirksMode()
50 ? HTMLQuirksMode 62 ? HTMLQuirksMode
51 : HTMLStandardMode; 63 : HTMLStandardMode;
52 } else { 64 } else {
53 m_matchMode = m_mode; 65 m_matchMode = m_mode;
54 } 66 }
55 } 67 }
56 68
57 CSSParserContext::CSSParserContext(const CSSParserContext& other, 69 CSSParserContext::CSSParserContext(const CSSParserContext* other,
58 UseCounter* useCounter) 70 UseCounter* useCounter)
59 : m_baseURL(other.m_baseURL), 71 : m_baseURL(other->m_baseURL),
60 m_charset(other.m_charset), 72 m_charset(other->m_charset),
61 m_mode(other.m_mode), 73 m_mode(other->m_mode),
62 m_matchMode(other.m_matchMode), 74 m_matchMode(other->m_matchMode),
63 m_profile(other.m_profile), 75 m_profile(other->m_profile),
64 m_referrer(other.m_referrer), 76 m_referrer(other->m_referrer),
65 m_isHTMLDocument(other.m_isHTMLDocument), 77 m_isHTMLDocument(other->m_isHTMLDocument),
66 m_useLegacyBackgroundSizeShorthandBehavior( 78 m_useLegacyBackgroundSizeShorthandBehavior(
67 other.m_useLegacyBackgroundSizeShorthandBehavior), 79 other->m_useLegacyBackgroundSizeShorthandBehavior),
68 m_shouldCheckContentSecurityPolicy( 80 m_shouldCheckContentSecurityPolicy(
69 other.m_shouldCheckContentSecurityPolicy), 81 other->m_shouldCheckContentSecurityPolicy),
70 m_useCounter(useCounter) {} 82 m_useCounter(useCounter) {}
71 83
72 bool CSSParserContext::operator==(const CSSParserContext& other) const { 84 bool CSSParserContext::operator==(const CSSParserContext& other) const {
73 return m_baseURL == other.m_baseURL && m_charset == other.m_charset && 85 return m_baseURL == other.m_baseURL && m_charset == other.m_charset &&
74 m_mode == other.m_mode && m_matchMode == other.m_matchMode && 86 m_mode == other.m_mode && m_matchMode == other.m_matchMode &&
75 m_profile == other.m_profile && 87 m_profile == other.m_profile &&
76 m_isHTMLDocument == other.m_isHTMLDocument && 88 m_isHTMLDocument == other.m_isHTMLDocument &&
77 m_useLegacyBackgroundSizeShorthandBehavior == 89 m_useLegacyBackgroundSizeShorthandBehavior ==
78 other.m_useLegacyBackgroundSizeShorthandBehavior; 90 other.m_useLegacyBackgroundSizeShorthandBehavior;
79 } 91 }
80 92
81 const CSSParserContext& strictCSSParserContext() { 93 const CSSParserContext* strictCSSParserContext() {
82 DEFINE_STATIC_LOCAL(CSSParserContext, strictContext, 94 DEFINE_STATIC_LOCAL(CSSParserContext, strictContext,
83 (HTMLStandardMode, nullptr)); 95 (new CSSParserContext(HTMLStandardMode)));
84 return strictContext; 96 return &strictContext;
haraken 2017/01/12 04:51:13 Or you can change the type of the return value to
Bret 2017/01/13 02:15:28 I think this is okay, as long as it isn't wrong. T
85 } 97 }
86 98
87 KURL CSSParserContext::completeURL(const String& url) const { 99 KURL CSSParserContext::completeURL(const String& url) const {
88 if (url.isNull()) 100 if (url.isNull())
89 return KURL(); 101 return KURL();
90 if (charset().isEmpty()) 102 if (charset().isEmpty())
91 return KURL(baseURL(), url); 103 return KURL(baseURL(), url);
92 return KURL(baseURL(), url, charset()); 104 return KURL(baseURL(), url, charset());
93 } 105 }
94 106
95 } // namespace blink 107 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698