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

Side by Side Diff: Source/core/inspector/InspectorStyleSheet.cpp

Issue 15832007: DevTools: Add support for //# sourceURL (sourceMappingURL) comments and deprecate //@ ones (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "core/dom/Document.h" 48 #include "core/dom/Document.h"
49 #include "core/dom/Element.h" 49 #include "core/dom/Element.h"
50 #include "core/dom/Node.h" 50 #include "core/dom/Node.h"
51 #include "core/html/HTMLHeadElement.h" 51 #include "core/html/HTMLHeadElement.h"
52 #include "core/html/parser/HTMLParserIdioms.h" 52 #include "core/html/parser/HTMLParserIdioms.h"
53 #include "core/inspector/ContentSearchUtils.h" 53 #include "core/inspector/ContentSearchUtils.h"
54 #include "core/inspector/InspectorCSSAgent.h" 54 #include "core/inspector/InspectorCSSAgent.h"
55 #include "core/inspector/InspectorPageAgent.h" 55 #include "core/inspector/InspectorPageAgent.h"
56 #include "core/inspector/InspectorValues.h" 56 #include "core/inspector/InspectorValues.h"
57 #include "core/page/ContentSecurityPolicy.h" 57 #include "core/page/ContentSecurityPolicy.h"
58 #include "core/page/PageConsole.h"
58 #include "core/platform/text/RegularExpression.h" 59 #include "core/platform/text/RegularExpression.h"
59 60
60 #include <wtf/OwnPtr.h> 61 #include <wtf/OwnPtr.h>
61 #include <wtf/PassOwnPtr.h> 62 #include <wtf/PassOwnPtr.h>
62 #include <wtf/text/StringBuilder.h> 63 #include <wtf/text/StringBuilder.h>
63 #include <wtf/Vector.h> 64 #include <wtf/Vector.h>
64 65
65 using WebCore::TypeBuilder::Array; 66 using WebCore::TypeBuilder::Array;
66 using WebCore::RuleSourceDataList; 67 using WebCore::RuleSourceDataList;
67 using WebCore::CSSRuleSourceData; 68 using WebCore::CSSRuleSourceData;
(...skipping 1410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 if (!m_sourceURL.isNull()) 1479 if (!m_sourceURL.isNull())
1479 return m_sourceURL; 1480 return m_sourceURL;
1480 if (m_origin != TypeBuilder::CSS::StyleSheetOrigin::Regular) { 1481 if (m_origin != TypeBuilder::CSS::StyleSheetOrigin::Regular) {
1481 m_sourceURL = ""; 1482 m_sourceURL = "";
1482 return m_sourceURL; 1483 return m_sourceURL;
1483 } 1484 }
1484 1485
1485 String styleSheetText; 1486 String styleSheetText;
1486 bool success = getText(&styleSheetText); 1487 bool success = getText(&styleSheetText);
1487 if (success) { 1488 if (success) {
1488 String commentValue = ContentSearchUtils::findSourceURL(styleSheetText, ContentSearchUtils::CSSMagicComment); 1489 bool deprecated;
1490 String commentValue = ContentSearchUtils::findSourceURL(styleSheetText, ContentSearchUtils::CSSMagicComment, &deprecated);
1489 if (!commentValue.isEmpty()) { 1491 if (!commentValue.isEmpty()) {
1492 if (deprecated)
1493 m_pageAgent->page()->console()->addMessage(NetworkMessageSource, WarningMessageLevel, "\"/*@ sourceURL=\" source url declaration is deprecated, \"/*# sourceURL=\" declaration should be used instead.", finalURL(), 0);
apavlov 2013/05/29 13:58:05 We need a kind of utility for this :(
1490 m_sourceURL = commentValue; 1494 m_sourceURL = commentValue;
1491 return m_sourceURL; 1495 return commentValue;
1492 } 1496 }
1493 } 1497 }
1494 m_sourceURL = ""; 1498 m_sourceURL = "";
1495 return m_sourceURL; 1499 return m_sourceURL;
1496 } 1500 }
1497 1501
1498 String InspectorStyleSheet::url() const 1502 String InspectorStyleSheet::url() const
1499 { 1503 {
1500 // "sourceURL" is present only for regular rules, otherwise "origin" should be used in the frontend. 1504 // "sourceURL" is present only for regular rules, otherwise "origin" should be used in the frontend.
1501 if (m_origin != TypeBuilder::CSS::StyleSheetOrigin::Regular) 1505 if (m_origin != TypeBuilder::CSS::StyleSheetOrigin::Regular)
(...skipping 21 matching lines...) Expand all
1523 { 1527 {
1524 CSSStyleSheet* styleSheet = pageStyleSheet(); 1528 CSSStyleSheet* styleSheet = pageStyleSheet();
1525 if (!styleSheet) 1529 if (!styleSheet)
1526 return true; 1530 return true;
1527 1531
1528 return styleSheet->startPositionInSource() == TextPosition::minimumPosition( ); 1532 return styleSheet->startPositionInSource() == TextPosition::minimumPosition( );
1529 } 1533 }
1530 1534
1531 String InspectorStyleSheet::sourceMapURL() const 1535 String InspectorStyleSheet::sourceMapURL() const
1532 { 1536 {
1533 DEFINE_STATIC_LOCAL(String, sourceMapHttpHeader, (ASCIILiteral("X-SourceMap" )));
1534
1535 if (m_origin != TypeBuilder::CSS::StyleSheetOrigin::Regular) 1537 if (m_origin != TypeBuilder::CSS::StyleSheetOrigin::Regular)
1536 return String(); 1538 return String();
1537 1539
1538 String styleSheetText; 1540 String styleSheetText;
1539 bool success = getText(&styleSheetText); 1541 bool success = getText(&styleSheetText);
1540 if (success) { 1542 if (success) {
1541 String commentValue = ContentSearchUtils::findSourceMapURL(styleSheetTex t, ContentSearchUtils::CSSMagicComment); 1543 bool deprecated;
1542 if (!commentValue.isEmpty()) 1544 String commentValue = ContentSearchUtils::findSourceMapURL(styleSheetTex t, ContentSearchUtils::CSSMagicComment, &deprecated);
1545 if (!commentValue.isEmpty()) {
1546 if (deprecated)
1547 m_pageAgent->page()->console()->addMessage(NetworkMessageSource, WarningMessageLevel, "\"/*@ sourceMapURL=\" source mapping url declaration is d eprecated, \"/*# sourceMapURL=\" declaration should be used instead.", finalURL( ), 0);
1543 return commentValue; 1548 return commentValue;
1549 }
1544 } 1550 }
1545 1551 return m_pageAgent->resourceSourceMapURL(finalURL());
1546 if (finalURL().isEmpty())
1547 return String();
1548
1549 CachedResource* resource = m_pageAgent->cachedResource(m_pageAgent->mainFram e(), KURL(ParsedURLString, finalURL()));
1550 if (resource)
1551 return resource->response().httpHeaderField(sourceMapHttpHeader);
1552 return String();
1553 } 1552 }
1554 1553
1555 InspectorCSSId InspectorStyleSheet::ruleOrStyleId(CSSStyleDeclaration* style) co nst 1554 InspectorCSSId InspectorStyleSheet::ruleOrStyleId(CSSStyleDeclaration* style) co nst
1556 { 1555 {
1557 unsigned index = ruleIndexByStyle(style); 1556 unsigned index = ruleIndexByStyle(style);
1558 if (index != UINT_MAX) 1557 if (index != UINT_MAX)
1559 return InspectorCSSId(id(), index); 1558 return InspectorCSSId(id(), index);
1560 return InspectorCSSId(); 1559 return InspectorCSSId();
1561 } 1560 }
1562 1561
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 1896
1898 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c reate(); 1897 RefPtr<MutableStylePropertySet> tempDeclaration = MutableStylePropertySet::c reate();
1899 RuleSourceDataList ruleSourceDataResult; 1898 RuleSourceDataList ruleSourceDataResult;
1900 StyleSheetHandler handler(m_styleText, m_element->document(), m_element->doc ument()->elementSheet()->contents(), &ruleSourceDataResult); 1899 StyleSheetHandler handler(m_styleText, m_element->document(), m_element->doc ument()->elementSheet()->contents(), &ruleSourceDataResult);
1901 createCSSParser(m_element->document())->parseDeclaration(tempDeclaration.get (), m_styleText, &handler, m_element->document()->elementSheet()->contents()); 1900 createCSSParser(m_element->document())->parseDeclaration(tempDeclaration.get (), m_styleText, &handler, m_element->document()->elementSheet()->contents());
1902 return ruleSourceDataResult.first().release(); 1901 return ruleSourceDataResult.first().release();
1903 } 1902 }
1904 1903
1905 } // namespace WebCore 1904 } // namespace WebCore
1906 1905
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698