Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: extensions/browser/extension_function_dispatcher.cc

Issue 670173002: Fix webrequest api for webview in webui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: extension id fixed in callers Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 if (!extension_id.empty()) {
not at google - send to devlin 2014/10/22 19:12:06 This isn't the same as the other code - see line 3
guohui 2014/10/22 19:53:47 Done.
259 extension_info_map->IsIncognitoEnabled(extension->id())); 260 function->set_include_incognito(
261 extension_info_map->IsIncognitoEnabled(extension_id));
262 }
260 263
261 if (!CheckPermissions(function.get(), params, callback)) 264 if (!CheckPermissions(function.get(), params, callback))
262 return; 265 return;
263 266
264 QuotaService* quota = extension_info_map->GetQuotaService(); 267 QuotaService* quota = extension_info_map->GetQuotaService();
265 std::string violation_error = quota->Assess(extension->id(), 268 const std::string& violation_error = extension_id.empty() ?
266 function.get(), 269 base::EmptyString() :
267 &params.arguments, 270 quota->Assess(extension_id, function.get(), &params.arguments,
268 base::TimeTicks::Now()); 271 base::TimeTicks::Now());
269 if (violation_error.empty()) { 272 if (violation_error.empty()) {
270 scoped_ptr<base::ListValue> args(params.arguments.DeepCopy()); 273 scoped_ptr<base::ListValue> args(params.arguments.DeepCopy());
271 NotifyApiFunctionCalled(extension->id(), 274 NotifyApiFunctionCalled(extension_id,
272 params.name, 275 params.name,
273 args.Pass(), 276 args.Pass(),
274 static_cast<content::BrowserContext*>(profile_id)); 277 static_cast<content::BrowserContext*>(profile_id));
275 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls", 278 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls",
276 function->histogram_value()); 279 function->histogram_value());
277 function->Run()->Execute(); 280 function->Run()->Execute();
278 } else { 281 } else {
279 function->OnQuotaExceeded(violation_error); 282 function->OnQuotaExceeded(violation_error);
280 } 283 }
281 } 284 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 465
463 // static 466 // static
464 void ExtensionFunctionDispatcher::SendAccessDenied( 467 void ExtensionFunctionDispatcher::SendAccessDenied(
465 const ExtensionFunction::ResponseCallback& callback) { 468 const ExtensionFunction::ResponseCallback& callback) {
466 base::ListValue empty_list; 469 base::ListValue empty_list;
467 callback.Run(ExtensionFunction::FAILED, empty_list, 470 callback.Run(ExtensionFunction::FAILED, empty_list,
468 "Access to extension API denied."); 471 "Access to extension API denied.");
469 } 472 }
470 473
471 } // namespace extensions 474 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_function.h ('k') | extensions/browser/guest_view/guest_view_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698