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

Unified Diff: Source/core/inspector/InspectorResourceAgent.cpp

Issue 1328273003: [DevTools] Allow stars in blocked url pattern. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fprintf Created 5 years, 3 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 | « LayoutTests/http/tests/inspector/network/network-blocked-reason-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/InspectorResourceAgent.cpp
diff --git a/Source/core/inspector/InspectorResourceAgent.cpp b/Source/core/inspector/InspectorResourceAgent.cpp
index 8aec85c9d0b3695925377e18911f1eced012a139..31a4c054726ce33f600f0485ef752921fe62c508 100644
--- a/Source/core/inspector/InspectorResourceAgent.cpp
+++ b/Source/core/inspector/InspectorResourceAgent.cpp
@@ -95,6 +95,22 @@ namespace {
// Keep in sync with kDevToolsRequestInitiator defined in devtools_network_controller.cc
const char kDevToolsEmulateNetworkConditionsClientId[] = "X-DevTools-Emulate-Network-Conditions-Client-Id";
+// Pattern may contain stars ('*') which match to any (possibly empty) string.
+// Stars implicitly assumed at the begin/end of pattern.
+bool matches(const String& url, const String& pattern)
+{
+ Vector<String> parts;
+ pattern.split("*", parts);
+ size_t pos = 0;
+ for (const String& part : parts) {
+ pos = url.find(part, pos);
+ if (pos == kNotFound)
+ return false;
+ pos += part.length();
+ }
+ return true;
+}
+
static PassRefPtr<JSONObject> buildObjectForHeaders(const HTTPHeaderMap& headers)
{
RefPtr<JSONObject> headersObject = JSONObject::create();
@@ -407,7 +423,7 @@ bool InspectorResourceAgent::shouldBlockRequest(const ResourceRequest& request)
String url = request.url().string();
RefPtr<JSONObject> blockedURLs = m_state->getObject(ResourceAgentState::blockedURLs);
for (const auto& entry : *blockedURLs) {
- if (url.contains(entry.key))
+ if (matches(url, entry.key))
return true;
}
return false;
« no previous file with comments | « LayoutTests/http/tests/inspector/network/network-blocked-reason-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698