| 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/browser/extensions/extension_function_dispatcher.h" | 5 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 void ExtensionFunctionDispatcher::ResetFunctions() { | 119 void ExtensionFunctionDispatcher::ResetFunctions() { |
| 120 ExtensionFunctionRegistry::GetInstance()->ResetFunctions(); | 120 ExtensionFunctionRegistry::GetInstance()->ResetFunctions(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // static | 123 // static |
| 124 void ExtensionFunctionDispatcher::DispatchOnIOThread( | 124 void ExtensionFunctionDispatcher::DispatchOnIOThread( |
| 125 ExtensionInfoMap* extension_info_map, | 125 ExtensionInfoMap* extension_info_map, |
| 126 void* profile, | 126 void* profile, |
| 127 int render_process_id, | 127 int render_process_id, |
| 128 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, | 128 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, |
| 129 int routing_id, | |
| 130 const ExtensionHostMsg_Request_Params& params) { | 129 const ExtensionHostMsg_Request_Params& params) { |
| 131 const Extension* extension = | 130 const Extension* extension = |
| 132 extension_info_map->extensions().GetByID(params.extension_id); | 131 extension_info_map->extensions().GetByID(params.extension_id); |
| 133 | 132 |
| 134 scoped_refptr<ExtensionFunction> function( | 133 scoped_refptr<ExtensionFunction> function( |
| 135 CreateExtensionFunction(params, extension, render_process_id, | 134 CreateExtensionFunction(params, extension, render_process_id, |
| 136 extension_info_map->process_map(), | 135 extension_info_map->process_map(), |
| 137 g_global_io_data.Get().api.get(), | 136 g_global_io_data.Get().api.get(), |
| 138 profile, | 137 profile, |
| 139 ipc_sender, routing_id)); | 138 ipc_sender)); |
| 140 if (!function) { | 139 if (!function) { |
| 141 LogFailure(extension, params.name, kAccessDenied); | 140 LogFailure(extension, params.name, kAccessDenied); |
| 142 return; | 141 return; |
| 143 } | 142 } |
| 144 | 143 |
| 145 IOThreadExtensionFunction* function_io = | 144 IOThreadExtensionFunction* function_io = |
| 146 function->AsIOThreadExtensionFunction(); | 145 function->AsIOThreadExtensionFunction(); |
| 147 if (!function_io) { | 146 if (!function_io) { |
| 148 NOTREACHED(); | 147 NOTREACHED(); |
| 149 return; | 148 return; |
| 150 } | 149 } |
| 151 function_io->set_ipc_sender(ipc_sender, routing_id); | 150 function_io->set_ipc_sender(ipc_sender); |
| 152 function_io->set_extension_info_map(extension_info_map); | 151 function_io->set_extension_info_map(extension_info_map); |
| 153 function->set_include_incognito( | 152 function->set_include_incognito( |
| 154 extension_info_map->IsIncognitoEnabled(extension->id())); | 153 extension_info_map->IsIncognitoEnabled(extension->id())); |
| 155 | 154 |
| 156 ExtensionsQuotaService* quota = extension_info_map->GetQuotaService(); | 155 ExtensionsQuotaService* quota = extension_info_map->GetQuotaService(); |
| 157 if (quota->Assess(extension->id(), function, ¶ms.arguments, | 156 if (quota->Assess(extension->id(), function, ¶ms.arguments, |
| 158 base::TimeTicks::Now())) { | 157 base::TimeTicks::Now())) { |
| 159 function->Run(); | 158 function->Run(); |
| 160 LogSuccess(extension, params); | 159 LogSuccess(extension, params); |
| 161 } else { | 160 } else { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 182 return; | 181 return; |
| 183 | 182 |
| 184 const Extension* extension = service->extensions()->GetByID( | 183 const Extension* extension = service->extensions()->GetByID( |
| 185 params.extension_id); | 184 params.extension_id); |
| 186 if (!extension) | 185 if (!extension) |
| 187 extension = service->extensions()->GetHostedAppByURL(ExtensionURLInfo( | 186 extension = service->extensions()->GetHostedAppByURL(ExtensionURLInfo( |
| 188 WebSecurityOrigin::createFromString(params.source_origin), | 187 WebSecurityOrigin::createFromString(params.source_origin), |
| 189 params.source_url)); | 188 params.source_url)); |
| 190 | 189 |
| 191 scoped_refptr<ExtensionFunction> function( | 190 scoped_refptr<ExtensionFunction> function( |
| 192 CreateExtensionFunction(params, extension, | 191 CreateExtensionFunction(params, |
| 192 extension, |
| 193 render_view_host->GetProcess()->GetID(), | 193 render_view_host->GetProcess()->GetID(), |
| 194 *(service->process_map()), | 194 *(service->process_map()), |
| 195 extensions::ExtensionAPI::GetSharedInstance(), | 195 extensions::ExtensionAPI::GetSharedInstance(), |
| 196 profile(), render_view_host, | 196 profile(), |
| 197 render_view_host->GetRoutingID())); | 197 render_view_host)); |
| 198 if (!function) { | 198 if (!function) { |
| 199 LogFailure(extension, params.name, kAccessDenied); | 199 LogFailure(extension, params.name, kAccessDenied); |
| 200 return; | 200 return; |
| 201 } | 201 } |
| 202 | 202 |
| 203 UIThreadExtensionFunction* function_ui = | 203 UIThreadExtensionFunction* function_ui = |
| 204 function->AsUIThreadExtensionFunction(); | 204 function->AsUIThreadExtensionFunction(); |
| 205 if (!function_ui) { | 205 if (!function_ui) { |
| 206 NOTREACHED(); | 206 NOTREACHED(); |
| 207 return; | 207 return; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 243 } |
| 244 | 244 |
| 245 // static | 245 // static |
| 246 ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction( | 246 ExtensionFunction* ExtensionFunctionDispatcher::CreateExtensionFunction( |
| 247 const ExtensionHostMsg_Request_Params& params, | 247 const ExtensionHostMsg_Request_Params& params, |
| 248 const Extension* extension, | 248 const Extension* extension, |
| 249 int requesting_process_id, | 249 int requesting_process_id, |
| 250 const extensions::ProcessMap& process_map, | 250 const extensions::ProcessMap& process_map, |
| 251 extensions::ExtensionAPI* api, | 251 extensions::ExtensionAPI* api, |
| 252 void* profile, | 252 void* profile, |
| 253 IPC::Sender* ipc_sender, | 253 IPC::Sender* ipc_sender) { |
| 254 int routing_id) { | |
| 255 if (!extension) { | 254 if (!extension) { |
| 256 LOG(ERROR) << "Specified extension does not exist."; | 255 LOG(ERROR) << "Specified extension does not exist."; |
| 257 SendAccessDenied(ipc_sender, routing_id, params.request_id); | 256 SendAccessDenied(ipc_sender, params.request_id); |
| 258 return NULL; | 257 return NULL; |
| 259 } | 258 } |
| 260 | 259 |
| 261 if (api->IsPrivileged(params.name) && | 260 if (api->IsPrivileged(params.name) && |
| 262 !process_map.Contains(extension->id(), requesting_process_id)) { | 261 !process_map.Contains(extension->id(), requesting_process_id)) { |
| 263 LOG(ERROR) << "Extension API called from incorrect process " | 262 LOG(ERROR) << "Extension API called from incorrect process " |
| 264 << requesting_process_id | 263 << requesting_process_id |
| 265 << " from URL " << params.source_url.spec(); | 264 << " from URL " << params.source_url.spec(); |
| 266 SendAccessDenied(ipc_sender, routing_id, params.request_id); | 265 SendAccessDenied(ipc_sender, params.request_id); |
| 267 return NULL; | 266 return NULL; |
| 268 } | 267 } |
| 269 | 268 |
| 270 if (!extension->HasAPIPermission(params.name)) { | 269 if (!extension->HasAPIPermission(params.name)) { |
| 271 LOG(ERROR) << "Extension " << extension->id() << " does not have " | 270 LOG(ERROR) << "Extension " << extension->id() << " does not have " |
| 272 << "permission to function: " << params.name; | 271 << "permission to function: " << params.name; |
| 273 SendAccessDenied(ipc_sender, routing_id, params.request_id); | 272 SendAccessDenied(ipc_sender, params.request_id); |
| 274 return NULL; | 273 return NULL; |
| 275 } | 274 } |
| 276 | 275 |
| 277 ExtensionFunction* function = | 276 ExtensionFunction* function = |
| 278 ExtensionFunctionRegistry::GetInstance()->NewFunction(params.name); | 277 ExtensionFunctionRegistry::GetInstance()->NewFunction(params.name); |
| 279 function->SetArgs(¶ms.arguments); | 278 function->SetArgs(¶ms.arguments); |
| 280 function->set_source_url(params.source_url); | 279 function->set_source_url(params.source_url); |
| 281 function->set_request_id(params.request_id); | 280 function->set_request_id(params.request_id); |
| 282 function->set_has_callback(params.has_callback); | 281 function->set_has_callback(params.has_callback); |
| 283 function->set_user_gesture(params.user_gesture); | 282 function->set_user_gesture(params.user_gesture); |
| 284 function->set_extension(extension); | 283 function->set_extension(extension); |
| 285 function->set_profile_id(profile); | 284 function->set_profile_id(profile); |
| 286 return function; | 285 return function; |
| 287 } | 286 } |
| 288 | 287 |
| 289 // static | 288 // static |
| 290 void ExtensionFunctionDispatcher::SendAccessDenied( | 289 void ExtensionFunctionDispatcher::SendAccessDenied( |
| 291 IPC::Sender* ipc_sender, int routing_id, int request_id) { | 290 IPC::Sender* ipc_sender, int request_id) { |
| 292 ListValue empty_list; | 291 ListValue empty_list; |
| 293 ipc_sender->Send(new ExtensionMsg_Response( | 292 ipc_sender->Send(new ExtensionMsg_Response( |
| 294 routing_id, request_id, false, empty_list, | 293 request_id, false, empty_list, |
| 295 "Access to extension API denied.")); | 294 "Access to extension API denied.")); |
| 296 } | 295 } |
| OLD | NEW |