OLD | NEW |
---|---|
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 23 matching lines...) Expand all Loading... | |
34 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 34 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
35 #include "bindings/core/v8/ScriptCallStackFactory.h" | 35 #include "bindings/core/v8/ScriptCallStackFactory.h" |
36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
37 #include "core/dom/ScriptableDocumentParser.h" | 37 #include "core/dom/ScriptableDocumentParser.h" |
38 #include "core/fetch/FetchInitiatorInfo.h" | 38 #include "core/fetch/FetchInitiatorInfo.h" |
39 #include "core/fetch/FetchInitiatorTypeNames.h" | 39 #include "core/fetch/FetchInitiatorTypeNames.h" |
40 #include "core/fetch/MemoryCache.h" | 40 #include "core/fetch/MemoryCache.h" |
41 #include "core/fetch/Resource.h" | 41 #include "core/fetch/Resource.h" |
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/fetch/UniqueIdentifier.h" | |
44 #include "core/fileapi/FileReaderLoader.h" | 45 #include "core/fileapi/FileReaderLoader.h" |
45 #include "core/fileapi/FileReaderLoaderClient.h" | 46 #include "core/fileapi/FileReaderLoaderClient.h" |
46 #include "core/frame/FrameHost.h" | 47 #include "core/frame/FrameHost.h" |
47 #include "core/frame/LocalFrame.h" | 48 #include "core/frame/LocalFrame.h" |
48 #include "core/html/HTMLFrameOwnerElement.h" | 49 #include "core/html/HTMLFrameOwnerElement.h" |
49 #include "core/inspector/ConsoleMessage.h" | 50 #include "core/inspector/ConsoleMessage.h" |
50 #include "core/inspector/ConsoleMessageStorage.h" | 51 #include "core/inspector/ConsoleMessageStorage.h" |
51 #include "core/inspector/IdentifiersFactory.h" | 52 #include "core/inspector/IdentifiersFactory.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" |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 | 360 |
360 DEFINE_TRACE(InspectorResourceAgent) | 361 DEFINE_TRACE(InspectorResourceAgent) |
361 { | 362 { |
362 visitor->trace(m_pageAgent); | 363 visitor->trace(m_pageAgent); |
363 visitor->trace(m_replayXHRs); | 364 visitor->trace(m_replayXHRs); |
364 visitor->trace(m_replayXHRsToBeDeleted); | 365 visitor->trace(m_replayXHRsToBeDeleted); |
365 visitor->trace(m_pendingXHRReplayData); | 366 visitor->trace(m_pendingXHRReplayData); |
366 InspectorBaseAgent::trace(visitor); | 367 InspectorBaseAgent::trace(visitor); |
367 } | 368 } |
368 | 369 |
369 bool InspectorResourceAgent::shouldBlockRequest(const ResourceRequest& request) | 370 bool InspectorResourceAgent::shouldBlockRequest(LocalFrame* frame, const Resourc eRequest& request, DocumentLoader* loader, const FetchInitiatorInfo& initiatorIn fo) |
370 { | 371 { |
371 String url = request.url().string(); | 372 String url = request.url().string(); |
372 RefPtr<JSONObject> blockedURLs = m_state->getObject(ResourceAgentState::bloc kedURLs); | 373 RefPtr<JSONObject> blockedURLs = m_state->getObject(ResourceAgentState::bloc kedURLs); |
373 for (const auto& blocked : *blockedURLs) { | 374 for (const auto& blocked : *blockedURLs) { |
374 if (url.contains(blocked.key)) | 375 if (url.contains(blocked.key)) { |
376 unsigned long identifier = createUniqueIdentifier(); | |
377 willSendRequestInternal(frame, identifier, loader, request, Resource Response(), initiatorInfo); | |
378 | |
379 String requestId = IdentifiersFactory::requestId(identifier); | |
380 bool blocked = true; | |
brucedawson
2015/08/28 17:19:56
This 'blocked' variable shadows the 'blocked' vari
dgozman
2015/08/28 17:48:34
Thank you for spotting this! I will follow up with
| |
381 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), InspectorPageAgent::resourceTypeJson(m_resourcesData->resourceType(requestId)), String(), nullptr, &blocked); | |
375 return true; | 382 return true; |
383 } | |
376 } | 384 } |
377 return false; | 385 return false; |
378 } | 386 } |
379 | 387 |
380 void InspectorResourceAgent::willSendRequest(LocalFrame* frame, unsigned long id entifier, DocumentLoader* loader, ResourceRequest& request, const ResourceRespon se& redirectResponse, const FetchInitiatorInfo& initiatorInfo) | 388 void InspectorResourceAgent::willSendRequestInternal(LocalFrame* frame, unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiatorInfo& initiatorInfo) |
381 { | 389 { |
382 // Ignore the request initiated internally. | |
383 if (initiatorInfo.name == FetchInitiatorTypeNames::internal) | |
384 return; | |
385 | |
386 if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader->subst ituteData().isValid()) | |
387 return; | |
388 | |
389 String requestId = IdentifiersFactory::requestId(identifier); | 390 String requestId = IdentifiersFactory::requestId(identifier); |
390 String loaderId = IdentifiersFactory::loaderId(loader); | 391 String loaderId = IdentifiersFactory::loaderId(loader); |
391 m_resourcesData->resourceCreated(requestId, loaderId); | 392 m_resourcesData->resourceCreated(requestId, loaderId); |
392 | 393 |
393 InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource; | 394 InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource; |
394 if (initiatorInfo.name == FetchInitiatorTypeNames::xmlhttprequest) { | 395 if (initiatorInfo.name == FetchInitiatorTypeNames::xmlhttprequest) { |
395 type = InspectorPageAgent::XHRResource; | 396 type = InspectorPageAgent::XHRResource; |
396 m_resourcesData->setResourceType(requestId, type); | 397 m_resourcesData->setResourceType(requestId, type); |
397 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) { | 398 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) { |
398 type = InspectorPageAgent::DocumentResource; | 399 type = InspectorPageAgent::DocumentResource; |
399 m_resourcesData->setResourceType(requestId, type); | 400 m_resourcesData->setResourceType(requestId, type); |
400 } | 401 } |
401 | 402 |
403 String frameId = loader->frame() ? IdentifiersFactory::frameId(loader->frame ()) : ""; | |
404 RefPtr<TypeBuilder::Network::Initiator> initiatorObject = buildInitiatorObje ct(loader->frame() ? loader->frame()->document() : 0, initiatorInfo); | |
405 if (initiatorInfo.name == FetchInitiatorTypeNames::document) { | |
406 FrameNavigationInitiatorMap::iterator it = m_frameNavigationInitiatorMap .find(frameId); | |
407 if (it != m_frameNavigationInitiatorMap.end()) | |
408 initiatorObject = it->value; | |
409 } | |
410 | |
411 RefPtr<TypeBuilder::Network::Request> requestInfo(buildObjectForResourceRequ est(request)); | |
412 | |
413 requestInfo->setMixedContentType(mixedContentTypeForContextType(MixedContent Checker::contextTypeForInspector(frame, request))); | |
414 | |
415 TypeBuilder::Page::ResourceType::Enum resourceType = InspectorPageAgent::res ourceTypeJson(type); | |
416 frontend()->requestWillBeSent(requestId, frameId, loaderId, urlWithoutFragme nt(loader->url()).string(), requestInfo.release(), monotonicallyIncreasingTime() , currentTime(), initiatorObject, buildObjectForResourceResponse(redirectRespons e), &resourceType); | |
417 if (m_pendingXHRReplayData && !m_pendingXHRReplayData->async()) | |
418 frontend()->flush(); | |
419 } | |
420 | |
421 void InspectorResourceAgent::willSendRequest(LocalFrame* frame, unsigned long id entifier, DocumentLoader* loader, ResourceRequest& request, const ResourceRespon se& redirectResponse, const FetchInitiatorInfo& initiatorInfo) | |
422 { | |
423 // Ignore the request initiated internally. | |
424 if (initiatorInfo.name == FetchInitiatorTypeNames::internal) | |
425 return; | |
426 | |
427 if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader->subst ituteData().isValid()) | |
428 return; | |
429 | |
402 RefPtr<JSONObject> headers = m_state->getObject(ResourceAgentState::extraReq uestHeaders); | 430 RefPtr<JSONObject> headers = m_state->getObject(ResourceAgentState::extraReq uestHeaders); |
403 | 431 |
404 if (headers) { | 432 if (headers) { |
405 for (const auto& header : *headers) { | 433 for (const auto& header : *headers) { |
406 String value; | 434 String value; |
407 if (header.value->asString(&value)) | 435 if (header.value->asString(&value)) |
408 request.setHTTPHeaderField(AtomicString(header.key), AtomicStrin g(value)); | 436 request.setHTTPHeaderField(AtomicString(header.key), AtomicStrin g(value)); |
409 } | 437 } |
410 } | 438 } |
411 | 439 |
412 request.setReportRawHeaders(true); | 440 request.setReportRawHeaders(true); |
413 | 441 |
414 if (m_state->getBoolean(ResourceAgentState::cacheDisabled)) { | 442 if (m_state->getBoolean(ResourceAgentState::cacheDisabled)) { |
415 request.setCachePolicy(ReloadBypassingCache); | 443 request.setCachePolicy(ReloadBypassingCache); |
416 request.setShouldResetAppCache(true); | 444 request.setShouldResetAppCache(true); |
417 } | 445 } |
418 | 446 |
419 String frameId = loader->frame() ? IdentifiersFactory::frameId(loader->frame ()) : ""; | |
420 RefPtr<TypeBuilder::Network::Initiator> initiatorObject = buildInitiatorObje ct(loader->frame() ? loader->frame()->document() : 0, initiatorInfo); | |
421 if (initiatorInfo.name == FetchInitiatorTypeNames::document) { | |
422 FrameNavigationInitiatorMap::iterator it = m_frameNavigationInitiatorMap .find(frameId); | |
423 if (it != m_frameNavigationInitiatorMap.end()) | |
424 initiatorObject = it->value; | |
425 } | |
426 | |
427 RefPtr<TypeBuilder::Network::Request> requestInfo(buildObjectForResourceRequ est(request)); | |
428 | |
429 requestInfo->setMixedContentType(mixedContentTypeForContextType(MixedContent Checker::contextTypeForInspector(frame, request))); | |
430 | |
431 if (!m_hostId.isEmpty()) | 447 if (!m_hostId.isEmpty()) |
432 request.addHTTPHeaderField(kDevToolsEmulateNetworkConditionsClientId, At omicString(m_hostId)); | 448 request.addHTTPHeaderField(kDevToolsEmulateNetworkConditionsClientId, At omicString(m_hostId)); |
433 | 449 |
434 TypeBuilder::Page::ResourceType::Enum resourceType = InspectorPageAgent::res ourceTypeJson(type); | 450 willSendRequestInternal(frame, identifier, loader, request, redirectResponse , initiatorInfo); |
435 frontend()->requestWillBeSent(requestId, frameId, loaderId, urlWithoutFragme nt(loader->url()).string(), requestInfo.release(), monotonicallyIncreasingTime() , currentTime(), initiatorObject, buildObjectForResourceResponse(redirectRespons e), &resourceType); | |
436 if (m_pendingXHRReplayData && !m_pendingXHRReplayData->async()) | |
437 frontend()->flush(); | |
438 } | 451 } |
439 | 452 |
440 void InspectorResourceAgent::markResourceAsCached(unsigned long identifier) | 453 void InspectorResourceAgent::markResourceAsCached(unsigned long identifier) |
441 { | 454 { |
442 frontend()->requestServedFromCache(IdentifiersFactory::requestId(identifier) ); | 455 frontend()->requestServedFromCache(IdentifiersFactory::requestId(identifier) ); |
443 } | 456 } |
444 | 457 |
445 bool isResponseEmpty(PassRefPtr<TypeBuilder::Network::Response> response) | 458 bool isResponseEmpty(PassRefPtr<TypeBuilder::Network::Response> response) |
446 { | 459 { |
447 if (!response) | 460 if (!response) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 { | 541 { |
529 // Update the response and finish loading | 542 // Update the response and finish loading |
530 didReceiveResourceResponse(frame, identifier, loader, response, resourceLoad er); | 543 didReceiveResourceResponse(frame, identifier, loader, response, resourceLoad er); |
531 didFinishLoading(identifier, 0, WebURLLoaderClient::kUnknownEncodedDataLengt h); | 544 didFinishLoading(identifier, 0, WebURLLoaderClient::kUnknownEncodedDataLengt h); |
532 } | 545 } |
533 | 546 |
534 void InspectorResourceAgent::didFailLoading(unsigned long identifier, const Reso urceError& error) | 547 void InspectorResourceAgent::didFailLoading(unsigned long identifier, const Reso urceError& error) |
535 { | 548 { |
536 String requestId = IdentifiersFactory::requestId(identifier); | 549 String requestId = IdentifiersFactory::requestId(identifier); |
537 bool canceled = error.isCancellation(); | 550 bool canceled = error.isCancellation(); |
538 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), Inspecto rPageAgent::resourceTypeJson(m_resourcesData->resourceType(requestId)), error.lo calizedDescription(), canceled ? &canceled : 0); | 551 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), Inspecto rPageAgent::resourceTypeJson(m_resourcesData->resourceType(requestId)), error.lo calizedDescription(), canceled ? &canceled : 0, nullptr); |
539 } | 552 } |
540 | 553 |
541 void InspectorResourceAgent::scriptImported(unsigned long identifier, const Stri ng& sourceString) | 554 void InspectorResourceAgent::scriptImported(unsigned long identifier, const Stri ng& sourceString) |
542 { | 555 { |
543 m_resourcesData->setResourceContent(IdentifiersFactory::requestId(identifier ), sourceString); | 556 m_resourcesData->setResourceContent(IdentifiersFactory::requestId(identifier ), sourceString); |
544 } | 557 } |
545 | 558 |
546 void InspectorResourceAgent::didReceiveScriptResponse(unsigned long identifier) | 559 void InspectorResourceAgent::didReceiveScriptResponse(unsigned long identifier) |
547 { | 560 { |
548 m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::ScriptResource); | 561 m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::ScriptResource); |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1032 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired) | 1045 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired) |
1033 { | 1046 { |
1034 } | 1047 } |
1035 | 1048 |
1036 bool InspectorResourceAgent::shouldForceCORSPreflight() | 1049 bool InspectorResourceAgent::shouldForceCORSPreflight() |
1037 { | 1050 { |
1038 return m_state->getBoolean(ResourceAgentState::cacheDisabled); | 1051 return m_state->getBoolean(ResourceAgentState::cacheDisabled); |
1039 } | 1052 } |
1040 | 1053 |
1041 } // namespace blink | 1054 } // namespace blink |
OLD | NEW |