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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 if (pos == kNotFound) | 112 if (pos == kNotFound) |
113 return false; | 113 return false; |
114 pos += part.length(); | 114 pos += part.length(); |
115 } | 115 } |
116 return true; | 116 return true; |
117 } | 117 } |
118 | 118 |
119 static std::unique_ptr<protocol::Network::Headers> buildObjectForHeaders(const H
TTPHeaderMap& headers) | 119 static std::unique_ptr<protocol::Network::Headers> buildObjectForHeaders(const H
TTPHeaderMap& headers) |
120 { | 120 { |
121 std::unique_ptr<protocol::DictionaryValue> headersObject = protocol::Diction
aryValue::create(); | 121 std::unique_ptr<protocol::DictionaryValue> headersObject = protocol::Diction
aryValue::create(); |
122 for (const auto& header : headers) | 122 for (const auto& header : headers) { |
| 123 if (header.key == HTTPNames::X_DevTools_Emulate_Network_Conditions_Clien
t_Id) |
| 124 continue; |
123 headersObject->setString(header.key.getString(), header.value); | 125 headersObject->setString(header.key.getString(), header.value); |
| 126 } |
124 protocol::ErrorSupport errors; | 127 protocol::ErrorSupport errors; |
125 return protocol::Network::Headers::parse(headersObject.get(), &errors); | 128 return protocol::Network::Headers::parse(headersObject.get(), &errors); |
126 } | 129 } |
127 | 130 |
128 class InspectorFileReaderLoaderClient final : public FileReaderLoaderClient { | 131 class InspectorFileReaderLoaderClient final : public FileReaderLoaderClient { |
129 WTF_MAKE_NONCOPYABLE(InspectorFileReaderLoaderClient); | 132 WTF_MAKE_NONCOPYABLE(InspectorFileReaderLoaderClient); |
130 public: | 133 public: |
131 InspectorFileReaderLoaderClient(PassRefPtr<BlobDataHandle> blob, const Strin
g& mimeType, const String& textEncodingName, std::unique_ptr<GetResponseBodyCall
back> callback) | 134 InspectorFileReaderLoaderClient(PassRefPtr<BlobDataHandle> blob, const Strin
g& mimeType, const String& textEncodingName, std::unique_ptr<GetResponseBodyCall
back> callback) |
132 : m_blob(blob) | 135 : m_blob(blob) |
133 , m_mimeType(mimeType) | 136 , m_mimeType(mimeType) |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 auto entry = blockedURLs->at(i); | 480 auto entry = blockedURLs->at(i); |
478 if (matches(url, entry.first)) | 481 if (matches(url, entry.first)) |
479 return true; | 482 return true; |
480 } | 483 } |
481 return false; | 484 return false; |
482 } | 485 } |
483 | 486 |
484 void InspectorNetworkAgent::didBlockRequest(LocalFrame* frame, const ResourceReq
uest& request, DocumentLoader* loader, const FetchInitiatorInfo& initiatorInfo,
ResourceRequestBlockedReason reason) | 487 void InspectorNetworkAgent::didBlockRequest(LocalFrame* frame, const ResourceReq
uest& request, DocumentLoader* loader, const FetchInitiatorInfo& initiatorInfo,
ResourceRequestBlockedReason reason) |
485 { | 488 { |
486 unsigned long identifier = createUniqueIdentifier(); | 489 unsigned long identifier = createUniqueIdentifier(); |
487 willSendRequestInternal(frame, identifier, loader, request, ResourceResponse
(), initiatorInfo); | 490 willSendRequest(frame, identifier, loader, request, ResourceResponse(), init
iatorInfo); |
488 | 491 |
489 String requestId = IdentifiersFactory::requestId(identifier); | 492 String requestId = IdentifiersFactory::requestId(identifier); |
490 String protocolReason = buildBlockedReason(reason); | 493 String protocolReason = buildBlockedReason(reason); |
491 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), Inspecto
rPageAgent::resourceTypeJson(m_resourcesData->resourceType(requestId)), String()
, false, protocolReason); | 494 frontend()->loadingFailed(requestId, monotonicallyIncreasingTime(), Inspecto
rPageAgent::resourceTypeJson(m_resourcesData->resourceType(requestId)), String()
, false, protocolReason); |
492 } | 495 } |
493 | 496 |
494 void InspectorNetworkAgent::didChangeResourcePriority(unsigned long identifier,
ResourceLoadPriority loadPriority) | 497 void InspectorNetworkAgent::didChangeResourcePriority(unsigned long identifier,
ResourceLoadPriority loadPriority) |
495 { | 498 { |
496 String requestId = IdentifiersFactory::requestId(identifier); | 499 String requestId = IdentifiersFactory::requestId(identifier); |
497 frontend()->resourceChangedPriority(requestId, resourcePriorityJSON(loadPrio
rity), monotonicallyIncreasingTime()); | 500 frontend()->resourceChangedPriority(requestId, resourcePriorityJSON(loadPrio
rity), monotonicallyIncreasingTime()); |
498 } | 501 } |
499 | 502 |
500 void InspectorNetworkAgent::willSendRequestInternal(LocalFrame* frame, unsigned
long identifier, DocumentLoader* loader, const ResourceRequest& request, const R
esourceResponse& redirectResponse, const FetchInitiatorInfo& initiatorInfo) | 503 void InspectorNetworkAgent::willSendRequest(LocalFrame* frame, unsigned long ide
ntifier, DocumentLoader* loader, const ResourceRequest& request, const ResourceR
esponse& redirectResponse, const FetchInitiatorInfo& initiatorInfo) |
501 { | 504 { |
| 505 // Ignore the request initiated internally. |
| 506 if (initiatorInfo.name == FetchInitiatorTypeNames::internal) |
| 507 return; |
| 508 |
| 509 if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader->subst
ituteData().isValid()) |
| 510 return; |
| 511 |
502 String requestId = IdentifiersFactory::requestId(identifier); | 512 String requestId = IdentifiersFactory::requestId(identifier); |
503 String loaderId = IdentifiersFactory::loaderId(loader); | 513 String loaderId = IdentifiersFactory::loaderId(loader); |
504 m_resourcesData->resourceCreated(requestId, loaderId, request.url()); | 514 m_resourcesData->resourceCreated(requestId, loaderId, request.url()); |
505 | 515 |
506 InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource; | 516 InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource; |
507 if (initiatorInfo.name == FetchInitiatorTypeNames::xmlhttprequest) { | 517 if (initiatorInfo.name == FetchInitiatorTypeNames::xmlhttprequest) { |
508 type = InspectorPageAgent::XHRResource; | 518 type = InspectorPageAgent::XHRResource; |
509 m_resourcesData->setResourceType(requestId, type); | 519 m_resourcesData->setResourceType(requestId, type); |
510 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) { | 520 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) { |
511 type = InspectorPageAgent::DocumentResource; | 521 type = InspectorPageAgent::DocumentResource; |
(...skipping 11 matching lines...) Expand all Loading... |
523 std::unique_ptr<protocol::Network::Request> requestInfo(buildObjectForResour
ceRequest(request)); | 533 std::unique_ptr<protocol::Network::Request> requestInfo(buildObjectForResour
ceRequest(request)); |
524 | 534 |
525 requestInfo->setMixedContentType(mixedContentTypeForContextType(MixedContent
Checker::contextTypeForInspector(frame, request))); | 535 requestInfo->setMixedContentType(mixedContentTypeForContextType(MixedContent
Checker::contextTypeForInspector(frame, request))); |
526 | 536 |
527 String resourceType = InspectorPageAgent::resourceTypeJson(type); | 537 String resourceType = InspectorPageAgent::resourceTypeJson(type); |
528 frontend()->requestWillBeSent(requestId, frameId, loaderId, urlWithoutFragme
nt(loader->url()).getString(), std::move(requestInfo), monotonicallyIncreasingTi
me(), currentTime(), std::move(initiatorObject), buildObjectForResourceResponse(
redirectResponse), resourceType); | 538 frontend()->requestWillBeSent(requestId, frameId, loaderId, urlWithoutFragme
nt(loader->url()).getString(), std::move(requestInfo), monotonicallyIncreasingTi
me(), currentTime(), std::move(initiatorObject), buildObjectForResourceResponse(
redirectResponse), resourceType); |
529 if (m_pendingXHRReplayData && !m_pendingXHRReplayData->async()) | 539 if (m_pendingXHRReplayData && !m_pendingXHRReplayData->async()) |
530 frontend()->flush(); | 540 frontend()->flush(); |
531 } | 541 } |
532 | 542 |
533 void InspectorNetworkAgent::willSendRequest(LocalFrame* frame, unsigned long ide
ntifier, DocumentLoader* loader, ResourceRequest& request, const ResourceRespons
e& redirectResponse, const FetchInitiatorInfo& initiatorInfo) | 543 void InspectorNetworkAgent::prepareRequest(DocumentLoader* loader, ResourceReque
st& request) |
534 { | 544 { |
535 // Ignore the request initiated internally. | |
536 if (initiatorInfo.name == FetchInitiatorTypeNames::internal) | |
537 return; | |
538 | |
539 if (initiatorInfo.name == FetchInitiatorTypeNames::document && loader->subst
ituteData().isValid()) | |
540 return; | |
541 | |
542 protocol::DictionaryValue* headers = m_state->getObject(NetworkAgentState::e
xtraRequestHeaders); | 545 protocol::DictionaryValue* headers = m_state->getObject(NetworkAgentState::e
xtraRequestHeaders); |
543 if (headers) { | 546 if (headers) { |
544 for (size_t i = 0; i < headers->size(); ++i) { | 547 for (size_t i = 0; i < headers->size(); ++i) { |
545 auto header = headers->at(i); | 548 auto header = headers->at(i); |
546 String16 value; | 549 String16 value; |
547 if (header.second->asString(&value)) | 550 if (header.second->asString(&value)) |
548 request.setHTTPHeaderField(AtomicString(header.first), AtomicStr
ing(String(value))); | 551 request.setHTTPHeaderField(AtomicString(header.first), AtomicStr
ing(String(value))); |
549 } | 552 } |
550 } | 553 } |
551 | 554 |
552 request.setReportRawHeaders(true); | 555 request.setReportRawHeaders(true); |
553 | 556 |
554 if (m_state->booleanProperty(NetworkAgentState::cacheDisabled, false)) { | 557 if (m_state->booleanProperty(NetworkAgentState::cacheDisabled, false)) { |
555 request.setCachePolicy(WebCachePolicy::BypassingCache); | 558 request.setCachePolicy(WebCachePolicy::BypassingCache); |
556 request.setShouldResetAppCache(true); | 559 request.setShouldResetAppCache(true); |
557 } | 560 } |
558 if (m_state->booleanProperty(NetworkAgentState::bypassServiceWorker, false)) | 561 if (m_state->booleanProperty(NetworkAgentState::bypassServiceWorker, false)) |
559 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); | 562 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); |
560 | 563 |
561 willSendRequestInternal(frame, identifier, loader, request, redirectResponse
, initiatorInfo); | |
562 | |
563 if (!m_hostId.isEmpty()) | 564 if (!m_hostId.isEmpty()) |
564 request.addHTTPHeaderField(HTTPNames::X_DevTools_Emulate_Network_Conditi
ons_Client_Id, AtomicString(m_hostId)); | 565 request.addHTTPHeaderField(HTTPNames::X_DevTools_Emulate_Network_Conditi
ons_Client_Id, AtomicString(m_hostId)); |
565 } | 566 } |
566 | 567 |
567 void InspectorNetworkAgent::markResourceAsCached(unsigned long identifier) | 568 void InspectorNetworkAgent::markResourceAsCached(unsigned long identifier) |
568 { | 569 { |
569 frontend()->requestServedFromCache(IdentifiersFactory::requestId(identifier)
); | 570 frontend()->requestServedFromCache(IdentifiersFactory::requestId(identifier)
); |
570 } | 571 } |
571 | 572 |
572 void InspectorNetworkAgent::didReceiveResourceResponse(LocalFrame* frame, unsign
ed long identifier, DocumentLoader* loader, const ResourceResponse& response, Re
source* cachedResource) | 573 void InspectorNetworkAgent::didReceiveResourceResponse(LocalFrame* frame, unsign
ed long identifier, DocumentLoader* loader, const ResourceResponse& response, Re
source* cachedResource) |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 , m_removeFinishedReplayXHRTimer(this, &InspectorNetworkAgent::removeFinishe
dReplayXHRFired) | 1182 , m_removeFinishedReplayXHRTimer(this, &InspectorNetworkAgent::removeFinishe
dReplayXHRFired) |
1182 { | 1183 { |
1183 } | 1184 } |
1184 | 1185 |
1185 bool InspectorNetworkAgent::shouldForceCORSPreflight() | 1186 bool InspectorNetworkAgent::shouldForceCORSPreflight() |
1186 { | 1187 { |
1187 return m_state->booleanProperty(NetworkAgentState::cacheDisabled, false); | 1188 return m_state->booleanProperty(NetworkAgentState::cacheDisabled, false); |
1188 } | 1189 } |
1189 | 1190 |
1190 } // namespace blink | 1191 } // namespace blink |
OLD | NEW |