Commit 2654127d authored by timothy@apple.com's avatar timothy@apple.com

Web Inspector: determine the resource type in InspectorResourceAgent::willSendRequest.

This allows the Network timeline and Resources sidebar to filter Resources earlier,
before the server sends a response. Useful for long polling (comet) XHRs.

https://webkit.org/b/74935
rdar://problem/13726105

Reviewed by Joseph Pecoraro.

* inspector/Inspector.json:
(Network.requestWillBeSent): Added.
* inspector/InspectorResourceAgent.cpp:
(WebCore::InspectorResourceAgent::willSendRequest): Send the type if it isn't Other along in requestWillBeSent.
(WebCore::InspectorResourceAgent::didReceiveResponse): Don't determine the type here anymore. Clear the CachedResource
if isNotModified like the old code path did by not setting cachedResource if !isNotModified.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@149905 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d4ffb762
2013-05-10 Timothy Hatcher <timothy@apple.com>
Web Inspector: determine the resource type in InspectorResourceAgent::willSendRequest.
This allows the Network timeline and Resources sidebar to filter Resources earlier,
before the server sends a response. Useful for long polling (comet) XHRs.
https://webkit.org/b/74935
rdar://problem/13726105
Reviewed by Joseph Pecoraro.
* inspector/Inspector.json:
(Network.requestWillBeSent): Added.
* inspector/InspectorResourceAgent.cpp:
(WebCore::InspectorResourceAgent::willSendRequest): Send the type if it isn't Other along in requestWillBeSent.
(WebCore::InspectorResourceAgent::didReceiveResponse): Don't determine the type here anymore. Clear the CachedResource
if isNotModified like the old code path did by not setting cachedResource if !isNotModified.
2013-05-10 Laszlo Gombos <l.gombos@samsung.com>
[CMake] Consolidate list of files to build for WebCore plugin support
......
......@@ -1093,7 +1093,8 @@
{ "name": "request", "$ref": "Request", "description": "Request data." },
{ "name": "timestamp", "$ref": "Timestamp", "description": "Timestamp." },
{ "name": "initiator", "$ref": "Initiator", "description": "Request initiator." },
{ "name": "redirectResponse", "optional": true, "$ref": "Response", "description": "Redirect response data." }
{ "name": "redirectResponse", "optional": true, "$ref": "Response", "description": "Redirect response data." },
{ "name": "type", "$ref": "Page.ResourceType", "optional": true, "description": "Resource type." }
]
},
{
......
......@@ -198,9 +198,20 @@ void InspectorResourceAgent::willSendRequest(unsigned long identifier, DocumentL
String requestId = IdentifiersFactory::requestId(identifier);
m_resourcesData->resourceCreated(requestId, m_pageAgent->loaderId(loader));
RefPtr<InspectorObject> headers = m_state->getObject(ResourceAgentState::extraRequestHeaders);
CachedResource* cachedResource = loader ? InspectorPageAgent::cachedResource(loader->frame(), request.url()) : 0;
InspectorPageAgent::ResourceType type = cachedResource ? InspectorPageAgent::cachedResourceType(*cachedResource) : m_resourcesData->resourceType(requestId);
if (type == InspectorPageAgent::OtherResource) {
if (m_loadingXHRSynchronously)
type = InspectorPageAgent::XHRResource;
else if (equalIgnoringFragmentIdentifier(request.url(), loader->frameLoader()->icon()->url()))
type = InspectorPageAgent::ImageResource;
else if (equalIgnoringFragmentIdentifier(request.url(), loader->url()) && !loader->isCommitted())
type = InspectorPageAgent::DocumentResource;
}
m_resourcesData->setResourceType(requestId, type);
if (headers) {
if (RefPtr<InspectorObject> headers = m_state->getObject(ResourceAgentState::extraRequestHeaders)) {
InspectorObject::const_iterator end = headers->end();
for (InspectorObject::const_iterator it = headers->begin(); it != end; ++it) {
String value;
......@@ -218,8 +229,10 @@ void InspectorResourceAgent::willSendRequest(unsigned long identifier, DocumentL
request.setHTTPHeaderField("Cache-Control", "no-cache");
}
TypeBuilder::Page::ResourceType::Enum resourceType = InspectorPageAgent::resourceTypeJson(type);
RefPtr<TypeBuilder::Network::Initiator> initiatorObject = buildInitiatorObject(loader->frame() ? loader->frame()->document() : 0);
m_frontend->requestWillBeSent(requestId, m_pageAgent->frameId(loader->frame()), m_pageAgent->loaderId(loader), loader->url().string(), buildObjectForResourceRequest(request), currentTime(), initiatorObject, buildObjectForResourceResponse(redirectResponse, loader));
m_frontend->requestWillBeSent(requestId, m_pageAgent->frameId(loader->frame()), m_pageAgent->loaderId(loader), loader->url().string(), buildObjectForResourceRequest(request), currentTime(), initiatorObject, buildObjectForResourceResponse(redirectResponse, loader), type != InspectorPageAgent::OtherResource ? &resourceType : 0);
}
void InspectorResourceAgent::markResourceAsCached(unsigned long identifier)
......@@ -247,19 +260,19 @@ void InspectorResourceAgent::didReceiveResponse(unsigned long identifier, Docume
m_resourcesData->addCachedResource(requestId, cachedResource);
}
InspectorPageAgent::ResourceType type = cachedResource ? InspectorPageAgent::cachedResourceType(*cachedResource) : InspectorPageAgent::OtherResource;
if (m_loadingXHRSynchronously || m_resourcesData->resourceType(requestId) == InspectorPageAgent::XHRResource)
type = InspectorPageAgent::XHRResource;
else if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::ScriptResource)
type = InspectorPageAgent::ScriptResource;
else if (equalIgnoringFragmentIdentifier(response.url(), loader->frameLoader()->icon()->url()))
type = InspectorPageAgent::ImageResource;
else if (equalIgnoringFragmentIdentifier(response.url(), loader->url()) && !loader->isCommitted())
type = InspectorPageAgent::DocumentResource;
InspectorPageAgent::ResourceType type = m_resourcesData->resourceType(requestId);
InspectorPageAgent::ResourceType newType = cachedResource ? InspectorPageAgent::cachedResourceType(*cachedResource) : type;
// FIXME: XHRResource is returned for CachedResource::RawResource, it should be OtherResource unless it truly is an XHR.
// RawResource is used for loading worker scripts, and those should stay as ScriptResource and not change to XHRResource.
if (type != newType && newType != InspectorPageAgent::XHRResource && newType != InspectorPageAgent::OtherResource)
type = newType;
m_resourcesData->responseReceived(requestId, m_pageAgent->frameId(loader->frame()), response);
m_resourcesData->setResourceType(requestId, type);
m_frontend->responseReceived(requestId, m_pageAgent->frameId(loader->frame()), m_pageAgent->loaderId(loader), currentTime(), InspectorPageAgent::resourceTypeJson(type), resourceResponse);
// If we revalidated the resource and got Not modified, send content length following didReceiveResponse
// as there will be no calls to didReceiveData from the network stack.
if (isNotModified && cachedResource && cachedResource->encodedSize())
......
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