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..873fbcfa1354b4c305f325294cdd0e63ba13037f 100644 |
| --- a/chrome/renderer/pepper/pepper_extensions_common_host.cc |
| +++ b/chrome/renderer/pepper/pepper_extensions_common_host.cc |
| @@ -26,14 +26,13 @@ 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) {} |
| PepperExtensionsCommonHost::~PepperExtensionsCommonHost() { |
| - dispatcher_->request_sender()->InvalidateSource(this); |
| + pepper_request_proxy_->InvalidateSource(this); |
| } |
| // static |
| @@ -48,11 +47,25 @@ PepperExtensionsCommonHost* PepperExtensionsCommonHost::Create( |
| extensions::ExtensionHelper::Get(render_view); |
| if (!extension_helper) |
| return NULL; |
| + blink::WebPluginContainer* container = |
|
yzshen1
2013/11/26 19:33:11
It seems better to move line 54-56 to be right bel
Sam McNally
2013/11/27 23:40:26
Done.
|
| + host->GetContainerForInstance(instance); |
| + if (!container) |
| + return NULL; |
| extensions::Dispatcher* dispatcher = extension_helper->dispatcher(); |
| if (!dispatcher) |
| 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 +80,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 +100,13 @@ int32_t PepperExtensionsCommonHost::OnPost( |
| 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(); |
| - dispatcher_->request_sender()->StartRequest(this, request_name, request_id, |
| - false, false, &args); |
| + int request_id; |
| + std::string error; |
| + bool success = pepper_request_proxy_->StartRequest( |
|
yzshen1
2013/11/26 19:33:11
Please add a TODO (maybe in pepper_request_proxy f
Sam McNally
2013/11/27 23:40:26
Done.
|
| + this, request_name, false, args, &request_id, &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_->StartRequest( |
| + this, request_name, true, args, &request_id, &error); |
| + if (!success) |
| + return PP_ERROR_FAILED; |
| + |
| pending_request_map_[request_id] = |
| 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; |
| } |