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

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

Issue 1085033003: Introduce InspectorIdentifiers<> and use it to assign/lookup LocalFrame and DocumentLoader (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: win build error fixed Created 5 years, 8 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "core/fetch/ResourceFetcher.h" 42 #include "core/fetch/ResourceFetcher.h"
43 #include "core/fetch/ResourceLoader.h" 43 #include "core/fetch/ResourceLoader.h"
44 #include "core/fileapi/FileReaderLoader.h" 44 #include "core/fileapi/FileReaderLoader.h"
45 #include "core/fileapi/FileReaderLoaderClient.h" 45 #include "core/fileapi/FileReaderLoaderClient.h"
46 #include "core/frame/FrameHost.h" 46 #include "core/frame/FrameHost.h"
47 #include "core/frame/LocalFrame.h" 47 #include "core/frame/LocalFrame.h"
48 #include "core/html/HTMLFrameOwnerElement.h" 48 #include "core/html/HTMLFrameOwnerElement.h"
49 #include "core/inspector/ConsoleMessage.h" 49 #include "core/inspector/ConsoleMessage.h"
50 #include "core/inspector/ConsoleMessageStorage.h" 50 #include "core/inspector/ConsoleMessageStorage.h"
51 #include "core/inspector/IdentifiersFactory.h" 51 #include "core/inspector/IdentifiersFactory.h"
52 #include "core/inspector/InspectorIdentifiers.h"
52 #include "core/inspector/InspectorOverlay.h" 53 #include "core/inspector/InspectorOverlay.h"
53 #include "core/inspector/InspectorPageAgent.h" 54 #include "core/inspector/InspectorPageAgent.h"
54 #include "core/inspector/InspectorState.h" 55 #include "core/inspector/InspectorState.h"
55 #include "core/inspector/InstrumentingAgents.h" 56 #include "core/inspector/InstrumentingAgents.h"
56 #include "core/inspector/NetworkResourcesData.h" 57 #include "core/inspector/NetworkResourcesData.h"
57 #include "core/inspector/ScriptAsyncCallStack.h" 58 #include "core/inspector/ScriptAsyncCallStack.h"
58 #include "core/inspector/ScriptCallStack.h" 59 #include "core/inspector/ScriptCallStack.h"
59 #include "core/loader/DocumentLoader.h" 60 #include "core/loader/DocumentLoader.h"
60 #include "core/loader/FrameLoader.h" 61 #include "core/loader/FrameLoader.h"
61 #include "core/loader/ThreadableLoaderClient.h" 62 #include "core/loader/ThreadableLoaderClient.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 #endif 316 #endif
316 InspectorBaseAgent::trace(visitor); 317 InspectorBaseAgent::trace(visitor);
317 } 318 }
318 319
319 void InspectorResourceAgent::willSendRequest(unsigned long identifier, DocumentL oader* loader, ResourceRequest& request, const ResourceResponse& redirectRespons e, const FetchInitiatorInfo& initiatorInfo) 320 void InspectorResourceAgent::willSendRequest(unsigned long identifier, DocumentL oader* loader, ResourceRequest& request, const ResourceResponse& redirectRespons e, const FetchInitiatorInfo& initiatorInfo)
320 { 321 {
321 // Ignore the request initiated internally. 322 // Ignore the request initiated internally.
322 if (initiatorInfo.name == FetchInitiatorTypeNames::internal) 323 if (initiatorInfo.name == FetchInitiatorTypeNames::internal)
323 return; 324 return;
324 325
325 if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader && loa der->substituteData().isValid()) 326 if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader->subst ituteData().isValid())
326 return; 327 return;
327 328
328 String requestId = IdentifiersFactory::requestId(identifier); 329 String requestId = IdentifiersFactory::requestId(identifier);
329 m_resourcesData->resourceCreated(requestId, m_pageAgent->loaderId(loader)); 330 String loaderId = InspectorIdentifiers<DocumentLoader>::identifier(loader);
331 m_resourcesData->resourceCreated(requestId, loaderId);
330 332
331 InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource; 333 InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource;
332 if (initiatorInfo.name == FetchInitiatorTypeNames::xmlhttprequest) { 334 if (initiatorInfo.name == FetchInitiatorTypeNames::xmlhttprequest) {
333 type = InspectorPageAgent::XHRResource; 335 type = InspectorPageAgent::XHRResource;
334 m_resourcesData->setResourceType(requestId, type); 336 m_resourcesData->setResourceType(requestId, type);
335 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) { 337 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) {
336 type = InspectorPageAgent::DocumentResource; 338 type = InspectorPageAgent::DocumentResource;
337 m_resourcesData->setResourceType(requestId, type); 339 m_resourcesData->setResourceType(requestId, type);
338 } 340 }
339 341
340 RefPtr<JSONObject> headers = m_state->getObject(ResourceAgentState::extraReq uestHeaders); 342 RefPtr<JSONObject> headers = m_state->getObject(ResourceAgentState::extraReq uestHeaders);
341 343
342 if (headers) { 344 if (headers) {
343 for (const auto& header : *headers) { 345 for (const auto& header : *headers) {
344 String value; 346 String value;
345 if (header.value->asString(&value)) 347 if (header.value->asString(&value))
346 request.setHTTPHeaderField(AtomicString(header.key), AtomicStrin g(value)); 348 request.setHTTPHeaderField(AtomicString(header.key), AtomicStrin g(value));
347 } 349 }
348 } 350 }
349 351
350 request.setReportRawHeaders(true); 352 request.setReportRawHeaders(true);
351 353
352 if (m_state->getBoolean(ResourceAgentState::cacheDisabled)) { 354 if (m_state->getBoolean(ResourceAgentState::cacheDisabled)) {
353 request.setCachePolicy(ReloadBypassingCache); 355 request.setCachePolicy(ReloadBypassingCache);
354 request.setShouldResetAppCache(true); 356 request.setShouldResetAppCache(true);
355 } 357 }
356 358
357 String frameId = m_pageAgent->frameId(loader->frame()); 359 String frameId = loader->frame() ? InspectorIdentifiers<LocalFrame>::identif ier(loader->frame()) : "";
358
359 RefPtr<TypeBuilder::Network::Initiator> initiatorObject = buildInitiatorObje ct(loader->frame() ? loader->frame()->document() : 0, initiatorInfo); 360 RefPtr<TypeBuilder::Network::Initiator> initiatorObject = buildInitiatorObje ct(loader->frame() ? loader->frame()->document() : 0, initiatorInfo);
360 if (initiatorInfo.name == FetchInitiatorTypeNames::document) { 361 if (initiatorInfo.name == FetchInitiatorTypeNames::document) {
361 FrameNavigationInitiatorMap::iterator it = m_frameNavigationInitiatorMap .find(frameId); 362 FrameNavigationInitiatorMap::iterator it = m_frameNavigationInitiatorMap .find(frameId);
362 if (it != m_frameNavigationInitiatorMap.end()) 363 if (it != m_frameNavigationInitiatorMap.end())
363 initiatorObject = it->value; 364 initiatorObject = it->value;
364 } 365 }
365 366
366 RefPtr<TypeBuilder::Network::Request> requestInfo(buildObjectForResourceRequ est(request)); 367 RefPtr<TypeBuilder::Network::Request> requestInfo(buildObjectForResourceRequ est(request));
367 368
368 if (!m_hostId.isEmpty()) 369 if (!m_hostId.isEmpty())
369 request.addHTTPHeaderField(kDevToolsEmulateNetworkConditionsClientId, At omicString(m_hostId)); 370 request.addHTTPHeaderField(kDevToolsEmulateNetworkConditionsClientId, At omicString(m_hostId));
370 371
371 TypeBuilder::Page::ResourceType::Enum resourceType = InspectorPageAgent::res ourceTypeJson(type); 372 TypeBuilder::Page::ResourceType::Enum resourceType = InspectorPageAgent::res ourceTypeJson(type);
372 frontend()->requestWillBeSent(requestId, frameId, m_pageAgent->loaderId(load er), urlWithoutFragment(loader->url()).string(), requestInfo.release(), monotoni callyIncreasingTime(), currentTime(), initiatorObject, buildObjectForResourceRes ponse(redirectResponse), &resourceType); 373 frontend()->requestWillBeSent(requestId, frameId, loaderId, urlWithoutFragme nt(loader->url()).string(), requestInfo.release(), monotonicallyIncreasingTime() , currentTime(), initiatorObject, buildObjectForResourceResponse(redirectRespons e), &resourceType);
373 } 374 }
374 375
375 void InspectorResourceAgent::markResourceAsCached(unsigned long identifier) 376 void InspectorResourceAgent::markResourceAsCached(unsigned long identifier)
376 { 377 {
377 frontend()->requestServedFromCache(IdentifiersFactory::requestId(identifier) ); 378 frontend()->requestServedFromCache(IdentifiersFactory::requestId(identifier) );
378 } 379 }
379 380
380 bool isResponseEmpty(PassRefPtr<TypeBuilder::Network::Response> response) 381 bool isResponseEmpty(PassRefPtr<TypeBuilder::Network::Response> response)
381 { 382 {
382 if (!response) 383 if (!response)
(...skipping 28 matching lines...) Expand all
411 // Override with already discovered resource type. 412 // Override with already discovered resource type.
412 InspectorPageAgent::ResourceType savedType = m_resourcesData->resourceType(r equestId); 413 InspectorPageAgent::ResourceType savedType = m_resourcesData->resourceType(r equestId);
413 if (savedType == InspectorPageAgent::ScriptResource || savedType == Inspecto rPageAgent::XHRResource || savedType == InspectorPageAgent::DocumentResource) 414 if (savedType == InspectorPageAgent::ScriptResource || savedType == Inspecto rPageAgent::XHRResource || savedType == InspectorPageAgent::DocumentResource)
414 type = savedType; 415 type = savedType;
415 416
416 if (type == InspectorPageAgent::DocumentResource && loader && loader->substi tuteData().isValid()) 417 if (type == InspectorPageAgent::DocumentResource && loader && loader->substi tuteData().isValid())
417 return; 418 return;
418 419
419 if (cachedResource) 420 if (cachedResource)
420 m_resourcesData->addResource(requestId, cachedResource); 421 m_resourcesData->addResource(requestId, cachedResource);
421 m_resourcesData->responseReceived(requestId, m_pageAgent->frameId(frame), re sponse); 422 String frameId = InspectorIdentifiers<LocalFrame>::identifier(frame);
423 String loaderId = loader ? InspectorIdentifiers<DocumentLoader>::identifier( loader) : "";
424 m_resourcesData->responseReceived(requestId, frameId, response);
422 m_resourcesData->setResourceType(requestId, type); 425 m_resourcesData->setResourceType(requestId, type);
423 426
424 if (!isResponseEmpty(resourceResponse)) 427 if (!isResponseEmpty(resourceResponse))
425 frontend()->responseReceived(requestId, m_pageAgent->frameId(frame), m_p ageAgent->loaderId(loader), monotonicallyIncreasingTime(), InspectorPageAgent::r esourceTypeJson(type), resourceResponse); 428 frontend()->responseReceived(requestId, frameId, loaderId, monotonically IncreasingTime(), InspectorPageAgent::resourceTypeJson(type), resourceResponse);
426 // If we revalidated the resource and got Not modified, send content length following didReceiveResponse 429 // If we revalidated the resource and got Not modified, send content length following didReceiveResponse
427 // as there will be no calls to didReceiveData from the network stack. 430 // as there will be no calls to didReceiveData from the network stack.
428 if (isNotModified && cachedResource && cachedResource->encodedSize()) 431 if (isNotModified && cachedResource && cachedResource->encodedSize())
429 didReceiveData(frame, identifier, 0, cachedResource->encodedSize(), 0); 432 didReceiveData(frame, identifier, 0, cachedResource->encodedSize(), 0);
430 } 433 }
431 434
432 static bool isErrorStatusCode(int statusCode) 435 static bool isErrorStatusCode(int statusCode)
433 { 436 {
434 return statusCode >= 400; 437 return statusCode >= 400;
435 } 438 }
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 } 857 }
855 858
856 void InspectorResourceAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* lo ader) 859 void InspectorResourceAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* lo ader)
857 { 860 {
858 if (loader->frame() != m_pageAgent->inspectedFrame()) 861 if (loader->frame() != m_pageAgent->inspectedFrame())
859 return; 862 return;
860 863
861 if (m_state->getBoolean(ResourceAgentState::cacheDisabled)) 864 if (m_state->getBoolean(ResourceAgentState::cacheDisabled))
862 memoryCache()->evictResources(); 865 memoryCache()->evictResources();
863 866
864 m_resourcesData->clear(m_pageAgent->loaderId(loader)); 867 m_resourcesData->clear(InspectorIdentifiers<DocumentLoader>::identifier(load er));
865 } 868 }
866 869
867 void InspectorResourceAgent::frameScheduledNavigation(LocalFrame* frame, double) 870 void InspectorResourceAgent::frameScheduledNavigation(LocalFrame* frame, double)
868 { 871 {
869 RefPtr<TypeBuilder::Network::Initiator> initiator = buildInitiatorObject(fra me->document(), FetchInitiatorInfo()); 872 RefPtr<TypeBuilder::Network::Initiator> initiator = buildInitiatorObject(fra me->document(), FetchInitiatorInfo());
870 m_frameNavigationInitiatorMap.set(m_pageAgent->frameId(frame), initiator); 873 m_frameNavigationInitiatorMap.set(InspectorIdentifiers<LocalFrame>::identifi er(frame), initiator);
871 } 874 }
872 875
873 void InspectorResourceAgent::frameClearedScheduledNavigation(LocalFrame* frame) 876 void InspectorResourceAgent::frameClearedScheduledNavigation(LocalFrame* frame)
874 { 877 {
875 m_frameNavigationInitiatorMap.remove(m_pageAgent->frameId(frame)); 878 m_frameNavigationInitiatorMap.remove(InspectorIdentifiers<LocalFrame>::ident ifier(frame));
876 } 879 }
877 880
878 void InspectorResourceAgent::setHostId(const String& hostId) 881 void InspectorResourceAgent::setHostId(const String& hostId)
879 { 882 {
880 m_hostId = hostId; 883 m_hostId = hostId;
881 } 884 }
882 885
883 bool InspectorResourceAgent::fetchResourceContent(Document* document, const KURL & url, String* content, bool* base64Encoded) 886 bool InspectorResourceAgent::fetchResourceContent(Document* document, const KURL & url, String* content, bool* base64Encoded)
884 { 887 {
885 // First try to fetch content from the cached resource. 888 // First try to fetch content from the cached resource.
(...skipping 28 matching lines...) Expand all
914 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired) 917 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired)
915 { 918 {
916 } 919 }
917 920
918 bool InspectorResourceAgent::shouldForceCORSPreflight() 921 bool InspectorResourceAgent::shouldForceCORSPreflight()
919 { 922 {
920 return m_state->getBoolean(ResourceAgentState::cacheDisabled); 923 return m_state->getBoolean(ResourceAgentState::cacheDisabled);
921 } 924 }
922 925
923 } // namespace blink 926 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorPageAgent.cpp ('k') | Source/core/inspector/InspectorStyleSheet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698