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

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

Issue 1169223002: [Extensions] Clean up the handling of ExtensionHostMsg_Request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 5 years, 6 months 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"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 198
199 base::WeakPtr<ExtensionFunctionDispatcher> dispatcher_; 199 base::WeakPtr<ExtensionFunctionDispatcher> dispatcher_;
200 content::RenderViewHost* render_view_host_; 200 content::RenderViewHost* render_view_host_;
201 base::WeakPtrFactory<UIThreadResponseCallbackWrapper> weak_ptr_factory_; 201 base::WeakPtrFactory<UIThreadResponseCallbackWrapper> weak_ptr_factory_;
202 202
203 DISALLOW_COPY_AND_ASSIGN(UIThreadResponseCallbackWrapper); 203 DISALLOW_COPY_AND_ASSIGN(UIThreadResponseCallbackWrapper);
204 }; 204 };
205 205
206 WindowController* 206 WindowController*
207 ExtensionFunctionDispatcher::Delegate::GetExtensionWindowController() const { 207 ExtensionFunctionDispatcher::Delegate::GetExtensionWindowController() const {
208 return NULL; 208 return nullptr;
209 } 209 }
210 210
211 content::WebContents* 211 content::WebContents*
212 ExtensionFunctionDispatcher::Delegate::GetAssociatedWebContents() const { 212 ExtensionFunctionDispatcher::Delegate::GetAssociatedWebContents() const {
213 return NULL; 213 return nullptr;
214 } 214 }
215 215
216 content::WebContents* 216 content::WebContents*
217 ExtensionFunctionDispatcher::Delegate::GetVisibleWebContents() const { 217 ExtensionFunctionDispatcher::Delegate::GetVisibleWebContents() const {
218 return GetAssociatedWebContents(); 218 return GetAssociatedWebContents();
219 } 219 }
220 220
221 void ExtensionFunctionDispatcher::GetAllFunctionNames( 221 void ExtensionFunctionDispatcher::GetAllFunctionNames(
222 std::vector<std::string>* names) { 222 std::vector<std::string>* names) {
223 ExtensionFunctionRegistry::GetInstance()->GetAllNames(names); 223 ExtensionFunctionRegistry::GetInstance()->GetAllNames(names);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 tracked_objects::ScopedProfile scoped_profile( 294 tracked_objects::ScopedProfile scoped_profile(
295 FROM_HERE_WITH_EXPLICIT_FUNCTION(function->name()), 295 FROM_HERE_WITH_EXPLICIT_FUNCTION(function->name()),
296 tracked_objects::ScopedProfile::ENABLED); 296 tracked_objects::ScopedProfile::ENABLED);
297 function->Run()->Execute(); 297 function->Run()->Execute();
298 } else { 298 } else {
299 function->OnQuotaExceeded(violation_error); 299 function->OnQuotaExceeded(violation_error);
300 } 300 }
301 } 301 }
302 302
303 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( 303 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(
304 content::BrowserContext* browser_context, 304 content::BrowserContext* browser_context)
305 Delegate* delegate) 305 : browser_context_(browser_context) {
306 : browser_context_(browser_context),
307 delegate_(delegate) {
308 } 306 }
309 307
310 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { 308 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() {
311 } 309 }
312 310
313 void ExtensionFunctionDispatcher::Dispatch( 311 void ExtensionFunctionDispatcher::Dispatch(
314 const ExtensionHostMsg_Request_Params& params, 312 const ExtensionHostMsg_Request_Params& params,
315 RenderViewHost* render_view_host) { 313 RenderViewHost* render_view_host) {
316 UIThreadResponseCallbackWrapperMap::const_iterator 314 UIThreadResponseCallbackWrapperMap::const_iterator
317 iter = ui_thread_response_callback_wrappers_.find(render_view_host); 315 iter = ui_thread_response_callback_wrappers_.find(render_view_host);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 431 }
434 432
435 void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted( 433 void ExtensionFunctionDispatcher::OnExtensionFunctionCompleted(
436 const Extension* extension) { 434 const Extension* extension) {
437 if (extension) { 435 if (extension) {
438 ProcessManager::Get(browser_context_) 436 ProcessManager::Get(browser_context_)
439 ->DecrementLazyKeepaliveCount(extension); 437 ->DecrementLazyKeepaliveCount(extension);
440 } 438 }
441 } 439 }
442 440
441 WindowController*
442 ExtensionFunctionDispatcher::GetExtensionWindowController() const {
443 return delegate_ ? delegate_->GetExtensionWindowController() : nullptr;
444 }
445
446 content::WebContents*
447 ExtensionFunctionDispatcher::GetAssociatedWebContents() const {
448 return delegate_ ? delegate_->GetAssociatedWebContents() : nullptr;
449 }
450
451 content::WebContents*
452 ExtensionFunctionDispatcher::GetVisibleWebContents() const {
453 return delegate_ ? delegate_->GetVisibleWebContents() :
454 GetAssociatedWebContents();
455 }
456
443 // static 457 // static
444 bool ExtensionFunctionDispatcher::CheckPermissions( 458 bool ExtensionFunctionDispatcher::CheckPermissions(
445 ExtensionFunction* function, 459 ExtensionFunction* function,
446 const ExtensionHostMsg_Request_Params& params, 460 const ExtensionHostMsg_Request_Params& params,
447 const ExtensionFunction::ResponseCallback& callback) { 461 const ExtensionFunction::ResponseCallback& callback) {
448 if (!function->HasPermission()) { 462 if (!function->HasPermission()) {
449 LOG(ERROR) << "Permission denied for " << params.name; 463 LOG(ERROR) << "Permission denied for " << params.name;
450 SendAccessDenied(callback, function->histogram_value()); 464 SendAccessDenied(callback, function->histogram_value());
451 return false; 465 return false;
452 } 466 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 // static 502 // static
489 void ExtensionFunctionDispatcher::SendAccessDenied( 503 void ExtensionFunctionDispatcher::SendAccessDenied(
490 const ExtensionFunction::ResponseCallback& callback, 504 const ExtensionFunction::ResponseCallback& callback,
491 functions::HistogramValue histogram_value) { 505 functions::HistogramValue histogram_value) {
492 base::ListValue empty_list; 506 base::ListValue empty_list;
493 callback.Run(ExtensionFunction::FAILED, empty_list, 507 callback.Run(ExtensionFunction::FAILED, empty_list,
494 "Access to extension API denied.", histogram_value); 508 "Access to extension API denied.", histogram_value);
495 } 509 }
496 510
497 } // namespace extensions 511 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698