Chromium Code Reviews| 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/chrome_v8_extension.h" | 5 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 GURL url = document.url(); | 71 GURL url = document.url(); |
| 72 const ExtensionSet* extensions = extension_dispatcher_->extensions(); | 72 const ExtensionSet* extensions = extension_dispatcher_->extensions(); |
| 73 if (!extensions->ExtensionBindingsAllowed( | 73 if (!extensions->ExtensionBindingsAllowed( |
| 74 ExtensionURLInfo(document.securityOrigin(), url))) | 74 ExtensionURLInfo(document.securityOrigin(), url))) |
| 75 return NULL; | 75 return NULL; |
| 76 | 76 |
| 77 return extensions->GetExtensionOrAppByURL( | 77 return extensions->GetExtensionOrAppByURL( |
| 78 ExtensionURLInfo(document.securityOrigin(), url)); | 78 ExtensionURLInfo(document.securityOrigin(), url)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool ChromeV8Extension::CheckCurrentContextAccessToExtensionAPI( | 81 bool ChromeV8Extension::CheckCurrentContextAccessToExtensionAPI( |
|
not at google - send to devlin
2012/03/30 03:14:31
You can probably just delete this method, from wha
koz (OOO until 15th September)
2012/04/03 00:15:17
Done.
| |
| 82 const std::string& function_name) const { | 82 const std::string& function_name) const { |
| 83 ChromeV8Context* context = | 83 return extension_dispatcher_->CheckCurrentContextAccessToExtensionAPI( |
| 84 extension_dispatcher_->v8_context_set().GetCurrent(); | 84 function_name); |
| 85 if (!context) { | |
| 86 DLOG(ERROR) << "Not in a v8::Context"; | |
| 87 return false; | |
| 88 } | |
| 89 | |
| 90 const ::Extension* extension = NULL; | |
| 91 if (!context->extension_id().empty()) { | |
| 92 extension = | |
| 93 extension_dispatcher_->extensions()->GetByID(context->extension_id()); | |
| 94 } | |
| 95 | |
| 96 if (!extension || !extension->HasAPIPermission(function_name)) { | |
| 97 static const char kMessage[] = | |
| 98 "You do not have permission to use '%s'. Be sure to declare" | |
| 99 " in your manifest what permissions you need."; | |
| 100 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | |
| 101 v8::ThrowException( | |
| 102 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | |
| 103 return false; | |
| 104 } | |
| 105 | |
| 106 if (!extension_dispatcher_->IsExtensionActive(extension->id()) && | |
| 107 ExtensionAPI::GetInstance()->IsPrivileged(function_name)) { | |
| 108 static const char kMessage[] = | |
| 109 "%s can only be used in an extension process."; | |
| 110 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | |
| 111 v8::ThrowException( | |
| 112 v8::Exception::Error(v8::String::New(error_msg.c_str()))); | |
| 113 return false; | |
| 114 } | |
| 115 | |
| 116 return true; | |
| 117 } | 85 } |
| OLD | NEW |