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 <map> | 7 #include <map> |
8 | 8 |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 // If the delegate has an associated browser, that is always the right answer. | 664 // If the delegate has an associated browser, that is always the right answer. |
665 if (browser) | 665 if (browser) |
666 return browser; | 666 return browser; |
667 | 667 |
668 // Otherwise, try to default to a reasonable browser. If |include_incognito| | 668 // Otherwise, try to default to a reasonable browser. If |include_incognito| |
669 // is true, we will also search browsers in the incognito version of this | 669 // is true, we will also search browsers in the incognito version of this |
670 // profile. Note that the profile may already be incognito, in which case | 670 // profile. Note that the profile may already be incognito, in which case |
671 // we will search the incognito version only, regardless of the value of | 671 // we will search the incognito version only, regardless of the value of |
672 // |include_incognito|. | 672 // |include_incognito|. |
673 Profile* profile = Profile::FromBrowserContext( | 673 Profile* profile = Profile::FromBrowserContext( |
674 render_view_host->process()->GetBrowserContext()); | 674 render_view_host->GetProcess()->GetBrowserContext()); |
675 browser = BrowserList::FindAnyBrowser(profile, include_incognito); | 675 browser = BrowserList::FindAnyBrowser(profile, include_incognito); |
676 | 676 |
677 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, | 677 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, |
678 // a background_page onload chrome.tabs api call can make it into here | 678 // a background_page onload chrome.tabs api call can make it into here |
679 // before the browser is sufficiently initialized to return here. | 679 // before the browser is sufficiently initialized to return here. |
680 // A similar situation may arise during shutdown. | 680 // A similar situation may arise during shutdown. |
681 // TODO(rafaelw): Delay creation of background_page until the browser | 681 // TODO(rafaelw): Delay creation of background_page until the browser |
682 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 | 682 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 |
683 return browser; | 683 return browser; |
684 } | 684 } |
685 | 685 |
686 void ExtensionFunctionDispatcher::Dispatch( | 686 void ExtensionFunctionDispatcher::Dispatch( |
687 const ExtensionHostMsg_Request_Params& params, | 687 const ExtensionHostMsg_Request_Params& params, |
688 RenderViewHost* render_view_host) { | 688 RenderViewHost* render_view_host) { |
689 ExtensionService* service = profile()->GetExtensionService(); | 689 ExtensionService* service = profile()->GetExtensionService(); |
690 extensions::ProcessMap* process_map = service->process_map(); | 690 extensions::ProcessMap* process_map = service->process_map(); |
691 if (!service || !process_map) | 691 if (!service || !process_map) |
692 return; | 692 return; |
693 | 693 |
694 const Extension* extension = service->extensions()->GetByID( | 694 const Extension* extension = service->extensions()->GetByID( |
695 params.extension_id); | 695 params.extension_id); |
696 if (!extension) | 696 if (!extension) |
697 extension = service->extensions()->GetHostedAppByURL(ExtensionURLInfo( | 697 extension = service->extensions()->GetHostedAppByURL(ExtensionURLInfo( |
698 WebSecurityOrigin::createFromString(params.source_origin), | 698 WebSecurityOrigin::createFromString(params.source_origin), |
699 params.source_url)); | 699 params.source_url)); |
700 | 700 |
701 scoped_refptr<ExtensionFunction> function( | 701 scoped_refptr<ExtensionFunction> function( |
702 CreateExtensionFunction(params, extension, | 702 CreateExtensionFunction(params, extension, |
703 render_view_host->process()->GetID(), | 703 render_view_host->GetProcess()->GetID(), |
704 *(service->process_map()), | 704 *(service->process_map()), |
705 profile(), render_view_host, | 705 profile(), render_view_host, |
706 render_view_host->routing_id())); | 706 render_view_host->GetRoutingID())); |
707 if (!function) { | 707 if (!function) { |
708 LogFailure(extension, params.name, kAccessDenied); | 708 LogFailure(extension, params.name, kAccessDenied); |
709 return; | 709 return; |
710 } | 710 } |
711 | 711 |
712 UIThreadExtensionFunction* function_ui = | 712 UIThreadExtensionFunction* function_ui = |
713 function->AsUIThreadExtensionFunction(); | 713 function->AsUIThreadExtensionFunction(); |
714 if (!function_ui) { | 714 if (!function_ui) { |
715 NOTREACHED(); | 715 NOTREACHED(); |
716 return; | 716 return; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 return function; | 790 return function; |
791 } | 791 } |
792 | 792 |
793 // static | 793 // static |
794 void ExtensionFunctionDispatcher::SendAccessDenied( | 794 void ExtensionFunctionDispatcher::SendAccessDenied( |
795 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { | 795 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { |
796 ipc_sender->Send(new ExtensionMsg_Response( | 796 ipc_sender->Send(new ExtensionMsg_Response( |
797 routing_id, request_id, false, std::string(), | 797 routing_id, request_id, false, std::string(), |
798 "Access to extension API denied.")); | 798 "Access to extension API denied.")); |
799 } | 799 } |
OLD | NEW |