Index: third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp |
diff --git a/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp |
index dc0f1bcb799dcf223df370b0c09ae2217958734f..3ac075d732daad83d28166de5a8f745e2b5a9b29 100644 |
--- a/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp |
+++ b/third_party/WebKit/Source/core/inspector/InspectorNetworkAgent.cpp |
@@ -51,6 +51,7 @@ |
#include "core/loader/ThreadableLoaderClient.h" |
#include "core/page/Page.h" |
#include "core/probe/CoreProbes.h" |
+#include "core/workers/WorkerGlobalScope.h" |
#include "core/xmlhttprequest/XMLHttpRequest.h" |
#include "platform/RuntimeEnabledFeatures.h" |
#include "platform/blob/BlobData.h" |
@@ -548,6 +549,7 @@ InspectorNetworkAgent::~InspectorNetworkAgent() {} |
DEFINE_TRACE(InspectorNetworkAgent) { |
visitor->Trace(inspected_frames_); |
+ visitor->Trace(worker_global_scope_); |
visitor->Trace(resources_data_); |
visitor->Trace(replay_xhrs_); |
visitor->Trace(replay_xhrs_to_be_deleted_); |
@@ -574,14 +576,13 @@ void InspectorNetworkAgent::ShouldBlockRequest(const ResourceRequest& request, |
} |
void InspectorNetworkAgent::DidBlockRequest( |
- LocalFrame* frame, |
const ResourceRequest& request, |
DocumentLoader* loader, |
const FetchInitiatorInfo& initiator_info, |
ResourceRequestBlockedReason reason) { |
unsigned long identifier = CreateUniqueIdentifier(); |
- WillSendRequestInternal(frame, identifier, loader, request, |
- ResourceResponse(), initiator_info); |
+ WillSendRequestInternal(identifier, loader, request, ResourceResponse(), |
+ initiator_info); |
String request_id = IdentifiersFactory::RequestId(identifier); |
String protocol_reason = BuildBlockedReason(reason); |
@@ -602,14 +603,13 @@ void InspectorNetworkAgent::DidChangeResourcePriority( |
} |
void InspectorNetworkAgent::WillSendRequestInternal( |
- LocalFrame* frame, |
unsigned long identifier, |
DocumentLoader* loader, |
const ResourceRequest& request, |
const ResourceResponse& redirect_response, |
const FetchInitiatorInfo& initiator_info) { |
String request_id = IdentifiersFactory::RequestId(identifier); |
- String loader_id = IdentifiersFactory::LoaderId(loader); |
+ String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : ""; |
resources_data_->ResourceCreated(request_id, loader_id, request.Url()); |
InspectorPageAgent::ResourceType type = InspectorPageAgent::kOtherResource; |
@@ -621,11 +621,12 @@ void InspectorNetworkAgent::WillSendRequestInternal( |
resources_data_->SetResourceType(request_id, type); |
} |
- String frame_id = |
- loader->GetFrame() ? IdentifiersFactory::FrameId(loader->GetFrame()) : ""; |
+ String frame_id = loader && loader->GetFrame() |
+ ? IdentifiersFactory::FrameId(loader->GetFrame()) |
+ : ""; |
std::unique_ptr<protocol::Network::Initiator> initiator_object = |
BuildInitiatorObject( |
- loader->GetFrame() ? loader->GetFrame()->GetDocument() : 0, |
+ loader && loader->GetFrame() ? loader->GetFrame()->GetDocument() : 0, |
initiator_info); |
if (initiator_info.name == FetchInitiatorTypeNames::document) { |
FrameNavigationInitiatorMap::iterator it = |
@@ -637,8 +638,14 @@ void InspectorNetworkAgent::WillSendRequestInternal( |
std::unique_ptr<protocol::Network::Request> request_info( |
BuildObjectForResourceRequest(request)); |
- request_info->setMixedContentType(MixedContentTypeForContextType( |
- MixedContentChecker::ContextTypeForInspector(frame, request))); |
+ // |loader| is null while inspecting worker if off-main-thread-fetch is |
+ // enabled. TODO(horo): Refactor MixedContentChecker and set mixed content |
+ // type even if |loader| is null. |
+ if (loader) { |
+ request_info->setMixedContentType(MixedContentTypeForContextType( |
+ MixedContentChecker::ContextTypeForInspector(loader->GetFrame(), |
+ request))); |
+ } |
request_info->setReferrerPolicy( |
GetReferrerPolicy(request.GetReferrerPolicy())); |
@@ -648,15 +655,15 @@ void InspectorNetworkAgent::WillSendRequestInternal( |
String resource_type = InspectorPageAgent::ResourceTypeJson(type); |
GetFrontend()->requestWillBeSent( |
request_id, frame_id, loader_id, |
- UrlWithoutFragment(loader->Url()).GetString(), std::move(request_info), |
- MonotonicallyIncreasingTime(), CurrentTime(), std::move(initiator_object), |
+ loader ? UrlWithoutFragment(loader->Url()).GetString() : "", |
+ std::move(request_info), MonotonicallyIncreasingTime(), CurrentTime(), |
+ std::move(initiator_object), |
BuildObjectForResourceResponse(redirect_response), resource_type); |
if (pending_xhr_replay_data_ && !pending_xhr_replay_data_->Async()) |
GetFrontend()->flush(); |
} |
void InspectorNetworkAgent::WillSendRequest( |
- LocalFrame* frame, |
unsigned long identifier, |
DocumentLoader* loader, |
ResourceRequest& request, |
@@ -696,7 +703,7 @@ void InspectorNetworkAgent::WillSendRequest( |
if (state_->booleanProperty(NetworkAgentState::kBypassServiceWorker, false)) |
request.SetServiceWorkerMode(WebURLRequest::ServiceWorkerMode::kNone); |
- WillSendRequestInternal(frame, identifier, loader, request, redirect_response, |
+ WillSendRequestInternal(identifier, loader, request, redirect_response, |
initiator_info); |
if (!host_id_.IsEmpty()) |
@@ -711,7 +718,6 @@ void InspectorNetworkAgent::MarkResourceAsCached(unsigned long identifier) { |
} |
void InspectorNetworkAgent::DidReceiveResourceResponse( |
- LocalFrame* frame, |
unsigned long identifier, |
DocumentLoader* loader, |
const ResourceResponse& response, |
@@ -747,7 +753,9 @@ void InspectorNetworkAgent::DidReceiveResourceResponse( |
// doesn't affect Resource lifetime. |
if (cached_resource) |
resources_data_->AddResource(request_id, cached_resource); |
- String frame_id = IdentifiersFactory::FrameId(frame); |
+ String frame_id = loader && loader->GetFrame() |
+ ? IdentifiersFactory::FrameId(loader->GetFrame()) |
+ : ""; |
String loader_id = loader ? IdentifiersFactory::LoaderId(loader) : ""; |
resources_data_->ResponseReceived(request_id, frame_id, response); |
resources_data_->SetResourceType(request_id, type); |
@@ -770,15 +778,15 @@ void InspectorNetworkAgent::DidReceiveResourceResponse( |
// following didReceiveResponse as there will be no calls to didReceiveData |
// from the network stack. |
if (is_not_modified && cached_resource && cached_resource->EncodedSize()) |
- DidReceiveData(frame, identifier, 0, cached_resource->EncodedSize()); |
+ DidReceiveData(identifier, loader, 0, cached_resource->EncodedSize()); |
} |
static bool IsErrorStatusCode(int status_code) { |
return status_code >= 400; |
} |
-void InspectorNetworkAgent::DidReceiveData(LocalFrame*, |
- unsigned long identifier, |
+void InspectorNetworkAgent::DidReceiveData(unsigned long identifier, |
+ DocumentLoader* loader, |
const char* data, |
int data_length) { |
String request_id = IdentifiersFactory::RequestId(identifier); |
@@ -800,15 +808,14 @@ void InspectorNetworkAgent::DidReceiveData(LocalFrame*, |
} |
void InspectorNetworkAgent::DidReceiveEncodedDataLength( |
- LocalFrame*, |
unsigned long identifier, |
int encoded_data_length) { |
String request_id = IdentifiersFactory::RequestId(identifier); |
resources_data_->AddPendingEncodedDataLength(request_id, encoded_data_length); |
} |
-void InspectorNetworkAgent::DidFinishLoading(LocalFrame*, |
- unsigned long identifier, |
+void InspectorNetworkAgent::DidFinishLoading(unsigned long identifier, |
+ DocumentLoader*, |
double monotonic_finish_time, |
int64_t encoded_data_length, |
int64_t decoded_body_length) { |
@@ -845,8 +852,8 @@ void InspectorNetworkAgent::DidReceiveCORSRedirectResponse( |
const ResourceResponse& response, |
Resource* resource) { |
// Update the response and finish loading |
- DidReceiveResourceResponse(frame, identifier, loader, response, resource); |
- DidFinishLoading(frame, identifier, 0, |
+ DidReceiveResourceResponse(identifier, loader, response, resource); |
+ DidFinishLoading(identifier, loader, 0, |
WebURLLoaderClient::kUnknownEncodedDataLength, 0); |
} |
@@ -1248,6 +1255,8 @@ bool InspectorNetworkAgent::CanGetResponseBodyBlob(const String& request_id) { |
resource_data ? resource_data->DownloadedFileBlob() : nullptr; |
if (!blob) |
return false; |
+ if (worker_global_scope_) |
+ return true; |
LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_, |
resource_data->FrameId()); |
return frame && frame->GetDocument(); |
@@ -1259,12 +1268,17 @@ void InspectorNetworkAgent::GetResponseBodyBlob( |
NetworkResourcesData::ResourceData const* resource_data = |
resources_data_->Data(request_id); |
BlobDataHandle* blob = resource_data->DownloadedFileBlob(); |
- LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_, |
- resource_data->FrameId()); |
- Document* document = frame->GetDocument(); |
InspectorFileReaderLoaderClient* client = new InspectorFileReaderLoaderClient( |
blob, resource_data->MimeType(), resource_data->TextEncodingName(), |
std::move(callback)); |
+ if (worker_global_scope_) { |
+ client->Start(worker_global_scope_); |
+ return; |
+ } |
+ DCHECK(inspected_frames_); |
+ LocalFrame* frame = IdentifiersFactory::FrameById(inspected_frames_, |
+ resource_data->FrameId()); |
+ Document* document = frame->GetDocument(); |
client->Start(document); |
} |
@@ -1401,7 +1415,7 @@ Response InspectorNetworkAgent::setCacheDisabled(bool cache_disabled) { |
// We should extract network cache state into a global entity which can be |
// queried from FrameLoader and other places. |
state_->setBoolean(NetworkAgentState::kCacheDisabled, cache_disabled); |
- if (cache_disabled) |
+ if (cache_disabled && IsMainThread()) |
GetMemoryCache()->EvictResources(); |
return Response::OK(); |
} |
@@ -1438,11 +1452,14 @@ Response InspectorNetworkAgent::getCertificate( |
void InspectorNetworkAgent::DidCommitLoad(LocalFrame* frame, |
DocumentLoader* loader) { |
+ DCHECK(inspected_frames_); |
if (loader->GetFrame() != inspected_frames_->Root()) |
return; |
- if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) |
+ if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false) && |
+ IsMainThread()) { |
kinuko
2017/05/22 06:53:40
DCHECK(IsMainThread()) seems fine
horo
2017/05/22 07:32:17
Done.
|
GetMemoryCache()->EvictResources(MemoryCache::kDoNotEvictUnusedPreloads); |
+ } |
resources_data_->Clear(IdentifiersFactory::LoaderId(loader)); |
} |
@@ -1493,9 +1510,10 @@ bool InspectorNetworkAgent::FetchResourceContent(Document* document, |
bool* base64_encoded) { |
// First try to fetch content from the cached resource. |
Resource* cached_resource = document->Fetcher()->CachedResource(url); |
- if (!cached_resource) |
+ if (!cached_resource && IsMainThread()) { |
kinuko
2017/05/22 06:53:40
This seems to be only called for document case (fo
horo
2017/05/22 07:32:17
Done.
|
cached_resource = GetMemoryCache()->ResourceForURL( |
url, document->Fetcher()->GetCacheIdentifier()); |
+ } |
if (cached_resource && InspectorPageAgent::CachedResourceContent( |
cached_resource, content, base64_encoded)) |
return true; |
@@ -1523,6 +1541,7 @@ void InspectorNetworkAgent::RemoveFinishedReplayXHRFired(TimerBase*) { |
InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspected_frames) |
: inspected_frames_(inspected_frames), |
+ worker_global_scope_(nullptr), |
resources_data_( |
NetworkResourcesData::Create(g_maximum_total_buffer_size, |
g_maximum_resource_buffer_size)), |
@@ -1531,7 +1550,25 @@ InspectorNetworkAgent::InspectorNetworkAgent(InspectedFrames* inspected_frames) |
TaskRunnerHelper::Get(TaskType::kUnspecedLoading, |
inspected_frames->Root()), |
this, |
- &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) {} |
+ &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) { |
+ DCHECK(IsMainThread()); |
+} |
+ |
+InspectorNetworkAgent::InspectorNetworkAgent( |
+ WorkerGlobalScope* worker_global_scope) |
+ : inspected_frames_(nullptr), |
+ worker_global_scope_(worker_global_scope), |
+ resources_data_( |
+ NetworkResourcesData::Create(g_maximum_total_buffer_size, |
+ g_maximum_resource_buffer_size)), |
+ pending_request_(nullptr), |
+ remove_finished_replay_xhr_timer_( |
+ TaskRunnerHelper::Get(TaskType::kUnspecedLoading, |
+ worker_global_scope), |
+ this, |
+ &InspectorNetworkAgent::RemoveFinishedReplayXHRFired) { |
+ DCHECK(!IsMainThread()); |
+} |
void InspectorNetworkAgent::ShouldForceCORSPreflight(bool* result) { |
if (state_->booleanProperty(NetworkAgentState::kCacheDisabled, false)) |