OLD | NEW |
---|---|
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/frame/Settings.h" | 7 #include "core/frame/Settings.h" |
8 #include "core/frame/csp/ContentSecurityPolicy.h" | 8 #include "core/frame/csp/ContentSecurityPolicy.h" |
9 #include "core/html/imports/HTMLImportsController.h" | 9 #include "core/html/imports/HTMLImportsController.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 CSSParserContext::CSSParserContext(CSSParserMode mode, | 13 CSSParserContext::CSSParserContext(CSSParserMode mode, SelectorProfile profile) |
14 UseCounter* useCounter, | |
15 SelectorProfile profile) | |
16 : m_mode(mode), | 14 : m_mode(mode), |
17 m_matchMode(mode), | 15 m_matchMode(mode), |
18 m_profile(profile), | 16 m_profile(profile), |
19 m_isHTMLDocument(false), | 17 m_isHTMLDocument(false), |
20 m_useLegacyBackgroundSizeShorthandBehavior(false), | 18 m_useLegacyBackgroundSizeShorthandBehavior(false), |
21 m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy), | 19 m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy), |
22 m_useCounter(useCounter) {} | 20 m_useCounter(nullptr) {} |
23 | 21 |
24 CSSParserContext::CSSParserContext(const Document& document, | 22 CSSParserContext::CSSParserContext(const Document& document, |
25 UseCounter* useCounter, | |
26 const KURL& baseURL, | 23 const KURL& baseURL, |
27 const String& charset, | 24 const String& charset, |
28 SelectorProfile profile) | 25 SelectorProfile profile) |
29 : m_baseURL(baseURL.isNull() ? document.baseURL() : baseURL), | 26 : m_baseURL(baseURL.isNull() ? document.baseURL() : baseURL), |
30 m_charset(charset), | 27 m_charset(charset), |
31 m_mode(document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode), | 28 m_mode(document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode), |
32 m_profile(profile), | 29 m_profile(profile), |
33 m_referrer(m_baseURL.strippedForUseAsReferrer(), | 30 m_referrer(m_baseURL.strippedForUseAsReferrer(), |
34 document.getReferrerPolicy()), | 31 document.getReferrerPolicy()), |
35 m_isHTMLDocument(document.isHTMLDocument()), | 32 m_isHTMLDocument(document.isHTMLDocument()), |
36 m_useLegacyBackgroundSizeShorthandBehavior( | 33 m_useLegacyBackgroundSizeShorthandBehavior( |
37 document.settings() | 34 document.settings() |
38 ? document.settings() | 35 ? document.settings() |
39 ->getUseLegacyBackgroundSizeShorthandBehavior() | 36 ->getUseLegacyBackgroundSizeShorthandBehavior() |
40 : false), | 37 : false), |
41 m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy), | 38 m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy), |
42 m_useCounter(useCounter) { | 39 m_useCounter(nullptr) { |
43 if (ContentSecurityPolicy::shouldBypassMainWorld(&document)) | 40 if (ContentSecurityPolicy::shouldBypassMainWorld(&document)) |
44 m_shouldCheckContentSecurityPolicy = DoNotCheckContentSecurityPolicy; | 41 m_shouldCheckContentSecurityPolicy = DoNotCheckContentSecurityPolicy; |
45 else | 42 else |
46 m_shouldCheckContentSecurityPolicy = CheckContentSecurityPolicy; | 43 m_shouldCheckContentSecurityPolicy = CheckContentSecurityPolicy; |
47 | 44 |
48 if (HTMLImportsController* importsController = document.importsController()) { | 45 if (HTMLImportsController* importsController = document.importsController()) { |
49 m_matchMode = importsController->master()->inQuirksMode() | 46 m_matchMode = importsController->master()->inQuirksMode() |
50 ? HTMLQuirksMode | 47 ? HTMLQuirksMode |
51 : HTMLStandardMode; | 48 : HTMLStandardMode; |
52 } else { | 49 } else { |
53 m_matchMode = m_mode; | 50 m_matchMode = m_mode; |
54 } | 51 } |
55 } | 52 } |
56 | 53 |
57 CSSParserContext::CSSParserContext(const CSSParserContext& other, | 54 CSSParserContext::CSSParserContext(const CSSParserContext* other, |
58 UseCounter* useCounter) | 55 UseCounter* useCounter) |
59 : m_baseURL(other.m_baseURL), | 56 : m_baseURL(other->m_baseURL), |
60 m_charset(other.m_charset), | 57 m_charset(other->m_charset), |
61 m_mode(other.m_mode), | 58 m_mode(other->m_mode), |
62 m_matchMode(other.m_matchMode), | 59 m_matchMode(other->m_matchMode), |
63 m_profile(other.m_profile), | 60 m_profile(other->m_profile), |
64 m_referrer(other.m_referrer), | 61 m_referrer(other->m_referrer), |
65 m_isHTMLDocument(other.m_isHTMLDocument), | 62 m_isHTMLDocument(other->m_isHTMLDocument), |
66 m_useLegacyBackgroundSizeShorthandBehavior( | 63 m_useLegacyBackgroundSizeShorthandBehavior( |
67 other.m_useLegacyBackgroundSizeShorthandBehavior), | 64 other->m_useLegacyBackgroundSizeShorthandBehavior), |
68 m_shouldCheckContentSecurityPolicy( | 65 m_shouldCheckContentSecurityPolicy( |
69 other.m_shouldCheckContentSecurityPolicy), | 66 other->m_shouldCheckContentSecurityPolicy), |
70 m_useCounter(useCounter) {} | 67 m_useCounter(useCounter) {} |
71 | 68 |
72 bool CSSParserContext::operator==(const CSSParserContext& other) const { | 69 bool CSSParserContext::operator==(const CSSParserContext& other) const { |
73 return m_baseURL == other.m_baseURL && m_charset == other.m_charset && | 70 return m_baseURL == other.m_baseURL && m_charset == other.m_charset && |
74 m_mode == other.m_mode && m_matchMode == other.m_matchMode && | 71 m_mode == other.m_mode && m_matchMode == other.m_matchMode && |
75 m_profile == other.m_profile && | 72 m_profile == other.m_profile && |
76 m_isHTMLDocument == other.m_isHTMLDocument && | 73 m_isHTMLDocument == other.m_isHTMLDocument && |
77 m_useLegacyBackgroundSizeShorthandBehavior == | 74 m_useLegacyBackgroundSizeShorthandBehavior == |
78 other.m_useLegacyBackgroundSizeShorthandBehavior; | 75 other.m_useLegacyBackgroundSizeShorthandBehavior; |
79 } | 76 } |
80 | 77 |
81 const CSSParserContext& strictCSSParserContext() { | 78 const CSSParserContext* strictCSSParserContext() { |
82 DEFINE_STATIC_LOCAL(CSSParserContext, strictContext, | 79 static CSSParserContext* strictContext = |
rune
2017/01/11 12:59:26
Doesn't it need to be Persistent?
haraken
2017/01/11 13:04:54
Nice catch! This needs to be DEFINE_STATIC_LOCAL(P
sof
2017/01/11 13:09:21
DEFINE_STATIC_LOCAL(T, ...) will implicitly wrap a
Bret
2017/01/11 23:05:15
Done... though needing "&strictContext" doesn't se
| |
83 (HTMLStandardMode, nullptr)); | 80 new CSSParserContext(HTMLStandardMode); |
84 return strictContext; | 81 return strictContext; |
85 } | 82 } |
86 | 83 |
87 KURL CSSParserContext::completeURL(const String& url) const { | 84 KURL CSSParserContext::completeURL(const String& url) const { |
88 if (url.isNull()) | 85 if (url.isNull()) |
89 return KURL(); | 86 return KURL(); |
90 if (charset().isEmpty()) | 87 if (charset().isEmpty()) |
91 return KURL(baseURL(), url); | 88 return KURL(baseURL(), url); |
92 return KURL(baseURL(), url, charset()); | 89 return KURL(baseURL(), url, charset()); |
93 } | 90 } |
94 | 91 |
95 } // namespace blink | 92 } // namespace blink |
OLD | NEW |