| 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 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 // If the delegate has an associated browser, that is always the right answer. | 574 // If the delegate has an associated browser, that is always the right answer. |
| 575 if (browser) | 575 if (browser) |
| 576 return browser; | 576 return browser; |
| 577 | 577 |
| 578 // Otherwise, try to default to a reasonable browser. If |include_incognito| | 578 // Otherwise, try to default to a reasonable browser. If |include_incognito| |
| 579 // is true, we will also search browsers in the incognito version of this | 579 // is true, we will also search browsers in the incognito version of this |
| 580 // profile. Note that the profile may already be incognito, in which case | 580 // profile. Note that the profile may already be incognito, in which case |
| 581 // we will search the incognito version only, regardless of the value of | 581 // we will search the incognito version only, regardless of the value of |
| 582 // |include_incognito|. | 582 // |include_incognito|. |
| 583 Profile* profile = Profile::FromBrowserContext( | 583 Profile* profile = Profile::FromBrowserContext( |
| 584 render_view_host->process()->browser_context()); | 584 render_view_host->process()->GetBrowserContext()); |
| 585 browser = BrowserList::FindTabbedBrowser(profile, include_incognito); | 585 browser = BrowserList::FindTabbedBrowser(profile, include_incognito); |
| 586 | 586 |
| 587 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, | 587 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, |
| 588 // a background_page onload chrome.tabs api call can make it into here | 588 // a background_page onload chrome.tabs api call can make it into here |
| 589 // before the browser is sufficiently initialized to return here. | 589 // before the browser is sufficiently initialized to return here. |
| 590 // A similar situation may arise during shutdown. | 590 // A similar situation may arise during shutdown. |
| 591 // TODO(rafaelw): Delay creation of background_page until the browser | 591 // TODO(rafaelw): Delay creation of background_page until the browser |
| 592 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 | 592 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 |
| 593 return browser; | 593 return browser; |
| 594 } | 594 } |
| 595 | 595 |
| 596 void ExtensionFunctionDispatcher::Dispatch( | 596 void ExtensionFunctionDispatcher::Dispatch( |
| 597 const ExtensionHostMsg_Request_Params& params, | 597 const ExtensionHostMsg_Request_Params& params, |
| 598 RenderViewHost* render_view_host) { | 598 RenderViewHost* render_view_host) { |
| 599 ExtensionService* service = profile()->GetExtensionService(); | 599 ExtensionService* service = profile()->GetExtensionService(); |
| 600 extensions::ProcessMap* process_map = service->process_map(); | 600 extensions::ProcessMap* process_map = service->process_map(); |
| 601 if (!service || !process_map) | 601 if (!service || !process_map) |
| 602 return; | 602 return; |
| 603 | 603 |
| 604 const Extension* extension = service->GetExtensionById( | 604 const Extension* extension = service->GetExtensionById( |
| 605 params.extension_id, false); | 605 params.extension_id, false); |
| 606 if (!extension) | 606 if (!extension) |
| 607 extension = service->GetExtensionByWebExtent(params.source_url); | 607 extension = service->GetExtensionByWebExtent(params.source_url); |
| 608 | 608 |
| 609 scoped_refptr<ExtensionFunction> function( | 609 scoped_refptr<ExtensionFunction> function( |
| 610 CreateExtensionFunction(params, extension, | 610 CreateExtensionFunction(params, extension, |
| 611 render_view_host->process()->id(), | 611 render_view_host->process()->GetID(), |
| 612 *(service->process_map()), | 612 *(service->process_map()), |
| 613 profile(), render_view_host, | 613 profile(), render_view_host, |
| 614 render_view_host->routing_id())); | 614 render_view_host->routing_id())); |
| 615 if (!function) | 615 if (!function) |
| 616 return; | 616 return; |
| 617 | 617 |
| 618 UIThreadExtensionFunction* function_ui = | 618 UIThreadExtensionFunction* function_ui = |
| 619 function->AsUIThreadExtensionFunction(); | 619 function->AsUIThreadExtensionFunction(); |
| 620 if (!function_ui) { | 620 if (!function_ui) { |
| 621 NOTREACHED(); | 621 NOTREACHED(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 return function; | 681 return function; |
| 682 } | 682 } |
| 683 | 683 |
| 684 // static | 684 // static |
| 685 void ExtensionFunctionDispatcher::SendAccessDenied( | 685 void ExtensionFunctionDispatcher::SendAccessDenied( |
| 686 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { | 686 IPC::Message::Sender* ipc_sender, int routing_id, int request_id) { |
| 687 ipc_sender->Send(new ExtensionMsg_Response( | 687 ipc_sender->Send(new ExtensionMsg_Response( |
| 688 routing_id, request_id, false, std::string(), | 688 routing_id, request_id, false, std::string(), |
| 689 "Access to extension API denied.")); | 689 "Access to extension API denied.")); |
| 690 } | 690 } |
| OLD | NEW |