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

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

Issue 179027: Make a bunch of backlogged breaking changes to the extensions (Closed)
Patch Set: Put chrome.self back Created 11 years, 3 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/extension_process_bindings.h" 5 #include "chrome/renderer/extensions/extension_process_bindings.h"
6 6
7 #include "base/singleton.h" 7 #include "base/singleton.h"
8 #include "chrome/common/extensions/extension.h" 8 #include "chrome/common/extensions/extension.h"
9 #include "chrome/common/extensions/url_pattern.h" 9 #include "chrome/common/extensions/url_pattern.h"
10 #include "chrome/common/render_messages.h" 10 #include "chrome/common/render_messages.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 !args[2]->IsInt32() || !args[3]->IsBoolean()) 243 !args[2]->IsInt32() || !args[3]->IsBoolean())
244 return v8::Undefined(); 244 return v8::Undefined();
245 245
246 std::string name = *v8::String::AsciiValue(args[0]); 246 std::string name = *v8::String::AsciiValue(args[0]);
247 if (GetFunctionNameSet()->find(name) == GetFunctionNameSet()->end()) { 247 if (GetFunctionNameSet()->find(name) == GetFunctionNameSet()->end()) {
248 NOTREACHED() << "Unexpected function " << name; 248 NOTREACHED() << "Unexpected function " << name;
249 return v8::Undefined(); 249 return v8::Undefined();
250 } 250 }
251 251
252 if (!ExtensionProcessBindings::CurrentContextHasPermission(name)) { 252 if (!ExtensionProcessBindings::CurrentContextHasPermission(name)) {
253 #if EXTENSION_TIME_TO_BREAK_API
254 return ExtensionProcessBindings::ThrowPermissionDeniedException(name); 253 return ExtensionProcessBindings::ThrowPermissionDeniedException(name);
255 #else
256 ExtensionProcessBindings::ThrowPermissionDeniedException(name);
257 #endif
258 } 254 }
259 255
260 std::string json_args = *v8::String::Utf8Value(args[1]); 256 std::string json_args = *v8::String::Utf8Value(args[1]);
261 int request_id = args[2]->Int32Value(); 257 int request_id = args[2]->Int32Value();
262 bool has_callback = args[3]->BooleanValue(); 258 bool has_callback = args[3]->BooleanValue();
263 259
264 v8::Persistent<v8::Context> current_context = 260 v8::Persistent<v8::Context> current_context =
265 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent()); 261 v8::Persistent<v8::Context>::New(v8::Context::GetCurrent());
266 DCHECK(!current_context.IsEmpty()); 262 DCHECK(!current_context.IsEmpty());
267 GetPendingRequestMap()[request_id].reset(new PendingRequest( 263 GetPendingRequestMap()[request_id].reset(new PendingRequest(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 362
367 // static 363 // static
368 bool ExtensionProcessBindings::CurrentContextHasPermission( 364 bool ExtensionProcessBindings::CurrentContextHasPermission(
369 const std::string& function_name) { 365 const std::string& function_name) {
370 std::string extension_id = ExtensionImpl::ExtensionIdForCurrentContext(); 366 std::string extension_id = ExtensionImpl::ExtensionIdForCurrentContext();
371 PermissionsMap& permissions_map = *GetPermissionsMap(extension_id); 367 PermissionsMap& permissions_map = *GetPermissionsMap(extension_id);
372 std::string permission_name = GetPermissionName(function_name); 368 std::string permission_name = GetPermissionName(function_name);
373 PermissionsMap::iterator it = permissions_map.find(permission_name); 369 PermissionsMap::iterator it = permissions_map.find(permission_name);
374 370
375 // We explicitly check if the permission entry is present and false, because 371 // We explicitly check if the permission entry is present and false, because
376 // some APIs do not have a required permission entry (ie, "chrome.self"). 372 // some APIs do not have a required permission entry (ie, "chrome.extension").
377 return (it == permissions_map.end() || it->second); 373 return (it == permissions_map.end() || it->second);
378 } 374 }
379 375
380 // static 376 // static
381 v8::Handle<v8::Value> 377 v8::Handle<v8::Value>
382 ExtensionProcessBindings::ThrowPermissionDeniedException( 378 ExtensionProcessBindings::ThrowPermissionDeniedException(
383 const std::string& function_name) { 379 const std::string& function_name) {
384 static const char kMessage[] = 380 static const char kMessage[] =
385 "You do not have permission to use 'chrome.%s'. Be sure to declare" 381 "You do not have permission to use 'chrome.%s'. Be sure to declare"
386 " in your manifest what permissions you need."; 382 " in your manifest what permissions you need.";
387 std::string permission_name = GetPermissionName(function_name); 383 std::string permission_name = GetPermissionName(function_name);
388 std::string error_msg = StringPrintf(kMessage, permission_name.c_str()); 384 std::string error_msg = StringPrintf(kMessage, permission_name.c_str());
389 385
390 #if EXTENSION_TIME_TO_BREAK_API
391 return v8::ThrowException(v8::Exception::Error( 386 return v8::ThrowException(v8::Exception::Error(
392 v8::String::New(error_msg.c_str()))); 387 v8::String::New(error_msg.c_str())));
393 #else
394 // Call console.error for now.
395
396 v8::HandleScope scope;
397
398 v8::Local<v8::Value> console =
399 v8::Context::GetCurrent()->Global()->Get(v8::String::New("console"));
400 v8::Local<v8::Value> console_error;
401 if (!console.IsEmpty() && console->IsObject())
402 console_error = console->ToObject()->Get(v8::String::New("error"));
403 if (console_error.IsEmpty() || !console_error->IsFunction())
404 return v8::Undefined();
405
406 v8::Local<v8::Function> function =
407 v8::Local<v8::Function>::Cast(console_error);
408 v8::Local<v8::Value> argv[] = { v8::String::New(error_msg.c_str()) };
409 if (!function.IsEmpty())
410 function->Call(console->ToObject(), arraysize(argv), argv);
411
412 return v8::Undefined();
413 #endif
414 } 388 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/static/background_pages.html ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698