Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/renderer/extensions/app_bindings.cc

Issue 12680004: Remove chrome/ code to handle App Notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge conflicts. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/extensions/app_bindings.h ('k') | chrome/renderer/extensions/dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 if (!IsCheckoutURL(frame->document().url().spec())) { 44 if (!IsCheckoutURL(frame->document().url().spec())) {
45 std::string error("Access denied for URL: "); 45 std::string error("Access denied for URL: ");
46 error += frame->document().url().spec(); 46 error += frame->document().url().spec();
47 v8::ThrowException(v8::String::New(error.c_str())); 47 v8::ThrowException(v8::String::New(error.c_str()));
48 return false; 48 return false;
49 } 49 }
50 50
51 return true; 51 return true;
52 } 52 }
53 53
54 const char* kMissingClientIdError = "Missing clientId parameter";
55 const char* kInvalidClientIdError = "Invalid clientId";
56 const char* kInvalidCallbackIdError = "Invalid callbackId"; 54 const char* kInvalidCallbackIdError = "Invalid callbackId";
57 55
58 } // namespace 56 } // namespace
59 57
60 AppBindings::AppBindings(Dispatcher* dispatcher, ChromeV8Context* context) 58 AppBindings::AppBindings(Dispatcher* dispatcher, ChromeV8Context* context)
61 : ChromeV8Extension(dispatcher, context->v8_context()), 59 : ChromeV8Extension(dispatcher, context->v8_context()),
62 ChromeV8ExtensionHandler(context) { 60 ChromeV8ExtensionHandler(context) {
63 RouteFunction("GetIsInstalled", 61 RouteFunction("GetIsInstalled",
64 base::Bind(&AppBindings::GetIsInstalled, base::Unretained(this))); 62 base::Bind(&AppBindings::GetIsInstalled, base::Unretained(this)));
65 RouteFunction("Install", 63 RouteFunction("Install",
66 base::Bind(&AppBindings::Install, base::Unretained(this))); 64 base::Bind(&AppBindings::Install, base::Unretained(this)));
67 RouteFunction("GetDetails", 65 RouteFunction("GetDetails",
68 base::Bind(&AppBindings::GetDetails, base::Unretained(this))); 66 base::Bind(&AppBindings::GetDetails, base::Unretained(this)));
69 RouteFunction("GetDetailsForFrame", 67 RouteFunction("GetDetailsForFrame",
70 base::Bind(&AppBindings::GetDetailsForFrame, base::Unretained(this))); 68 base::Bind(&AppBindings::GetDetailsForFrame, base::Unretained(this)));
71 RouteFunction("GetAppNotifyChannel",
72 base::Bind(&AppBindings::GetAppNotifyChannel, base::Unretained(this)));
73 RouteFunction("GetInstallState", 69 RouteFunction("GetInstallState",
74 base::Bind(&AppBindings::GetInstallState, base::Unretained(this))); 70 base::Bind(&AppBindings::GetInstallState, base::Unretained(this)));
75 RouteFunction("GetRunningState", 71 RouteFunction("GetRunningState",
76 base::Bind(&AppBindings::GetRunningState, base::Unretained(this))); 72 base::Bind(&AppBindings::GetRunningState, base::Unretained(this)));
77 } 73 }
78 74
79 v8::Handle<v8::Value> AppBindings::GetIsInstalled( 75 v8::Handle<v8::Value> AppBindings::GetIsInstalled(
80 const v8::Arguments& args) { 76 const v8::Arguments& args) {
81 const Extension* extension = context_->extension(); 77 const Extension* extension = context_->extension();
82 78
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return v8::Null(); 139 return v8::Null();
144 140
145 scoped_ptr<DictionaryValue> manifest_copy( 141 scoped_ptr<DictionaryValue> manifest_copy(
146 extension->manifest()->value()->DeepCopy()); 142 extension->manifest()->value()->DeepCopy());
147 manifest_copy->SetString("id", extension->id()); 143 manifest_copy->SetString("id", extension->id());
148 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 144 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
149 return converter->ToV8Value(manifest_copy.get(), 145 return converter->ToV8Value(manifest_copy.get(),
150 frame->mainWorldScriptContext()); 146 frame->mainWorldScriptContext());
151 } 147 }
152 148
153 v8::Handle<v8::Value> AppBindings::GetAppNotifyChannel(
154 const v8::Arguments& args) {
155 // Read the required 'clientId' value out of the object at args[0].
156 std::string client_id;
157 if (args.Length() < 1 || !args[0]->IsObject()) {
158 v8::ThrowException(v8::String::New(kMissingClientIdError));
159 return v8::Undefined();
160 }
161 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(args[0]);
162 v8::Local<v8::String> client_id_key = v8::String::New("clientId");
163 if (obj->Has(client_id_key)) {
164 v8::String::Utf8Value id_value(obj->Get(client_id_key));
165 if (id_value.length() > 0)
166 client_id = std::string(*id_value);
167 }
168 if (client_id.empty()) {
169 v8::ThrowException(v8::String::New(kInvalidClientIdError));
170 return v8::Undefined();
171 }
172
173 // Get the callbackId if specified.
174 int callback_id = 0;
175 if (args.Length() > 1) {
176 if (!args[1]->IsInt32()) {
177 v8::ThrowException(v8::String::New(kInvalidCallbackIdError));
178 return v8::Undefined();
179 }
180 callback_id = args[1]->Int32Value();
181 }
182
183 content::RenderView* render_view = context_->GetRenderView();
184 CHECK(render_view);
185
186 Send(new ExtensionHostMsg_GetAppNotifyChannel(
187 render_view->GetRoutingID(), context_->web_frame()->document().url(),
188 client_id, GetRoutingID(), callback_id));
189 return v8::Undefined();
190 }
191
192 v8::Handle<v8::Value> AppBindings::GetInstallState(const v8::Arguments& args) { 149 v8::Handle<v8::Value> AppBindings::GetInstallState(const v8::Arguments& args) {
193 // Get the callbackId. 150 // Get the callbackId.
194 int callback_id = 0; 151 int callback_id = 0;
195 if (args.Length() == 1) { 152 if (args.Length() == 1) {
196 if (!args[0]->IsInt32()) { 153 if (!args[0]->IsInt32()) {
197 v8::ThrowException(v8::String::New(kInvalidCallbackIdError)); 154 v8::ThrowException(v8::String::New(kInvalidCallbackIdError));
198 return v8::Undefined(); 155 return v8::Undefined();
199 } 156 }
200 callback_id = args[0]->Int32Value(); 157 callback_id = args[0]->Int32Value();
201 } 158 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 state = extension_misc::kAppStateReadyToRun; 196 state = extension_misc::kAppStateReadyToRun;
240 } else { 197 } else {
241 state = extension_misc::kAppStateCannotRun; 198 state = extension_misc::kAppStateCannotRun;
242 } 199 }
243 200
244 return v8::String::New(state); 201 return v8::String::New(state);
245 } 202 }
246 203
247 bool AppBindings::OnMessageReceived(const IPC::Message& message) { 204 bool AppBindings::OnMessageReceived(const IPC::Message& message) {
248 IPC_BEGIN_MESSAGE_MAP(AppBindings, message) 205 IPC_BEGIN_MESSAGE_MAP(AppBindings, message)
249 IPC_MESSAGE_HANDLER(ExtensionMsg_GetAppNotifyChannelResponse,
250 OnGetAppNotifyChannelResponse)
251 IPC_MESSAGE_HANDLER(ExtensionMsg_GetAppInstallStateResponse, 206 IPC_MESSAGE_HANDLER(ExtensionMsg_GetAppInstallStateResponse,
252 OnAppInstallStateResponse) 207 OnAppInstallStateResponse)
253 IPC_MESSAGE_UNHANDLED(CHECK(false) << "Unhandled IPC message") 208 IPC_MESSAGE_UNHANDLED(CHECK(false) << "Unhandled IPC message")
254 IPC_END_MESSAGE_MAP() 209 IPC_END_MESSAGE_MAP()
255 return true; 210 return true;
256 } 211 }
257 212
258 void AppBindings::OnGetAppNotifyChannelResponse(
259 const std::string& channel_id, const std::string& error, int callback_id) {
260 v8::HandleScope handle_scope;
261 v8::Context::Scope context_scope(context_->v8_context());
262 v8::Handle<v8::Value> argv[3];
263 argv[0] = v8::String::New(channel_id.c_str());
264 argv[1] = v8::String::New(error.c_str());
265 argv[2] = v8::Integer::New(callback_id);
266 CHECK(context_->CallChromeHiddenMethod("app.onGetAppNotifyChannelResponse",
267 arraysize(argv), argv, NULL));
268 }
269
270 void AppBindings::OnAppInstallStateResponse( 213 void AppBindings::OnAppInstallStateResponse(
271 const std::string& state, int callback_id) { 214 const std::string& state, int callback_id) {
272 v8::HandleScope handle_scope; 215 v8::HandleScope handle_scope;
273 v8::Context::Scope context_scope(context_->v8_context()); 216 v8::Context::Scope context_scope(context_->v8_context());
274 v8::Handle<v8::Value> argv[2]; 217 v8::Handle<v8::Value> argv[2];
275 argv[0] = v8::String::New(state.c_str()); 218 argv[0] = v8::String::New(state.c_str());
276 argv[1] = v8::Integer::New(callback_id); 219 argv[1] = v8::Integer::New(callback_id);
277 CHECK(context_->CallChromeHiddenMethod("app.onInstallStateResponse", 220 CHECK(context_->CallChromeHiddenMethod("app.onInstallStateResponse",
278 arraysize(argv), argv, NULL)); 221 arraysize(argv), argv, NULL));
279 } 222 }
280 223
281 } // namespace extensions 224 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/app_bindings.h ('k') | chrome/renderer/extensions/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698