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

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: rebase 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 typedef blink::InspectorBackendDispatcher::NetworkCommandHandler::GetResponseBod yCallback GetResponseBodyCallback; 79 typedef blink::InspectorBackendDispatcher::NetworkCommandHandler::GetResponseBod yCallback GetResponseBodyCallback;
80 80
81 namespace blink { 81 namespace blink {
82 82
83 namespace ResourceAgentState { 83 namespace ResourceAgentState {
84 static const char resourceAgentEnabled[] = "resourceAgentEnabled"; 84 static const char resourceAgentEnabled[] = "resourceAgentEnabled";
85 static const char extraRequestHeaders[] = "extraRequestHeaders"; 85 static const char extraRequestHeaders[] = "extraRequestHeaders";
86 static const char cacheDisabled[] = "cacheDisabled"; 86 static const char cacheDisabled[] = "cacheDisabled";
87 static const char userAgentOverride[] = "userAgentOverride"; 87 static const char userAgentOverride[] = "userAgentOverride";
88 static const char monitoringXHR[] = "monitoringXHR"; 88 static const char monitoringXHR[] = "monitoringXHR";
89 static const char blockedURLs[] = "blockedURLs";
89 } 90 }
90 91
91 namespace { 92 namespace {
92 93
93 // Keep in sync with kDevToolsRequestInitiator defined in devtools_network_contr oller.cc 94 // Keep in sync with kDevToolsRequestInitiator defined in devtools_network_contr oller.cc
94 const char kDevToolsEmulateNetworkConditionsClientId[] = "X-DevTools-Emulate-Net work-Conditions-Client-Id"; 95 const char kDevToolsEmulateNetworkConditionsClientId[] = "X-DevTools-Emulate-Net work-Conditions-Client-Id";
95 96
96 static PassRefPtr<JSONObject> buildObjectForHeaders(const HTTPHeaderMap& headers ) 97 static PassRefPtr<JSONObject> buildObjectForHeaders(const HTTPHeaderMap& headers )
97 { 98 {
98 RefPtr<JSONObject> headersObject = JSONObject::create(); 99 RefPtr<JSONObject> headersObject = JSONObject::create();
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 359
359 DEFINE_TRACE(InspectorResourceAgent) 360 DEFINE_TRACE(InspectorResourceAgent)
360 { 361 {
361 visitor->trace(m_pageAgent); 362 visitor->trace(m_pageAgent);
362 visitor->trace(m_replayXHRs); 363 visitor->trace(m_replayXHRs);
363 visitor->trace(m_replayXHRsToBeDeleted); 364 visitor->trace(m_replayXHRsToBeDeleted);
364 visitor->trace(m_pendingXHRReplayData); 365 visitor->trace(m_pendingXHRReplayData);
365 InspectorBaseAgent::trace(visitor); 366 InspectorBaseAgent::trace(visitor);
366 } 367 }
367 368
369 bool InspectorResourceAgent::shouldBlockRequest(const ResourceRequest& request)
370 {
371 String url = request.url().string();
372 RefPtr<JSONObject> blockedURLs = m_state->getObject(ResourceAgentState::bloc kedURLs);
373 for (const auto& blocked : *blockedURLs) {
374 if (url.contains(blocked.key))
375 return true;
376 }
377 return false;
378 }
379
368 void InspectorResourceAgent::willSendRequest(LocalFrame* frame, unsigned long id entifier, DocumentLoader* loader, ResourceRequest& request, const ResourceRespon se& redirectResponse, const FetchInitiatorInfo& initiatorInfo) 380 void InspectorResourceAgent::willSendRequest(LocalFrame* frame, unsigned long id entifier, DocumentLoader* loader, ResourceRequest& request, const ResourceRespon se& redirectResponse, const FetchInitiatorInfo& initiatorInfo)
369 { 381 {
370 // Ignore the request initiated internally. 382 // Ignore the request initiated internally.
371 if (initiatorInfo.name == FetchInitiatorTypeNames::internal) 383 if (initiatorInfo.name == FetchInitiatorTypeNames::internal)
372 return; 384 return;
373 385
374 if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader->subst ituteData().isValid()) 386 if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader->subst ituteData().isValid())
375 return; 387 return;
376 388
377 String requestId = IdentifiersFactory::requestId(identifier); 389 String requestId = IdentifiersFactory::requestId(identifier);
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 return; 887 return;
876 } 888 }
877 } 889 }
878 890
879 if (getResponseBodyBlob(requestId, callback)) 891 if (getResponseBodyBlob(requestId, callback))
880 return; 892 return;
881 893
882 callback->sendFailure("No data found for resource with given identifier"); 894 callback->sendFailure("No data found for resource with given identifier");
883 } 895 }
884 896
897 void InspectorResourceAgent::addBlockedURL(ErrorString*, const String& url)
898 {
899 RefPtr<JSONObject> blockedURLs = m_state->getObject(ResourceAgentState::bloc kedURLs);
900 blockedURLs->setBoolean(url, true);
901 m_state->setObject(ResourceAgentState::blockedURLs, blockedURLs.release());
902 }
903
904 void InspectorResourceAgent::removeBlockedURL(ErrorString*, const String& url)
905 {
906 RefPtr<JSONObject> blockedURLs = m_state->getObject(ResourceAgentState::bloc kedURLs);
907 blockedURLs->remove(url);
908 m_state->setObject(ResourceAgentState::blockedURLs, blockedURLs.release());
909 }
910
885 void InspectorResourceAgent::replayXHR(ErrorString*, const String& requestId) 911 void InspectorResourceAgent::replayXHR(ErrorString*, const String& requestId)
886 { 912 {
887 String actualRequestId = requestId; 913 String actualRequestId = requestId;
888 914
889 XHRReplayData* xhrReplayData = m_resourcesData->xhrReplayData(requestId); 915 XHRReplayData* xhrReplayData = m_resourcesData->xhrReplayData(requestId);
890 if (!xhrReplayData) 916 if (!xhrReplayData)
891 return; 917 return;
892 918
893 ExecutionContext* executionContext = xhrReplayData->executionContext(); 919 ExecutionContext* executionContext = xhrReplayData->executionContext();
894 if (!executionContext) { 920 if (!executionContext) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired) 1032 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired)
1007 { 1033 {
1008 } 1034 }
1009 1035
1010 bool InspectorResourceAgent::shouldForceCORSPreflight() 1036 bool InspectorResourceAgent::shouldForceCORSPreflight()
1011 { 1037 {
1012 return m_state->getBoolean(ResourceAgentState::cacheDisabled); 1038 return m_state->getBoolean(ResourceAgentState::cacheDisabled);
1013 } 1039 }
1014 1040
1015 } // namespace blink 1041 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorResourceAgent.h ('k') | Source/core/loader/FrameFetchContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698