| Index: chrome/renderer/extensions/webstore_bindings.cc
|
| diff --git a/chrome/renderer/extensions/webstore_bindings.cc b/chrome/renderer/extensions/webstore_bindings.cc
|
| index 2a3c2aa6dd7a01f5fcf61bc2b8d9958482aabe7a..290814ede899c5f6e70812bb4b731f7cc7520fe9 100644
|
| --- a/chrome/renderer/extensions/webstore_bindings.cc
|
| +++ b/chrome/renderer/extensions/webstore_bindings.cc
|
| @@ -9,8 +9,8 @@
|
| #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 "components/crx_file/id_util.h"
|
| +#include "content/public/common/associated_interface_provider.h"
|
| #include "content/public/renderer/render_frame.h"
|
| #include "extensions/common/extension.h"
|
| #include "extensions/common/extension_urls.h"
|
| @@ -45,7 +45,7 @@ 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
|
| @@ -54,6 +54,59 @@ WebstoreBindings::WebstoreBindings(ScriptContext* context)
|
| : ObjectBackedNativeHandler(context) {
|
| RouteFunction("Install", "webstore",
|
| base::Bind(&WebstoreBindings::Install, base::Unretained(this)));
|
| + content::RenderFrame* render_frame = context->GetRenderFrame();
|
| + if (render_frame)
|
| + render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
|
| + &inline_installer_);
|
| +}
|
| +
|
| +WebstoreBindings::~WebstoreBindings() {}
|
| +
|
| +void WebstoreBindings::InlineInstallResponse(int install_id,
|
| + bool success,
|
| + const std::string& error,
|
| + webstore_install::Result result) {
|
| + v8::Isolate* isolate = context()->isolate();
|
| + v8::HandleScope handle_scope(isolate);
|
| + v8::Context::Scope context_scope(context()->v8_context());
|
| + v8::Local<v8::Value> argv[] = {
|
| + v8::Integer::New(isolate, install_id), v8::Boolean::New(isolate, success),
|
| + v8::String::NewFromUtf8(isolate, error.c_str()),
|
| + v8::String::NewFromUtf8(
|
| + isolate,
|
| + api::webstore::kInstallResultCodes[static_cast<int>(result)])};
|
| + context()->module_system()->CallModuleMethodSafe(
|
| + "webstore", "onInstallResponse", arraysize(argv), argv);
|
| +}
|
| +
|
| +void WebstoreBindings::InlineInstallStageChanged(
|
| + api::webstore::InstallStage stage) {
|
| + const char* stage_string = nullptr;
|
| + switch (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::InlineInstallDownloadProgress(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);
|
| }
|
|
|
| void WebstoreBindings::Install(
|
| @@ -91,10 +144,13 @@ 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));
|
| + mojom::InlineInstallProgressListenerPtr install_progress_listener =
|
| + install_progress_listener_bindings_.CreateInterfacePtrAndBind(this);
|
|
|
| + inline_installer_->DoInlineInstall(
|
| + webstore_item_id, listener_mask, std::move(install_progress_listener),
|
| + base::Bind(&WebstoreBindings::InlineInstallResponse,
|
| + base::Unretained(this), install_id));
|
| args.GetReturnValue().Set(static_cast<int32_t>(install_id));
|
| }
|
|
|
| @@ -186,67 +242,4 @@ bool WebstoreBindings::GetWebstoreItemIdFromFrame(
|
| return false;
|
| }
|
|
|
| -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();
|
| - v8::HandleScope handle_scope(isolate);
|
| - v8::Context::Scope context_scope(context()->v8_context());
|
| - v8::Local<v8::Value> argv[] = {
|
| - v8::Integer::New(isolate, install_id),
|
| - v8::Boolean::New(isolate, success),
|
| - v8::String::NewFromUtf8(isolate, error.c_str()),
|
| - v8::String::NewFromUtf8(
|
| - isolate, api::webstore::kInstallResultCodes[static_cast<int>(result)])
|
| - };
|
| - context()->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
|
|
|