| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_function_dispatcher.h" | 5 #include "extensions/browser/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/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
| 13 #include "base/process/process.h" | 13 #include "base/process/process.h" |
| 14 #include "base/strings/string_util.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/browser/web_contents_observer.h" | 23 #include "content/public/browser/web_contents_observer.h" |
| 23 #include "content/public/common/result_codes.h" | 24 #include "content/public/common/result_codes.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 // static | 223 // static |
| 223 void ExtensionFunctionDispatcher::DispatchOnIOThread( | 224 void ExtensionFunctionDispatcher::DispatchOnIOThread( |
| 224 InfoMap* extension_info_map, | 225 InfoMap* extension_info_map, |
| 225 void* profile_id, | 226 void* profile_id, |
| 226 int render_process_id, | 227 int render_process_id, |
| 227 base::WeakPtr<ExtensionMessageFilter> ipc_sender, | 228 base::WeakPtr<ExtensionMessageFilter> ipc_sender, |
| 228 int routing_id, | 229 int routing_id, |
| 229 const ExtensionHostMsg_Request_Params& params) { | 230 const ExtensionHostMsg_Request_Params& params) { |
| 230 const Extension* extension = | 231 const Extension* extension = |
| 231 extension_info_map->extensions().GetByID(params.extension_id); | 232 extension_info_map->extensions().GetByID(params.extension_id); |
| 232 if (!extension) | 233 const std::string& extension_id = extension ? |
| 233 return; | 234 extension->id() : base::EmptyString(); |
| 234 | 235 |
| 235 ExtensionFunction::ResponseCallback callback( | 236 ExtensionFunction::ResponseCallback callback( |
| 236 base::Bind(&IOThreadResponseCallback, ipc_sender, routing_id, | 237 base::Bind(&IOThreadResponseCallback, ipc_sender, routing_id, |
| 237 params.request_id)); | 238 params.request_id)); |
| 238 | 239 |
| 239 scoped_refptr<ExtensionFunction> function( | 240 scoped_refptr<ExtensionFunction> function( |
| 240 CreateExtensionFunction(params, | 241 CreateExtensionFunction(params, |
| 241 extension, | 242 extension, |
| 242 render_process_id, | 243 render_process_id, |
| 243 extension_info_map->process_map(), | 244 extension_info_map->process_map(), |
| 244 g_global_io_data.Get().api.get(), | 245 g_global_io_data.Get().api.get(), |
| 245 profile_id, | 246 profile_id, |
| 246 callback)); | 247 callback)); |
| 247 if (!function.get()) | 248 if (!function.get()) |
| 248 return; | 249 return; |
| 249 | 250 |
| 250 IOThreadExtensionFunction* function_io = | 251 IOThreadExtensionFunction* function_io = |
| 251 function->AsIOThreadExtensionFunction(); | 252 function->AsIOThreadExtensionFunction(); |
| 252 if (!function_io) { | 253 if (!function_io) { |
| 253 NOTREACHED(); | 254 NOTREACHED(); |
| 254 return; | 255 return; |
| 255 } | 256 } |
| 256 function_io->set_ipc_sender(ipc_sender, routing_id); | 257 function_io->set_ipc_sender(ipc_sender, routing_id); |
| 257 function_io->set_extension_info_map(extension_info_map); | 258 function_io->set_extension_info_map(extension_info_map); |
| 258 function->set_include_incognito( | 259 function->set_include_incognito( |
| 259 extension_info_map->IsIncognitoEnabled(extension->id())); | 260 extension_info_map->IsIncognitoEnabled(extension_id)); |
| 260 | 261 |
| 261 if (!CheckPermissions(function.get(), params, callback)) | 262 if (!CheckPermissions(function.get(), params, callback)) |
| 262 return; | 263 return; |
| 263 | 264 |
| 264 QuotaService* quota = extension_info_map->GetQuotaService(); | 265 QuotaService* quota = extension_info_map->GetQuotaService(); |
| 265 std::string violation_error = quota->Assess(extension->id(), | 266 std::string violation_error = quota->Assess( |
| 266 function.get(), | 267 extension_id, function.get(), ¶ms.arguments, base::TimeTicks::Now()); |
| 267 ¶ms.arguments, | |
| 268 base::TimeTicks::Now()); | |
| 269 if (violation_error.empty()) { | 268 if (violation_error.empty()) { |
| 270 scoped_ptr<base::ListValue> args(params.arguments.DeepCopy()); | 269 scoped_ptr<base::ListValue> args(params.arguments.DeepCopy()); |
| 271 NotifyApiFunctionCalled(extension->id(), | 270 NotifyApiFunctionCalled(extension_id, |
| 272 params.name, | 271 params.name, |
| 273 args.Pass(), | 272 args.Pass(), |
| 274 static_cast<content::BrowserContext*>(profile_id)); | 273 static_cast<content::BrowserContext*>(profile_id)); |
| 275 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls", | 274 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls", |
| 276 function->histogram_value()); | 275 function->histogram_value()); |
| 277 function->Run()->Execute(); | 276 function->Run()->Execute(); |
| 278 } else { | 277 } else { |
| 279 function->OnQuotaExceeded(violation_error); | 278 function->OnQuotaExceeded(violation_error); |
| 280 } | 279 } |
| 281 } | 280 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 | 461 |
| 463 // static | 462 // static |
| 464 void ExtensionFunctionDispatcher::SendAccessDenied( | 463 void ExtensionFunctionDispatcher::SendAccessDenied( |
| 465 const ExtensionFunction::ResponseCallback& callback) { | 464 const ExtensionFunction::ResponseCallback& callback) { |
| 466 base::ListValue empty_list; | 465 base::ListValue empty_list; |
| 467 callback.Run(ExtensionFunction::FAILED, empty_list, | 466 callback.Run(ExtensionFunction::FAILED, empty_list, |
| 468 "Access to extension API denied."); | 467 "Access to extension API denied."); |
| 469 } | 468 } |
| 470 | 469 |
| 471 } // namespace extensions | 470 } // namespace extensions |
| OLD | NEW |