Skip to content

Commit

Permalink
Hook up status notifications in the Proxy.
Browse files Browse the repository at this point in the history
TEST=manual
BUG=none
Review URL: http://codereview.chromium.org/6724042

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79687 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
brettw@chromium.org committed Mar 29, 2011
1 parent 93b4301 commit 90c4f7c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 7 deletions.
51 changes: 49 additions & 2 deletions ppapi/proxy/ppb_url_loader_proxy.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -296,6 +296,27 @@ InterfaceProxy* CreateURLLoaderTrustedProxy(Dispatcher* dispatcher,
return new PPB_URLLoaderTrusted_Proxy(dispatcher, target_interface);
}

// Called in the renderer when the byte counts have changed. We send a message
// to the plugin to synchronize its counts so it can respond to status polls
// from the plugin.
void UpdateResourceLoadStatus(PP_Instance pp_instance,
PP_Resource pp_resource,
int64 bytes_sent,
int64 total_bytes_to_be_sent,
int64 bytes_received,
int64 total_bytes_to_be_received) {
Dispatcher* dispatcher = HostDispatcher::GetForInstance(pp_instance);
PPBURLLoader_UpdateProgress_Params params;
params.instance = pp_instance;
params.resource.SetHostResource(pp_instance, pp_resource);
params.bytes_sent = bytes_sent;
params.total_bytes_to_be_sent = total_bytes_to_be_sent;
params.bytes_received = bytes_received;
params.total_bytes_to_be_received = total_bytes_to_be_received;
dispatcher->Send(new PpapiMsg_PPBURLLoader_UpdateProgress(
INTERFACE_ID_PPB_URL_LOADER, params));
}

} // namespace

// PPB_URLLoader_Proxy ---------------------------------------------------------
Expand All @@ -308,7 +329,8 @@ struct PPB_URLLoader_Proxy::ReadCallbackInfo {
PPB_URLLoader_Proxy::PPB_URLLoader_Proxy(Dispatcher* dispatcher,
const void* target_interface)
: InterfaceProxy(dispatcher, target_interface),
callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
host_urlloader_trusted_interface_(NULL) {
}

PPB_URLLoader_Proxy::~PPB_URLLoader_Proxy() {
Expand Down Expand Up @@ -361,9 +383,17 @@ bool PPB_URLLoader_Proxy::OnMessageReceived(const IPC::Message& msg) {
return handled;
}

void PPB_URLLoader_Proxy::PrepareURLLoaderForSendingToPlugin(
PP_Resource resource) {
// So the plugin can query load status, we need to register our status
// callback before sending any URLLoader to the plugin.
RegisterStatusCallback(resource);
}

void PPB_URLLoader_Proxy::OnMsgCreate(PP_Instance instance,
HostResource* result) {
result->SetHostResource(instance, ppb_url_loader_target()->Create(instance));
PrepareURLLoaderForSendingToPlugin(result->host_resource());
}

void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader,
Expand Down Expand Up @@ -490,6 +520,23 @@ void PPB_URLLoader_Proxy::OnMsgReadResponseBodyAck(
PP_RunCompletionCallback(&temp_callback, result);
}

void PPB_URLLoader_Proxy::RegisterStatusCallback(PP_Resource resource) {
DCHECK(!dispatcher()->IsPlugin());
if (!host_urlloader_trusted_interface_) {
host_urlloader_trusted_interface_ =
static_cast<const PPB_URLLoaderTrusted*>(
dispatcher()->GetLocalInterface(PPB_URLLOADERTRUSTED_INTERFACE));
if (!host_urlloader_trusted_interface_) {
NOTREACHED();
return;
}
}

host_urlloader_trusted_interface_->RegisterStatusCallback(
resource,
&UpdateResourceLoadStatus);
}

void PPB_URLLoader_Proxy::OnReadCallback(int32_t result,
ReadCallbackInfo* info) {
int32_t bytes_read = 0;
Expand Down
16 changes: 15 additions & 1 deletion ppapi/proxy/ppb_url_loader_proxy.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -45,6 +45,12 @@ class PPB_URLLoader_Proxy : public InterfaceProxy {
// InterfaceProxy implementation.
virtual bool OnMessageReceived(const IPC::Message& msg);

// URLLoader objects are sent from places other than just URLLoader.Create,
// in particular when doing a full-frame plugin. This function does the
// necessary setup in the host before the resource is sent. Call this any
// time you're sending a new URLLoader that the plugin hasn't seen yet.
void PrepareURLLoaderForSendingToPlugin(PP_Resource resource);

private:
// Data associated with callbacks for ReadResponseBody.
struct ReadCallbackInfo;
Expand Down Expand Up @@ -72,12 +78,20 @@ class PPB_URLLoader_Proxy : public InterfaceProxy {
int32_t result,
const std::string& data);

// Hooks the given URLLoader resource up in the host for receiving download
// and upload status callbacks.
void RegisterStatusCallback(PP_Resource resource);

// Handles callbacks for read complete messages. Takes ownership of the info
// pointer.
void OnReadCallback(int32_t result, ReadCallbackInfo* info);

CompletionCallbackFactory<PPB_URLLoader_Proxy,
ProxyNonThreadSafeRefCount> callback_factory_;

// Valid only in the host, this lazily-initialized pointer indicates the
// URLLoaderTrusted interface.
const PPB_URLLoaderTrusted* host_urlloader_trusted_interface_;
};

class PPB_URLLoaderTrusted_Proxy : public InterfaceProxy {
Expand Down
14 changes: 10 additions & 4 deletions ppapi/proxy/ppp_instance_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,18 @@ PP_Bool HandleInputEvent(PP_Instance instance,
PP_Bool HandleDocumentLoad(PP_Instance instance,
PP_Resource url_loader) {
PP_Bool result = PP_FALSE;
HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);

// Set up the URLLoader for proxying.

PPB_URLLoader_Proxy* url_loader_proxy = static_cast<PPB_URLLoader_Proxy*>(
dispatcher->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_URL_LOADER));
url_loader_proxy->PrepareURLLoaderForSendingToPlugin(url_loader);

HostResource serialized_loader;
serialized_loader.SetHostResource(instance, url_loader);
HostDispatcher::GetForInstance(instance)->Send(
new PpapiMsg_PPPInstance_HandleDocumentLoad(INTERFACE_ID_PPP_INSTANCE,
instance, serialized_loader,
&result));
dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad(
INTERFACE_ID_PPP_INSTANCE, instance, serialized_loader, &result));
return result;
}

Expand Down

0 comments on commit 90c4f7c

Please sign in to comment.