Chromium Code Reviews| Index: chrome/renderer/extensions/webstore_bindings.cc |
| diff --git a/chrome/renderer/extensions/webstore_bindings.cc b/chrome/renderer/extensions/webstore_bindings.cc |
| index 5fd175a5f6ea863b9999df4e3d7dff8fb0cc4a40..7ce25564ac99680281b6a01f5bfff9be3e916863 100644 |
| --- a/chrome/renderer/extensions/webstore_bindings.cc |
| +++ b/chrome/renderer/extensions/webstore_bindings.cc |
| @@ -9,12 +9,15 @@ |
| #include "base/macros.h" |
| #include "base/strings/string_util.h" |
| #include "chrome/common/extensions/api/webstore/webstore_api_constants.h" |
| -#include "chrome/common/extensions/chrome_extension_messages.h" |
| +#include "chrome/renderer/extensions/webstore_bindings_helper.h" |
| #include "components/crx_file/id_util.h" |
| #include "content/public/renderer/render_frame.h" |
| #include "extensions/common/extension.h" |
| #include "extensions/common/extension_urls.h" |
| #include "extensions/renderer/script_context.h" |
| +#include "mojo/public/cpp/bindings/strong_binding.h" |
| +#include "services/service_manager/public/cpp/interface_provider.h" |
| +#include "services/service_manager/public/cpp/interface_registry.h" |
| #include "third_party/WebKit/public/web/WebDocument.h" |
| #include "third_party/WebKit/public/web/WebElement.h" |
| #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| @@ -45,17 +48,26 @@ const char kInvalidWebstoreItemUrlError[] = |
| // chrome.webstore.install() calls generate an install ID so that the install's |
| // callbacks may be fired when the browser notifies us of install completion |
| -// (successful or not) via OnInlineWebstoreInstallResponse. |
| +// (successful or not) via InlineInstallResponse. |
| int g_next_install_id = 0; |
| } // anonymous namespace |
| +ScriptContext* WebstoreBindings::context_ = NULL; |
| + |
| WebstoreBindings::WebstoreBindings(ScriptContext* context) |
| : ObjectBackedNativeHandler(context) { |
| + WebstoreBindings::SetContext(context); |
|
Devlin
2017/04/12 01:16:07
This would only work if the WebstoreBindings we wa
catmullings
2017/04/14 20:59:40
Ok. Is it possible to check for the most-recently
Devlin
2017/04/24 20:08:32
We don't necessarily want to check for the most-re
catmullings
2017/04/26 20:36:34
Done.
|
| RouteFunction("Install", "webstore", |
| base::Bind(&WebstoreBindings::Install, base::Unretained(this))); |
| + context->GetRenderFrame()->GetRemoteInterfaces()->GetInterface( |
| + &inline_install_); |
| + context->GetRenderFrame()->GetInterfaceRegistry()->AddInterface( |
| + base::Bind(&WebstoreBindingsHelper::Create, context)); |
| } |
| +WebstoreBindings::~WebstoreBindings() {} |
| + |
| void WebstoreBindings::Install( |
| const v8::FunctionCallbackInfo<v8::Value>& args) { |
| content::RenderFrame* render_frame = context()->GetRenderFrame(); |
| @@ -91,9 +103,9 @@ void WebstoreBindings::Install( |
| int install_id = g_next_install_id++; |
| - Send(new ExtensionHostMsg_InlineWebstoreInstall( |
| - render_frame->GetRoutingID(), install_id, GetRoutingID(), |
| - webstore_item_id, listener_mask)); |
| + inline_install_->DoInlineInstall( |
| + install_id, GetRoutingID(), webstore_item_id, listener_mask, |
| + base::Bind(&WebstoreBindings::InlineInstallResponse)); |
| args.GetReturnValue().Set(static_cast<int32_t>(install_id)); |
| } |
| @@ -187,26 +199,18 @@ bool WebstoreBindings::GetWebstoreItemIdFromFrame( |
| } |
| bool WebstoreBindings::OnMessageReceived(const IPC::Message& message) { |
| - IPC_BEGIN_MESSAGE_MAP(WebstoreBindings, message) |
| - IPC_MESSAGE_HANDLER(ExtensionMsg_InlineWebstoreInstallResponse, |
| - OnInlineWebstoreInstallResponse) |
| - IPC_MESSAGE_HANDLER(ExtensionMsg_InlineInstallStageChanged, |
| - OnInlineInstallStageChanged) |
| - IPC_MESSAGE_HANDLER(ExtensionMsg_InlineInstallDownloadProgress, |
| - OnInlineInstallDownloadProgress) |
| - IPC_MESSAGE_UNHANDLED(CHECK(false) << "Unhandled IPC message") |
| - IPC_END_MESSAGE_MAP() |
| return true; |
| } |
| -void WebstoreBindings::OnInlineWebstoreInstallResponse( |
| - int install_id, |
| - bool success, |
| - const std::string& error, |
| - webstore_install::Result result) { |
| - v8::Isolate* isolate = context()->isolate(); |
| +// static |
| +void WebstoreBindings::InlineInstallResponse(int install_id, |
| + bool success, |
| + const std::string& error, |
| + webstore_install::Result result) { |
| + v8::Isolate* isolate = WebstoreBindings::GetContext()->isolate(); |
| v8::HandleScope handle_scope(isolate); |
| - v8::Context::Scope context_scope(context()->v8_context()); |
| + v8::Context::Scope context_scope( |
| + WebstoreBindings::GetContext()->v8_context()); |
| v8::Local<v8::Value> argv[] = { |
| v8::Integer::New(isolate, install_id), |
| v8::Boolean::New(isolate, success), |
| @@ -214,39 +218,8 @@ void WebstoreBindings::OnInlineWebstoreInstallResponse( |
| v8::String::NewFromUtf8( |
| isolate, api::webstore::kInstallResultCodes[static_cast<int>(result)]) |
| }; |
| - context()->module_system()->CallModuleMethodSafe( |
| + WebstoreBindings::GetContext()->module_system()->CallModuleMethodSafe( |
| "webstore", "onInstallResponse", arraysize(argv), argv); |
| } |
| -void WebstoreBindings::OnInlineInstallStageChanged(int stage) { |
| - const char* stage_string = NULL; |
| - api::webstore::InstallStage install_stage = |
| - static_cast<api::webstore::InstallStage>(stage); |
| - switch (install_stage) { |
| - case api::webstore::INSTALL_STAGE_DOWNLOADING: |
| - stage_string = api::webstore::kInstallStageDownloading; |
| - break; |
| - case api::webstore::INSTALL_STAGE_INSTALLING: |
| - stage_string = api::webstore::kInstallStageInstalling; |
| - break; |
| - } |
| - v8::Isolate* isolate = context()->isolate(); |
| - v8::HandleScope handle_scope(isolate); |
| - v8::Context::Scope context_scope(context()->v8_context()); |
| - v8::Local<v8::Value> argv[] = { |
| - v8::String::NewFromUtf8(isolate, stage_string)}; |
| - context()->module_system()->CallModuleMethodSafe( |
| - "webstore", "onInstallStageChanged", arraysize(argv), argv); |
| -} |
| - |
| -void WebstoreBindings::OnInlineInstallDownloadProgress(int percent_downloaded) { |
| - v8::Isolate* isolate = context()->isolate(); |
| - v8::HandleScope handle_scope(isolate); |
| - v8::Context::Scope context_scope(context()->v8_context()); |
| - v8::Local<v8::Value> argv[] = { |
| - v8::Number::New(isolate, percent_downloaded / 100.0)}; |
| - context()->module_system()->CallModuleMethodSafe( |
| - "webstore", "onDownloadProgress", arraysize(argv), argv); |
| -} |
| - |
| } // namespace extensions |