| 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" | |
| 21 #include "chrome/browser/extensions/extension_util.h" | 20 #include "chrome/browser/extensions/extension_util.h" |
| 22 #include "chrome/browser/extensions/extension_web_ui.h" | 21 #include "chrome/browser/extensions/extension_web_ui.h" |
| 23 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 22 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 24 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 23 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
| 25 #include "chrome/common/extensions/extension_messages.h" | 24 #include "chrome/common/extensions/extension_messages.h" |
| 26 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 27 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
| 29 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
| 30 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
| 31 #include "content/public/browser/user_metrics.h" | 30 #include "content/public/browser/user_metrics.h" |
| 32 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/browser/web_contents_observer.h" | 32 #include "content/public/browser/web_contents_observer.h" |
| 34 #include "content/public/common/result_codes.h" | 33 #include "content/public/common/result_codes.h" |
| 34 #include "extensions/browser/extension_system.h" |
| 35 #include "extensions/browser/process_map.h" | 35 #include "extensions/browser/process_map.h" |
| 36 #include "extensions/browser/quota_service.h" | 36 #include "extensions/browser/quota_service.h" |
| 37 #include "extensions/common/extension_api.h" | 37 #include "extensions/common/extension_api.h" |
| 38 #include "extensions/common/extension_set.h" | 38 #include "extensions/common/extension_set.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; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 324 } |
| 325 | 325 |
| 326 void ExtensionFunctionDispatcher::DispatchWithCallbackInternal( | 326 void ExtensionFunctionDispatcher::DispatchWithCallbackInternal( |
| 327 const ExtensionHostMsg_Request_Params& params, | 327 const ExtensionHostMsg_Request_Params& params, |
| 328 RenderViewHost* render_view_host, | 328 RenderViewHost* render_view_host, |
| 329 content::RenderFrameHost* render_frame_host, | 329 content::RenderFrameHost* render_frame_host, |
| 330 const ExtensionFunction::ResponseCallback& callback) { | 330 const ExtensionFunction::ResponseCallback& callback) { |
| 331 DCHECK(render_view_host || render_frame_host); | 331 DCHECK(render_view_host || render_frame_host); |
| 332 // TODO(yzshen): There is some shared logic between this method and | 332 // TODO(yzshen): There is some shared logic between this method and |
| 333 // DispatchOnIOThread(). It is nice to deduplicate. | 333 // DispatchOnIOThread(). It is nice to deduplicate. |
| 334 ExtensionSystem* extension_system = | 334 ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_); |
| 335 ExtensionSystem::GetForBrowserContext(browser_context_); | |
| 336 ExtensionService* service = extension_system->extension_service(); | 335 ExtensionService* service = extension_system->extension_service(); |
| 337 extensions::ProcessMap* process_map = | 336 extensions::ProcessMap* process_map = |
| 338 extensions::ProcessMap::Get(browser_context_); | 337 extensions::ProcessMap::Get(browser_context_); |
| 339 if (!process_map) | 338 if (!process_map) |
| 340 return; | 339 return; |
| 341 | 340 |
| 342 const Extension* extension = service->extensions()->GetByID( | 341 const Extension* extension = service->extensions()->GetByID( |
| 343 params.extension_id); | 342 params.extension_id); |
| 344 if (!extension) | 343 if (!extension) |
| 345 extension = service->extensions()->GetHostedAppByURL(params.source_url); | 344 extension = service->extensions()->GetHostedAppByURL(params.source_url); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 400 |
| 402 // We only adjust the keepalive count for UIThreadExtensionFunction for | 401 // We only adjust the keepalive count for UIThreadExtensionFunction for |
| 403 // now, largely for simplicity's sake. This is OK because currently, only | 402 // now, largely for simplicity's sake. This is OK because currently, only |
| 404 // the webRequest API uses IOThreadExtensionFunction, and that API is not | 403 // the webRequest API uses IOThreadExtensionFunction, and that API is not |
| 405 // compatible with lazy background pages. | 404 // compatible with lazy background pages. |
| 406 extension_system->process_manager()->IncrementLazyKeepaliveCount(extension); | 405 extension_system->process_manager()->IncrementLazyKeepaliveCount(extension); |
| 407 } | 406 } |
| 408 | 407 |
| 409 void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted( | 408 void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted( |
| 410 const Extension* extension) { | 409 const Extension* extension) { |
| 411 ExtensionSystem::GetForBrowserContext(browser_context_)->process_manager()-> | 410 ExtensionSystem::Get(browser_context_)->process_manager()-> |
| 412 DecrementLazyKeepaliveCount(extension); | 411 DecrementLazyKeepaliveCount(extension); |
| 413 } | 412 } |
| 414 | 413 |
| 415 // static | 414 // static |
| 416 bool ExtensionFunctionDispatcher::CheckPermissions( | 415 bool ExtensionFunctionDispatcher::CheckPermissions( |
| 417 ExtensionFunction* function, | 416 ExtensionFunction* function, |
| 418 const Extension* extension, | 417 const Extension* extension, |
| 419 const ExtensionHostMsg_Request_Params& params, | 418 const ExtensionHostMsg_Request_Params& params, |
| 420 const ExtensionFunction::ResponseCallback& callback) { | 419 const ExtensionFunction::ResponseCallback& callback) { |
| 421 if (!function->HasPermission()) { | 420 if (!function->HasPermission()) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 return function; | 509 return function; |
| 511 } | 510 } |
| 512 | 511 |
| 513 // static | 512 // static |
| 514 void ExtensionFunctionDispatcher::SendAccessDenied( | 513 void ExtensionFunctionDispatcher::SendAccessDenied( |
| 515 const ExtensionFunction::ResponseCallback& callback) { | 514 const ExtensionFunction::ResponseCallback& callback) { |
| 516 base::ListValue empty_list; | 515 base::ListValue empty_list; |
| 517 callback.Run(ExtensionFunction::FAILED, empty_list, | 516 callback.Run(ExtensionFunction::FAILED, empty_list, |
| 518 "Access to extension API denied."); | 517 "Access to extension API denied."); |
| 519 } | 518 } |
| OLD | NEW |