diff options
author | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-26 04:36:30 +0000 |
---|---|---|
committer | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-26 04:36:30 +0000 |
commit | c80fe5faf691860c344bcc98aa784a6eeefae08d (patch) | |
tree | e8cab8e0ccf96d953c05ef4b44f0cd172ddf8f0c /chrome/renderer/extensions | |
parent | 5ad5f93029e1767bb46ed6b8310b608cd7b7460a (diff) | |
download | chromium_src-c80fe5faf691860c344bcc98aa784a6eeefae08d.zip chromium_src-c80fe5faf691860c344bcc98aa784a6eeefae08d.tar.gz chromium_src-c80fe5faf691860c344bcc98aa784a6eeefae08d.tar.bz2 |
Add chrome.webstore API methods to allow sites to see progress of installation
Add two chrome.webstore API methods for progress updates:
chrome.webstore.setInstallStageListener(function(string stage))
- stage is either "downloading" or "installing"
chrome.webstore.setDownloadProgressListener(function(int percent_downloaded))
Update InstallObserver to have methods for install stages.
Make WebstoreInstaller provide more frequent download updates (current consumers
like WebstoreResult imply this was intended from the start).
BUG=308634
Review URL: https://codereview.chromium.org/175263003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259483 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/extensions')
-rw-r--r-- | chrome/renderer/extensions/webstore_bindings.cc | 97 | ||||
-rw-r--r-- | chrome/renderer/extensions/webstore_bindings.h | 4 |
2 files changed, 63 insertions, 38 deletions
diff --git a/chrome/renderer/extensions/webstore_bindings.cc b/chrome/renderer/extensions/webstore_bindings.cc index 21f3b22..08e9d9a 100644 --- a/chrome/renderer/extensions/webstore_bindings.cc +++ b/chrome/renderer/extensions/webstore_bindings.cc @@ -5,11 +5,12 @@ #include "chrome/renderer/extensions/webstore_bindings.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/common/extensions/extension_constants.h" #include "chrome/renderer/extensions/chrome_v8_context.h" #include "content/public/renderer/render_view.h" #include "extensions/common/extension.h" -#include "extensions/common/extension_messages.h" #include "grit/renderer_resources.h" #include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebElement.h" @@ -32,12 +33,6 @@ namespace { const char kWebstoreLinkRelation[] = "chrome-webstore-item"; -const char kPreferredStoreLinkUrlNotAString[] = - "The Chrome Web Store item link URL parameter must be a string."; -const char kSuccessCallbackNotAFunctionError[] = - "The success callback parameter must be a function."; -const char kFailureCallbackNotAFunctionError[] = - "The failure callback parameter must be a function."; const char kNotInTopFrameError[] = "Chrome Web Store installations can only be started by the top frame."; const char kNotUserGestureError[] = @@ -64,28 +59,30 @@ WebstoreBindings::WebstoreBindings(Dispatcher* dispatcher, void WebstoreBindings::Install( const v8::FunctionCallbackInfo<v8::Value>& args) { - WebFrame* frame = WebFrame::frameForContext(context()->v8_context()); - if (!frame || !frame->view()) - return; - - content::RenderView* render_view = - content::RenderView::FromWebView(frame->view()); + content::RenderView* render_view = GetRenderView(); if (!render_view) return; + // The first two arguments indicate whether or not there are install stage + // or download progress listeners. + int listener_mask = 0; + CHECK(args[0]->IsBoolean()); + if (args[0]->BooleanValue()) + listener_mask |= api::webstore::INSTALL_STAGE_LISTENER; + CHECK(args[1]->IsBoolean()); + if (args[1]->BooleanValue()) + listener_mask |= api::webstore::DOWNLOAD_PROGRESS_LISTENER; + std::string preferred_store_link_url; - if (!args[0]->IsUndefined()) { - if (args[0]->IsString()) { - preferred_store_link_url = std::string(*v8::String::Utf8Value(args[0])); - } else { - args.GetIsolate()->ThrowException(v8::String::NewFromUtf8( - args.GetIsolate(), kPreferredStoreLinkUrlNotAString)); - return; - } + if (!args[2]->IsUndefined()) { + CHECK(args[2]->IsString()); + preferred_store_link_url = std::string(*v8::String::Utf8Value(args[2])); } std::string webstore_item_id; std::string error; + WebFrame* frame = context()->web_frame(); + if (!GetWebstoreItemIdFromFrame( frame, preferred_store_link_url, &webstore_item_id, &error)) { args.GetIsolate()->ThrowException( @@ -94,24 +91,13 @@ void WebstoreBindings::Install( } int install_id = g_next_install_id++; - if (!args[1]->IsUndefined() && !args[1]->IsFunction()) { - args.GetIsolate()->ThrowException(v8::String::NewFromUtf8( - args.GetIsolate(), kSuccessCallbackNotAFunctionError)); - return; - } - if (!args[2]->IsUndefined() && !args[2]->IsFunction()) { - args.GetIsolate()->ThrowException(v8::String::NewFromUtf8( - args.GetIsolate(), kFailureCallbackNotAFunctionError)); - return; - } - - Send(new ExtensionHostMsg_InlineWebstoreInstall( - render_view->GetRoutingID(), - install_id, - GetRoutingID(), - webstore_item_id, - frame->document().url())); + Send(new ExtensionHostMsg_InlineWebstoreInstall(render_view->GetRoutingID(), + install_id, + GetRoutingID(), + webstore_item_id, + frame->document().url(), + listener_mask)); args.GetReturnValue().Set(static_cast<int32_t>(install_id)); } @@ -207,6 +193,10 @@ 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; @@ -228,4 +218,35 @@ void WebstoreBindings::OnInlineWebstoreInstallResponse( "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::Handle<v8::Value> argv[] = { + v8::String::NewFromUtf8(isolate, stage_string)}; + context()->module_system()->CallModuleMethod( + "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::Handle<v8::Value> argv[] = { + v8::Number::New(isolate, percent_downloaded / 100.0)}; + context()->module_system()->CallModuleMethod( + "webstore", "onDownloadProgress", arraysize(argv), argv); +} + } // namespace extensions diff --git a/chrome/renderer/extensions/webstore_bindings.h b/chrome/renderer/extensions/webstore_bindings.h index b729150..5df521a 100644 --- a/chrome/renderer/extensions/webstore_bindings.h +++ b/chrome/renderer/extensions/webstore_bindings.h @@ -30,6 +30,10 @@ class WebstoreBindings : public ChromeV8Extension, void OnInlineWebstoreInstallResponse( int install_id, bool success, const std::string& error); + void OnInlineInstallStageChanged(int stage); + + void OnInlineInstallDownloadProgress(int percent_downloaded); + // Extracts a Web Store item ID from a <link rel="chrome-webstore-item" // href="https://chrome.google.com/webstore/detail/id"> node found in the // frame. On success, true will be returned and the |webstore_item_id| |