| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 return FactoryRegistry::GetInstance()->OverrideFunction(name, factory); | 391 return FactoryRegistry::GetInstance()->OverrideFunction(name, factory); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void ExtensionFunctionDispatcher::ResetFunctions() { | 394 void ExtensionFunctionDispatcher::ResetFunctions() { |
| 395 FactoryRegistry::GetInstance()->ResetFunctions(); | 395 FactoryRegistry::GetInstance()->ResetFunctions(); |
| 396 } | 396 } |
| 397 | 397 |
| 398 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(Profile* profile, | 398 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(Profile* profile, |
| 399 Delegate* delegate) | 399 Delegate* delegate) |
| 400 : profile_(profile), | 400 : profile_(profile), |
| 401 delegate_(delegate), | 401 delegate_(delegate) { |
| 402 ALLOW_THIS_IN_INITIALIZER_LIST(peer_(new Peer(this))) { | |
| 403 } | 402 } |
| 404 | 403 |
| 405 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { | 404 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { |
| 406 peer_->dispatcher_ = NULL; | |
| 407 } | 405 } |
| 408 | 406 |
| 409 Browser* ExtensionFunctionDispatcher::GetCurrentBrowser( | 407 Browser* ExtensionFunctionDispatcher::GetCurrentBrowser( |
| 410 RenderViewHost* render_view_host, bool include_incognito) { | 408 RenderViewHost* render_view_host, bool include_incognito) { |
| 411 Browser* browser = delegate_->GetBrowser(); | 409 Browser* browser = delegate_->GetBrowser(); |
| 412 | 410 |
| 413 // If the delegate has an associated browser, that is always the right answer. | 411 // If the delegate has an associated browser, that is always the right answer. |
| 414 if (browser) | 412 if (browser) |
| 415 return browser; | 413 return browser; |
| 416 | 414 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 if (!extension->HasApiPermission(params.name)) { | 473 if (!extension->HasApiPermission(params.name)) { |
| 476 LOG(ERROR) << "Extension " << extension->id() << " does not have " | 474 LOG(ERROR) << "Extension " << extension->id() << " does not have " |
| 477 << "permission to function: " << params.name; | 475 << "permission to function: " << params.name; |
| 478 SendAccessDenied(render_view_host, params.request_id); | 476 SendAccessDenied(render_view_host, params.request_id); |
| 479 return; | 477 return; |
| 480 } | 478 } |
| 481 | 479 |
| 482 scoped_refptr<ExtensionFunction> function( | 480 scoped_refptr<ExtensionFunction> function( |
| 483 FactoryRegistry::GetInstance()->NewFunction(params.name)); | 481 FactoryRegistry::GetInstance()->NewFunction(params.name)); |
| 484 function->SetRenderViewHost(render_view_host); | 482 function->SetRenderViewHost(render_view_host); |
| 485 function->set_dispatcher_peer(peer_); | 483 function->set_dispatcher(AsWeakPtr()); |
| 486 function->set_profile(profile_); | 484 function->set_profile(profile_); |
| 487 function->set_extension_id(extension->id()); | 485 function->set_extension_id(extension->id()); |
| 488 function->SetArgs(¶ms.arguments); | 486 function->SetArgs(¶ms.arguments); |
| 489 function->set_source_url(params.source_url); | 487 function->set_source_url(params.source_url); |
| 490 function->set_request_id(params.request_id); | 488 function->set_request_id(params.request_id); |
| 491 function->set_has_callback(params.has_callback); | 489 function->set_has_callback(params.has_callback); |
| 492 function->set_user_gesture(params.user_gesture); | 490 function->set_user_gesture(params.user_gesture); |
| 493 function->set_include_incognito(service->CanCrossIncognito(extension)); | 491 function->set_include_incognito(service->CanCrossIncognito(extension)); |
| 494 | 492 |
| 495 ExtensionsQuotaService* quota = service->quota_service(); | 493 ExtensionsQuotaService* quota = service->quota_service(); |
| 496 if (quota->Assess(extension->id(), function, ¶ms.arguments, | 494 if (quota->Assess(extension->id(), function, ¶ms.arguments, |
| 497 base::TimeTicks::Now())) { | 495 base::TimeTicks::Now())) { |
| 498 // See crbug.com/39178. | 496 // See crbug.com/39178. |
| 499 ExternalProtocolHandler::PermitLaunchUrl(); | 497 ExternalProtocolHandler::PermitLaunchUrl(); |
| 500 | 498 |
| 501 function->Run(); | 499 function->Run(); |
| 502 } else { | 500 } else { |
| 503 render_view_host->Send(new ExtensionMsg_Response( | 501 render_view_host->Send(new ExtensionMsg_Response( |
| 504 render_view_host->routing_id(), function->request_id(), false, | 502 render_view_host->routing_id(), function->request_id(), false, |
| 505 std::string(), QuotaLimitHeuristic::kGenericOverQuotaError)); | 503 std::string(), QuotaLimitHeuristic::kGenericOverQuotaError)); |
| 506 } | 504 } |
| 507 } | 505 } |
| 508 | 506 |
| 509 void ExtensionFunctionDispatcher::SendAccessDenied( | 507 void ExtensionFunctionDispatcher::SendAccessDenied( |
| 510 RenderViewHost* render_view_host, int request_id) { | 508 RenderViewHost* render_view_host, int request_id) { |
| 511 render_view_host->Send(new ExtensionMsg_Response( | 509 render_view_host->Send(new ExtensionMsg_Response( |
| 512 render_view_host->routing_id(), request_id, false, std::string(), | 510 render_view_host->routing_id(), request_id, false, std::string(), |
| 513 "Access to extension API denied.")); | 511 "Access to extension API denied.")); |
| 514 } | 512 } |
| OLD | NEW |