| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/extensions/app_bindings.h" | 5 #include "chrome/renderer/extensions/app_bindings.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 const char* kMissingClientIdError = "Missing clientId parameter"; | 52 const char* kMissingClientIdError = "Missing clientId parameter"; |
| 53 const char* kInvalidClientIdError = "Invalid clientId"; | 53 const char* kInvalidClientIdError = "Invalid clientId"; |
| 54 const char* kInvalidCallbackIdError = "Invalid callbackId"; | 54 const char* kInvalidCallbackIdError = "Invalid callbackId"; |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 | |
| 59 AppBindings::AppBindings(ExtensionDispatcher* dispatcher, | 58 AppBindings::AppBindings(ExtensionDispatcher* dispatcher, |
| 60 ChromeV8Context* context) | 59 ChromeV8Context* context) |
| 61 : ChromeV8Extension(dispatcher), | 60 : ChromeV8Extension(dispatcher), |
| 62 ChromeV8ExtensionHandler(context) { | 61 ChromeV8ExtensionHandler(context) { |
| 63 RouteFunction("GetIsInstalled", | 62 RouteFunction("GetIsInstalled", |
| 64 base::Bind(&AppBindings::GetIsInstalled, base::Unretained(this))); | 63 base::Bind(&AppBindings::GetIsInstalled, base::Unretained(this))); |
| 65 RouteFunction("Install", | 64 RouteFunction("Install", |
| 66 base::Bind(&AppBindings::Install, base::Unretained(this))); | 65 base::Bind(&AppBindings::Install, base::Unretained(this))); |
| 67 RouteFunction("GetDetails", | 66 RouteFunction("GetDetails", |
| 68 base::Bind(&AppBindings::GetDetails, base::Unretained(this))); | 67 base::Bind(&AppBindings::GetDetails, base::Unretained(this))); |
| 69 RouteFunction("GetDetailsForFrame", | 68 RouteFunction("GetDetailsForFrame", |
| 70 base::Bind(&AppBindings::GetDetailsForFrame, base::Unretained(this))); | 69 base::Bind(&AppBindings::GetDetailsForFrame, base::Unretained(this))); |
| 71 RouteFunction("GetAppNotifyChannel", | 70 RouteFunction("GetAppNotifyChannel", |
| 72 base::Bind(&AppBindings::GetAppNotifyChannel, base::Unretained(this))); | 71 base::Bind(&AppBindings::GetAppNotifyChannel, base::Unretained(this))); |
| 73 } | 72 } |
| 74 | 73 |
| 75 | |
| 76 v8::Handle<v8::Value> AppBindings::GetIsInstalled( | 74 v8::Handle<v8::Value> AppBindings::GetIsInstalled( |
| 77 const v8::Arguments& args) { | 75 const v8::Arguments& args) { |
| 78 // TODO(aa): Hm, maybe ExtensionBindingsContext should have GetExtension() | 76 // TODO(aa): Hm, maybe ExtensionBindingsContext should have GetExtension() |
| 79 // afterall? | 77 // afterall? |
| 80 const ::Extension* extension = | 78 const ::Extension* extension = |
| 81 extension_dispatcher_->extensions()->GetByID(context_->extension_id()); | 79 extension_dispatcher_->extensions()->GetByID(context_->extension_id()); |
| 82 | 80 |
| 83 // TODO(aa): Why only hosted app? | 81 // TODO(aa): Why only hosted app? |
| 84 // TODO(aa): GARRR - why is there IsExtensionActive and IsApplicationActive!? | |
| 85 bool result = extension && extension->is_hosted_app() && | 82 bool result = extension && extension->is_hosted_app() && |
| 86 extension_dispatcher_->IsApplicationActive(extension->id()); | 83 extension_dispatcher_->IsExtensionActive(extension->id()); |
| 87 return v8::Boolean::New(result); | 84 return v8::Boolean::New(result); |
| 88 } | 85 } |
| 89 | 86 |
| 90 v8::Handle<v8::Value> AppBindings::Install(const v8::Arguments& args) { | 87 v8::Handle<v8::Value> AppBindings::Install(const v8::Arguments& args) { |
| 91 content::RenderView* render_view = context_->GetRenderView(); | 88 content::RenderView* render_view = context_->GetRenderView(); |
| 92 CHECK(render_view); | 89 CHECK(render_view); |
| 93 | 90 |
| 94 string16 error; | 91 string16 error; |
| 95 ExtensionHelper* helper = ExtensionHelper::Get(render_view); | 92 ExtensionHelper* helper = ExtensionHelper::Get(render_view); |
| 96 if (!helper->InstallWebApplicationUsingDefinitionFile( | 93 if (!helper->InstallWebApplicationUsingDefinitionFile( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 const std::string& channel_id, const std::string& error, int callback_id) { | 200 const std::string& channel_id, const std::string& error, int callback_id) { |
| 204 v8::HandleScope handle_scope; | 201 v8::HandleScope handle_scope; |
| 205 v8::Context::Scope context_scope(context_->v8_context()); | 202 v8::Context::Scope context_scope(context_->v8_context()); |
| 206 v8::Handle<v8::Value> argv[3]; | 203 v8::Handle<v8::Value> argv[3]; |
| 207 argv[0] = v8::String::New(channel_id.c_str()); | 204 argv[0] = v8::String::New(channel_id.c_str()); |
| 208 argv[1] = v8::String::New(error.c_str()); | 205 argv[1] = v8::String::New(error.c_str()); |
| 209 argv[2] = v8::Integer::New(callback_id); | 206 argv[2] = v8::Integer::New(callback_id); |
| 210 CHECK(context_->CallChromeHiddenMethod("app.onGetAppNotifyChannelResponse", | 207 CHECK(context_->CallChromeHiddenMethod("app.onGetAppNotifyChannelResponse", |
| 211 arraysize(argv), argv, NULL)); | 208 arraysize(argv), argv, NULL)); |
| 212 } | 209 } |
| OLD | NEW |