Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: Source/core/css/CSSStyleSheet.cpp

Issue 756313002: Remove CSSCharsetRule (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: tests Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/css/CSSGroupingRule.cpp ('k') | Source/core/css/StyleRule.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #include "config.h" 21 #include "config.h"
22 #include "core/css/CSSStyleSheet.h" 22 #include "core/css/CSSStyleSheet.h"
23 23
24 #include "bindings/core/v8/ExceptionState.h" 24 #include "bindings/core/v8/ExceptionState.h"
25 #include "bindings/core/v8/V8Binding.h" 25 #include "bindings/core/v8/V8Binding.h"
26 #include "bindings/core/v8/V8PerIsolateData.h" 26 #include "bindings/core/v8/V8PerIsolateData.h"
27 #include "core/HTMLNames.h" 27 #include "core/HTMLNames.h"
28 #include "core/SVGNames.h" 28 #include "core/SVGNames.h"
29 #include "core/css/CSSCharsetRule.h"
30 #include "core/css/CSSImportRule.h" 29 #include "core/css/CSSImportRule.h"
31 #include "core/css/CSSRuleList.h" 30 #include "core/css/CSSRuleList.h"
32 #include "core/css/MediaList.h" 31 #include "core/css/MediaList.h"
33 #include "core/css/StyleRule.h" 32 #include "core/css/StyleRule.h"
34 #include "core/css/StyleSheetContents.h" 33 #include "core/css/StyleSheetContents.h"
35 #include "core/css/parser/CSSParser.h" 34 #include "core/css/parser/CSSParser.h"
36 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
37 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
38 #include "core/dom/Node.h" 37 #include "core/dom/Node.h"
39 #include "core/frame/UseCounter.h" 38 #include "core/frame/UseCounter.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 { 244 {
246 unsigned ruleCount = length(); 245 unsigned ruleCount = length();
247 if (index >= ruleCount) 246 if (index >= ruleCount)
248 return 0; 247 return 0;
249 248
250 if (m_childRuleCSSOMWrappers.isEmpty()) 249 if (m_childRuleCSSOMWrappers.isEmpty())
251 m_childRuleCSSOMWrappers.grow(ruleCount); 250 m_childRuleCSSOMWrappers.grow(ruleCount);
252 ASSERT(m_childRuleCSSOMWrappers.size() == ruleCount); 251 ASSERT(m_childRuleCSSOMWrappers.size() == ruleCount);
253 252
254 RefPtrWillBeMember<CSSRule>& cssRule = m_childRuleCSSOMWrappers[index]; 253 RefPtrWillBeMember<CSSRule>& cssRule = m_childRuleCSSOMWrappers[index];
255 if (!cssRule) { 254 if (!cssRule)
256 if (index == 0 && m_contents->hasCharsetRule()) { 255 cssRule = m_contents->ruleAt(index)->createCSSOMWrapper(this);
257 ASSERT(!m_contents->ruleAt(0));
258 cssRule = CSSCharsetRule::create(this, m_contents->encodingFromChars etRule());
259 } else
260 cssRule = m_contents->ruleAt(index)->createCSSOMWrapper(this);
261 }
262 return cssRule.get(); 256 return cssRule.get();
263 } 257 }
264 258
265 void CSSStyleSheet::clearOwnerNode() 259 void CSSStyleSheet::clearOwnerNode()
266 { 260 {
267 didMutate(EntireStyleSheetUpdate); 261 didMutate(EntireStyleSheetUpdate);
268 if (m_ownerNode) 262 if (m_ownerNode)
269 m_contents->unregisterClient(this); 263 m_contents->unregisterClient(this);
270 m_ownerNode = nullptr; 264 m_ownerNode = nullptr;
271 } 265 }
272 266
273 bool CSSStyleSheet::canAccessRules() const 267 bool CSSStyleSheet::canAccessRules() const
274 { 268 {
275 if (m_isInlineStylesheet) 269 if (m_isInlineStylesheet)
276 return true; 270 return true;
277 KURL baseURL = m_contents->baseURL(); 271 KURL baseURL = m_contents->baseURL();
278 if (baseURL.isEmpty()) 272 if (baseURL.isEmpty())
279 return true; 273 return true;
280 Document* document = ownerDocument(); 274 Document* document = ownerDocument();
281 if (!document) 275 if (!document)
282 return true; 276 return true;
283 if (document->securityOrigin()->canRequest(baseURL)) 277 if (document->securityOrigin()->canRequest(baseURL))
284 return true; 278 return true;
285 return false; 279 return false;
286 } 280 }
287 281
288 PassRefPtrWillBeRawPtr<CSSRuleList> CSSStyleSheet::rules() 282 PassRefPtrWillBeRawPtr<CSSRuleList> CSSStyleSheet::rules()
289 { 283 {
290 if (!canAccessRules()) 284 return cssRules();
291 return nullptr;
292 // IE behavior.
293 RefPtrWillBeRawPtr<StaticCSSRuleList> nonCharsetRules(StaticCSSRuleList::cre ate());
294 unsigned ruleCount = length();
295 for (unsigned i = 0; i < ruleCount; ++i) {
296 CSSRule* rule = item(i);
297 if (rule->type() == CSSRule::CHARSET_RULE)
298 continue;
299 nonCharsetRules->rules().append(rule);
300 }
301 return nonCharsetRules.release();
302 } 285 }
303 286
304 unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, Exc eptionState& exceptionState) 287 unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, Exc eptionState& exceptionState)
305 { 288 {
306 ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size() == m_contents->ruleCount()); 289 ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size() == m_contents->ruleCount());
307 290
308 if (index > length()) { 291 if (index > length()) {
309 exceptionState.throwDOMException(IndexSizeError, "The index provided (" + String::number(index) + ") is larger than the maximum index (" + String::numbe r(length()) + ")."); 292 exceptionState.throwDOMException(IndexSizeError, "The index provided (" + String::number(index) + ") is larger than the maximum index (" + String::numbe r(length()) + ").");
310 return 0; 293 return 0;
311 } 294 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 visitor->trace(m_mediaQueries); 442 visitor->trace(m_mediaQueries);
460 visitor->trace(m_ownerNode); 443 visitor->trace(m_ownerNode);
461 visitor->trace(m_ownerRule); 444 visitor->trace(m_ownerRule);
462 visitor->trace(m_mediaCSSOMWrapper); 445 visitor->trace(m_mediaCSSOMWrapper);
463 visitor->trace(m_childRuleCSSOMWrappers); 446 visitor->trace(m_childRuleCSSOMWrappers);
464 visitor->trace(m_ruleListCSSOMWrapper); 447 visitor->trace(m_ruleListCSSOMWrapper);
465 StyleSheet::trace(visitor); 448 StyleSheet::trace(visitor);
466 } 449 }
467 450
468 } // namespace blink 451 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/CSSGroupingRule.cpp ('k') | Source/core/css/StyleRule.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698