diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-19 18:52:50 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-19 18:52:50 +0000 |
commit | f44265b0b203289b76b7d28b46bbfed1708829ea (patch) | |
tree | f4cd4bb88f20825863c90ec281bf48cb02cf8bd5 /chrome/browser/automation/automation_provider.cc | |
parent | 0b7b45d3b8642aa9d3acb422ae7ed7efd3c18f73 (diff) | |
download | chromium_src-f44265b0b203289b76b7d28b46bbfed1708829ea.zip chromium_src-f44265b0b203289b76b7d28b46bbfed1708829ea.tar.gz chromium_src-f44265b0b203289b76b7d28b46bbfed1708829ea.tar.bz2 |
Allow connecting and messaging with extension ports by funneling external
ports through the automation postMessage interface.
See original review at: http://codereview.chromium.org/113461
Patch by Siggi Asgeirsson <sigurdur.asgeirsson@gmail.com>
Review URL: http://codereview.chromium.org/113538
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16396 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation/automation_provider.cc')
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index c48f1eb..0030946 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -8,6 +8,7 @@ #include "base/file_version_info.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/stl_util-inl.h" #include "base/string_util.h" #include "base/thread.h" #include "chrome/app/chrome_dll_resource.h" @@ -15,6 +16,7 @@ #include "chrome/browser/app_modal_dialog_queue.h" #include "chrome/browser/automation/automation_extension_function.h" #include "chrome/browser/automation/automation_provider_list.h" +#include "chrome/browser/automation/extension_port_container.h" #include "chrome/browser/automation/url_request_failed_dns_job.h" #include "chrome/browser/automation/url_request_mock_http_job.h" #include "chrome/browser/automation/url_request_slow_download_job.h" @@ -888,6 +890,10 @@ AutomationProvider::AutomationProvider(Profile* profile) } AutomationProvider::~AutomationProvider() { + STLDeleteContainerPairSecondPointers(port_containers_.begin(), + port_containers_.end()); + port_containers_.clear(); + // Make sure that any outstanding NotificationObservers also get destroyed. ObserverList<NotificationObserver>::Iterator it(notification_observer_list_); NotificationObserver* observer; @@ -963,6 +969,36 @@ void AutomationProvider::RemoveLoginHandler(NavigationController* tab) { login_handler_map_.erase(tab); } +void AutomationProvider::AddPortContainer(ExtensionPortContainer* port) { + int port_id = port->port_id(); + DCHECK_NE(-1, port_id); + DCHECK(port_containers_.find(port_id) == port_containers_.end()); + + port_containers_[port_id] = port; +} + +void AutomationProvider::RemovePortContainer(ExtensionPortContainer* port) { + int port_id = port->port_id(); + DCHECK_NE(-1, port_id); + + PortContainerMap::iterator it = port_containers_.find(port_id); + DCHECK(it != port_containers_.end()); + + if (it != port_containers_.end()) { + delete it->second; + port_containers_.erase(it); + } +} + +ExtensionPortContainer* AutomationProvider::GetPortContainer( + int port_id) const { + PortContainerMap::const_iterator it = port_containers_.find(port_id); + if (it == port_containers_.end()) + return NULL; + + return it->second; +} + int AutomationProvider::GetIndexForNavigationController( const NavigationController* controller, const Browser* parent) const { DCHECK(parent); @@ -2687,6 +2723,7 @@ void AutomationProvider::OnMessageFromExternalHost(int handle, NOTREACHED(); return; } + TabContents* tab_contents = tab->tab_contents(); if (!tab_contents) { NOTREACHED(); @@ -2698,10 +2735,19 @@ void AutomationProvider::OnMessageFromExternalHost(int handle, return; } - if (!AutomationExtensionFunction::InterceptMessageFromExternalHost( + if (AutomationExtensionFunction::InterceptMessageFromExternalHost( view_host, message, origin, target)) { - view_host->ForwardMessageFromExternalHost(message, origin, target); + // Message was diverted. + return; } + + if (ExtensionPortContainer::InterceptMessageFromExternalHost(message, + origin, target, this, view_host, handle)) { + // Message was diverted. + return; + } + + view_host->ForwardMessageFromExternalHost(message, origin, target); } } #endif // defined(OS_WIN) || defined(OS_LINUX) |