[email protected] | 64c82073 | 2012-01-05 20:50:34 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 6 | |
[email protected] | 745feedb | 2010-08-02 04:08:07 | [diff] [blame] | 7 | #include <map> |
| 8 | |
[email protected] | ffbec69 | 2012-02-26 20:26:42 | [diff] [blame] | 9 | #include "base/json/json_string_value_serializer.h" |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 10 | #include "base/lazy_instance.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 12 | #include "base/process_util.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 13 | #include "base/values.h" |
[email protected] | 17d40f0 | 2010-07-01 01:18:06 | [diff] [blame] | 14 | #include "build/build_config.h" |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 15 | #include "chrome/browser/extensions/extension_activity_log.h" |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 16 | #include "chrome/browser/extensions/extension_function.h" |
[email protected] | ae33d32 | 2012-03-19 22:24:35 | [diff] [blame] | 17 | #include "chrome/browser/extensions/extension_function_registry.h" |
[email protected] | 2f69b38 | 2011-02-19 00:34:25 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 19 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extensions_quota_service.h" |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 21 | #include "chrome/browser/extensions/process_map.h" |
[email protected] | ed2b100 | 2011-05-25 14:12:10 | [diff] [blame] | 22 | #include "chrome/browser/external_protocol/external_protocol_handler.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 23 | #include "chrome/browser/profiles/profile.h" |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 24 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | 71b73f0 | 2011-04-06 15:57:29 | [diff] [blame] | 25 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 26 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 27 | #include "chrome/common/extensions/api/extension_api.h" |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 28 | #include "chrome/common/extensions/extension_messages.h" |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 29 | #include "chrome/common/extensions/extension_set.h" |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 30 | #include "chrome/common/url_constants.h" |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 31 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 32 | #include "content/public/browser/render_view_host.h" |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 33 | #include "ipc/ipc_message.h" |
| 34 | #include "ipc/ipc_message_macros.h" |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 35 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 36 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | ae33d32 | 2012-03-19 22:24:35 | [diff] [blame] | 37 | #include "webkit/glue/resource_type.h" |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 38 | |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 39 | using extensions::ExtensionAPI; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 40 | using content::RenderViewHost; |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 41 | using WebKit::WebSecurityOrigin; |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 42 | |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 43 | namespace { |
| 44 | |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 45 | const char kAccessDenied[] = "access denied"; |
| 46 | const char kQuotaExceeded[] = "quota exceeded"; |
| 47 | |
| 48 | void LogSuccess(const Extension* extension, |
| 49 | const ExtensionHostMsg_Request_Params& params) { |
| 50 | ExtensionActivityLog* extension_activity_log = |
| 51 | ExtensionActivityLog::GetInstance(); |
| 52 | if (extension_activity_log->HasObservers(extension)) { |
| 53 | std::string call_signature = params.name + "("; |
| 54 | ListValue::const_iterator it = params.arguments.begin(); |
| 55 | for (; it != params.arguments.end(); ++it) { |
| 56 | std::string arg; |
| 57 | JSONStringValueSerializer serializer(&arg); |
| 58 | if (serializer.SerializeAndOmitBinaryValues(**it)) { |
| 59 | if (it != params.arguments.begin()) |
| 60 | call_signature += ", "; |
| 61 | call_signature += arg; |
| 62 | } |
| 63 | } |
| 64 | call_signature += ")"; |
| 65 | |
| 66 | extension_activity_log->Log( |
| 67 | extension, |
| 68 | ExtensionActivityLog::ACTIVITY_EXTENSION_API_CALL, |
| 69 | call_signature); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | void LogFailure(const Extension* extension, |
| 74 | const std::string& func_name, |
| 75 | const char* reason) { |
| 76 | ExtensionActivityLog* extension_activity_log = |
| 77 | ExtensionActivityLog::GetInstance(); |
| 78 | if (extension_activity_log->HasObservers(extension)) { |
| 79 | extension_activity_log->Log( |
| 80 | extension, |
| 81 | ExtensionActivityLog::ACTIVITY_EXTENSION_API_BLOCK, |
| 82 | func_name + ": " + reason); |
| 83 | } |
| 84 | } |
| 85 | |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 86 | // Separate copy of ExtensionAPI used for IO thread extension functions. We need |
| 87 | // this because ExtensionAPI has mutable data. It should be possible to remove |
| 88 | // this once all the extension APIs are updated to the feature system. |
| 89 | struct Static { |
| 90 | Static() |
| 91 | : api(extensions::ExtensionAPI::CreateWithDefaultConfiguration()) { |
| 92 | } |
| 93 | scoped_ptr<extensions::ExtensionAPI> api; |
| 94 | }; |
| 95 | base::LazyInstance<Static> g_global_io_data = LAZY_INSTANCE_INITIALIZER; |
| 96 | |
| 97 | } // namespace |
| 98 | |
| 99 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 100 | void ExtensionFunctionDispatcher::GetAllFunctionNames( |
| 101 | std::vector<std::string>* names) { |
[email protected] | ae33d32 | 2012-03-19 22:24:35 | [diff] [blame] | 102 | ExtensionFunctionRegistry::GetInstance()->GetAllNames(names); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 103 | } |
| 104 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 105 | bool ExtensionFunctionDispatcher::OverrideFunction( |
| 106 | const std::string& name, ExtensionFunctionFactory factory) { |
[email protected] | ae33d32 | 2012-03-19 22:24:35 | [diff] [blame] | 107 | return ExtensionFunctionRegistry::GetInstance()->OverrideFunction(name, |
| 108 | factory); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void ExtensionFunctionDispatcher::ResetFunctions() { |
[email protected] | ae33d32 | 2012-03-19 22:24:35 | [diff] [blame] | 112 | ExtensionFunctionRegistry::GetInstance()->ResetFunctions(); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 113 | } |
| 114 | |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 115 | // static |
| 116 | void ExtensionFunctionDispatcher::DispatchOnIOThread( |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 117 | ExtensionInfoMap* extension_info_map, |
[email protected] | 67351452 | 2011-07-13 18:17:18 | [diff] [blame] | 118 | void* profile, |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 119 | int render_process_id, |
| 120 | base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, |
| 121 | int routing_id, |
| 122 | const ExtensionHostMsg_Request_Params& params) { |
| 123 | const Extension* extension = |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 124 | extension_info_map->extensions().GetByID(params.extension_id); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 125 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 126 | scoped_refptr<ExtensionFunction> function( |
| 127 | CreateExtensionFunction(params, extension, render_process_id, |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 128 | extension_info_map->process_map(), |
| 129 | g_global_io_data.Get().api.get(), |
| 130 | profile, |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 131 | ipc_sender, routing_id)); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 132 | if (!function) { |
| 133 | LogFailure(extension, params.name, kAccessDenied); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 134 | return; |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 135 | } |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 136 | |
| 137 | IOThreadExtensionFunction* function_io = |
| 138 | function->AsIOThreadExtensionFunction(); |
| 139 | if (!function_io) { |
| 140 | NOTREACHED(); |
| 141 | return; |
| 142 | } |
| 143 | function_io->set_ipc_sender(ipc_sender, routing_id); |
| 144 | function_io->set_extension_info_map(extension_info_map); |
| 145 | function->set_include_incognito( |
| 146 | extension_info_map->IsIncognitoEnabled(extension->id())); |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 147 | |
[email protected] | 3629691 | 2012-03-20 11:08:49 | [diff] [blame] | 148 | ExtensionsQuotaService* quota = extension_info_map->GetQuotaService(); |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 149 | if (quota->Assess(extension->id(), function, ¶ms.arguments, |
| 150 | base::TimeTicks::Now())) { |
| 151 | function->Run(); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 152 | LogSuccess(extension, params); |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 153 | } else { |
| 154 | function->OnQuotaExceeded(); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 155 | LogFailure(extension, params.name, kQuotaExceeded); |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 156 | } |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 157 | } |
| 158 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 159 | ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(Profile* profile, |
| 160 | Delegate* delegate) |
| 161 | : profile_(profile), |
[email protected] | 55ce33071 | 2011-05-24 19:04:27 | [diff] [blame] | 162 | delegate_(delegate) { |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 163 | } |
| 164 | |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 165 | ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 166 | } |
| 167 | |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 168 | Browser* ExtensionFunctionDispatcher::GetCurrentBrowser( |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 169 | RenderViewHost* render_view_host, bool include_incognito) { |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 170 | Browser* browser = delegate_->GetBrowser(); |
[email protected] | 7eecaed5 | 2009-05-07 21:44:12 | [diff] [blame] | 171 | |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 172 | // If the delegate has an associated browser, that is always the right answer. |
| 173 | if (browser) |
| 174 | return browser; |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 175 | |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 176 | // Otherwise, try to default to a reasonable browser. If |include_incognito| |
| 177 | // is true, we will also search browsers in the incognito version of this |
| 178 | // profile. Note that the profile may already be incognito, in which case |
| 179 | // we will search the incognito version only, regardless of the value of |
| 180 | // |include_incognito|. |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 181 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 182 | render_view_host->GetProcess()->GetBrowserContext()); |
[email protected] | 8ecca49 | 2012-01-19 17:29:42 | [diff] [blame] | 183 | browser = BrowserList::FindAnyBrowser(profile, include_incognito); |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 184 | |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 185 | // NOTE(rafaelw): This can return NULL in some circumstances. In particular, |
[email protected] | 6d7a604 | 2010-08-12 20:12:42 | [diff] [blame] | 186 | // a background_page onload chrome.tabs api call can make it into here |
| 187 | // before the browser is sufficiently initialized to return here. |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 188 | // A similar situation may arise during shutdown. |
| 189 | // TODO(rafaelw): Delay creation of background_page until the browser |
| 190 | // is available. http://code.google.com/p/chromium/issues/detail?id=13284 |
| 191 | return browser; |
[email protected] | b2725756 | 2009-11-16 23:28:26 | [diff] [blame] | 192 | } |
| 193 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 194 | void ExtensionFunctionDispatcher::Dispatch( |
| 195 | const ExtensionHostMsg_Request_Params& params, |
| 196 | RenderViewHost* render_view_host) { |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 197 | ExtensionService* service = profile()->GetExtensionService(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 198 | extensions::ProcessMap* process_map = service->process_map(); |
| 199 | if (!service || !process_map) |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 200 | return; |
| 201 | |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 202 | const Extension* extension = service->extensions()->GetByID( |
| 203 | params.extension_id); |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 204 | if (!extension) |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 205 | extension = service->extensions()->GetHostedAppByURL(ExtensionURLInfo( |
| 206 | WebSecurityOrigin::createFromString(params.source_origin), |
| 207 | params.source_url)); |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 208 | |
[email protected] | 8add541 | 2011-10-01 21:02:14 | [diff] [blame] | 209 | scoped_refptr<ExtensionFunction> function( |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 210 | CreateExtensionFunction(params, extension, |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 211 | render_view_host->GetProcess()->GetID(), |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 212 | *(service->process_map()), |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 213 | extensions::ExtensionAPI::GetSharedInstance(), |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 214 | profile(), render_view_host, |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 215 | render_view_host->GetRoutingID())); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 216 | if (!function) { |
| 217 | LogFailure(extension, params.name, kAccessDenied); |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 218 | return; |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 219 | } |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 220 | |
[email protected] | a2aef2e | 2011-05-26 22:48:12 | [diff] [blame] | 221 | UIThreadExtensionFunction* function_ui = |
| 222 | function->AsUIThreadExtensionFunction(); |
| 223 | if (!function_ui) { |
| 224 | NOTREACHED(); |
| 225 | return; |
| 226 | } |
| 227 | function_ui->SetRenderViewHost(render_view_host); |
| 228 | function_ui->set_dispatcher(AsWeakPtr()); |
| 229 | function_ui->set_profile(profile_); |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 230 | function->set_include_incognito(service->CanCrossIncognito(extension)); |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 231 | |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 232 | ExtensionsQuotaService* quota = service->quota_service(); |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 233 | if (quota->Assess(extension->id(), function, ¶ms.arguments, |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 234 | base::TimeTicks::Now())) { |
[email protected] | d070ec6 | 2010-07-27 21:28:26 | [diff] [blame] | 235 | // See crbug.com/39178. |
| 236 | ExternalProtocolHandler::PermitLaunchUrl(); |
| 237 | |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 238 | function->Run(); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 239 | LogSuccess(extension, params); |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 240 | } else { |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 241 | function->OnQuotaExceeded(); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 242 | LogFailure(extension, params.name, kQuotaExceeded); |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 243 | } |
[email protected] | 720ad131 | 2012-02-27 23:07:36 | [diff] [blame] | 244 | |
| 245 | // We only adjust the keepalive count for UIThreadExtensionFunction for |
| 246 | // now, largely for simplicity's sake. This is OK because currently, only |
| 247 | // the webRequest API uses IOThreadExtensionFunction, and that API is not |
| 248 | // compatible with lazy background pages. |
| 249 | profile()->GetExtensionProcessManager()->IncrementLazyKeepaliveCount( |
| 250 | extension); |
| 251 | } |
| 252 | |
| 253 | void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted( |
| 254 | const Extension* extension) { |
| 255 | profile()->GetExtensionProcessManager()->DecrementLazyKeepaliveCount( |
| 256 | extension); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 257 | } |
| 258 | |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 259 | // static |
| 260 | ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction( |
| 261 | const ExtensionHostMsg_Request_Params& params, |
| 262 | const Extension* extension, |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 263 | int requesting_process_id, |
| 264 | const extensions::ProcessMap& process_map, |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 265 | extensions::ExtensionAPI* api, |
[email protected] | 67351452 | 2011-07-13 18:17:18 | [diff] [blame] | 266 | void* profile, |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 267 | IPC::Message::Sender* ipc_sender, |
| 268 | int routing_id) { |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 269 | if (!extension) { |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 270 | LOG(ERROR) << "Specified extension does not exist."; |
| 271 | SendAccessDenied(ipc_sender, routing_id, params.request_id); |
| 272 | return NULL; |
| 273 | } |
| 274 | |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 275 | if (api->IsPrivileged(params.name) && |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 276 | !process_map.Contains(extension->id(), requesting_process_id)) { |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 277 | LOG(ERROR) << "Extension API called from incorrect process " |
| 278 | << requesting_process_id |
| 279 | << " from URL " << params.source_url.spec(); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 280 | SendAccessDenied(ipc_sender, routing_id, params.request_id); |
| 281 | return NULL; |
| 282 | } |
| 283 | |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 284 | if (!extension->HasAPIPermission(params.name)) { |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 285 | LOG(ERROR) << "Extension " << extension->id() << " does not have " |
| 286 | << "permission to function: " << params.name; |
| 287 | SendAccessDenied(ipc_sender, routing_id, params.request_id); |
| 288 | return NULL; |
| 289 | } |
| 290 | |
| 291 | ExtensionFunction* function = |
[email protected] | ae33d32 | 2012-03-19 22:24:35 | [diff] [blame] | 292 | ExtensionFunctionRegistry::GetInstance()->NewFunction(params.name); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 293 | function->SetArgs(¶ms.arguments); |
| 294 | function->set_source_url(params.source_url); |
| 295 | function->set_request_id(params.request_id); |
| 296 | function->set_has_callback(params.has_callback); |
| 297 | function->set_user_gesture(params.user_gesture); |
| 298 | function->set_extension(extension); |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 299 | function->set_profile_id(profile); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 300 | return function; |
| 301 | } |
| 302 | |
| 303 | // static |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 304 | void ExtensionFunctionDispatcher::SendAccessDenied( |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 305 | IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { |
[email protected] | 602542d | 2012-04-20 02:48:01 | [diff] [blame^] | 306 | ListValue empty_list; |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 307 | ipc_sender->Send(new ExtensionMsg_Response( |
[email protected] | 602542d | 2012-04-20 02:48:01 | [diff] [blame^] | 308 | routing_id, request_id, false, empty_list, |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 309 | "Access to extension API denied.")); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 310 | } |