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

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

Issue 1295903005: [DevTools] Implementation of resource requests blocked by specific urls. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 typedef blink::InspectorBackendDispatcher::NetworkCommandHandler::GetResponseBod yCallback GetResponseBodyCallback; 78 typedef blink::InspectorBackendDispatcher::NetworkCommandHandler::GetResponseBod yCallback GetResponseBodyCallback;
79 79
80 namespace blink { 80 namespace blink {
81 81
82 namespace ResourceAgentState { 82 namespace ResourceAgentState {
83 static const char resourceAgentEnabled[] = "resourceAgentEnabled"; 83 static const char resourceAgentEnabled[] = "resourceAgentEnabled";
84 static const char extraRequestHeaders[] = "extraRequestHeaders"; 84 static const char extraRequestHeaders[] = "extraRequestHeaders";
85 static const char cacheDisabled[] = "cacheDisabled"; 85 static const char cacheDisabled[] = "cacheDisabled";
86 static const char userAgentOverride[] = "userAgentOverride"; 86 static const char userAgentOverride[] = "userAgentOverride";
87 static const char monitoringXHR[] = "monitoringXHR"; 87 static const char monitoringXHR[] = "monitoringXHR";
88 static const char blockedURLs[] = "blockedURLs";
88 } 89 }
89 90
90 namespace { 91 namespace {
91 92
92 // Keep in sync with kDevToolsRequestInitiator defined in devtools_network_contr oller.cc 93 // Keep in sync with kDevToolsRequestInitiator defined in devtools_network_contr oller.cc
93 const char kDevToolsEmulateNetworkConditionsClientId[] = "X-DevTools-Emulate-Net work-Conditions-Client-Id"; 94 const char kDevToolsEmulateNetworkConditionsClientId[] = "X-DevTools-Emulate-Net work-Conditions-Client-Id";
94 95
95 static PassRefPtr<JSONObject> buildObjectForHeaders(const HTTPHeaderMap& headers ) 96 static PassRefPtr<JSONObject> buildObjectForHeaders(const HTTPHeaderMap& headers )
96 { 97 {
97 RefPtr<JSONObject> headersObject = JSONObject::create(); 98 RefPtr<JSONObject> headersObject = JSONObject::create();
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 343
343 DEFINE_TRACE(InspectorResourceAgent) 344 DEFINE_TRACE(InspectorResourceAgent)
344 { 345 {
345 visitor->trace(m_pageAgent); 346 visitor->trace(m_pageAgent);
346 visitor->trace(m_replayXHRs); 347 visitor->trace(m_replayXHRs);
347 visitor->trace(m_replayXHRsToBeDeleted); 348 visitor->trace(m_replayXHRsToBeDeleted);
348 visitor->trace(m_pendingXHRReplayData); 349 visitor->trace(m_pendingXHRReplayData);
349 InspectorBaseAgent::trace(visitor); 350 InspectorBaseAgent::trace(visitor);
350 } 351 }
351 352
353 bool InspectorResourceAgent::shouldBlockRequest(const ResourceRequest& request)
354 {
355 String url = request.url().string();
356 RefPtr<JSONObject> blockedURLs = m_state->getObject(ResourceAgentState::bloc kedURLs);
357 for (const auto& blocked : *blockedURLs) {
358 if (url.contains(blocked.key))
359 return true;
360 }
361 return false;
362 }
363
352 void InspectorResourceAgent::willSendRequest(unsigned long identifier, DocumentL oader* loader, ResourceRequest& request, const ResourceResponse& redirectRespons e, const FetchInitiatorInfo& initiatorInfo) 364 void InspectorResourceAgent::willSendRequest(unsigned long identifier, DocumentL oader* loader, ResourceRequest& request, const ResourceResponse& redirectRespons e, const FetchInitiatorInfo& initiatorInfo)
353 { 365 {
354 // Ignore the request initiated internally. 366 // Ignore the request initiated internally.
355 if (initiatorInfo.name == FetchInitiatorTypeNames::internal) 367 if (initiatorInfo.name == FetchInitiatorTypeNames::internal)
356 return; 368 return;
357 369
358 if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader->subst ituteData().isValid()) 370 if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader->subst ituteData().isValid())
359 return; 371 return;
360 372
361 String requestId = IdentifiersFactory::requestId(identifier); 373 String requestId = IdentifiersFactory::requestId(identifier);
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 return; 869 return;
858 } 870 }
859 } 871 }
860 872
861 if (getResponseBodyBlob(requestId, callback)) 873 if (getResponseBodyBlob(requestId, callback))
862 return; 874 return;
863 875
864 callback->sendFailure("No data found for resource with given identifier"); 876 callback->sendFailure("No data found for resource with given identifier");
865 } 877 }
866 878
879 void InspectorResourceAgent::addBlockedURL(ErrorString*, const String& url)
880 {
881 RefPtr<JSONObject> blockedURLs = m_state->getObject(ResourceAgentState::bloc kedURLs);
882 blockedURLs->setBoolean(url, true);
883 m_state->setObject(ResourceAgentState::blockedURLs, blockedURLs.release());
884 }
885
886 void InspectorResourceAgent::removeBlockedURL(ErrorString*, const String& url)
887 {
888 RefPtr<JSONObject> blockedURLs = m_state->getObject(ResourceAgentState::bloc kedURLs);
889 blockedURLs->remove(url);
890 m_state->setObject(ResourceAgentState::blockedURLs, blockedURLs.release());
891 }
892
867 void InspectorResourceAgent::replayXHR(ErrorString*, const String& requestId) 893 void InspectorResourceAgent::replayXHR(ErrorString*, const String& requestId)
868 { 894 {
869 String actualRequestId = requestId; 895 String actualRequestId = requestId;
870 896
871 XHRReplayData* xhrReplayData = m_resourcesData->xhrReplayData(requestId); 897 XHRReplayData* xhrReplayData = m_resourcesData->xhrReplayData(requestId);
872 if (!xhrReplayData) 898 if (!xhrReplayData)
873 return; 899 return;
874 900
875 ExecutionContext* executionContext = xhrReplayData->executionContext(); 901 ExecutionContext* executionContext = xhrReplayData->executionContext();
876 if (!executionContext) { 902 if (!executionContext) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired) 1014 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired)
989 { 1015 {
990 } 1016 }
991 1017
992 bool InspectorResourceAgent::shouldForceCORSPreflight() 1018 bool InspectorResourceAgent::shouldForceCORSPreflight()
993 { 1019 {
994 return m_state->getBoolean(ResourceAgentState::cacheDisabled); 1020 return m_state->getBoolean(ResourceAgentState::cacheDisabled);
995 } 1021 }
996 1022
997 } // namespace blink 1023 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698