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

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp

Issue 2178153004: [DevTools] Do not expose findSource{Map}URL from v8_inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove more String16 Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp
diff --git a/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp b/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp
index 1fdc7f4497f84385b14bb552c52501f4bfd5316f..3831b62c180e98e02161799333e4f6d0d342fcae 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorStyleSheet.cpp
@@ -52,7 +52,6 @@
#include "core/inspector/InspectorNetworkAgent.h"
#include "core/inspector/InspectorResourceContainer.h"
#include "core/svg/SVGStyleElement.h"
-#include "platform/v8_inspector/public/V8ContentSearchUtil.h"
#include "wtf/PtrUtil.h"
#include "wtf/text/StringBuilder.h"
#include "wtf/text/TextPosition.h"
@@ -72,6 +71,68 @@ static CSSParserContext parserContextForDocument(Document *document)
return document ? CSSParserContext(*document, nullptr) : strictCSSParserContext();
}
+String findMagicComment(const String& content, const String& name)
+{
+ DCHECK(name.find("=") == kNotFound);
+
+ unsigned length = content.length();
+ unsigned nameLength = name.length();
+ const bool multiline = true;
+
+ size_t pos = length;
+ size_t equalSignPos = 0;
+ size_t closingCommentPos = 0;
+ while (true) {
+ pos = content.reverseFind(name, pos);
+ if (pos == kNotFound)
+ return emptyString();
+
+ // Check for a /\/[\/*][@#][ \t]/ regexp (length of 4) before found name.
+ if (pos < 4)
+ return emptyString();
+ pos -= 4;
+ if (content[pos] != '/')
+ continue;
+ if ((content[pos + 1] != '/' || multiline)
+ && (content[pos + 1] != '*' || !multiline))
+ continue;
+ if (content[pos + 2] != '#' && content[pos + 2] != '@')
+ continue;
+ if (content[pos + 3] != ' ' && content[pos + 3] != '\t')
+ continue;
+ equalSignPos = pos + 4 + nameLength;
+ if (equalSignPos < length && content[equalSignPos] != '=')
+ continue;
+ if (multiline) {
+ closingCommentPos = content.find("*/", equalSignPos + 1);
+ if (closingCommentPos == kNotFound)
+ return emptyString();
+ }
+
+ break;
+ }
+
+ DCHECK(equalSignPos);
+ DCHECK(!multiline || closingCommentPos);
+ size_t urlPos = equalSignPos + 1;
+ String match = multiline
+ ? content.substring(urlPos, closingCommentPos - urlPos)
+ : content.substring(urlPos);
+
+ size_t newLine = match.find("\n");
+ if (newLine != kNotFound)
+ match = match.substring(0, newLine);
+ match = match.stripWhiteSpace();
+
+ String disallowedChars("\"' \t");
+ for (unsigned i = 0; i < match.length(); ++i) {
+ if (disallowedChars.find(match[i]) != kNotFound)
+ return emptyString();
+ }
+
+ return match;
+}
+
class StyleSheetHandler final : public CSSParserObserver {
public:
StyleSheetHandler(const String& parsedText, Document* document, RuleSourceDataList* result)
@@ -1482,8 +1543,7 @@ String InspectorStyleSheet::sourceURL()
String styleSheetText;
bool success = getText(&styleSheetText);
if (success) {
- bool deprecated = false;
- String commentValue = V8ContentSearchUtil::findSourceURL(styleSheetText, true, &deprecated);
+ String commentValue = findMagicComment(styleSheetText, "sourceURL");
if (!commentValue.isEmpty()) {
m_sourceURL = commentValue;
return commentValue;
@@ -1534,8 +1594,7 @@ String InspectorStyleSheet::sourceMapURL()
String styleSheetText;
bool success = getText(&styleSheetText);
if (success) {
- bool deprecated = false;
- String commentValue = V8ContentSearchUtil::findSourceMapURL(styleSheetText, true, &deprecated);
+ String commentValue = findMagicComment(styleSheetText, "sourceMappingURL");
if (!commentValue.isEmpty())
return commentValue;
}
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698