| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/process/process.h" | 12 #include "base/process/process.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" | 15 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" |
| 16 #include "chrome/browser/extensions/activity_log/activity_log.h" | 16 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 17 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat
e_api.h" | 17 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat
e_api.h" |
| 18 #include "chrome/browser/extensions/extension_function_registry.h" | 18 #include "chrome/browser/extensions/extension_function_registry.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/extensions/extension_system.h" | 20 #include "chrome/browser/extensions/extension_system.h" |
| 21 #include "chrome/browser/extensions/extension_util.h" | 21 #include "chrome/browser/extensions/extension_util.h" |
| 22 #include "chrome/browser/extensions/extension_web_ui.h" | 22 #include "chrome/browser/extensions/extension_web_ui.h" |
| 23 #include "chrome/browser/extensions/extensions_quota_service.h" | |
| 24 #include "chrome/browser/extensions/process_map.h" | 23 #include "chrome/browser/extensions/process_map.h" |
| 25 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 24 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 26 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
| 28 #include "chrome/common/extensions/extension_messages.h" | 27 #include "chrome/common/extensions/extension_messages.h" |
| 29 #include "chrome/common/extensions/extension_set.h" | 28 #include "chrome/common/extensions/extension_set.h" |
| 30 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 31 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
| 33 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 34 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
| 35 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/browser/web_contents_observer.h" | 35 #include "content/public/browser/web_contents_observer.h" |
| 37 #include "content/public/common/result_codes.h" | 36 #include "content/public/common/result_codes.h" |
| 37 #include "extensions/browser/quota_service.h" |
| 38 #include "extensions/common/extension_api.h" | 38 #include "extensions/common/extension_api.h" |
| 39 #include "ipc/ipc_message.h" | 39 #include "ipc/ipc_message.h" |
| 40 #include "ipc/ipc_message_macros.h" | 40 #include "ipc/ipc_message_macros.h" |
| 41 #include "webkit/common/resource_type.h" | 41 #include "webkit/common/resource_type.h" |
| 42 | 42 |
| 43 using extensions::Extension; | 43 using extensions::Extension; |
| 44 using extensions::ExtensionAPI; | 44 using extensions::ExtensionAPI; |
| 45 using extensions::Feature; | 45 using extensions::Feature; |
| 46 using content::RenderViewHost; | 46 using content::RenderViewHost; |
| 47 | 47 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 return ExtensionFunctionRegistry::GetInstance()->OverrideFunction(name, | 227 return ExtensionFunctionRegistry::GetInstance()->OverrideFunction(name, |
| 228 factory); | 228 factory); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void ExtensionFunctionDispatcher::ResetFunctions() { | 231 void ExtensionFunctionDispatcher::ResetFunctions() { |
| 232 ExtensionFunctionRegistry::GetInstance()->ResetFunctions(); | 232 ExtensionFunctionRegistry::GetInstance()->ResetFunctions(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 // static | 235 // static |
| 236 void ExtensionFunctionDispatcher::DispatchOnIOThread( | 236 void ExtensionFunctionDispatcher::DispatchOnIOThread( |
| 237 ExtensionInfoMap* extension_info_map, | 237 extensions::InfoMap* extension_info_map, |
| 238 void* profile, | 238 void* profile, |
| 239 int render_process_id, | 239 int render_process_id, |
| 240 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, | 240 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender, |
| 241 int routing_id, | 241 int routing_id, |
| 242 const ExtensionHostMsg_Request_Params& params) { | 242 const ExtensionHostMsg_Request_Params& params) { |
| 243 const Extension* extension = | 243 const Extension* extension = |
| 244 extension_info_map->extensions().GetByID(params.extension_id); | 244 extension_info_map->extensions().GetByID(params.extension_id); |
| 245 Profile* profile_cast = static_cast<Profile*>(profile); | 245 Profile* profile_cast = static_cast<Profile*>(profile); |
| 246 | 246 |
| 247 ExtensionFunction::ResponseCallback callback( | 247 ExtensionFunction::ResponseCallback callback( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 function_io->set_ipc_sender(ipc_sender, routing_id); | 267 function_io->set_ipc_sender(ipc_sender, routing_id); |
| 268 function_io->set_extension_info_map(extension_info_map); | 268 function_io->set_extension_info_map(extension_info_map); |
| 269 function->set_include_incognito( | 269 function->set_include_incognito( |
| 270 extension_info_map->IsIncognitoEnabled(extension->id())); | 270 extension_info_map->IsIncognitoEnabled(extension->id())); |
| 271 | 271 |
| 272 if (!CheckPermissions(function.get(), extension, params, callback)) | 272 if (!CheckPermissions(function.get(), extension, params, callback)) |
| 273 return; | 273 return; |
| 274 | 274 |
| 275 ExtensionsQuotaService* quota = extension_info_map->GetQuotaService(); | 275 extensions::QuotaService* quota = extension_info_map->GetQuotaService(); |
| 276 std::string violation_error = quota->Assess(extension->id(), | 276 std::string violation_error = quota->Assess(extension->id(), |
| 277 function.get(), | 277 function.get(), |
| 278 ¶ms.arguments, | 278 ¶ms.arguments, |
| 279 base::TimeTicks::Now()); | 279 base::TimeTicks::Now()); |
| 280 if (violation_error.empty()) { | 280 if (violation_error.empty()) { |
| 281 LogSuccess(extension->id(), | 281 LogSuccess(extension->id(), |
| 282 params.name, | 282 params.name, |
| 283 args.Pass(), | 283 args.Pass(), |
| 284 profile_cast); | 284 profile_cast); |
| 285 function->Run(); | 285 function->Run(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 352 } |
| 353 function_ui->SetRenderViewHost(render_view_host); | 353 function_ui->SetRenderViewHost(render_view_host); |
| 354 function_ui->set_dispatcher(AsWeakPtr()); | 354 function_ui->set_dispatcher(AsWeakPtr()); |
| 355 function_ui->set_context(profile_); | 355 function_ui->set_context(profile_); |
| 356 function->set_include_incognito(extension_util::CanCrossIncognito(extension, | 356 function->set_include_incognito(extension_util::CanCrossIncognito(extension, |
| 357 service)); | 357 service)); |
| 358 | 358 |
| 359 if (!CheckPermissions(function.get(), extension, params, callback)) | 359 if (!CheckPermissions(function.get(), extension, params, callback)) |
| 360 return; | 360 return; |
| 361 | 361 |
| 362 ExtensionsQuotaService* quota = service->quota_service(); | 362 extensions::QuotaService* quota = service->quota_service(); |
| 363 std::string violation_error = quota->Assess(extension->id(), | 363 std::string violation_error = quota->Assess(extension->id(), |
| 364 function.get(), | 364 function.get(), |
| 365 ¶ms.arguments, | 365 ¶ms.arguments, |
| 366 base::TimeTicks::Now()); | 366 base::TimeTicks::Now()); |
| 367 if (violation_error.empty()) { | 367 if (violation_error.empty()) { |
| 368 // See crbug.com/39178. | 368 // See crbug.com/39178. |
| 369 ExternalProtocolHandler::PermitLaunchUrl(); | 369 ExternalProtocolHandler::PermitLaunchUrl(); |
| 370 LogSuccess(extension->id(), params.name, args.Pass(), profile()); | 370 LogSuccess(extension->id(), params.name, args.Pass(), profile()); |
| 371 function->Run(); | 371 function->Run(); |
| 372 } else { | 372 } else { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 return function; | 488 return function; |
| 489 } | 489 } |
| 490 | 490 |
| 491 // static | 491 // static |
| 492 void ExtensionFunctionDispatcher::SendAccessDenied( | 492 void ExtensionFunctionDispatcher::SendAccessDenied( |
| 493 const ExtensionFunction::ResponseCallback& callback) { | 493 const ExtensionFunction::ResponseCallback& callback) { |
| 494 ListValue empty_list; | 494 ListValue empty_list; |
| 495 callback.Run(ExtensionFunction::FAILED, empty_list, | 495 callback.Run(ExtensionFunction::FAILED, empty_list, |
| 496 "Access to extension API denied."); | 496 "Access to extension API denied."); |
| 497 } | 497 } |
| OLD | NEW |