Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / renderer / extensions / webstore_bindings.cc
index 08e9d9a..c46a23c 100644 (file)
@@ -7,11 +7,11 @@
 #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 "components/crx_file/id_util.h"
 #include "content/public/renderer/render_view.h"
 #include "extensions/common/extension.h"
-#include "grit/renderer_resources.h"
+#include "extensions/common/extension_urls.h"
+#include "extensions/renderer/script_context.h"
 #include "third_party/WebKit/public/web/WebDocument.h"
 #include "third_party/WebKit/public/web/WebElement.h"
 #include "third_party/WebKit/public/web/WebNode.h"
@@ -49,17 +49,15 @@ int g_next_install_id = 0;
 
 } // anonymous namespace
 
-WebstoreBindings::WebstoreBindings(Dispatcher* dispatcher,
-                                   ChromeV8Context* context)
-    : ChromeV8Extension(dispatcher, context),
-      ChromeV8ExtensionHandler(context) {
+WebstoreBindings::WebstoreBindings(ScriptContext* context)
+    : ObjectBackedNativeHandler(context), ChromeV8ExtensionHandler(context) {
   RouteFunction("Install",
                 base::Bind(&WebstoreBindings::Install, base::Unretained(this)));
 }
 
 void WebstoreBindings::Install(
     const v8::FunctionCallbackInfo<v8::Value>& args) {
-  content::RenderView* render_view = GetRenderView();
+  content::RenderView* render_view = context()->GetRenderView();
   if (!render_view)
     return;
 
@@ -137,7 +135,7 @@ bool WebstoreBindings::GetWebstoreItemIdFromFrame(
       continue;
     WebElement elem = child.to<WebElement>();
 
-    if (!elem.hasTagName("link") || !elem.hasAttribute("rel") ||
+    if (!elem.hasHTMLTagName("link") || !elem.hasAttribute("rel") ||
         !elem.hasAttribute("href"))
       continue;
 
@@ -168,7 +166,7 @@ bool WebstoreBindings::GetWebstoreItemIdFromFrame(
 
     std::string candidate_webstore_item_id = webstore_url.path().substr(
         webstore_base_url.path().length());
-    if (!extensions::Extension::IdIsValid(candidate_webstore_item_id)) {
+    if (!crx_file::id_util::IdIsValid(candidate_webstore_item_id)) {
       *error = kInvalidWebstoreItemUrlError;
       return false;
     }
@@ -205,14 +203,17 @@ bool WebstoreBindings::OnMessageReceived(const IPC::Message& message) {
 void WebstoreBindings::OnInlineWebstoreInstallResponse(
     int install_id,
     bool success,
-    const std::string& error) {
+    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::Handle<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, error.c_str()),
+    v8::String::NewFromUtf8(
+        isolate, api::webstore::kInstallResultCodes[static_cast<int>(result)])
   };
   context()->module_system()->CallModuleMethod(
       "webstore", "onInstallResponse", arraysize(argv), argv);