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