| Index: content/child/resource_dispatcher.cc
|
| diff --git a/content/child/resource_dispatcher.cc b/content/child/resource_dispatcher.cc
|
| index b6a877fa65d5f8b9b91658ac2d14d5e01bb74680..47d53319229f15bf6a2f4c55cffbbc98242b47bb 100644
|
| --- a/content/child/resource_dispatcher.cc
|
| +++ b/content/child/resource_dispatcher.cc
|
| @@ -28,7 +28,6 @@
|
| #include "net/base/net_util.h"
|
| #include "net/base/request_priority.h"
|
| #include "net/http/http_response_headers.h"
|
| -#include "webkit/child/resource_loader_bridge.h"
|
| #include "webkit/common/resource_type.h"
|
|
|
| using webkit_glue::ResourceLoaderBridge;
|
| @@ -47,10 +46,7 @@ void RemoteToLocalTimeTicks(
|
| *time = converter.ToLocalTimeTicks(remote_time).ToTimeTicks();
|
| }
|
|
|
| -
|
| -} // namespace
|
| -
|
| -static void CrashOnMapFailure() {
|
| +void CrashOnMapFailure() {
|
| #if defined(OS_WIN)
|
| DWORD last_err = GetLastError();
|
| base::debug::Alias(&last_err);
|
| @@ -59,7 +55,7 @@ static void CrashOnMapFailure() {
|
| }
|
|
|
| // Each resource request is assigned an ID scoped to this process.
|
| -static int MakeRequestID() {
|
| +int MakeRequestID() {
|
| // NOTE: The resource_dispatcher_host also needs probably unique
|
| // request_ids, so they count down from -2 (-1 is a special we're
|
| // screwed value), while the renderer process counts up.
|
| @@ -67,216 +63,34 @@ static int MakeRequestID() {
|
| return next_request_id++;
|
| }
|
|
|
| -// ResourceLoaderBridge implementation ----------------------------------------
|
| -
|
| -class IPCResourceLoaderBridge : public ResourceLoaderBridge {
|
| - public:
|
| - IPCResourceLoaderBridge(ResourceDispatcher* dispatcher,
|
| - const RequestInfo& request_info);
|
| - virtual ~IPCResourceLoaderBridge();
|
| -
|
| - // ResourceLoaderBridge
|
| - virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE;
|
| - virtual bool Start(RequestPeer* peer) OVERRIDE;
|
| - virtual void Cancel() OVERRIDE;
|
| - virtual void SetDefersLoading(bool value) OVERRIDE;
|
| - virtual void DidChangePriority(net::RequestPriority new_priority,
|
| - int intra_priority_value) OVERRIDE;
|
| - virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE;
|
| -
|
| - private:
|
| - RequestPeer* peer_;
|
| -
|
| - // The resource dispatcher for this loader. The bridge doesn't own it, but
|
| - // it's guaranteed to outlive the bridge.
|
| - ResourceDispatcher* dispatcher_;
|
| -
|
| - // The request to send, created on initialization for modification and
|
| - // appending data.
|
| - ResourceHostMsg_Request request_;
|
| -
|
| - // ID for the request, valid once Start()ed, -1 if not valid yet.
|
| - int request_id_;
|
| -
|
| - // The routing id used when sending IPC messages.
|
| - int routing_id_;
|
| -
|
| - // The security origin of the frame that initiates this request.
|
| - GURL frame_origin_;
|
| -
|
| - bool is_synchronous_request_;
|
| -};
|
| +} // namespace
|
|
|
| -IPCResourceLoaderBridge::IPCResourceLoaderBridge(
|
| - ResourceDispatcher* dispatcher,
|
| - const RequestInfo& request_info)
|
| - : peer_(NULL),
|
| - dispatcher_(dispatcher),
|
| +ResourceDispatcher::ResourceDispatcher(IPC::Sender* sender)
|
| + : message_sender_(sender),
|
| + peer_(NULL),
|
| request_id_(-1),
|
| - routing_id_(request_info.routing_id),
|
| - is_synchronous_request_(false) {
|
| - DCHECK(dispatcher_) << "no resource dispatcher";
|
| - request_.method = request_info.method;
|
| - request_.url = request_info.url;
|
| - request_.first_party_for_cookies = request_info.first_party_for_cookies;
|
| - request_.referrer = request_info.referrer;
|
| - request_.referrer_policy = request_info.referrer_policy;
|
| - request_.headers = request_info.headers;
|
| - request_.load_flags = request_info.load_flags;
|
| - request_.origin_pid = request_info.requestor_pid;
|
| - request_.resource_type = request_info.request_type;
|
| - request_.priority = request_info.priority;
|
| - request_.request_context = request_info.request_context;
|
| - request_.appcache_host_id = request_info.appcache_host_id;
|
| - request_.download_to_file = request_info.download_to_file;
|
| - request_.has_user_gesture = request_info.has_user_gesture;
|
| -
|
| - const RequestExtraData kEmptyData;
|
| - const RequestExtraData* extra_data;
|
| - if (request_info.extra_data)
|
| - extra_data = static_cast<RequestExtraData*>(request_info.extra_data);
|
| - else
|
| - extra_data = &kEmptyData;
|
| - request_.visiblity_state = extra_data->visibility_state();
|
| - request_.render_frame_id = extra_data->render_frame_id();
|
| - request_.is_main_frame = extra_data->is_main_frame();
|
| - request_.parent_is_main_frame = extra_data->parent_is_main_frame();
|
| - request_.parent_render_frame_id = extra_data->parent_render_frame_id();
|
| - request_.allow_download = extra_data->allow_download();
|
| - request_.transition_type = extra_data->transition_type();
|
| - request_.should_replace_current_entry =
|
| - extra_data->should_replace_current_entry();
|
| - request_.transferred_request_child_id =
|
| - extra_data->transferred_request_child_id();
|
| - request_.transferred_request_request_id =
|
| - extra_data->transferred_request_request_id();
|
| - request_.service_worker_provider_id =
|
| - extra_data->service_worker_provider_id();
|
| - frame_origin_ = extra_data->frame_origin();
|
| + routing_id_(-1),
|
| + is_synchronous_request_(false),
|
| + weak_factory_(this),
|
| + delegate_(NULL),
|
| + io_timestamp_(base::TimeTicks()) {
|
| }
|
|
|
| -IPCResourceLoaderBridge::~IPCResourceLoaderBridge() {
|
| - // we remove our hook for the resource dispatcher only when going away, since
|
| +ResourceDispatcher::~ResourceDispatcher() {
|
| + // We remove our hook for the resource dispatcher only when going away, since
|
| // it doesn't keep track of whether we've force terminated the request
|
| if (request_id_ >= 0) {
|
| - // this operation may fail, as the dispatcher will have preemptively
|
| + // This operation may fail, as the dispatcher will have preemptively
|
| // removed us when the renderer sends the ReceivedAllData message.
|
| - dispatcher_->RemovePendingRequest(request_id_);
|
| + RemovePendingRequest(request_id_);
|
|
|
| - if (request_.download_to_file) {
|
| - dispatcher_->message_sender()->Send(
|
| + if (request_->download_to_file) {
|
| + message_sender_->Send(
|
| new ResourceHostMsg_ReleaseDownloadedFile(request_id_));
|
| }
|
| }
|
| }
|
|
|
| -void IPCResourceLoaderBridge::SetRequestBody(
|
| - ResourceRequestBody* request_body) {
|
| - DCHECK(request_id_ == -1) << "request already started";
|
| - request_.request_body = request_body;
|
| -}
|
| -
|
| -// Writes a footer on the message and sends it
|
| -bool IPCResourceLoaderBridge::Start(RequestPeer* peer) {
|
| - if (request_id_ != -1) {
|
| - NOTREACHED() << "Starting a request twice";
|
| - return false;
|
| - }
|
| -
|
| - peer_ = peer;
|
| -
|
| - // generate the request ID, and append it to the message
|
| - request_id_ = dispatcher_->AddPendingRequest(peer_,
|
| - request_.resource_type,
|
| - request_.origin_pid,
|
| - frame_origin_,
|
| - request_.url);
|
| -
|
| - return dispatcher_->message_sender()->Send(
|
| - new ResourceHostMsg_RequestResource(routing_id_, request_id_, request_));
|
| -}
|
| -
|
| -void IPCResourceLoaderBridge::Cancel() {
|
| - if (request_id_ < 0) {
|
| - NOTREACHED() << "Trying to cancel an unstarted request";
|
| - return;
|
| - }
|
| -
|
| - if (!is_synchronous_request_)
|
| - dispatcher_->CancelPendingRequest(request_id_);
|
| -
|
| - // We can't remove the request ID from the resource dispatcher because more
|
| - // data might be pending. Sending the cancel message may cause more data
|
| - // to be flushed, and will then cause a complete message to be sent.
|
| -}
|
| -
|
| -void IPCResourceLoaderBridge::SetDefersLoading(bool value) {
|
| - if (request_id_ < 0) {
|
| - NOTREACHED() << "Trying to (un)defer an unstarted request";
|
| - return;
|
| - }
|
| -
|
| - dispatcher_->SetDefersLoading(request_id_, value);
|
| -}
|
| -
|
| -void IPCResourceLoaderBridge::DidChangePriority(
|
| - net::RequestPriority new_priority, int intra_priority_value) {
|
| - if (request_id_ < 0) {
|
| - NOTREACHED() << "Trying to change priority of an unstarted request";
|
| - return;
|
| - }
|
| -
|
| - dispatcher_->DidChangePriority(routing_id_, request_id_, new_priority,
|
| - intra_priority_value);
|
| -}
|
| -
|
| -void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) {
|
| - if (request_id_ != -1) {
|
| - NOTREACHED() << "Starting a request twice";
|
| - response->error_code = net::ERR_FAILED;
|
| - return;
|
| - }
|
| -
|
| - request_id_ = MakeRequestID();
|
| - is_synchronous_request_ = true;
|
| -
|
| - SyncLoadResult result;
|
| - IPC::SyncMessage* msg = new ResourceHostMsg_SyncLoad(routing_id_, request_id_,
|
| - request_, &result);
|
| - // NOTE: This may pump events (see RenderThread::Send).
|
| - if (!dispatcher_->message_sender()->Send(msg)) {
|
| - response->error_code = net::ERR_FAILED;
|
| - return;
|
| - }
|
| -
|
| - response->error_code = result.error_code;
|
| - response->url = result.final_url;
|
| - response->headers = result.headers;
|
| - response->mime_type = result.mime_type;
|
| - response->charset = result.charset;
|
| - response->request_time = result.request_time;
|
| - response->response_time = result.response_time;
|
| - response->encoded_data_length = result.encoded_data_length;
|
| - response->load_timing = result.load_timing;
|
| - response->devtools_info = result.devtools_info;
|
| - response->data.swap(result.data);
|
| - response->download_file_path = result.download_file_path;
|
| -}
|
| -
|
| -// ResourceDispatcher ---------------------------------------------------------
|
| -
|
| -ResourceDispatcher::ResourceDispatcher(IPC::Sender* sender)
|
| - : message_sender_(sender),
|
| - weak_factory_(this),
|
| - delegate_(NULL),
|
| - io_timestamp_(base::TimeTicks()) {
|
| -}
|
| -
|
| -ResourceDispatcher::~ResourceDispatcher() {
|
| -}
|
| -
|
| -// ResourceDispatcher implementation ------------------------------------------
|
| -
|
| bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) {
|
| if (!IsResourceDispatcherMessage(message)) {
|
| return false;
|
| @@ -615,9 +429,10 @@ void ResourceDispatcher::SetDefersLoading(int request_id, bool value) {
|
| }
|
| }
|
|
|
| -void ResourceDispatcher::DidChangePriority(
|
| - int routing_id, int request_id, net::RequestPriority new_priority,
|
| - int intra_priority_value) {
|
| +void ResourceDispatcher::DidChangePriority(int routing_id,
|
| + int request_id,
|
| + net::RequestPriority new_priority,
|
| + int intra_priority_value) {
|
| DCHECK(ContainsKey(pending_requests_, request_id));
|
| message_sender()->Send(new ResourceHostMsg_DidChangePriority(
|
| request_id, new_priority, intra_priority_value));
|
| @@ -694,9 +509,137 @@ void ResourceDispatcher::FlushDeferredMessages(int request_id) {
|
| }
|
| }
|
|
|
| -ResourceLoaderBridge* ResourceDispatcher::CreateBridge(
|
| - const RequestInfo& request_info) {
|
| - return new IPCResourceLoaderBridge(this, request_info);
|
| +void ResourceDispatcher::CreateBridge(const RequestInfo& request_info) {
|
| + request_.reset(new ResourceHostMsg_Request);
|
| + request_->method = request_info.method;
|
| + request_->url = request_info.url;
|
| + request_->first_party_for_cookies = request_info.first_party_for_cookies;
|
| + request_->referrer = request_info.referrer;
|
| + request_->referrer_policy = request_info.referrer_policy;
|
| + request_->headers = request_info.headers;
|
| + request_->load_flags = request_info.load_flags;
|
| + request_->origin_pid = request_info.requestor_pid;
|
| + request_->resource_type = request_info.request_type;
|
| + request_->priority = request_info.priority;
|
| + request_->request_context = request_info.request_context;
|
| + request_->appcache_host_id = request_info.appcache_host_id;
|
| + request_->download_to_file = request_info.download_to_file;
|
| + request_->has_user_gesture = request_info.has_user_gesture;
|
| +
|
| + const RequestExtraData kEmptyData;
|
| + const RequestExtraData* extra_data;
|
| + if (request_info.extra_data)
|
| + extra_data = static_cast<RequestExtraData*>(request_info.extra_data);
|
| + else
|
| + extra_data = &kEmptyData;
|
| + request_->visiblity_state = extra_data->visibility_state();
|
| + request_->render_frame_id = extra_data->render_frame_id();
|
| + request_->is_main_frame = extra_data->is_main_frame();
|
| + request_->parent_is_main_frame = extra_data->parent_is_main_frame();
|
| + request_->parent_render_frame_id = extra_data->parent_render_frame_id();
|
| + request_->allow_download = extra_data->allow_download();
|
| + request_->transition_type = extra_data->transition_type();
|
| + request_->should_replace_current_entry =
|
| + extra_data->should_replace_current_entry();
|
| + request_->transferred_request_child_id =
|
| + extra_data->transferred_request_child_id();
|
| + request_->transferred_request_request_id =
|
| + extra_data->transferred_request_request_id();
|
| + request_->service_worker_provider_id =
|
| + extra_data->service_worker_provider_id();
|
| + frame_origin_ = extra_data->frame_origin();
|
| +}
|
| +
|
| +void ResourceDispatcher::SetRequestBody(ResourceRequestBody* request_body) {
|
| + DCHECK(request_id_ == -1) << "request already started";
|
| + request_->request_body = request_body;
|
| +}
|
| +
|
| +bool ResourceDispatcher::Start(RequestPeer* peer) {
|
| + if (request_id_ != -1) {
|
| + NOTREACHED() << "Starting a request twice";
|
| + return false;
|
| + }
|
| +
|
| + peer_ = peer;
|
| +
|
| + // generate the request ID, and append it to the message
|
| + request_id_ = AddPendingRequest(peer_,
|
| + request_->resource_type,
|
| + request_->origin_pid,
|
| + frame_origin_,
|
| + request_->url);
|
| +
|
| + return message_sender_->Send(new ResourceHostMsg_RequestResource(
|
| + routing_id_, request_id_, *request_.get()));
|
| +}
|
| +
|
| +void ResourceDispatcher::Cancel() {
|
| + if (request_id_ < 0) {
|
| + NOTREACHED() << "Trying to cancel an unstarted request";
|
| + return;
|
| + }
|
| +
|
| + if (!is_synchronous_request_)
|
| + CancelPendingRequest(request_id_);
|
| +
|
| + // We can't remove the request ID from the resource dispatcher because more
|
| + // data might be pending. Sending the cancel message may cause more data
|
| + // to be flushed, and will then cause a complete message to be sent.
|
| +}
|
| +
|
| +void ResourceDispatcher::SetDefersLoading(bool value) {
|
| + if (request_id_ < 0) {
|
| + NOTREACHED() << "Trying to (un)defer an unstarted request";
|
| + return;
|
| + }
|
| +
|
| + SetDefersLoading(request_id_, value);
|
| +}
|
| +
|
| +void ResourceDispatcher::DidChangePriority(net::RequestPriority new_priority,
|
| + int intra_priority_value) {
|
| + if (request_id_ < 0) {
|
| + NOTREACHED() << "Trying to change priority of an unstarted request";
|
| + return;
|
| + }
|
| +
|
| + DidChangePriority(
|
| + routing_id_, request_id_, new_priority, intra_priority_value);
|
| +}
|
| +
|
| +void ResourceDispatcher::SyncLoad(SyncLoadResponse* response) {
|
| + if (request_id_ != -1) {
|
| + NOTREACHED() << "Starting a request twice";
|
| + response->error_code = net::ERR_FAILED;
|
| + return;
|
| + }
|
| +
|
| + request_id_ = MakeRequestID();
|
| + is_synchronous_request_ = true;
|
| +
|
| + SyncLoadResult result;
|
| + IPC::SyncMessage* msg = new ResourceHostMsg_SyncLoad(
|
| + routing_id_, request_id_, *request_.get(), &result);
|
| +
|
| + // NOTE: This may pump events (see RenderThread::Send).
|
| + if (!message_sender_->Send(msg)) {
|
| + response->error_code = net::ERR_FAILED;
|
| + return;
|
| + }
|
| +
|
| + response->error_code = result.error_code;
|
| + response->url = result.final_url;
|
| + response->headers = result.headers;
|
| + response->mime_type = result.mime_type;
|
| + response->charset = result.charset;
|
| + response->request_time = result.request_time;
|
| + response->response_time = result.response_time;
|
| + response->encoded_data_length = result.encoded_data_length;
|
| + response->load_timing = result.load_timing;
|
| + response->devtools_info = result.devtools_info;
|
| + response->data.swap(result.data);
|
| + response->download_file_path = result.download_file_path;
|
| }
|
|
|
| void ResourceDispatcher::ToResourceResponseInfo(
|
|
|