Commit 3db979ae authored by dgozman@chromium.org's avatar dgozman@chromium.org

[DevTools] Show blocked requests in network log.

BUG=520259

Review URL: https://codereview.chromium.org/1309033003

git-svn-id: svn://svn.chromium.org/blink/trunk@201275 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 3a4eb7f6
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "core/fetch/Resource.h" #include "core/fetch/Resource.h"
#include "core/fetch/ResourceFetcher.h" #include "core/fetch/ResourceFetcher.h"
#include "core/fetch/ResourceLoader.h" #include "core/fetch/ResourceLoader.h"
#include "core/fetch/UniqueIdentifier.h"
#include "core/fileapi/FileReaderLoader.h" #include "core/fileapi/FileReaderLoader.h"
#include "core/fileapi/FileReaderLoaderClient.h" #include "core/fileapi/FileReaderLoaderClient.h"
#include "core/frame/FrameHost.h" #include "core/frame/FrameHost.h"
...@@ -366,26 +367,26 @@ DEFINE_TRACE(InspectorResourceAgent) ...@@ -366,26 +367,26 @@ DEFINE_TRACE(InspectorResourceAgent)
InspectorBaseAgent::trace(visitor); InspectorBaseAgent::trace(visitor);
} }
bool InspectorResourceAgent::shouldBlockRequest(const ResourceRequest& request) bool InspectorResourceAgent::shouldBlockRequest(LocalFrame* frame, const ResourceRequest& request, DocumentLoader* loader, const FetchInitiatorInfo& initiatorInfo)
{ {
String url = request.url().string(); String url = request.url().string();
RefPtr<JSONObject> blockedURLs = m_state->getObject(ResourceAgentState::blockedURLs); RefPtr<JSONObject> blockedURLs = m_state->getObject(ResourceAgentState::blockedURLs);
for (const auto& blocked : *blockedURLs) { for (const auto& blocked : *blockedURLs) {
if (url.contains(blocked.key)) if (url.contains(blocked.key)) {
unsigned long identifier = createUniqueIdentifier();
willSendRequestInternal(frame, identifier, loader, request, ResourceResponse(), initiatorInfo);
String requestId = IdentifiersFactory::requestId(identifier);
bool blocked = true;
frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), InspectorPageAgent::resourceTypeJson(m_resourcesData->resourceType(requestId)), String(), nullptr, &blocked);
return true; return true;
} }
}
return false; return false;
} }
void InspectorResourceAgent::willSendRequest(LocalFrame* frame, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& initiatorInfo) void InspectorResourceAgent::willSendRequestInternal(LocalFrame* frame, unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& initiatorInfo)
{ {
// Ignore the request initiated internally.
if (initiatorInfo.name == FetchInitiatorTypeNames::internal)
return;
if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader->substituteData().isValid())
return;
String requestId = IdentifiersFactory::requestId(identifier); String requestId = IdentifiersFactory::requestId(identifier);
String loaderId = IdentifiersFactory::loaderId(loader); String loaderId = IdentifiersFactory::loaderId(loader);
m_resourcesData->resourceCreated(requestId, loaderId); m_resourcesData->resourceCreated(requestId, loaderId);
...@@ -399,6 +400,33 @@ void InspectorResourceAgent::willSendRequest(LocalFrame* frame, unsigned long id ...@@ -399,6 +400,33 @@ void InspectorResourceAgent::willSendRequest(LocalFrame* frame, unsigned long id
m_resourcesData->setResourceType(requestId, type); m_resourcesData->setResourceType(requestId, type);
} }
String frameId = loader->frame() ? IdentifiersFactory::frameId(loader->frame()) : "";
RefPtr<TypeBuilder::Network::Initiator> initiatorObject = buildInitiatorObject(loader->frame() ? loader->frame()->document() : 0, initiatorInfo);
if (initiatorInfo.name == FetchInitiatorTypeNames::document) {
FrameNavigationInitiatorMap::iterator it = m_frameNavigationInitiatorMap.find(frameId);
if (it != m_frameNavigationInitiatorMap.end())
initiatorObject = it->value;
}
RefPtr<TypeBuilder::Network::Request> requestInfo(buildObjectForResourceRequest(request));
requestInfo->setMixedContentType(mixedContentTypeForContextType(MixedContentChecker::contextTypeForInspector(frame, request)));
TypeBuilder::Page::ResourceType::Enum resourceType = InspectorPageAgent::resourceTypeJson(type);
frontend()->requestWillBeSent(requestId, frameId, loaderId, urlWithoutFragment(loader->url()).string(), requestInfo.release(), monotonicallyIncreasingTime(), currentTime(), initiatorObject, buildObjectForResourceResponse(redirectResponse), &resourceType);
if (m_pendingXHRReplayData && !m_pendingXHRReplayData->async())
frontend()->flush();
}
void InspectorResourceAgent::willSendRequest(LocalFrame* frame, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& initiatorInfo)
{
// Ignore the request initiated internally.
if (initiatorInfo.name == FetchInitiatorTypeNames::internal)
return;
if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader->substituteData().isValid())
return;
RefPtr<JSONObject> headers = m_state->getObject(ResourceAgentState::extraRequestHeaders); RefPtr<JSONObject> headers = m_state->getObject(ResourceAgentState::extraRequestHeaders);
if (headers) { if (headers) {
...@@ -416,25 +444,10 @@ void InspectorResourceAgent::willSendRequest(LocalFrame* frame, unsigned long id ...@@ -416,25 +444,10 @@ void InspectorResourceAgent::willSendRequest(LocalFrame* frame, unsigned long id
request.setShouldResetAppCache(true); request.setShouldResetAppCache(true);
} }
String frameId = loader->frame() ? IdentifiersFactory::frameId(loader->frame()) : "";
RefPtr<TypeBuilder::Network::Initiator> initiatorObject = buildInitiatorObject(loader->frame() ? loader->frame()->document() : 0, initiatorInfo);
if (initiatorInfo.name == FetchInitiatorTypeNames::document) {
FrameNavigationInitiatorMap::iterator it = m_frameNavigationInitiatorMap.find(frameId);
if (it != m_frameNavigationInitiatorMap.end())
initiatorObject = it->value;
}
RefPtr<TypeBuilder::Network::Request> requestInfo(buildObjectForResourceRequest(request));
requestInfo->setMixedContentType(mixedContentTypeForContextType(MixedContentChecker::contextTypeForInspector(frame, request)));
if (!m_hostId.isEmpty()) if (!m_hostId.isEmpty())
request.addHTTPHeaderField(kDevToolsEmulateNetworkConditionsClientId, AtomicString(m_hostId)); request.addHTTPHeaderField(kDevToolsEmulateNetworkConditionsClientId, AtomicString(m_hostId));
TypeBuilder::Page::ResourceType::Enum resourceType = InspectorPageAgent::resourceTypeJson(type); willSendRequestInternal(frame, identifier, loader, request, redirectResponse, initiatorInfo);
frontend()->requestWillBeSent(requestId, frameId, loaderId, urlWithoutFragment(loader->url()).string(), requestInfo.release(), monotonicallyIncreasingTime(), currentTime(), initiatorObject, buildObjectForResourceResponse(redirectResponse), &resourceType);
if (m_pendingXHRReplayData && !m_pendingXHRReplayData->async())
frontend()->flush();
} }
void InspectorResourceAgent::markResourceAsCached(unsigned long identifier) void InspectorResourceAgent::markResourceAsCached(unsigned long identifier)
...@@ -535,7 +548,7 @@ void InspectorResourceAgent::didFailLoading(unsigned long identifier, const Reso ...@@ -535,7 +548,7 @@ void InspectorResourceAgent::didFailLoading(unsigned long identifier, const Reso
{ {
String requestId = IdentifiersFactory::requestId(identifier); String requestId = IdentifiersFactory::requestId(identifier);
bool canceled = error.isCancellation(); bool canceled = error.isCancellation();
frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), InspectorPageAgent::resourceTypeJson(m_resourcesData->resourceType(requestId)), error.localizedDescription(), canceled ? &canceled : 0); frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), InspectorPageAgent::resourceTypeJson(m_resourcesData->resourceType(requestId)), error.localizedDescription(), canceled ? &canceled : 0, nullptr);
} }
void InspectorResourceAgent::scriptImported(unsigned long identifier, const String& sourceString) void InspectorResourceAgent::scriptImported(unsigned long identifier, const String& sourceString)
......
...@@ -151,12 +151,13 @@ public: ...@@ -151,12 +151,13 @@ public:
// Called from other agents. // Called from other agents.
void setHostId(const String&); void setHostId(const String&);
bool fetchResourceContent(Document*, const KURL&, String* content, bool* base64Encoded); bool fetchResourceContent(Document*, const KURL&, String* content, bool* base64Encoded);
bool shouldBlockRequest(const ResourceRequest&); bool shouldBlockRequest(LocalFrame*, const ResourceRequest&, DocumentLoader*, const FetchInitiatorInfo&);
private: private:
explicit InspectorResourceAgent(InspectorPageAgent*); explicit InspectorResourceAgent(InspectorPageAgent*);
void enable(); void enable();
void willSendRequestInternal(LocalFrame*, unsigned long identifier, DocumentLoader*, const ResourceRequest&, const ResourceResponse& redirectResponse, const FetchInitiatorInfo&);
void delayedRemoveReplayXHR(XMLHttpRequest*); void delayedRemoveReplayXHR(XMLHttpRequest*);
void removeFinishedReplayXHRFired(Timer<InspectorResourceAgent>*); void removeFinishedReplayXHRFired(Timer<InspectorResourceAgent>*);
void didFinishXHRInternal(ExecutionContext*, XMLHttpRequest*, ThreadableLoaderClient*, const AtomicString&, const String&, bool); void didFinishXHRInternal(ExecutionContext*, XMLHttpRequest*, ThreadableLoaderClient*, const AtomicString&, const String&, bool);
......
...@@ -206,7 +206,7 @@ ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R ...@@ -206,7 +206,7 @@ ResourceRequestCachePolicy FrameFetchContext::resourceRequestCachePolicy(const R
// |loader| can be null if the resource is loaded from imported document. // |loader| can be null if the resource is loaded from imported document.
// This means inspector, which uses DocumentLoader as an grouping entity, // This means inspector, which uses DocumentLoader as an grouping entity,
// cannot see imported documents. // cannot see imported documents.
inline DocumentLoader* FrameFetchContext::ensureLoaderForNotifications() inline DocumentLoader* FrameFetchContext::ensureLoaderForNotifications() const
{ {
return m_documentLoader ? m_documentLoader.get() : frame()->loader().documentLoader(); return m_documentLoader ? m_documentLoader.get() : frame()->loader().documentLoader();
} }
...@@ -349,7 +349,7 @@ bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r ...@@ -349,7 +349,7 @@ bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r
{ {
InstrumentingAgents* agents = InspectorInstrumentation::instrumentingAgentsFor(frame()); InstrumentingAgents* agents = InspectorInstrumentation::instrumentingAgentsFor(frame());
if (agents && agents->inspectorResourceAgent()) { if (agents && agents->inspectorResourceAgent()) {
if (agents->inspectorResourceAgent()->shouldBlockRequest(resourceRequest)) if (agents->inspectorResourceAgent()->shouldBlockRequest(frame(), resourceRequest, ensureLoaderForNotifications(), options.initiatorInfo))
return false; return false;
} }
......
...@@ -116,7 +116,7 @@ public: ...@@ -116,7 +116,7 @@ public:
private: private:
explicit FrameFetchContext(DocumentLoader*); explicit FrameFetchContext(DocumentLoader*);
inline DocumentLoader* ensureLoaderForNotifications(); inline DocumentLoader* ensureLoaderForNotifications() const;
LocalFrame* frame() const; // Can be null LocalFrame* frame() const; // Can be null
void printAccessDeniedMessage(const KURL&) const; void printAccessDeniedMessage(const KURL&) const;
......
...@@ -260,7 +260,7 @@ WebInspector.NetworkDataGridNode.prototype = { ...@@ -260,7 +260,7 @@ WebInspector.NetworkDataGridNode.prototype = {
{ {
cell.classList.toggle("network-dim-cell", !this._isFailed() && (this._request.cached() || !this._request.statusCode)); cell.classList.toggle("network-dim-cell", !this._isFailed() && (this._request.cached() || !this._request.statusCode));
if (this._request.failed && !this._request.canceled) { if (this._request.failed && !this._request.canceled && !this._request.blocked) {
var failText = WebInspector.UIString("(failed)"); var failText = WebInspector.UIString("(failed)");
if (this._request.localizedFailDescription) { if (this._request.localizedFailDescription) {
cell.createTextChild(failText); cell.createTextChild(failText);
...@@ -278,6 +278,8 @@ WebInspector.NetworkDataGridNode.prototype = { ...@@ -278,6 +278,8 @@ WebInspector.NetworkDataGridNode.prototype = {
cell.setTextAndTitle(WebInspector.UIString("(data)")); cell.setTextAndTitle(WebInspector.UIString("(data)"));
} else if (this._request.canceled) { } else if (this._request.canceled) {
cell.setTextAndTitle(WebInspector.UIString("(canceled)")); cell.setTextAndTitle(WebInspector.UIString("(canceled)"));
} else if (this._request.blocked) {
cell.setTextAndTitle(WebInspector.UIString("(blocked)"));
} else if (this._request.finished) { } else if (this._request.finished) {
cell.setTextAndTitle(WebInspector.UIString("Finished")); cell.setTextAndTitle(WebInspector.UIString("Finished"));
} else { } else {
......
...@@ -429,8 +429,9 @@ WebInspector.NetworkDispatcher.prototype = { ...@@ -429,8 +429,9 @@ WebInspector.NetworkDispatcher.prototype = {
* @param {!PageAgent.ResourceType} resourceType * @param {!PageAgent.ResourceType} resourceType
* @param {string} localizedDescription * @param {string} localizedDescription
* @param {boolean=} canceled * @param {boolean=} canceled
* @param {boolean=} blocked
*/ */
loadingFailed: function(requestId, time, resourceType, localizedDescription, canceled) loadingFailed: function(requestId, time, resourceType, localizedDescription, canceled, blocked)
{ {
var networkRequest = this._inflightRequestsById[requestId]; var networkRequest = this._inflightRequestsById[requestId];
if (!networkRequest) if (!networkRequest)
...@@ -439,6 +440,7 @@ WebInspector.NetworkDispatcher.prototype = { ...@@ -439,6 +440,7 @@ WebInspector.NetworkDispatcher.prototype = {
networkRequest.failed = true; networkRequest.failed = true;
networkRequest.setResourceType(WebInspector.resourceTypes[resourceType]); networkRequest.setResourceType(WebInspector.resourceTypes[resourceType]);
networkRequest.canceled = canceled; networkRequest.canceled = canceled;
networkRequest.blocked = blocked;
networkRequest.localizedFailDescription = localizedDescription; networkRequest.localizedFailDescription = localizedDescription;
this._finishNetworkRequest(networkRequest, time, -1); this._finishNetworkRequest(networkRequest, time, -1);
}, },
......
...@@ -385,6 +385,19 @@ WebInspector.NetworkRequest.prototype = { ...@@ -385,6 +385,19 @@ WebInspector.NetworkRequest.prototype = {
this._canceled = x; this._canceled = x;
}, },
/**
* @return {boolean}
*/
get blocked()
{
return this._blocked;
},
set blocked(x)
{
this._blocked = x;
},
/** /**
* @return {boolean} * @return {boolean}
*/ */
......
...@@ -1547,7 +1547,8 @@ ...@@ -1547,7 +1547,8 @@
{ "name": "timestamp", "$ref": "Timestamp", "description": "Timestamp." }, { "name": "timestamp", "$ref": "Timestamp", "description": "Timestamp." },
{ "name": "type", "$ref": "Page.ResourceType", "description": "Resource type." }, { "name": "type", "$ref": "Page.ResourceType", "description": "Resource type." },
{ "name": "errorText", "type": "string", "description": "User friendly error message." }, { "name": "errorText", "type": "string", "description": "User friendly error message." },
{ "name": "canceled", "type": "boolean", "optional": true, "description": "True if loading was canceled." } { "name": "canceled", "type": "boolean", "optional": true, "description": "True if loading was canceled." },
{ "name": "blocked", "type": "boolean", "optional": true, "description": "True if loading was blocked by inspector." }
] ]
}, },
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment