Chromium Code Reviews| Index: chrome/renderer/pepper/pepper_extensions_common_host.cc |
| diff --git a/chrome/renderer/pepper/pepper_extensions_common_host.cc b/chrome/renderer/pepper/pepper_extensions_common_host.cc |
| index 3ad629aad01dcd79c4d580f40e8128e79e494db3..a1bcb492bae887229cca10db409d23310f0c0a8b 100644 |
| --- a/chrome/renderer/pepper/pepper_extensions_common_host.cc |
| +++ b/chrome/renderer/pepper/pepper_extensions_common_host.cc |
| @@ -26,15 +26,16 @@ PepperExtensionsCommonHost::PepperExtensionsCommonHost( |
| content::RendererPpapiHost* host, |
| PP_Instance instance, |
| PP_Resource resource, |
| - extensions::Dispatcher* dispatcher) |
| + extensions::PepperRequestProxy* pepper_request_proxy) |
| : ResourceHost(host->GetPpapiHost(), instance, resource), |
| renderer_ppapi_host_(host), |
| - dispatcher_(dispatcher) { |
| + pepper_request_proxy_(pepper_request_proxy), |
| + weak_factory_(this) { |
| + callback_ = base::Bind(&PepperExtensionsCommonHost::OnResponseReceived, |
|
not at google - send to devlin
2013/12/03 17:32:50
holding onto this callback is weird. just create i
Sam McNally
2013/12/04 00:01:36
Done.
|
| + weak_factory_.GetWeakPtr()); |
| } |
| -PepperExtensionsCommonHost::~PepperExtensionsCommonHost() { |
| - dispatcher_->request_sender()->InvalidateSource(this); |
| -} |
| +PepperExtensionsCommonHost::~PepperExtensionsCommonHost() {} |
| // static |
| PepperExtensionsCommonHost* PepperExtensionsCommonHost::Create( |
| @@ -51,8 +52,22 @@ PepperExtensionsCommonHost* PepperExtensionsCommonHost::Create( |
| extensions::Dispatcher* dispatcher = extension_helper->dispatcher(); |
| if (!dispatcher) |
| return NULL; |
| + blink::WebPluginContainer* container = |
| + host->GetContainerForInstance(instance); |
| + if (!container) |
| + return NULL; |
| + blink::WebFrame* frame = container->element().document().frame(); |
| + if (!frame) |
| + return NULL; |
| + v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| + extensions::ChromeV8Context* context = |
| + dispatcher->v8_context_set().GetByV8Context( |
| + frame->mainWorldScriptContext()); |
| + if (!context) |
| + return NULL; |
| - return new PepperExtensionsCommonHost(host, instance, resource, dispatcher); |
| + return new PepperExtensionsCommonHost( |
| + host, instance, resource, context->pepper_request_proxy()); |
| } |
| int32_t PepperExtensionsCommonHost::OnResourceMessageReceived( |
| @@ -67,31 +82,14 @@ int32_t PepperExtensionsCommonHost::OnResourceMessageReceived( |
| return PP_ERROR_FAILED; |
| } |
| -extensions::ChromeV8Context* PepperExtensionsCommonHost::GetContext() { |
| - blink::WebPluginContainer* container = |
| - renderer_ppapi_host_->GetContainerForInstance(pp_instance()); |
| - if (!container) |
| - return NULL; |
| - |
| - blink::WebFrame* frame = container->element().document().frame(); |
| - v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| - return dispatcher_->v8_context_set().GetByV8Context( |
| - frame->mainWorldScriptContext()); |
| -} |
| - |
| void PepperExtensionsCommonHost::OnResponseReceived( |
| - const std::string& /* name */, |
| int request_id, |
| bool success, |
| const base::ListValue& response, |
| const std::string& /* error */) { |
| PendingRequestMap::iterator iter = pending_request_map_.find(request_id); |
| - // Ignore responses resulted from calls to OnPost(). |
| - if (iter == pending_request_map_.end()) { |
| - DCHECK_EQ(0u, response.GetSize()); |
| - return; |
| - } |
| + DCHECK(iter != pending_request_map_.end()); |
| linked_ptr<ppapi::host::ReplyMessageContext> context = iter->second; |
| pending_request_map_.erase(iter); |
| @@ -104,11 +102,11 @@ int32_t PepperExtensionsCommonHost::OnPost( |
| ppapi::host::HostMessageContext* context, |
| const std::string& request_name, |
| base::ListValue& args) { |
|
not at google - send to devlin
2013/12/03 17:32:50
this (and below) is a non-const reference? ok well
Sam McNally
2013/12/04 00:01:36
Done.
|
| - // TODO(yzshen): Add support for calling into JS for APIs that have custom |
| - // bindings. |
| - int request_id = dispatcher_->request_sender()->GetNextRequestId(); |
| - dispatcher_->request_sender()->StartRequest(this, request_name, request_id, |
| - false, false, &args); |
| + std::string error; |
| + bool success = pepper_request_proxy_->StartPost(request_name, &args, &error); |
| + if (!success) |
| + return PP_ERROR_FAILED; |
| + |
| return PP_OK; |
| } |
| @@ -116,15 +114,17 @@ int32_t PepperExtensionsCommonHost::OnCall( |
| ppapi::host::HostMessageContext* context, |
| const std::string& request_name, |
| base::ListValue& args) { |
| - // TODO(yzshen): Add support for calling into JS for APIs that have custom |
| - // bindings. |
| - int request_id = dispatcher_->request_sender()->GetNextRequestId(); |
| + int request_id; |
| + std::string error; |
| + bool success = pepper_request_proxy_->StartCall( |
| + callback_, request_name, &args, &request_id, &error); |
| + if (!success) |
| + return PP_ERROR_FAILED; |
| + |
| pending_request_map_[request_id] = |
|
not at google - send to devlin
2013/12/03 17:32:50
I think that pending_request_map_ is unnecessary i
Sam McNally
2013/12/04 00:01:36
Done.
|
| linked_ptr<ppapi::host::ReplyMessageContext>( |
| new ppapi::host::ReplyMessageContext( |
| context->MakeReplyMessageContext())); |
| - dispatcher_->request_sender()->StartRequest(this, request_name, request_id, |
| - true, false, &args); |
| return PP_OK_COMPLETIONPENDING; |
| } |