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

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: Revert sync pref changes 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
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, 58 AppBindings::AppBindings(Dispatcher* dispatcher,
61 ChromeV8Context* context) 59 ChromeV8Context* context)
62 : ChromeV8Extension(dispatcher), 60 : ChromeV8Extension(dispatcher),
63 ChromeV8ExtensionHandler(context) { 61 ChromeV8ExtensionHandler(context) {
64 RouteFunction("GetIsInstalled", 62 RouteFunction("GetIsInstalled",
65 base::Bind(&AppBindings::GetIsInstalled, base::Unretained(this))); 63 base::Bind(&AppBindings::GetIsInstalled, base::Unretained(this)));
66 RouteFunction("Install", 64 RouteFunction("Install",
67 base::Bind(&AppBindings::Install, base::Unretained(this))); 65 base::Bind(&AppBindings::Install, base::Unretained(this)));
68 RouteFunction("GetDetails", 66 RouteFunction("GetDetails",
69 base::Bind(&AppBindings::GetDetails, base::Unretained(this))); 67 base::Bind(&AppBindings::GetDetails, base::Unretained(this)));
70 RouteFunction("GetDetailsForFrame", 68 RouteFunction("GetDetailsForFrame",
71 base::Bind(&AppBindings::GetDetailsForFrame, base::Unretained(this))); 69 base::Bind(&AppBindings::GetDetailsForFrame, base::Unretained(this)));
72 RouteFunction("GetAppNotifyChannel",
73 base::Bind(&AppBindings::GetAppNotifyChannel, base::Unretained(this)));
74 RouteFunction("GetInstallState", 70 RouteFunction("GetInstallState",
75 base::Bind(&AppBindings::GetInstallState, base::Unretained(this))); 71 base::Bind(&AppBindings::GetInstallState, base::Unretained(this)));
76 RouteFunction("GetRunningState", 72 RouteFunction("GetRunningState",
77 base::Bind(&AppBindings::GetRunningState, base::Unretained(this))); 73 base::Bind(&AppBindings::GetRunningState, base::Unretained(this)));
78 } 74 }
79 75
80 v8::Handle<v8::Value> AppBindings::GetIsInstalled( 76 v8::Handle<v8::Value> AppBindings::GetIsInstalled(
81 const v8::Arguments& args) { 77 const v8::Arguments& args) {
82 const Extension* extension = context_->extension(); 78 const Extension* extension = context_->extension();
83 79
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 return v8::Null(); 140 return v8::Null();
145 141
146 scoped_ptr<DictionaryValue> manifest_copy( 142 scoped_ptr<DictionaryValue> manifest_copy(
147 extension->manifest()->value()->DeepCopy()); 143 extension->manifest()->value()->DeepCopy());
148 manifest_copy->SetString("id", extension->id()); 144 manifest_copy->SetString("id", extension->id());
149 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 145 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
150 return converter->ToV8Value(manifest_copy.get(), 146 return converter->ToV8Value(manifest_copy.get(),
151 frame->mainWorldScriptContext()); 147 frame->mainWorldScriptContext());
152 } 148 }
153 149
154 v8::Handle<v8::Value> AppBindings::GetAppNotifyChannel(
155 const v8::Arguments& args) {
156 // Read the required 'clientId' value out of the object at args[0].
157 std::string client_id;
158 if (args.Length() < 1 || !args[0]->IsObject()) {
159 v8::ThrowException(v8::String::New(kMissingClientIdError));
160 return v8::Undefined();
161 }
162 v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(args[0]);
163 v8::Local<v8::String> client_id_key = v8::String::New("clientId");
164 if (obj->Has(client_id_key)) {
165 v8::String::Utf8Value id_value(obj->Get(client_id_key));
166 if (id_value.length() > 0)
167 client_id = std::string(*id_value);
168 }
169 if (client_id.empty()) {
170 v8::ThrowException(v8::String::New(kInvalidClientIdError));
171 return v8::Undefined();
172 }
173
174 // Get the callbackId if specified.
175 int callback_id = 0;
176 if (args.Length() > 1) {
177 if (!args[1]->IsInt32()) {
178 v8::ThrowException(v8::String::New(kInvalidCallbackIdError));
179 return v8::Undefined();
180 }
181 callback_id = args[1]->Int32Value();
182 }
183
184 content::RenderView* render_view = context_->GetRenderView();
185 CHECK(render_view);
186
187 Send(new ExtensionHostMsg_GetAppNotifyChannel(
188 render_view->GetRoutingID(), context_->web_frame()->document().url(),
189 client_id, GetRoutingID(), callback_id));
190 return v8::Undefined();
191 }
192
193 v8::Handle<v8::Value> AppBindings::GetInstallState(const v8::Arguments& args) { 150 v8::Handle<v8::Value> AppBindings::GetInstallState(const v8::Arguments& args) {
194 // Get the callbackId. 151 // Get the callbackId.
195 int callback_id = 0; 152 int callback_id = 0;
196 if (args.Length() == 1) { 153 if (args.Length() == 1) {
197 if (!args[0]->IsInt32()) { 154 if (!args[0]->IsInt32()) {
198 v8::ThrowException(v8::String::New(kInvalidCallbackIdError)); 155 v8::ThrowException(v8::String::New(kInvalidCallbackIdError));
199 return v8::Undefined(); 156 return v8::Undefined();
200 } 157 }
201 callback_id = args[0]->Int32Value(); 158 callback_id = args[0]->Int32Value();
202 } 159 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 state = extension_misc::kAppStateReadyToRun; 197 state = extension_misc::kAppStateReadyToRun;
241 } else { 198 } else {
242 state = extension_misc::kAppStateCannotRun; 199 state = extension_misc::kAppStateCannotRun;
243 } 200 }
244 201
245 return v8::String::New(state); 202 return v8::String::New(state);
246 } 203 }
247 204
248 bool AppBindings::OnMessageReceived(const IPC::Message& message) { 205 bool AppBindings::OnMessageReceived(const IPC::Message& message) {
249 IPC_BEGIN_MESSAGE_MAP(AppBindings, message) 206 IPC_BEGIN_MESSAGE_MAP(AppBindings, message)
250 IPC_MESSAGE_HANDLER(ExtensionMsg_GetAppNotifyChannelResponse,
251 OnGetAppNotifyChannelResponse)
252 IPC_MESSAGE_HANDLER(ExtensionMsg_GetAppInstallStateResponse, 207 IPC_MESSAGE_HANDLER(ExtensionMsg_GetAppInstallStateResponse,
253 OnAppInstallStateResponse) 208 OnAppInstallStateResponse)
254 IPC_MESSAGE_UNHANDLED(CHECK(false) << "Unhandled IPC message") 209 IPC_MESSAGE_UNHANDLED(CHECK(false) << "Unhandled IPC message")
255 IPC_END_MESSAGE_MAP() 210 IPC_END_MESSAGE_MAP()
256 return true; 211 return true;
257 } 212 }
258 213
259 void AppBindings::OnGetAppNotifyChannelResponse(
260 const std::string& channel_id, const std::string& error, int callback_id) {
261 v8::HandleScope handle_scope;
262 v8::Context::Scope context_scope(context_->v8_context());
263 v8::Handle<v8::Value> argv[3];
264 argv[0] = v8::String::New(channel_id.c_str());
265 argv[1] = v8::String::New(error.c_str());
266 argv[2] = v8::Integer::New(callback_id);
267 CHECK(context_->CallChromeHiddenMethod("app.onGetAppNotifyChannelResponse",
268 arraysize(argv), argv, NULL));
269 }
270
271 void AppBindings::OnAppInstallStateResponse( 214 void AppBindings::OnAppInstallStateResponse(
272 const std::string& state, int callback_id) { 215 const std::string& state, int callback_id) {
273 v8::HandleScope handle_scope; 216 v8::HandleScope handle_scope;
274 v8::Context::Scope context_scope(context_->v8_context()); 217 v8::Context::Scope context_scope(context_->v8_context());
275 v8::Handle<v8::Value> argv[2]; 218 v8::Handle<v8::Value> argv[2];
276 argv[0] = v8::String::New(state.c_str()); 219 argv[0] = v8::String::New(state.c_str());
277 argv[1] = v8::Integer::New(callback_id); 220 argv[1] = v8::Integer::New(callback_id);
278 CHECK(context_->CallChromeHiddenMethod("app.onInstallStateResponse", 221 CHECK(context_->CallChromeHiddenMethod("app.onInstallStateResponse",
279 arraysize(argv), argv, NULL)); 222 arraysize(argv), argv, NULL));
280 } 223 }
281 224
282 } // namespace extensions 225 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698