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" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/extensions/extension_messages.h" | 13 #include "chrome/common/extensions/extension_messages.h" |
14 #include "chrome/common/extensions/extension_set.h" | 14 #include "chrome/common/extensions/extension_set.h" |
15 #include "chrome/common/extensions/manifest.h" | 15 #include "chrome/common/extensions/manifest.h" |
16 #include "chrome/renderer/extensions/chrome_v8_context.h" | 16 #include "chrome/renderer/extensions/chrome_v8_context.h" |
17 #include "chrome/renderer/extensions/extension_dispatcher.h" | 17 #include "chrome/renderer/extensions/extension_dispatcher.h" |
18 #include "chrome/renderer/extensions/extension_helper.h" | 18 #include "chrome/renderer/extensions/extension_helper.h" |
19 #include "content/public/renderer/v8_value_converter.h" | 19 #include "content/public/renderer/v8_value_converter.h" |
20 #include "content/public/renderer/render_view.h" | 20 #include "content/public/renderer/render_view.h" |
21 #include "grit/renderer_resources.h" | 21 #include "grit/renderer_resources.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
24 #include "v8/include/v8.h" | 24 #include "v8/include/v8.h" |
25 | 25 |
26 using WebKit::WebFrame; | 26 using WebKit::WebFrame; |
27 using content::V8ValueConverter; | 27 using content::V8ValueConverter; |
| 28 using extensions::Extension; |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 bool IsCheckoutURL(const std::string& url_spec) { | 32 bool IsCheckoutURL(const std::string& url_spec) { |
32 std::string checkout_url_prefix = | 33 std::string checkout_url_prefix = |
33 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 34 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
34 switches::kAppsCheckoutURL); | 35 switches::kAppsCheckoutURL); |
35 if (checkout_url_prefix.empty()) | 36 if (checkout_url_prefix.empty()) |
36 checkout_url_prefix = "https://checkout.google.com/"; | 37 checkout_url_prefix = "https://checkout.google.com/"; |
37 | 38 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 RouteFunction("GetAppNotifyChannel", | 71 RouteFunction("GetAppNotifyChannel", |
71 base::Bind(&AppBindings::GetAppNotifyChannel, base::Unretained(this))); | 72 base::Bind(&AppBindings::GetAppNotifyChannel, base::Unretained(this))); |
72 RouteFunction("GetInstallState", | 73 RouteFunction("GetInstallState", |
73 base::Bind(&AppBindings::GetInstallState, base::Unretained(this))); | 74 base::Bind(&AppBindings::GetInstallState, base::Unretained(this))); |
74 RouteFunction("GetRunningState", | 75 RouteFunction("GetRunningState", |
75 base::Bind(&AppBindings::GetRunningState, base::Unretained(this))); | 76 base::Bind(&AppBindings::GetRunningState, base::Unretained(this))); |
76 } | 77 } |
77 | 78 |
78 v8::Handle<v8::Value> AppBindings::GetIsInstalled( | 79 v8::Handle<v8::Value> AppBindings::GetIsInstalled( |
79 const v8::Arguments& args) { | 80 const v8::Arguments& args) { |
80 const Extension* extension = context_->extension(); | 81 const extensions::Extension* extension = context_->extension(); |
81 | 82 |
82 // TODO(aa): Why only hosted app? | 83 // TODO(aa): Why only hosted app? |
83 bool result = extension && extension->is_hosted_app() && | 84 bool result = extension && extension->is_hosted_app() && |
84 extension_dispatcher_->IsExtensionActive(extension->id()); | 85 extension_dispatcher_->IsExtensionActive(extension->id()); |
85 return v8::Boolean::New(result); | 86 return v8::Boolean::New(result); |
86 } | 87 } |
87 | 88 |
88 v8::Handle<v8::Value> AppBindings::Install(const v8::Arguments& args) { | 89 v8::Handle<v8::Value> AppBindings::Install(const v8::Arguments& args) { |
89 content::RenderView* render_view = context_->GetRenderView(); | 90 content::RenderView* render_view = context_->GetRenderView(); |
90 CHECK(render_view); | 91 CHECK(render_view); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 if (!target_frame) { | 128 if (!target_frame) { |
128 return v8::ThrowException( | 129 return v8::ThrowException( |
129 v8::String::New("Could not find frame for specified object.")); | 130 v8::String::New("Could not find frame for specified object.")); |
130 } | 131 } |
131 | 132 |
132 return GetDetailsForFrameImpl(target_frame); | 133 return GetDetailsForFrameImpl(target_frame); |
133 } | 134 } |
134 | 135 |
135 v8::Handle<v8::Value> AppBindings::GetDetailsForFrameImpl( | 136 v8::Handle<v8::Value> AppBindings::GetDetailsForFrameImpl( |
136 WebFrame* frame) { | 137 WebFrame* frame) { |
137 const ::Extension* extension = | 138 const extensions::Extension* extension = |
138 extension_dispatcher_->extensions()->GetExtensionOrAppByURL( | 139 extension_dispatcher_->extensions()->GetExtensionOrAppByURL( |
139 ExtensionURLInfo(frame->document().securityOrigin(), | 140 ExtensionURLInfo(frame->document().securityOrigin(), |
140 frame->document().url())); | 141 frame->document().url())); |
141 if (!extension) | 142 if (!extension) |
142 return v8::Null(); | 143 return v8::Null(); |
143 | 144 |
144 scoped_ptr<DictionaryValue> manifest_copy( | 145 scoped_ptr<DictionaryValue> manifest_copy( |
145 extension->manifest()->value()->DeepCopy()); | 146 extension->manifest()->value()->DeepCopy()); |
146 manifest_copy->SetString("id", extension->id()); | 147 manifest_copy->SetString("id", extension->id()); |
147 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 148 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 void AppBindings::OnAppInstallStateResponse( | 270 void AppBindings::OnAppInstallStateResponse( |
270 const std::string& state, int callback_id) { | 271 const std::string& state, int callback_id) { |
271 v8::HandleScope handle_scope; | 272 v8::HandleScope handle_scope; |
272 v8::Context::Scope context_scope(context_->v8_context()); | 273 v8::Context::Scope context_scope(context_->v8_context()); |
273 v8::Handle<v8::Value> argv[2]; | 274 v8::Handle<v8::Value> argv[2]; |
274 argv[0] = v8::String::New(state.c_str()); | 275 argv[0] = v8::String::New(state.c_str()); |
275 argv[1] = v8::Integer::New(callback_id); | 276 argv[1] = v8::Integer::New(callback_id); |
276 CHECK(context_->CallChromeHiddenMethod("app.onInstallStateResponse", | 277 CHECK(context_->CallChromeHiddenMethod("app.onInstallStateResponse", |
277 arraysize(argv), argv, NULL)); | 278 arraysize(argv), argv, NULL)); |
278 } | 279 } |
OLD | NEW |