[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] | b1912d59 | 2012-08-17 22:29:38 | [diff] [blame] | 15 | #include "chrome/browser/extensions/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] | efb4b08 | 2012-10-17 22:28:28 | [diff] [blame^] | 19 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extensions_quota_service.h" |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 22 | #include "chrome/browser/extensions/process_map.h" |
[email protected] | ed2b100 | 2011-05-25 14:12:10 | [diff] [blame] | 23 | #include "chrome/browser/external_protocol/external_protocol_handler.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 24 | #include "chrome/browser/profiles/profile.h" |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 25 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 26 | #include "chrome/common/extensions/api/extension_api.h" |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 27 | #include "chrome/common/extensions/extension_messages.h" |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 28 | #include "chrome/common/extensions/extension_set.h" |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 29 | #include "chrome/common/url_constants.h" |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 30 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 31 | #include "content/public/browser/render_view_host.h" |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 32 | #include "ipc/ipc_message.h" |
| 33 | #include "ipc/ipc_message_macros.h" |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 34 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
[email protected] | ae33d32 | 2012-03-19 22:24:35 | [diff] [blame] | 35 | #include "webkit/glue/resource_type.h" |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 36 | |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 37 | using extensions::Extension; |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 38 | using extensions::ExtensionAPI; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 39 | using content::RenderViewHost; |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 40 | using WebKit::WebSecurityOrigin; |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 41 | |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 42 | namespace { |
| 43 | |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 44 | const char kAccessDenied[] = "access denied"; |
| 45 | const char kQuotaExceeded[] = "quota exceeded"; |
| 46 | |
| 47 | void LogSuccess(const Extension* extension, |
| 48 | const ExtensionHostMsg_Request_Params& params) { |
[email protected] | b1912d59 | 2012-08-17 22:29:38 | [diff] [blame] | 49 | extensions::ActivityLog* activity_log = |
| 50 | extensions::ActivityLog::GetInstance(); |
| 51 | if (activity_log->HasObservers(extension)) { |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 52 | std::string call_signature = params.name + "("; |
| 53 | ListValue::const_iterator it = params.arguments.begin(); |
| 54 | for (; it != params.arguments.end(); ++it) { |
| 55 | std::string arg; |
| 56 | JSONStringValueSerializer serializer(&arg); |
| 57 | if (serializer.SerializeAndOmitBinaryValues(**it)) { |
| 58 | if (it != params.arguments.begin()) |
| 59 | call_signature += ", "; |
| 60 | call_signature += arg; |
| 61 | } |
| 62 | } |
| 63 | call_signature += ")"; |
| 64 | |
[email protected] | b1912d59 | 2012-08-17 22:29:38 | [diff] [blame] | 65 | activity_log->Log(extension, |
| 66 | extensions::ActivityLog::ACTIVITY_EXTENSION_API_CALL, |
| 67 | call_signature); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | void LogFailure(const Extension* extension, |
| 72 | const std::string& func_name, |
| 73 | const char* reason) { |
[email protected] | b1912d59 | 2012-08-17 22:29:38 | [diff] [blame] | 74 | extensions::ActivityLog* activity_log = |
| 75 | extensions::ActivityLog::GetInstance(); |
| 76 | if (activity_log->HasObservers(extension)) { |
| 77 | activity_log->Log(extension, |
| 78 | extensions::ActivityLog::ACTIVITY_EXTENSION_API_BLOCK, |
| 79 | func_name + ": " + reason); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 83 | // Separate copy of ExtensionAPI used for IO thread extension functions. We need |
| 84 | // this because ExtensionAPI has mutable data. It should be possible to remove |
| 85 | // this once all the extension APIs are updated to the feature system. |
| 86 | struct Static { |
| 87 | Static() |
| 88 | : api(extensions::ExtensionAPI::CreateWithDefaultConfiguration()) { |
| 89 | } |
| 90 | scoped_ptr<extensions::ExtensionAPI> api; |
| 91 | }; |
| 92 | base::LazyInstance<Static> g_global_io_data = LAZY_INSTANCE_INITIALIZER; |
| 93 | |
| 94 | } // namespace |
| 95 | |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 96 | extensions::WindowController* |
| 97 | ExtensionFunctionDispatcher::Delegate::GetExtensionWindowController() |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 98 | const { |
| 99 | return NULL; |
| 100 | } |
| 101 | |
| 102 | content::WebContents* |
[email protected] | 44f4b13 | 2012-07-17 20:36:57 | [diff] [blame] | 103 | ExtensionFunctionDispatcher::Delegate::GetAssociatedWebContents() const { |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 104 | return NULL; |
| 105 | } |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 106 | |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 107 | void ExtensionFunctionDispatcher::GetAllFunctionNames( |
| 108 | std::vector<std::string>* names) { |
[email protected] | ae33d32 | 2012-03-19 22:24:35 | [diff] [blame] | 109 | ExtensionFunctionRegistry::GetInstance()->GetAllNames(names); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 110 | } |
| 111 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 112 | bool ExtensionFunctionDispatcher::OverrideFunction( |
| 113 | const std::string& name, ExtensionFunctionFactory factory) { |
[email protected] | ae33d32 | 2012-03-19 22:24:35 | [diff] [blame] | 114 | return ExtensionFunctionRegistry::GetInstance()->OverrideFunction(name, |
| 115 | factory); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void ExtensionFunctionDispatcher::ResetFunctions() { |
[email protected] | ae33d32 | 2012-03-19 22:24:35 | [diff] [blame] | 119 | ExtensionFunctionRegistry::GetInstance()->ResetFunctions(); |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 120 | } |
| 121 | |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 122 | // static |
| 123 | void ExtensionFunctionDispatcher::DispatchOnIOThread( |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 124 | ExtensionInfoMap* extension_info_map, |
[email protected] | 67351452 | 2011-07-13 18:17:18 | [diff] [blame] | 125 | void* profile, |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 126 | int render_process_id, |
| 127 | base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame] | 128 | int routing_id, |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 129 | const ExtensionHostMsg_Request_Params& params) { |
| 130 | const Extension* extension = |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 131 | extension_info_map->extensions().GetByID(params.extension_id); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 132 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 133 | scoped_refptr<ExtensionFunction> function( |
| 134 | CreateExtensionFunction(params, extension, render_process_id, |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 135 | extension_info_map->process_map(), |
| 136 | g_global_io_data.Get().api.get(), |
| 137 | profile, |
[email protected] | 3d0e226 | 2012-08-02 15:32:16 | [diff] [blame] | 138 | ipc_sender, NULL, routing_id)); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 139 | if (!function) { |
| 140 | LogFailure(extension, params.name, kAccessDenied); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 141 | return; |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 142 | } |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 143 | |
| 144 | IOThreadExtensionFunction* function_io = |
| 145 | function->AsIOThreadExtensionFunction(); |
| 146 | if (!function_io) { |
| 147 | NOTREACHED(); |
| 148 | return; |
| 149 | } |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame] | 150 | function_io->set_ipc_sender(ipc_sender, routing_id); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 151 | function_io->set_extension_info_map(extension_info_map); |
| 152 | function->set_include_incognito( |
| 153 | extension_info_map->IsIncognitoEnabled(extension->id())); |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 154 | |
[email protected] | d2fe22ff | 2012-10-03 00:40:07 | [diff] [blame] | 155 | if (!CheckPermissions(function, extension, params, ipc_sender, routing_id)) { |
| 156 | LogFailure(extension, params.name, kAccessDenied); |
| 157 | return; |
| 158 | } |
| 159 | |
[email protected] | 3629691 | 2012-03-20 11:08:49 | [diff] [blame] | 160 | ExtensionsQuotaService* quota = extension_info_map->GetQuotaService(); |
[email protected] | 85231d7 | 2012-08-31 09:45:29 | [diff] [blame] | 161 | std::string violation_error = quota->Assess(extension->id(), |
| 162 | function, |
| 163 | ¶ms.arguments, |
| 164 | base::TimeTicks::Now()); |
| 165 | if (violation_error.empty()) { |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 166 | function->Run(); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 167 | LogSuccess(extension, params); |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 168 | } else { |
[email protected] | 85231d7 | 2012-08-31 09:45:29 | [diff] [blame] | 169 | function->OnQuotaExceeded(violation_error); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 170 | LogFailure(extension, params.name, kQuotaExceeded); |
[email protected] | fd50e7b | 2011-11-03 09:20:25 | [diff] [blame] | 171 | } |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 172 | } |
| 173 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 174 | ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(Profile* profile, |
| 175 | Delegate* delegate) |
| 176 | : profile_(profile), |
[email protected] | 55ce33071 | 2011-05-24 19:04:27 | [diff] [blame] | 177 | delegate_(delegate) { |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 178 | } |
| 179 | |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 180 | ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { |
[email protected] | 32dda36 | 2009-06-05 19:07:01 | [diff] [blame] | 181 | } |
| 182 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 183 | void ExtensionFunctionDispatcher::Dispatch( |
| 184 | const ExtensionHostMsg_Request_Params& params, |
| 185 | RenderViewHost* render_view_host) { |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 186 | ExtensionService* service = profile()->GetExtensionService(); |
[email protected] | efb4b08 | 2012-10-17 22:28:28 | [diff] [blame^] | 187 | ExtensionProcessManager* process_manager = |
| 188 | extensions::ExtensionSystem::Get(profile())->process_manager(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 189 | extensions::ProcessMap* process_map = service->process_map(); |
| 190 | if (!service || !process_map) |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 191 | return; |
| 192 | |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 193 | const Extension* extension = service->extensions()->GetByID( |
| 194 | params.extension_id); |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 195 | if (!extension) |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 196 | extension = service->extensions()->GetHostedAppByURL(ExtensionURLInfo( |
| 197 | WebSecurityOrigin::createFromString(params.source_origin), |
| 198 | params.source_url)); |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 199 | |
[email protected] | 8add541 | 2011-10-01 21:02:14 | [diff] [blame] | 200 | scoped_refptr<ExtensionFunction> function( |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame] | 201 | CreateExtensionFunction(params, extension, |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 202 | render_view_host->GetProcess()->GetID(), |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 203 | *(service->process_map()), |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 204 | extensions::ExtensionAPI::GetSharedInstance(), |
[email protected] | 3d0e226 | 2012-08-02 15:32:16 | [diff] [blame] | 205 | profile(), render_view_host, render_view_host, |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame] | 206 | render_view_host->GetRoutingID())); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 207 | if (!function) { |
| 208 | LogFailure(extension, params.name, kAccessDenied); |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 209 | return; |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 210 | } |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 211 | |
[email protected] | a2aef2e | 2011-05-26 22:48:12 | [diff] [blame] | 212 | UIThreadExtensionFunction* function_ui = |
| 213 | function->AsUIThreadExtensionFunction(); |
| 214 | if (!function_ui) { |
| 215 | NOTREACHED(); |
| 216 | return; |
| 217 | } |
[email protected] | a2aef2e | 2011-05-26 22:48:12 | [diff] [blame] | 218 | function_ui->set_dispatcher(AsWeakPtr()); |
| 219 | function_ui->set_profile(profile_); |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 220 | function->set_include_incognito(service->CanCrossIncognito(extension)); |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 221 | |
[email protected] | d2fe22ff | 2012-10-03 00:40:07 | [diff] [blame] | 222 | if (!CheckPermissions(function, extension, params, render_view_host, |
| 223 | render_view_host->GetRoutingID())) { |
| 224 | LogFailure(extension, params.name, kAccessDenied); |
| 225 | return; |
| 226 | } |
| 227 | |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 228 | ExtensionsQuotaService* quota = service->quota_service(); |
[email protected] | 85231d7 | 2012-08-31 09:45:29 | [diff] [blame] | 229 | std::string violation_error = quota->Assess(extension->id(), |
| 230 | function, |
| 231 | ¶ms.arguments, |
| 232 | base::TimeTicks::Now()); |
| 233 | if (violation_error.empty()) { |
[email protected] | d070ec6 | 2010-07-27 21:28:26 | [diff] [blame] | 234 | // See crbug.com/39178. |
| 235 | ExternalProtocolHandler::PermitLaunchUrl(); |
| 236 | |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 237 | function->Run(); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 238 | LogSuccess(extension, params); |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 239 | } else { |
[email protected] | 85231d7 | 2012-08-31 09:45:29 | [diff] [blame] | 240 | function->OnQuotaExceeded(violation_error); |
[email protected] | efd7599 | 2011-12-15 22:42:42 | [diff] [blame] | 241 | LogFailure(extension, params.name, kQuotaExceeded); |
[email protected] | d13950e | 2009-12-04 01:43:02 | [diff] [blame] | 242 | } |
[email protected] | 720ad131 | 2012-02-27 23:07:36 | [diff] [blame] | 243 | |
[email protected] | efb4b08 | 2012-10-17 22:28:28 | [diff] [blame^] | 244 | // Note: do not access |this| after this point. We may have been deleted |
| 245 | // if function->Run() ended up closing the tab that owns us. |
| 246 | |
[email protected] | 5734e88 | 2012-05-04 22:17:56 | [diff] [blame] | 247 | // Check if extension was uninstalled by management.uninstall. |
| 248 | if (!service->extensions()->GetByID(params.extension_id)) |
| 249 | return; |
| 250 | |
[email protected] | 720ad131 | 2012-02-27 23:07:36 | [diff] [blame] | 251 | // We only adjust the keepalive count for UIThreadExtensionFunction for |
| 252 | // now, largely for simplicity's sake. This is OK because currently, only |
| 253 | // the webRequest API uses IOThreadExtensionFunction, and that API is not |
| 254 | // compatible with lazy background pages. |
[email protected] | efb4b08 | 2012-10-17 22:28:28 | [diff] [blame^] | 255 | process_manager->IncrementLazyKeepaliveCount(extension); |
[email protected] | 720ad131 | 2012-02-27 23:07:36 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted( |
| 259 | const Extension* extension) { |
| 260 | profile()->GetExtensionProcessManager()->DecrementLazyKeepaliveCount( |
| 261 | extension); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 262 | } |
| 263 | |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 264 | // static |
[email protected] | d2fe22ff | 2012-10-03 00:40:07 | [diff] [blame] | 265 | bool ExtensionFunctionDispatcher::CheckPermissions( |
| 266 | ExtensionFunction* function, |
| 267 | const Extension* extension, |
| 268 | const ExtensionHostMsg_Request_Params& params, |
| 269 | IPC::Sender* ipc_sender, |
| 270 | int routing_id) { |
| 271 | if (!function->HasPermission()) { |
| 272 | LOG(ERROR) << "Extension " << extension->id() << " does not have " |
| 273 | << "permission to function: " << params.name; |
| 274 | SendAccessDenied(ipc_sender, routing_id, params.request_id); |
| 275 | return false; |
| 276 | } |
| 277 | return true; |
| 278 | } |
| 279 | |
| 280 | // static |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 281 | ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction( |
| 282 | const ExtensionHostMsg_Request_Params& params, |
| 283 | const Extension* extension, |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 284 | int requesting_process_id, |
| 285 | const extensions::ProcessMap& process_map, |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 286 | extensions::ExtensionAPI* api, |
[email protected] | 67351452 | 2011-07-13 18:17:18 | [diff] [blame] | 287 | void* profile, |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame] | 288 | IPC::Sender* ipc_sender, |
[email protected] | 3d0e226 | 2012-08-02 15:32:16 | [diff] [blame] | 289 | RenderViewHost* render_view_host, |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame] | 290 | int routing_id) { |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 291 | if (!extension) { |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 292 | LOG(ERROR) << "Specified extension does not exist."; |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame] | 293 | SendAccessDenied(ipc_sender, routing_id, params.request_id); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 294 | return NULL; |
| 295 | } |
| 296 | |
[email protected] | 5bc248a | 2012-04-04 23:38:11 | [diff] [blame] | 297 | if (api->IsPrivileged(params.name) && |
[email protected] | 83820d4 | 2011-11-12 22:03:11 | [diff] [blame] | 298 | !process_map.Contains(extension->id(), requesting_process_id)) { |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 299 | LOG(ERROR) << "Extension API called from incorrect process " |
| 300 | << requesting_process_id |
| 301 | << " from URL " << params.source_url.spec(); |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame] | 302 | SendAccessDenied(ipc_sender, routing_id, params.request_id); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 303 | return NULL; |
| 304 | } |
| 305 | |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 306 | ExtensionFunction* function = |
[email protected] | ae33d32 | 2012-03-19 22:24:35 | [diff] [blame] | 307 | ExtensionFunctionRegistry::GetInstance()->NewFunction(params.name); |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 308 | function->SetArgs(¶ms.arguments); |
| 309 | function->set_source_url(params.source_url); |
| 310 | function->set_request_id(params.request_id); |
| 311 | function->set_has_callback(params.has_callback); |
| 312 | function->set_user_gesture(params.user_gesture); |
| 313 | function->set_extension(extension); |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 314 | function->set_profile_id(profile); |
[email protected] | 3d0e226 | 2012-08-02 15:32:16 | [diff] [blame] | 315 | |
| 316 | UIThreadExtensionFunction* function_ui = |
| 317 | function->AsUIThreadExtensionFunction(); |
| 318 | if (function_ui) { |
| 319 | function_ui->SetRenderViewHost(render_view_host); |
| 320 | } |
| 321 | |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 322 | return function; |
| 323 | } |
| 324 | |
| 325 | // static |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 326 | void ExtensionFunctionDispatcher::SendAccessDenied( |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame] | 327 | IPC::Sender* ipc_sender, int routing_id, int request_id) { |
[email protected] | 602542d | 2012-04-20 02:48:01 | [diff] [blame] | 328 | ListValue empty_list; |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 329 | ipc_sender->Send(new ExtensionMsg_Response( |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame] | 330 | routing_id, request_id, false, empty_list, |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 331 | "Access to extension API denied.")); |
[email protected] | bfdffe2b | 2009-04-24 22:05:35 | [diff] [blame] | 332 | } |