| 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, |
| 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/StyleSheetContents.h" | 22 #include "core/css/StyleSheetContents.h" |
| 23 | 23 |
| 24 #include "core/css/parser/BisonCSSParser.h" |
| 24 #include "core/css/CSSStyleSheet.h" | 25 #include "core/css/CSSStyleSheet.h" |
| 25 #include "core/css/MediaList.h" | 26 #include "core/css/MediaList.h" |
| 26 #include "core/css/StylePropertySet.h" | 27 #include "core/css/StylePropertySet.h" |
| 27 #include "core/css/StyleRule.h" | 28 #include "core/css/StyleRule.h" |
| 28 #include "core/css/StyleRuleImport.h" | 29 #include "core/css/StyleRuleImport.h" |
| 29 #include "core/css/parser/CSSParser.h" | |
| 30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
| 31 #include "core/dom/Node.h" | 31 #include "core/dom/Node.h" |
| 32 #include "core/dom/StyleEngine.h" | 32 #include "core/dom/StyleEngine.h" |
| 33 #include "core/fetch/CSSStyleSheetResource.h" | 33 #include "core/fetch/CSSStyleSheetResource.h" |
| 34 #include "core/frame/UseCounter.h" | 34 #include "core/frame/UseCounter.h" |
| 35 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
| 36 #include "platform/weborigin/SecurityOrigin.h" | 36 #include "platform/weborigin/SecurityOrigin.h" |
| 37 #include "wtf/Deque.h" | 37 #include "wtf/Deque.h" |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 { | 320 { |
| 321 TRACE_EVENT0("blink", "StyleSheetContents::parseAuthorStyleSheet"); | 321 TRACE_EVENT0("blink", "StyleSheetContents::parseAuthorStyleSheet"); |
| 322 | 322 |
| 323 bool quirksMode = isQuirksModeBehavior(m_parserContext.mode()); | 323 bool quirksMode = isQuirksModeBehavior(m_parserContext.mode()); |
| 324 | 324 |
| 325 bool enforceMIMEType = !quirksMode; | 325 bool enforceMIMEType = !quirksMode; |
| 326 bool hasValidMIMEType = false; | 326 bool hasValidMIMEType = false; |
| 327 String sheetText = cachedStyleSheet->sheetText(enforceMIMEType, &hasValidMIM
EType); | 327 String sheetText = cachedStyleSheet->sheetText(enforceMIMEType, &hasValidMIM
EType); |
| 328 | 328 |
| 329 CSSParserContext context(parserContext(), UseCounter::getFrom(this)); | 329 CSSParserContext context(parserContext(), UseCounter::getFrom(this)); |
| 330 CSSParser::parseSheet(context, this, sheetText, TextPosition::minimumPositio
n(), 0, true); | 330 BisonCSSParser p(context); |
| 331 p.parseSheet(this, sheetText, TextPosition::minimumPosition(), 0, true); |
| 331 | 332 |
| 332 // If we're loading a stylesheet cross-origin, and the MIME type is not stan
dard, require the CSS | 333 // If we're loading a stylesheet cross-origin, and the MIME type is not stan
dard, require the CSS |
| 333 // to at least start with a syntactically valid CSS rule. | 334 // to at least start with a syntactically valid CSS rule. |
| 334 // This prevents an attacker playing games by injecting CSS strings into HTM
L, XML, JSON, etc. etc. | 335 // This prevents an attacker playing games by injecting CSS strings into HTM
L, XML, JSON, etc. etc. |
| 335 if (!hasValidMIMEType && !hasSyntacticallyValidCSSHeader()) { | 336 if (!hasValidMIMEType && !hasSyntacticallyValidCSSHeader()) { |
| 336 bool isCrossOriginCSS = !securityOrigin || !securityOrigin->canRequest(b
aseURL()); | 337 bool isCrossOriginCSS = !securityOrigin || !securityOrigin->canRequest(b
aseURL()); |
| 337 if (isCrossOriginCSS) { | 338 if (isCrossOriginCSS) { |
| 338 clearRules(); | 339 clearRules(); |
| 339 return; | 340 return; |
| 340 } | 341 } |
| 341 } | 342 } |
| 342 } | 343 } |
| 343 | 344 |
| 344 bool StyleSheetContents::parseString(const String& sheetText) | 345 bool StyleSheetContents::parseString(const String& sheetText) |
| 345 { | 346 { |
| 346 return parseStringAtPosition(sheetText, TextPosition::minimumPosition(), fal
se); | 347 return parseStringAtPosition(sheetText, TextPosition::minimumPosition(), fal
se); |
| 347 } | 348 } |
| 348 | 349 |
| 349 bool StyleSheetContents::parseStringAtPosition(const String& sheetText, const Te
xtPosition& startPosition, bool createdByParser) | 350 bool StyleSheetContents::parseStringAtPosition(const String& sheetText, const Te
xtPosition& startPosition, bool createdByParser) |
| 350 { | 351 { |
| 351 CSSParserContext context(parserContext(), UseCounter::getFrom(this)); | 352 CSSParserContext context(parserContext(), UseCounter::getFrom(this)); |
| 352 CSSParser::parseSheet(context, this, sheetText, startPosition, 0, createdByP
arser); | 353 BisonCSSParser p(context); |
| 354 p.parseSheet(this, sheetText, startPosition, 0, createdByParser); |
| 353 | 355 |
| 354 return true; | 356 return true; |
| 355 } | 357 } |
| 356 | 358 |
| 357 bool StyleSheetContents::isLoading() const | 359 bool StyleSheetContents::isLoading() const |
| 358 { | 360 { |
| 359 for (unsigned i = 0; i < m_importRules.size(); ++i) { | 361 for (unsigned i = 0; i < m_importRules.size(); ++i) { |
| 360 if (m_importRules[i]->isLoading()) | 362 if (m_importRules[i]->isLoading()) |
| 361 return true; | 363 return true; |
| 362 } | 364 } |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 visitor->trace(m_ownerRule); | 689 visitor->trace(m_ownerRule); |
| 688 visitor->trace(m_importRules); | 690 visitor->trace(m_importRules); |
| 689 visitor->trace(m_childRules); | 691 visitor->trace(m_childRules); |
| 690 visitor->trace(m_loadingClients); | 692 visitor->trace(m_loadingClients); |
| 691 visitor->trace(m_completedClients); | 693 visitor->trace(m_completedClients); |
| 692 visitor->trace(m_ruleSet); | 694 visitor->trace(m_ruleSet); |
| 693 #endif | 695 #endif |
| 694 } | 696 } |
| 695 | 697 |
| 696 } | 698 } |
| OLD | NEW |