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/html/LinkStyle.h" | 5 #include "core/html/LinkStyle.h" |
6 | 6 |
7 #include "core/css/StyleSheetContents.h" | 7 #include "core/css/StyleSheetContents.h" |
8 #include "core/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
9 #include "core/frame/SubresourceIntegrity.h" | 9 #include "core/frame/SubresourceIntegrity.h" |
10 #include "core/frame/csp/ContentSecurityPolicy.h" | 10 #include "core/frame/csp/ContentSecurityPolicy.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return; | 229 return; |
230 } | 230 } |
231 | 231 |
232 m_owner->document().styleEngine().removePendingSheet(*m_owner, | 232 m_owner->document().styleEngine().removePendingSheet(*m_owner, |
233 m_styleEngineContext); | 233 m_styleEngineContext); |
234 } | 234 } |
235 | 235 |
236 void LinkStyle::setDisabledState(bool disabled) { | 236 void LinkStyle::setDisabledState(bool disabled) { |
237 LinkStyle::DisabledState oldDisabledState = m_disabledState; | 237 LinkStyle::DisabledState oldDisabledState = m_disabledState; |
238 m_disabledState = disabled ? Disabled : EnabledViaScript; | 238 m_disabledState = disabled ? Disabled : EnabledViaScript; |
239 if (oldDisabledState != m_disabledState) { | 239 if (oldDisabledState == m_disabledState) |
240 // If we change the disabled state while the sheet is still loading, then we | 240 return; |
241 // have to perform three checks: | |
242 if (styleSheetIsLoading()) { | |
243 // Check #1: The sheet becomes disabled while loading. | |
244 if (m_disabledState == Disabled) | |
245 removePendingSheet(); | |
246 | 241 |
247 // Check #2: An alternate sheet becomes enabled while it is still loading. | 242 // If we change the disabled state while the sheet is still loading, then we |
248 if (m_owner->relAttribute().isAlternate() && | 243 // have to perform three checks: |
249 m_disabledState == EnabledViaScript) | 244 if (styleSheetIsLoading()) { |
250 addPendingSheet(Blocking); | 245 // Check #1: The sheet becomes disabled while loading. |
| 246 if (m_disabledState == Disabled) |
| 247 removePendingSheet(); |
251 | 248 |
252 // Check #3: A main sheet becomes enabled while it was still loading and | 249 // Check #2: An alternate sheet becomes enabled while it is still loading. |
253 // after it was disabled via script. It takes really terrible code to make | 250 if (m_owner->relAttribute().isAlternate() && |
254 // this happen (a double toggle for no reason essentially). This happens | 251 m_disabledState == EnabledViaScript) |
255 // on virtualplastic.net, which manages to do about 12 enable/disables on | 252 addPendingSheet(Blocking); |
256 // only 3 sheets. :) | |
257 if (!m_owner->relAttribute().isAlternate() && | |
258 m_disabledState == EnabledViaScript && oldDisabledState == Disabled) | |
259 addPendingSheet(Blocking); | |
260 | 253 |
261 // If the sheet is already loading just bail. | 254 // Check #3: A main sheet becomes enabled while it was still loading and |
262 return; | 255 // after it was disabled via script. It takes really terrible code to make |
263 } | 256 // this happen (a double toggle for no reason essentially). This happens |
| 257 // on virtualplastic.net, which manages to do about 12 enable/disables on |
| 258 // only 3 sheets. :) |
| 259 if (!m_owner->relAttribute().isAlternate() && |
| 260 m_disabledState == EnabledViaScript && oldDisabledState == Disabled) |
| 261 addPendingSheet(Blocking); |
264 | 262 |
265 if (m_sheet) { | 263 // If the sheet is already loading just bail. |
266 m_sheet->setDisabled(disabled); | 264 return; |
267 return; | 265 } |
268 } | |
269 | 266 |
270 if (m_disabledState == EnabledViaScript && m_owner->shouldProcessStyle()) | 267 if (m_sheet) { |
271 process(); | 268 m_sheet->setDisabled(disabled); |
| 269 return; |
272 } | 270 } |
| 271 |
| 272 if (m_disabledState == EnabledViaScript && m_owner->shouldProcessStyle()) |
| 273 process(); |
273 } | 274 } |
274 | 275 |
275 void LinkStyle::setCrossOriginStylesheetStatus(CSSStyleSheet* sheet) { | 276 void LinkStyle::setCrossOriginStylesheetStatus(CSSStyleSheet* sheet) { |
276 if (m_fetchFollowingCORS && resource() && !resource()->errorOccurred()) { | 277 if (m_fetchFollowingCORS && resource() && !resource()->errorOccurred()) { |
277 // Record the security origin the CORS access check succeeded at, if cross | 278 // Record the security origin the CORS access check succeeded at, if cross |
278 // origin. Only origins that are script accessible to it may access the | 279 // origin. Only origins that are script accessible to it may access the |
279 // stylesheet's rules. | 280 // stylesheet's rules. |
280 sheet->setAllowRuleAccessFromOrigin( | 281 sheet->setAllowRuleAccessFromOrigin( |
281 m_owner->document().getSecurityOrigin()); | 282 m_owner->document().getSecurityOrigin()); |
282 } | 283 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 StyleEngine::ActiveSheetsUpdate updateActiveSheets) { | 400 StyleEngine::ActiveSheetsUpdate updateActiveSheets) { |
400 if (!m_owner->isInDocumentTree() || !m_owner->relAttribute().isStyleSheet()) | 401 if (!m_owner->isInDocumentTree() || !m_owner->relAttribute().isStyleSheet()) |
401 return; | 402 return; |
402 | 403 |
403 if (m_sheet) | 404 if (m_sheet) |
404 m_sheet->setTitle(title); | 405 m_sheet->setTitle(title); |
405 | 406 |
406 if (title.isEmpty() || !isUnset() || m_owner->isAlternate()) | 407 if (title.isEmpty() || !isUnset() || m_owner->isAlternate()) |
407 return; | 408 return; |
408 | 409 |
409 KURL href = m_owner->getNonEmptyURLAttribute(hrefAttr); | 410 const KURL& href = m_owner->getNonEmptyURLAttribute(hrefAttr); |
410 if (href.isValid() && !href.isEmpty()) { | 411 if (href.isValid() && !href.isEmpty()) { |
411 document().styleEngine().setPreferredStylesheetSetNameIfNotSet( | 412 document().styleEngine().setPreferredStylesheetSetNameIfNotSet( |
412 title, updateActiveSheets); | 413 title, updateActiveSheets); |
413 } | 414 } |
414 } | 415 } |
415 | 416 |
416 void LinkStyle::ownerRemoved() { | 417 void LinkStyle::ownerRemoved() { |
417 if (m_sheet) | 418 if (m_sheet) |
418 clearSheet(); | 419 clearSheet(); |
419 | 420 |
420 if (styleSheetIsLoading()) | 421 if (styleSheetIsLoading()) |
421 removePendingSheet(); | 422 removePendingSheet(); |
422 } | 423 } |
423 | 424 |
424 DEFINE_TRACE(LinkStyle) { | 425 DEFINE_TRACE(LinkStyle) { |
425 visitor->trace(m_sheet); | 426 visitor->trace(m_sheet); |
426 LinkResource::trace(visitor); | 427 LinkResource::trace(visitor); |
427 ResourceOwner<StyleSheetResource>::trace(visitor); | 428 ResourceOwner<StyleSheetResource>::trace(visitor); |
428 } | 429 } |
429 | 430 |
430 } // namespace blink | 431 } // namespace blink |
OLD | NEW |