| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "core/html/HTMLStyleElement.h" | 38 #include "core/html/HTMLStyleElement.h" |
| 39 #include "core/inspector/InspectorInstrumentation.h" | 39 #include "core/inspector/InspectorInstrumentation.h" |
| 40 #include "core/svg/SVGStyleElement.h" | 40 #include "core/svg/SVGStyleElement.h" |
| 41 #include "platform/weborigin/SecurityOrigin.h" | 41 #include "platform/weborigin/SecurityOrigin.h" |
| 42 #include "wtf/text/StringBuilder.h" | 42 #include "wtf/text/StringBuilder.h" |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 class StyleSheetCSSRuleList final : public CSSRuleList { | 46 class StyleSheetCSSRuleList final : public CSSRuleList { |
| 47 public: | 47 public: |
| 48 static PassOwnPtrWillBeRawPtr<StyleSheetCSSRuleList> create(CSSStyleSheet* s
heet) | 48 static RawPtr<StyleSheetCSSRuleList> create(CSSStyleSheet* sheet) |
| 49 { | 49 { |
| 50 return adoptPtrWillBeNoop(new StyleSheetCSSRuleList(sheet)); | 50 return (new StyleSheetCSSRuleList(sheet)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 DEFINE_INLINE_VIRTUAL_TRACE() | 53 DEFINE_INLINE_VIRTUAL_TRACE() |
| 54 { | 54 { |
| 55 visitor->trace(m_styleSheet); | 55 visitor->trace(m_styleSheet); |
| 56 CSSRuleList::trace(visitor); | 56 CSSRuleList::trace(visitor); |
| 57 } | 57 } |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 StyleSheetCSSRuleList(CSSStyleSheet* sheet) : m_styleSheet(sheet) { } | 60 StyleSheetCSSRuleList(CSSStyleSheet* sheet) : m_styleSheet(sheet) { } |
| 61 | 61 |
| 62 #if !ENABLE(OILPAN) | 62 #if !ENABLE(OILPAN) |
| 63 void ref() override { m_styleSheet->ref(); } | 63 void ref() override { m_styleSheet->ref(); } |
| 64 void deref() override { m_styleSheet->deref(); } | 64 void deref() override { m_styleSheet->deref(); } |
| 65 #endif | 65 #endif |
| 66 | 66 |
| 67 unsigned length() const override { return m_styleSheet->length(); } | 67 unsigned length() const override { return m_styleSheet->length(); } |
| 68 CSSRule* item(unsigned index) const override { return m_styleSheet->item(ind
ex); } | 68 CSSRule* item(unsigned index) const override { return m_styleSheet->item(ind
ex); } |
| 69 | 69 |
| 70 CSSStyleSheet* styleSheet() const override { return m_styleSheet; } | 70 CSSStyleSheet* styleSheet() const override { return m_styleSheet; } |
| 71 | 71 |
| 72 RawPtrWillBeMember<CSSStyleSheet> m_styleSheet; | 72 Member<CSSStyleSheet> m_styleSheet; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 #if ENABLE(ASSERT) | 75 #if ENABLE(ASSERT) |
| 76 static bool isAcceptableCSSStyleSheetParent(Node* parentNode) | 76 static bool isAcceptableCSSStyleSheetParent(Node* parentNode) |
| 77 { | 77 { |
| 78 // Only these nodes can be parents of StyleSheets, and they need to call | 78 // Only these nodes can be parents of StyleSheets, and they need to call |
| 79 // clearOwnerNode() when moved out of document. | 79 // clearOwnerNode() when moved out of document. |
| 80 // Destruction of the style sheet counts as being "moved out of the | 80 // Destruction of the style sheet counts as being "moved out of the |
| 81 // document", but only in the non-oilpan version of blink. I.e. don't call | 81 // document", but only in the non-oilpan version of blink. I.e. don't call |
| 82 // clearOwnerNode() in the owner's destructor in oilpan. | 82 // clearOwnerNode() in the owner's destructor in oilpan. |
| 83 return !parentNode | 83 return !parentNode |
| 84 || parentNode->isDocumentNode() | 84 || parentNode->isDocumentNode() |
| 85 || isHTMLLinkElement(*parentNode) | 85 || isHTMLLinkElement(*parentNode) |
| 86 || isHTMLStyleElement(*parentNode) | 86 || isHTMLStyleElement(*parentNode) |
| 87 || isSVGStyleElement(*parentNode) | 87 || isSVGStyleElement(*parentNode) |
| 88 || parentNode->nodeType() == Node::PROCESSING_INSTRUCTION_NODE; | 88 || parentNode->nodeType() == Node::PROCESSING_INSTRUCTION_NODE; |
| 89 } | 89 } |
| 90 #endif | 90 #endif |
| 91 | 91 |
| 92 PassRefPtrWillBeRawPtr<CSSStyleSheet> CSSStyleSheet::create(PassRefPtrWillBeRawP
tr<StyleSheetContents> sheet, CSSImportRule* ownerRule) | 92 RawPtr<CSSStyleSheet> CSSStyleSheet::create(RawPtr<StyleSheetContents> sheet, CS
SImportRule* ownerRule) |
| 93 { | 93 { |
| 94 return adoptRefWillBeNoop(new CSSStyleSheet(sheet, ownerRule)); | 94 return (new CSSStyleSheet(sheet, ownerRule)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 PassRefPtrWillBeRawPtr<CSSStyleSheet> CSSStyleSheet::create(PassRefPtrWillBeRawP
tr<StyleSheetContents> sheet, Node* ownerNode) | 97 RawPtr<CSSStyleSheet> CSSStyleSheet::create(RawPtr<StyleSheetContents> sheet, No
de* ownerNode) |
| 98 { | 98 { |
| 99 return adoptRefWillBeNoop(new CSSStyleSheet(sheet, ownerNode, false, TextPos
ition::minimumPosition())); | 99 return (new CSSStyleSheet(sheet, ownerNode, false, TextPosition::minimumPosi
tion())); |
| 100 } | 100 } |
| 101 | 101 |
| 102 PassRefPtrWillBeRawPtr<CSSStyleSheet> CSSStyleSheet::createInline(PassRefPtrWill
BeRawPtr<StyleSheetContents> sheet, Node* ownerNode, const TextPosition& startPo
sition) | 102 RawPtr<CSSStyleSheet> CSSStyleSheet::createInline(RawPtr<StyleSheetContents> she
et, Node* ownerNode, const TextPosition& startPosition) |
| 103 { | 103 { |
| 104 ASSERT(sheet); | 104 ASSERT(sheet); |
| 105 return adoptRefWillBeNoop(new CSSStyleSheet(sheet, ownerNode, true, startPos
ition)); | 105 return (new CSSStyleSheet(sheet, ownerNode, true, startPosition)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 PassRefPtrWillBeRawPtr<CSSStyleSheet> CSSStyleSheet::createInline(Node* ownerNod
e, const KURL& baseURL, const TextPosition& startPosition, const String& encodin
g) | 108 RawPtr<CSSStyleSheet> CSSStyleSheet::createInline(Node* ownerNode, const KURL& b
aseURL, const TextPosition& startPosition, const String& encoding) |
| 109 { | 109 { |
| 110 CSSParserContext parserContext(ownerNode->document(), 0, baseURL, encoding); | 110 CSSParserContext parserContext(ownerNode->document(), 0, baseURL, encoding); |
| 111 RefPtrWillBeRawPtr<StyleSheetContents> sheet = StyleSheetContents::create(ba
seURL.string(), parserContext); | 111 RawPtr<StyleSheetContents> sheet = StyleSheetContents::create(baseURL.string
(), parserContext); |
| 112 return adoptRefWillBeNoop(new CSSStyleSheet(sheet.release(), ownerNode, true
, startPosition)); | 112 return (new CSSStyleSheet(sheet.release(), ownerNode, true, startPosition)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 CSSStyleSheet::CSSStyleSheet(PassRefPtrWillBeRawPtr<StyleSheetContents> contents
, CSSImportRule* ownerRule) | 115 CSSStyleSheet::CSSStyleSheet(RawPtr<StyleSheetContents> contents, CSSImportRule*
ownerRule) |
| 116 : m_contents(contents) | 116 : m_contents(contents) |
| 117 , m_isInlineStylesheet(false) | 117 , m_isInlineStylesheet(false) |
| 118 , m_isDisabled(false) | 118 , m_isDisabled(false) |
| 119 , m_ownerNode(nullptr) | 119 , m_ownerNode(nullptr) |
| 120 , m_ownerRule(ownerRule) | 120 , m_ownerRule(ownerRule) |
| 121 , m_startPosition(TextPosition::minimumPosition()) | 121 , m_startPosition(TextPosition::minimumPosition()) |
| 122 , m_loadCompleted(false) | 122 , m_loadCompleted(false) |
| 123 { | 123 { |
| 124 m_contents->registerClient(this); | 124 m_contents->registerClient(this); |
| 125 } | 125 } |
| 126 | 126 |
| 127 CSSStyleSheet::CSSStyleSheet(PassRefPtrWillBeRawPtr<StyleSheetContents> contents
, Node* ownerNode, bool isInlineStylesheet, const TextPosition& startPosition) | 127 CSSStyleSheet::CSSStyleSheet(RawPtr<StyleSheetContents> contents, Node* ownerNod
e, bool isInlineStylesheet, const TextPosition& startPosition) |
| 128 : m_contents(contents) | 128 : m_contents(contents) |
| 129 , m_isInlineStylesheet(isInlineStylesheet) | 129 , m_isInlineStylesheet(isInlineStylesheet) |
| 130 , m_isDisabled(false) | 130 , m_isDisabled(false) |
| 131 , m_ownerNode(ownerNode) | 131 , m_ownerNode(ownerNode) |
| 132 , m_ownerRule(nullptr) | 132 , m_ownerRule(nullptr) |
| 133 , m_startPosition(startPosition) | 133 , m_startPosition(startPosition) |
| 134 , m_loadCompleted(false) | 134 , m_loadCompleted(false) |
| 135 { | 135 { |
| 136 ASSERT(isAcceptableCSSStyleSheetParent(ownerNode)); | 136 ASSERT(isAcceptableCSSStyleSheetParent(ownerNode)); |
| 137 m_contents->registerClient(this); | 137 m_contents->registerClient(this); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 214 |
| 215 void CSSStyleSheet::setDisabled(bool disabled) | 215 void CSSStyleSheet::setDisabled(bool disabled) |
| 216 { | 216 { |
| 217 if (disabled == m_isDisabled) | 217 if (disabled == m_isDisabled) |
| 218 return; | 218 return; |
| 219 m_isDisabled = disabled; | 219 m_isDisabled = disabled; |
| 220 | 220 |
| 221 didMutate(); | 221 didMutate(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void CSSStyleSheet::setMediaQueries(PassRefPtrWillBeRawPtr<MediaQuerySet> mediaQ
ueries) | 224 void CSSStyleSheet::setMediaQueries(RawPtr<MediaQuerySet> mediaQueries) |
| 225 { | 225 { |
| 226 m_mediaQueries = mediaQueries; | 226 m_mediaQueries = mediaQueries; |
| 227 if (m_mediaCSSOMWrapper && m_mediaQueries) | 227 if (m_mediaCSSOMWrapper && m_mediaQueries) |
| 228 m_mediaCSSOMWrapper->reattach(m_mediaQueries.get()); | 228 m_mediaCSSOMWrapper->reattach(m_mediaQueries.get()); |
| 229 | 229 |
| 230 } | 230 } |
| 231 | 231 |
| 232 unsigned CSSStyleSheet::length() const | 232 unsigned CSSStyleSheet::length() const |
| 233 { | 233 { |
| 234 return m_contents->ruleCount(); | 234 return m_contents->ruleCount(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 CSSRule* CSSStyleSheet::item(unsigned index) | 237 CSSRule* CSSStyleSheet::item(unsigned index) |
| 238 { | 238 { |
| 239 unsigned ruleCount = length(); | 239 unsigned ruleCount = length(); |
| 240 if (index >= ruleCount) | 240 if (index >= ruleCount) |
| 241 return nullptr; | 241 return nullptr; |
| 242 | 242 |
| 243 if (m_childRuleCSSOMWrappers.isEmpty()) | 243 if (m_childRuleCSSOMWrappers.isEmpty()) |
| 244 m_childRuleCSSOMWrappers.grow(ruleCount); | 244 m_childRuleCSSOMWrappers.grow(ruleCount); |
| 245 ASSERT(m_childRuleCSSOMWrappers.size() == ruleCount); | 245 ASSERT(m_childRuleCSSOMWrappers.size() == ruleCount); |
| 246 | 246 |
| 247 RefPtrWillBeMember<CSSRule>& cssRule = m_childRuleCSSOMWrappers[index]; | 247 Member<CSSRule>& cssRule = m_childRuleCSSOMWrappers[index]; |
| 248 if (!cssRule) | 248 if (!cssRule) |
| 249 cssRule = m_contents->ruleAt(index)->createCSSOMWrapper(this); | 249 cssRule = m_contents->ruleAt(index)->createCSSOMWrapper(this); |
| 250 return cssRule.get(); | 250 return cssRule.get(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void CSSStyleSheet::clearOwnerNode() | 253 void CSSStyleSheet::clearOwnerNode() |
| 254 { | 254 { |
| 255 didMutate(EntireStyleSheetUpdate); | 255 didMutate(EntireStyleSheetUpdate); |
| 256 if (m_ownerNode) | 256 if (m_ownerNode) |
| 257 m_contents->unregisterClient(this); | 257 m_contents->unregisterClient(this); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 268 Document* document = ownerDocument(); | 268 Document* document = ownerDocument(); |
| 269 if (!document) | 269 if (!document) |
| 270 return true; | 270 return true; |
| 271 if (document->securityOrigin()->canRequestNoSuborigin(baseURL)) | 271 if (document->securityOrigin()->canRequestNoSuborigin(baseURL)) |
| 272 return true; | 272 return true; |
| 273 if (m_allowRuleAccessFromOrigin && document->securityOrigin()->canAccessChec
kSuborigins(m_allowRuleAccessFromOrigin.get())) | 273 if (m_allowRuleAccessFromOrigin && document->securityOrigin()->canAccessChec
kSuborigins(m_allowRuleAccessFromOrigin.get())) |
| 274 return true; | 274 return true; |
| 275 return false; | 275 return false; |
| 276 } | 276 } |
| 277 | 277 |
| 278 PassRefPtrWillBeRawPtr<CSSRuleList> CSSStyleSheet::rules() | 278 RawPtr<CSSRuleList> CSSStyleSheet::rules() |
| 279 { | 279 { |
| 280 return cssRules(); | 280 return cssRules(); |
| 281 } | 281 } |
| 282 | 282 |
| 283 unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, Exc
eptionState& exceptionState) | 283 unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, Exc
eptionState& exceptionState) |
| 284 { | 284 { |
| 285 ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size()
== m_contents->ruleCount()); | 285 ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size()
== m_contents->ruleCount()); |
| 286 | 286 |
| 287 if (index > length()) { | 287 if (index > length()) { |
| 288 exceptionState.throwDOMException(IndexSizeError, "The index provided ("
+ String::number(index) + ") is larger than the maximum index (" + String::numbe
r(length()) + ")."); | 288 exceptionState.throwDOMException(IndexSizeError, "The index provided ("
+ String::number(index) + ") is larger than the maximum index (" + String::numbe
r(length()) + ")."); |
| 289 return 0; | 289 return 0; |
| 290 } | 290 } |
| 291 CSSParserContext context(m_contents->parserContext(), UseCounter::getFrom(th
is)); | 291 CSSParserContext context(m_contents->parserContext(), UseCounter::getFrom(th
is)); |
| 292 RefPtrWillBeRawPtr<StyleRuleBase> rule = CSSParser::parseRule(context, m_con
tents.get(), ruleString); | 292 RawPtr<StyleRuleBase> rule = CSSParser::parseRule(context, m_contents.get(),
ruleString); |
| 293 | 293 |
| 294 if (!rule) { | 294 if (!rule) { |
| 295 exceptionState.throwDOMException(SyntaxError, "Failed to parse the rule
'" + ruleString + "'."); | 295 exceptionState.throwDOMException(SyntaxError, "Failed to parse the rule
'" + ruleString + "'."); |
| 296 return 0; | 296 return 0; |
| 297 } | 297 } |
| 298 RuleMutationScope mutationScope(this); | 298 RuleMutationScope mutationScope(this); |
| 299 | 299 |
| 300 bool success = m_contents->wrapperInsertRule(rule, index); | 300 bool success = m_contents->wrapperInsertRule(rule, index); |
| 301 if (!success) { | 301 if (!success) { |
| 302 if (rule->isNamespaceRule()) | 302 if (rule->isNamespaceRule()) |
| 303 exceptionState.throwDOMException(InvalidStateError, "Failed to inser
t the rule"); | 303 exceptionState.throwDOMException(InvalidStateError, "Failed to inser
t the rule"); |
| 304 else | 304 else |
| 305 exceptionState.throwDOMException(HierarchyRequestError, "Failed to i
nsert the rule."); | 305 exceptionState.throwDOMException(HierarchyRequestError, "Failed to i
nsert the rule."); |
| 306 return 0; | 306 return 0; |
| 307 } | 307 } |
| 308 if (!m_childRuleCSSOMWrappers.isEmpty()) | 308 if (!m_childRuleCSSOMWrappers.isEmpty()) |
| 309 m_childRuleCSSOMWrappers.insert(index, RefPtrWillBeMember<CSSRule>(nullp
tr)); | 309 m_childRuleCSSOMWrappers.insert(index, Member<CSSRule>(nullptr)); |
| 310 | 310 |
| 311 return index; | 311 return index; |
| 312 } | 312 } |
| 313 | 313 |
| 314 unsigned CSSStyleSheet::insertRule(const String& rule, ExceptionState& exception
State) | 314 unsigned CSSStyleSheet::insertRule(const String& rule, ExceptionState& exception
State) |
| 315 { | 315 { |
| 316 UseCounter::countDeprecation(currentExecutionContext(V8PerIsolateData::mainT
hreadIsolate()), UseCounter::CSSStyleSheetInsertRuleOptionalArg); | 316 UseCounter::countDeprecation(currentExecutionContext(V8PerIsolateData::mainT
hreadIsolate()), UseCounter::CSSStyleSheetInsertRuleOptionalArg); |
| 317 return insertRule(rule, 0, exceptionState); | 317 return insertRule(rule, 0, exceptionState); |
| 318 } | 318 } |
| 319 | 319 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // As per Microsoft documentation, always return -1. | 354 // As per Microsoft documentation, always return -1. |
| 355 return -1; | 355 return -1; |
| 356 } | 356 } |
| 357 | 357 |
| 358 int CSSStyleSheet::addRule(const String& selector, const String& style, Exceptio
nState& exceptionState) | 358 int CSSStyleSheet::addRule(const String& selector, const String& style, Exceptio
nState& exceptionState) |
| 359 { | 359 { |
| 360 return addRule(selector, style, length(), exceptionState); | 360 return addRule(selector, style, length(), exceptionState); |
| 361 } | 361 } |
| 362 | 362 |
| 363 | 363 |
| 364 PassRefPtrWillBeRawPtr<CSSRuleList> CSSStyleSheet::cssRules() | 364 RawPtr<CSSRuleList> CSSStyleSheet::cssRules() |
| 365 { | 365 { |
| 366 if (!canAccessRules()) | 366 if (!canAccessRules()) |
| 367 return nullptr; | 367 return nullptr; |
| 368 if (!m_ruleListCSSOMWrapper) | 368 if (!m_ruleListCSSOMWrapper) |
| 369 m_ruleListCSSOMWrapper = StyleSheetCSSRuleList::create(this); | 369 m_ruleListCSSOMWrapper = StyleSheetCSSRuleList::create(this); |
| 370 return m_ruleListCSSOMWrapper.get(); | 370 return m_ruleListCSSOMWrapper.get(); |
| 371 } | 371 } |
| 372 | 372 |
| 373 String CSSStyleSheet::href() const | 373 String CSSStyleSheet::href() const |
| 374 { | 374 { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 visitor->trace(m_mediaQueries); | 450 visitor->trace(m_mediaQueries); |
| 451 visitor->trace(m_ownerNode); | 451 visitor->trace(m_ownerNode); |
| 452 visitor->trace(m_ownerRule); | 452 visitor->trace(m_ownerRule); |
| 453 visitor->trace(m_mediaCSSOMWrapper); | 453 visitor->trace(m_mediaCSSOMWrapper); |
| 454 visitor->trace(m_childRuleCSSOMWrappers); | 454 visitor->trace(m_childRuleCSSOMWrappers); |
| 455 visitor->trace(m_ruleListCSSOMWrapper); | 455 visitor->trace(m_ruleListCSSOMWrapper); |
| 456 StyleSheet::trace(visitor); | 456 StyleSheet::trace(visitor); |
| 457 } | 457 } |
| 458 | 458 |
| 459 } // namespace blink | 459 } // namespace blink |
| OLD | NEW |