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/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::createWithStyleSheet( |
15 SelectorProfile profile) | 17 const CSSParserContext* other, |
16 : m_mode(mode), | 18 const CSSStyleSheet* styleSheet) { |
17 m_matchMode(mode), | 19 return CSSParserContext::create(other, UseCounter::getFrom(styleSheet)); |
18 m_profile(profile), | |
19 m_isHTMLDocument(false), | |
20 m_useLegacyBackgroundSizeShorthandBehavior(false), | |
21 m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy), | |
22 m_useCounter(useCounter) {} | |
23 | |
24 CSSParserContext::CSSParserContext(const Document& document, | |
25 UseCounter* useCounter, | |
26 const KURL& baseURL, | |
27 const String& charset, | |
28 SelectorProfile profile) | |
29 : m_baseURL(baseURL.isNull() ? document.baseURL() : baseURL), | |
30 m_charset(charset), | |
31 m_mode(document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode), | |
32 m_profile(profile), | |
33 m_referrer(m_baseURL.strippedForUseAsReferrer(), | |
34 document.getReferrerPolicy()), | |
35 m_isHTMLDocument(document.isHTMLDocument()), | |
36 m_useLegacyBackgroundSizeShorthandBehavior( | |
37 document.settings() | |
38 ? document.settings() | |
39 ->getUseLegacyBackgroundSizeShorthandBehavior() | |
40 : false), | |
41 m_shouldCheckContentSecurityPolicy(DoNotCheckContentSecurityPolicy), | |
42 m_useCounter(useCounter) { | |
43 if (ContentSecurityPolicy::shouldBypassMainWorld(&document)) | |
44 m_shouldCheckContentSecurityPolicy = DoNotCheckContentSecurityPolicy; | |
45 else | |
46 m_shouldCheckContentSecurityPolicy = CheckContentSecurityPolicy; | |
47 | |
48 if (HTMLImportsController* importsController = document.importsController()) { | |
49 m_matchMode = importsController->master()->inQuirksMode() | |
50 ? HTMLQuirksMode | |
51 : HTMLStandardMode; | |
52 } else { | |
53 m_matchMode = m_mode; | |
54 } | |
55 } | 20 } |
56 | 21 |
57 CSSParserContext::CSSParserContext(const CSSParserContext& other, | 22 // static |
58 UseCounter* useCounter) | 23 CSSParserContext* CSSParserContext::createWithStyleSheetContents( |
59 : m_baseURL(other.m_baseURL), | 24 const CSSParserContext* other, |
60 m_charset(other.m_charset), | 25 const StyleSheetContents* styleSheetContents) { |
61 m_mode(other.m_mode), | 26 return CSSParserContext::create(other, |
62 m_matchMode(other.m_matchMode), | 27 UseCounter::getFrom(styleSheetContents)); |
63 m_profile(other.m_profile), | 28 } |
64 m_referrer(other.m_referrer), | 29 |
65 m_isHTMLDocument(other.m_isHTMLDocument), | 30 // static |
| 31 CSSParserContext* CSSParserContext::create(const CSSParserContext* other, |
| 32 UseCounter* useCounter) { |
| 33 return new CSSParserContext( |
| 34 other->m_baseURL, other->m_charset, other->m_mode, other->m_matchMode, |
| 35 other->m_profile, other->m_referrer, other->m_isHTMLDocument, |
| 36 other->m_useLegacyBackgroundSizeShorthandBehavior, |
| 37 other->m_shouldCheckContentSecurityPolicy, useCounter); |
| 38 } |
| 39 |
| 40 // static |
| 41 CSSParserContext* CSSParserContext::create(CSSParserMode mode, |
| 42 SelectorProfile profile, |
| 43 UseCounter* useCounter) { |
| 44 return new CSSParserContext(KURL(), emptyString(), mode, mode, profile, |
| 45 Referrer(), false, false, |
| 46 DoNotCheckContentSecurityPolicy, useCounter); |
| 47 } |
| 48 |
| 49 // static |
| 50 CSSParserContext* CSSParserContext::create(const Document& document, |
| 51 UseCounter* useCounter) { |
| 52 return CSSParserContext::create(document, KURL(), emptyString(), |
| 53 DynamicProfile, useCounter); |
| 54 } |
| 55 |
| 56 // static |
| 57 CSSParserContext* CSSParserContext::create(const Document& document, |
| 58 const KURL& baseURLOverride, |
| 59 const String& charset, |
| 60 SelectorProfile profile, |
| 61 UseCounter* useCounter) { |
| 62 const KURL baseURL = |
| 63 baseURLOverride.isNull() ? document.baseURL() : baseURLOverride; |
| 64 |
| 65 CSSParserMode mode = |
| 66 document.inQuirksMode() ? HTMLQuirksMode : HTMLStandardMode; |
| 67 CSSParserMode matchMode; |
| 68 if (HTMLImportsController* importsController = document.importsController()) { |
| 69 matchMode = importsController->master()->inQuirksMode() ? HTMLQuirksMode |
| 70 : HTMLStandardMode; |
| 71 } else { |
| 72 matchMode = mode; |
| 73 } |
| 74 |
| 75 const Referrer referrer(baseURL.strippedForUseAsReferrer(), |
| 76 document.getReferrerPolicy()); |
| 77 |
| 78 bool useLegacyBackgroundSizeShorthandBehavior = |
| 79 document.settings() |
| 80 ? document.settings()->getUseLegacyBackgroundSizeShorthandBehavior() |
| 81 : false; |
| 82 |
| 83 ContentSecurityPolicyDisposition policyDisposition; |
| 84 if (ContentSecurityPolicy::shouldBypassMainWorld(&document)) |
| 85 policyDisposition = DoNotCheckContentSecurityPolicy; |
| 86 else |
| 87 policyDisposition = CheckContentSecurityPolicy; |
| 88 |
| 89 return new CSSParserContext(baseURL, charset, mode, matchMode, profile, |
| 90 referrer, document.isHTMLDocument(), |
| 91 useLegacyBackgroundSizeShorthandBehavior, |
| 92 policyDisposition, useCounter); |
| 93 } |
| 94 |
| 95 CSSParserContext::CSSParserContext( |
| 96 const KURL& baseURL, |
| 97 const String& charset, |
| 98 CSSParserMode mode, |
| 99 CSSParserMode matchMode, |
| 100 SelectorProfile profile, |
| 101 const Referrer& referrer, |
| 102 bool isHTMLDocument, |
| 103 bool useLegacyBackgroundSizeShorthandBehavior, |
| 104 ContentSecurityPolicyDisposition policyDisposition, |
| 105 UseCounter* useCounter) |
| 106 : m_baseURL(baseURL), |
| 107 m_charset(charset), |
| 108 m_mode(mode), |
| 109 m_matchMode(matchMode), |
| 110 m_profile(profile), |
| 111 m_referrer(referrer), |
| 112 m_isHTMLDocument(isHTMLDocument), |
66 m_useLegacyBackgroundSizeShorthandBehavior( | 113 m_useLegacyBackgroundSizeShorthandBehavior( |
67 other.m_useLegacyBackgroundSizeShorthandBehavior), | 114 useLegacyBackgroundSizeShorthandBehavior), |
68 m_shouldCheckContentSecurityPolicy( | 115 m_shouldCheckContentSecurityPolicy(policyDisposition), |
69 other.m_shouldCheckContentSecurityPolicy), | |
70 m_useCounter(useCounter) {} | 116 m_useCounter(useCounter) {} |
71 | 117 |
72 bool CSSParserContext::operator==(const CSSParserContext& other) const { | 118 bool CSSParserContext::operator==(const CSSParserContext& other) const { |
73 return m_baseURL == other.m_baseURL && m_charset == other.m_charset && | 119 return m_baseURL == other.m_baseURL && m_charset == other.m_charset && |
74 m_mode == other.m_mode && m_matchMode == other.m_matchMode && | 120 m_mode == other.m_mode && m_matchMode == other.m_matchMode && |
75 m_profile == other.m_profile && | 121 m_profile == other.m_profile && |
76 m_isHTMLDocument == other.m_isHTMLDocument && | 122 m_isHTMLDocument == other.m_isHTMLDocument && |
77 m_useLegacyBackgroundSizeShorthandBehavior == | 123 m_useLegacyBackgroundSizeShorthandBehavior == |
78 other.m_useLegacyBackgroundSizeShorthandBehavior; | 124 other.m_useLegacyBackgroundSizeShorthandBehavior; |
79 } | 125 } |
80 | 126 |
81 const CSSParserContext& strictCSSParserContext() { | 127 const CSSParserContext* strictCSSParserContext() { |
82 DEFINE_STATIC_LOCAL(CSSParserContext, strictContext, | 128 DEFINE_STATIC_LOCAL(CSSParserContext, strictContext, |
83 (HTMLStandardMode, nullptr)); | 129 (CSSParserContext::create(HTMLStandardMode))); |
84 return strictContext; | 130 return &strictContext; |
85 } | 131 } |
86 | 132 |
87 KURL CSSParserContext::completeURL(const String& url) const { | 133 KURL CSSParserContext::completeURL(const String& url) const { |
88 if (url.isNull()) | 134 if (url.isNull()) |
89 return KURL(); | 135 return KURL(); |
90 if (charset().isEmpty()) | 136 if (charset().isEmpty()) |
91 return KURL(baseURL(), url); | 137 return KURL(baseURL(), url); |
92 return KURL(baseURL(), url, charset()); | 138 return KURL(baseURL(), url, charset()); |
93 } | 139 } |
94 | 140 |
95 } // namespace blink | 141 } // namespace blink |
OLD | NEW |