diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 15:18:04 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 15:18:04 +0000 |
commit | 7419d4b42d6be9b4b0f93c3fc4a85ca104e24821 (patch) | |
tree | 93896973bafb635a55e3595bb772356b21b405d0 /chrome/browser/automation | |
parent | e608d5644b2b4c76ffad9a7d443f338746256e8b (diff) | |
download | chromium_src-7419d4b42d6be9b4b0f93c3fc4a85ca104e24821.zip chromium_src-7419d4b42d6be9b4b0f93c3fc4a85ca104e24821.tar.gz chromium_src-7419d4b42d6be9b4b0f93c3fc4a85ca104e24821.tar.bz2 |
Remove extension automation support that was used only by CEEE.
BUG=none
TEST=all automated tests pass
Review URL: http://codereview.chromium.org/6756044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80626 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
11 files changed, 1 insertions, 890 deletions
diff --git a/chrome/browser/automation/automation_extension_function.cc b/chrome/browser/automation/automation_extension_function.cc deleted file mode 100644 index 4ef67b4..0000000 --- a/chrome/browser/automation/automation_extension_function.cc +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Implements AutomationExtensionFunction. - -#include "chrome/browser/automation/automation_extension_function.h" - -#include "base/json/json_reader.h" -#include "base/json/json_writer.h" -#include "base/values.h" -#include "chrome/browser/automation/extension_automation_constants.h" -#include "chrome/browser/extensions/extension_function_dispatcher.h" -#include "chrome/browser/extensions/extension_tabs_module.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/renderer_host/render_view_host_delegate.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/browser/tab_contents/tab_contents_delegate.h" - -TabContents* AutomationExtensionFunction::api_handler_tab_ = NULL; -AutomationExtensionFunction::PendingFunctionsMap - AutomationExtensionFunction::pending_functions_; - -AutomationExtensionFunction::AutomationExtensionFunction() { -} - -void AutomationExtensionFunction::SetArgs(const ListValue* args) { - // Need to JSON-encode for sending over the wire to the automation user. - base::JSONWriter::Write(args, false, &args_); -} - -const std::string AutomationExtensionFunction::GetResult() { - // Already JSON-encoded, so override the base class's implementation. - return json_result_; -} - -bool AutomationExtensionFunction::RunImpl() { - namespace keys = extension_automation_constants; - - DCHECK(api_handler_tab_) << - "Why is this function still enabled if no target tab?"; - if (!api_handler_tab_) { - error_ = "No longer automating functions."; - return false; - } - - // We are being driven through automation, so we send the extension API - // request over to the automation host. We do this before decoding the - // 'args' JSON, otherwise we'd be decoding it only to encode it again. - DictionaryValue message_to_host; - message_to_host.SetString(keys::kAutomationNameKey, name_); - message_to_host.SetString(keys::kAutomationArgsKey, args_); - message_to_host.SetInteger(keys::kAutomationRequestIdKey, request_id_); - message_to_host.SetBoolean(keys::kAutomationHasCallbackKey, has_callback_); - // Send the API request's associated tab along to the automation client, so - // that it can determine the execution context of the API call. - TabContents* contents = NULL; - ExtensionFunctionDispatcher* function_dispatcher = dispatcher(); - if (function_dispatcher && function_dispatcher->delegate()) { - contents = function_dispatcher->delegate()->associated_tab_contents(); - } else { - NOTREACHED() << "Extension function dispatcher delegate not found."; - } - if (contents) - message_to_host.Set(keys::kAutomationTabJsonKey, - ExtensionTabUtil::CreateTabValue(contents)); - - std::string message; - base::JSONWriter::Write(&message_to_host, false, &message); - if (api_handler_tab_->delegate()) { - api_handler_tab_->delegate()->ForwardMessageToExternalHost( - message, keys::kAutomationOrigin, keys::kAutomationRequestTarget); - } else { - NOTREACHED() << "ExternalTabContainer is supposed to correctly manage " - "lifetime of api_handler_tab_."; - } - - // Automation APIs are asynchronous so we need to stick around until - // our response comes back. Add ourselves to a static hash map keyed - // by request ID. The hash map keeps a reference count on us. - DCHECK(pending_functions_.find(request_id_) == pending_functions_.end()); - pending_functions_[request_id_] = this; - - return true; -} - -ExtensionFunction* AutomationExtensionFunction::Factory() { - return new AutomationExtensionFunction(); -} - -void AutomationExtensionFunction::Enable( - TabContents* api_handler_tab, - const std::vector<std::string>& functions_enabled) { - DCHECK(api_handler_tab); - if (api_handler_tab_ && api_handler_tab != api_handler_tab_) { - NOTREACHED() << "Don't call with different API handler."; - return; - } - api_handler_tab_ = api_handler_tab; - - std::vector<std::string> function_names; - if (functions_enabled.size() == 1 && functions_enabled[0] == "*") { - ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); - } else { - function_names = functions_enabled; - } - - for (std::vector<std::string>::iterator it = function_names.begin(); - it != function_names.end(); it++) { - // TODO(joi) Could make this a per-profile change rather than a global - // change. Could e.g. have the AutomationExtensionFunction store the - // profile pointer and dispatch to the original ExtensionFunction when the - // current profile is not that. - bool result = ExtensionFunctionDispatcher::OverrideFunction( - *it, AutomationExtensionFunction::Factory); - LOG_IF(WARNING, !result) << "Failed to override API function: " << *it; - } -} - -void AutomationExtensionFunction::Disable() { - api_handler_tab_ = NULL; - ExtensionFunctionDispatcher::ResetFunctions(); -} - -bool AutomationExtensionFunction::InterceptMessageFromExternalHost( - RenderViewHost* view_host, - const std::string& message, - const std::string& origin, - const std::string& target) { - namespace keys = extension_automation_constants; - - // We want only specially-tagged messages passed via the conduit tab. - if (api_handler_tab_ && - view_host == api_handler_tab_->render_view_host() && - origin == keys::kAutomationOrigin && - target == keys::kAutomationResponseTarget) { - // This is an extension API response being sent back via postMessage, - // so redirect it. - scoped_ptr<Value> message_value(base::JSONReader::Read(message, false)); - DCHECK(message_value->IsType(Value::TYPE_DICTIONARY)); - if (message_value->IsType(Value::TYPE_DICTIONARY)) { - DictionaryValue* message_dict = - reinterpret_cast<DictionaryValue*>(message_value.get()); - - int request_id = -1; - bool got_value = message_dict->GetInteger(keys::kAutomationRequestIdKey, - &request_id); - DCHECK(got_value); - if (got_value) { - std::string error; - bool success = !message_dict->GetString(keys::kAutomationErrorKey, - &error); - - std::string response; - got_value = message_dict->GetString(keys::kAutomationResponseKey, - &response); - DCHECK(!success || got_value); - - PendingFunctionsMap::iterator it = pending_functions_.find(request_id); - DCHECK(it != pending_functions_.end()); - - if (it != pending_functions_.end()) { - scoped_refptr<AutomationExtensionFunction> func = it->second; - pending_functions_.erase(it); - - // Our local ref should be the last remaining. - DCHECK(func && func->HasOneRef()); - - if (func) { - func->json_result_ = response; - func->error_ = error; - - func->SendResponse(success); - } - } - return true; - } - } - } - - return false; -} - -AutomationExtensionFunction::~AutomationExtensionFunction() { -} diff --git a/chrome/browser/automation/automation_extension_function.h b/chrome/browser/automation/automation_extension_function.h deleted file mode 100644 index 275d3c9..0000000 --- a/chrome/browser/automation/automation_extension_function.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Defines AutomationExtensionFunction. - -#ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ -#define CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ -#pragma once - -#include <map> -#include <string> -#include <vector> - -#include "chrome/browser/extensions/extension_function.h" - -class RenderViewHost; -class TabContents; - -// An extension function that pipes the extension API call through the -// automation interface, so that extensions can be tested using UITests. -class AutomationExtensionFunction : public AsyncExtensionFunction { - public: - AutomationExtensionFunction(); - - // ExtensionFunction implementation. - virtual void SetArgs(const ListValue* args); - virtual const std::string GetResult(); - virtual bool RunImpl(); - - static ExtensionFunction* Factory(); - - // Enable API automation of selected APIs. Overridden extension API messages - // will be routed to the automation client attached to |api_handler_tab|. - // - // If the list of enabled functions is non-empty, we enable according to the - // list ("*" means enable all, otherwise we enable individual named - // functions). An empty list makes this function a no-op. - // - // Note that all calls to this function are additive. Functions previously - // enabled will remain enabled until you call Disable(). - // - // Calling this function after enabling one or more functions with a - // tab other than the one previously used is an error. - static void Enable(TabContents* api_handler_tab, - const std::vector<std::string>& functions_enabled); - - // Restore the default API function implementations and reset the stored - // API handler. - static void Disable(); - - // Intercepts messages sent from the external host to check if they - // are actually responses to extension API calls. If they are, redirects - // the message to respond to the pending asynchronous API call and returns - // true, otherwise returns false to indicate the message was not intercepted. - static bool InterceptMessageFromExternalHost(RenderViewHost* view_host, - const std::string& message, - const std::string& origin, - const std::string& target); - - private: - ~AutomationExtensionFunction(); - - // Weak reference, lifetime managed by the ExternalTabContainer instance - // owning the TabContents in question. - static TabContents* api_handler_tab_; - - typedef std::map<int, scoped_refptr<AutomationExtensionFunction> > - PendingFunctionsMap; - static PendingFunctionsMap pending_functions_; - - std::string args_; - std::string json_result_; - - DISALLOW_COPY_AND_ASSIGN(AutomationExtensionFunction); -}; - -#endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index e1b2bb5..bacc9eb 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -34,7 +34,6 @@ #include "chrome/browser/automation/automation_resource_message_filter.h" #include "chrome/browser/automation/automation_tab_tracker.h" #include "chrome/browser/automation/automation_window_tracker.h" -#include "chrome/browser/automation/extension_port_container.h" #include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/blocked_content_container.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -132,10 +131,6 @@ AutomationProvider::AutomationProvider(Profile* profile) } AutomationProvider::~AutomationProvider() { - STLDeleteContainerPairSecondPointers(port_containers_.begin(), - port_containers_.end()); - port_containers_.clear(); - if (channel_.get()) channel_->Close(); @@ -222,36 +217,6 @@ 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); @@ -359,10 +324,6 @@ bool AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InstallExtension, InstallExtension) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_LoadExpandedExtension, - LoadExpandedExtension) - IPC_MESSAGE_HANDLER(AutomationMsg_GetEnabledExtensions, - GetEnabledExtensions) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForExtensionTestResult, WaitForExtensionTestResult) IPC_MESSAGE_HANDLER_DELAY_REPLY( @@ -399,8 +360,6 @@ bool AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(AutomationMsg_NavigateExternalTabAtIndex, NavigateExternalTabAtIndex) IPC_MESSAGE_HANDLER(AutomationMsg_ConnectExternalTab, ConnectExternalTab) - IPC_MESSAGE_HANDLER(AutomationMsg_SetEnableExtensionAutomation, - SetEnableExtensionAutomation) IPC_MESSAGE_HANDLER(AutomationMsg_HandleMessageFromExternalHost, OnMessageFromExternalHost) IPC_MESSAGE_HANDLER(AutomationMsg_BrowserMove, OnBrowserMoved) @@ -821,44 +780,6 @@ void AutomationProvider::InstallExtension(const FilePath& crx_path, } } -void AutomationProvider::LoadExpandedExtension( - const FilePath& extension_dir, - IPC::Message* reply_message) { - if (profile_->GetExtensionService()) { - // The observer will delete itself when done. - new ExtensionInstallNotificationObserver( - this, - AutomationMsg_LoadExpandedExtension::ID, - reply_message); - - profile_->GetExtensionService()->LoadExtension(extension_dir); - } else { - AutomationMsg_LoadExpandedExtension::WriteReplyParams( - reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); - Send(reply_message); - } -} - -void AutomationProvider::GetEnabledExtensions( - std::vector<FilePath>* result) { - ExtensionService* service = profile_->GetExtensionService(); - DCHECK(service); - if (service->extensions_enabled()) { - const ExtensionList* extensions = service->extensions(); - DCHECK(extensions); - for (size_t i = 0; i < extensions->size(); ++i) { - const Extension* extension = (*extensions)[i]; - DCHECK(extension); - // AutomationProvider only exposes non app internal/loaded extensions. - if (!extension->is_app() && - (extension->location() == Extension::INTERNAL || - extension->location() == Extension::LOAD)) { - result->push_back(extension->path()); - } - } - } -} - void AutomationProvider::WaitForExtensionTestResult( IPC::Message* reply_message) { DCHECK(!reply_message_); diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index 0bd06c7..f66ccec 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -123,14 +123,6 @@ class AutomationProvider void AddLoginHandler(NavigationController* tab, LoginHandler* handler); void RemoveLoginHandler(NavigationController* tab); - // Add an extension port container. - // Takes ownership of the container. - void AddPortContainer(ExtensionPortContainer* port); - // Remove and delete the port container. - void RemovePortContainer(ExtensionPortContainer* port); - // Get the port container for the given port id. - ExtensionPortContainer* GetPortContainer(int port_id) const; - // IPC implementations virtual bool Send(IPC::Message* msg); virtual void OnChannelConnected(int pid); @@ -257,11 +249,6 @@ class AutomationProvider void InstallExtension(const FilePath& crx_path, IPC::Message* reply_message); - void LoadExpandedExtension(const FilePath& extension_dir, - IPC::Message* reply_message); - - void GetEnabledExtensions(std::vector<FilePath>* result); - void WaitForExtensionTestResult(IPC::Message* reply_message); void InstallExtensionAndGetHandle(const FilePath& crx_path, @@ -301,11 +288,6 @@ class AutomationProvider const std::string& encoding_name, bool* success); - // Enables extension automation (for e.g. UITests). - void SetEnableExtensionAutomation( - int tab_handle, - const std::vector<std::string>& functions_enabled); - // Selects all contents on the page. void SelectAll(int tab_handle); @@ -376,12 +358,6 @@ class AutomationProvider const std::string& origin, const std::string& target); - // Determine if the message from the external host represents a browser - // event, and if so dispatch it. - bool InterceptBrowserEventMessageFromExternalHost(const std::string& message, - const std::string& origin, - const std::string& target); - void OnBrowserMoved(int handle); void OnRunUnloadHandlers(int handle, IPC::Message* reply_message); @@ -391,15 +367,12 @@ class AutomationProvider ExternalTabContainer* GetExternalTabForHandle(int handle); #endif // defined(OS_WIN) - typedef std::map<int, ExtensionPortContainer*> PortContainerMap; - scoped_ptr<IPC::ChannelProxy> channel_; scoped_ptr<NotificationObserver> new_tab_ui_load_observer_; scoped_ptr<NotificationObserver> find_in_page_observer_; scoped_ptr<ExtensionTestResultNotificationObserver> extension_test_result_observer_; scoped_ptr<AutomationExtensionTracker> extension_tracker_; - PortContainerMap port_containers_; // True iff connected to an AutomationProxy. bool is_connected_; diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index cd32925..78c09c1 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -492,10 +492,6 @@ void ExtensionInstallNotificationObserver::SendResponse( AutomationMsg_InstallExtension::WriteReplyParams(reply_message_.get(), response); break; - case AutomationMsg_LoadExpandedExtension::ID: - AutomationMsg_LoadExpandedExtension::WriteReplyParams( - reply_message_.get(), response); - break; default: NOTREACHED(); break; diff --git a/chrome/browser/automation/automation_provider_win.cc b/chrome/browser/automation/automation_provider_win.cc index 6cc06d9..9d41e50 100644 --- a/chrome/browser/automation/automation_provider_win.cc +++ b/chrome/browser/automation/automation_provider_win.cc @@ -8,14 +8,10 @@ #include "base/json/json_reader.h" #include "base/utf_string_conversions.h" #include "chrome/browser/automation/automation_browser_tracker.h" -#include "chrome/browser/automation/automation_extension_function.h" #include "chrome/browser/automation/automation_tab_tracker.h" #include "chrome/browser/automation/automation_window_tracker.h" -#include "chrome/browser/automation/extension_automation_constants.h" -#include "chrome/browser/automation/extension_port_container.h" #include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/browser_window.h" -#include "chrome/browser/extensions/extension_event_router.h" #include "chrome/browser/external_tab_container_win.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -405,21 +401,6 @@ void AutomationProvider::ConnectExternalTab( TRACE_EVENT_END("AutomationProvider::ConnectExternalTab", 0, ""); } -void AutomationProvider::SetEnableExtensionAutomation( - int tab_handle, - const std::vector<std::string>& functions_enabled) { - ExternalTabContainer* external_tab = GetExternalTabForHandle(tab_handle); - if (external_tab) { - external_tab->SetEnableExtensionAutomation(functions_enabled); - } else { - // Tab must exist, and must be an external tab so that its - // delegate has an on-empty - // implementation of ForwardMessageToExternalHost. - DLOG(WARNING) << - "SetEnableExtensionAutomation called with invalid tab handle."; - } -} - void AutomationProvider::OnBrowserMoved(int tab_handle) { ExternalTabContainer* external_tab = GetExternalTabForHandle(tab_handle); if (external_tab) { @@ -438,69 +419,9 @@ void AutomationProvider::OnMessageFromExternalHost(int handle, if (!view_host) return; - if (AutomationExtensionFunction::InterceptMessageFromExternalHost( - view_host, message, origin, target)) { - // Message was diverted. - return; - } - - if (ExtensionPortContainer::InterceptMessageFromExternalHost( - message, origin, target, this, view_host, handle)) { - // Message was diverted. - return; - } - - if (InterceptBrowserEventMessageFromExternalHost(message, origin, target)) { - // Message was diverted. - return; - } - view_host->ForwardMessageFromExternalHost(message, origin, target); } -bool AutomationProvider::InterceptBrowserEventMessageFromExternalHost( - const std::string& message, const std::string& origin, - const std::string& target) { - if (target != - extension_automation_constants::kAutomationBrowserEventRequestTarget) - return false; - - if (origin != extension_automation_constants::kAutomationOrigin) { - LOG(WARNING) << "Wrong origin on automation browser event " << origin; - return false; - } - - // The message is a JSON-encoded array with two elements, both strings. The - // first is the name of the event to dispatch. The second is a JSON-encoding - // of the arguments specific to that event. - scoped_ptr<Value> message_value(base::JSONReader::Read(message, false)); - if (!message_value.get() || !message_value->IsType(Value::TYPE_LIST)) { - LOG(WARNING) << "Invalid browser event specified through automation"; - return false; - } - - const ListValue* args = static_cast<const ListValue*>(message_value.get()); - - std::string event_name; - if (!args->GetString(0, &event_name)) { - LOG(WARNING) << "No browser event name specified through automation"; - return false; - } - - std::string json_args; - if (!args->GetString(1, &json_args)) { - LOG(WARNING) << "No browser event args specified through automation"; - return false; - } - - if (profile()->GetExtensionEventRouter()) { - profile()->GetExtensionEventRouter()->DispatchEventToRenderers( - event_name, json_args, profile(), GURL()); - } - - return true; -} - void AutomationProvider::NavigateInExternalTab( int handle, const GURL& url, const GURL& referrer, AutomationMsg_NavigationResponseValues* status) { diff --git a/chrome/browser/automation/chrome_frame_automation_provider.cc b/chrome/browser/automation/chrome_frame_automation_provider.cc index 7b699f1..07ef8b62 100644 --- a/chrome/browser/automation/chrome_frame_automation_provider.cc +++ b/chrome/browser/automation/chrome_frame_automation_provider.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -43,10 +43,6 @@ bool ChromeFrameAutomationProvider::IsValidMessage(uint32 type) { case AutomationMsg_NavigateInExternalTab::ID: case AutomationMsg_NavigateExternalTabAtIndex::ID: case AutomationMsg_Find::ID: - case AutomationMsg_InstallExtension::ID: - case AutomationMsg_LoadExpandedExtension::ID: - case AutomationMsg_GetEnabledExtensions::ID: - case AutomationMsg_SetEnableExtensionAutomation::ID: case AutomationMsg_SetInitialFocus::ID: case AutomationMsg_SetPageFontSize::ID: case AutomationMsg_SetProxyConfig::ID: @@ -77,4 +73,3 @@ bool ChromeFrameAutomationProvider::IsValidMessage(uint32 type) { return is_valid_message; } - diff --git a/chrome/browser/automation/extension_automation_constants.cc b/chrome/browser/automation/extension_automation_constants.cc deleted file mode 100644 index c4e6fce..0000000 --- a/chrome/browser/automation/extension_automation_constants.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/automation/extension_automation_constants.h" - -namespace extension_automation_constants { - -const char kAutomationOrigin[] = "__priv_xtapi"; -const char kAutomationRequestIdKey[] = "rqid"; - -const char kAutomationHasCallbackKey[] = "hascb"; -const char kAutomationErrorKey[] = "err"; -const char kAutomationNameKey[] = "name"; -const char kAutomationArgsKey[] = "args"; -const char kAutomationResponseKey[] = "res"; -const char kAutomationRequestTarget[] = "__priv_xtreq"; -const char kAutomationResponseTarget[] = "__priv_xtres"; - -const char kAutomationConnectionIdKey[] = "connid"; -const char kAutomationMessageDataKey[] = "data"; -const char kAutomationExtensionIdKey[] = "extid"; -const char kAutomationPortIdKey[] = "portid"; -const char kAutomationChannelNameKey[] = "chname"; -const char kAutomationTabJsonKey[] = "tab"; - -const char kAutomationPortRequestTarget[] = "__priv_prtreq"; -const char kAutomationPortResponseTarget[] = "__priv_prtres"; - -const char kAutomationBrowserEventRequestTarget[] = "__priv_evtreq"; - -} // namespace extension_automation_constants diff --git a/chrome/browser/automation/extension_automation_constants.h b/chrome/browser/automation/extension_automation_constants.h deleted file mode 100644 index dea4d2d..0000000 --- a/chrome/browser/automation/extension_automation_constants.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Constants used to encode requests and responses for automation. - -#ifndef CHROME_BROWSER_AUTOMATION_EXTENSION_AUTOMATION_CONSTANTS_H_ -#define CHROME_BROWSER_AUTOMATION_EXTENSION_AUTOMATION_CONSTANTS_H_ -#pragma once - -namespace extension_automation_constants { - -// All extension automation related messages will have this origin. -extern const char kAutomationOrigin[]; -// Key used for all extension automation request types. -extern const char kAutomationRequestIdKey[]; - -// Keys used for API communications -extern const char kAutomationHasCallbackKey[]; -extern const char kAutomationErrorKey[]; // not present implies success -extern const char kAutomationNameKey[]; -extern const char kAutomationArgsKey[]; -extern const char kAutomationResponseKey[]; -// All external API requests have this target. -extern const char kAutomationRequestTarget[]; -// All API responses should have this target. -extern const char kAutomationResponseTarget[]; - -// Keys used for port communications -extern const char kAutomationConnectionIdKey[]; -extern const char kAutomationMessageDataKey[]; -extern const char kAutomationExtensionIdKey[]; -extern const char kAutomationPortIdKey[]; -extern const char kAutomationChannelNameKey[]; -extern const char kAutomationTabJsonKey[]; - -// All external port message requests should have this target. -extern const char kAutomationPortRequestTarget[]; -// All external port message responses have this target. -extern const char kAutomationPortResponseTarget[]; - -// All external browser events have this target. -extern const char kAutomationBrowserEventRequestTarget[]; - -// The command codes for our private port protocol. -enum PrivatePortCommand { - OPEN_CHANNEL = 0, - CHANNEL_OPENED = 1, - POST_MESSAGE = 2, - CHANNEL_CLOSED = 3, -}; - -}; // namespace automation_extension_constants - -#endif // CHROME_BROWSER_AUTOMATION_EXTENSION_AUTOMATION_CONSTANTS_H_ diff --git a/chrome/browser/automation/extension_port_container.cc b/chrome/browser/automation/extension_port_container.cc deleted file mode 100644 index bdcbb7e..0000000 --- a/chrome/browser/automation/extension_port_container.cc +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/automation/extension_port_container.h" - -#include "base/logging.h" -#include "base/json/json_reader.h" -#include "base/json/json_writer.h" -#include "base/values.h" -#include "chrome/browser/automation/automation_provider.h" -#include "chrome/browser/automation/extension_automation_constants.h" -#include "chrome/browser/extensions/extension_message_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/automation_messages.h" -#include "chrome/common/extensions/extension_messages.h" -#include "content/browser/renderer_host/render_process_host.h" -#include "content/browser/renderer_host/render_view_host.h" - -// TODO(siggi): Find a more structured way to read and write JSON messages. - -namespace ext = extension_automation_constants; - -ExtensionPortContainer::ExtensionPortContainer(AutomationProvider* automation, - int tab_handle) : - automation_(automation), service_(NULL), port_id_(-1), - tab_handle_(tab_handle) { - service_ = automation_->profile()->GetExtensionMessageService(); - DCHECK(service_); -} - -ExtensionPortContainer::~ExtensionPortContainer() { - DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); - - if (port_id_ != -1) - service_->CloseChannel(port_id_); -} - -bool ExtensionPortContainer::PostResponseToExternalPort( - const std::string& message) { - return automation_->Send( - new AutomationMsg_ForwardMessageToExternalHost( - tab_handle_, message, ext::kAutomationOrigin, - ext::kAutomationPortResponseTarget)); -} - -bool ExtensionPortContainer::PostMessageToExternalPort( - const std::string& message) { - return automation_->Send( - new AutomationMsg_ForwardMessageToExternalHost( - tab_handle_, message, - ext::kAutomationOrigin, - ext::kAutomationPortRequestTarget)); -} - -void ExtensionPortContainer::PostMessageFromExternalPort( - const std::string &message) { - service_->PostMessageFromRenderer(port_id_, message); -} - -bool ExtensionPortContainer::Connect(const std::string &extension_id, - int process_id, - int routing_id, - int connection_id, - const std::string& channel_name, - const std::string& tab_json) { - DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); - - port_id_ = service_->OpenSpecialChannelToExtension( - extension_id, channel_name, tab_json, this); - if (port_id_ == -1) { - // In this case a disconnect message has been dispatched. - return false; - } - - SendConnectionResponse(connection_id, port_id_); - return true; -} - -void ExtensionPortContainer::SendConnectionResponse(int connection_id, - int port_id) { - // Compose the reply message. - scoped_ptr<DictionaryValue> msg_dict(new DictionaryValue()); - msg_dict->SetInteger(ext::kAutomationRequestIdKey, ext::CHANNEL_OPENED); - msg_dict->SetInteger(ext::kAutomationConnectionIdKey, connection_id); - msg_dict->SetInteger(ext::kAutomationPortIdKey, port_id); - - std::string msg_json; - base::JSONWriter::Write(msg_dict.get(), false, &msg_json); - - PostResponseToExternalPort(msg_json); -} - -bool ExtensionPortContainer::Send(IPC::Message *message) { - DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); - - IPC_BEGIN_MESSAGE_MAP(ExtensionPortContainer, *message) - IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) - IPC_MESSAGE_UNHANDLED_ERROR() - IPC_END_MESSAGE_MAP() - - delete message; - return true; -} - -void ExtensionPortContainer::OnExtensionMessageInvoke( - const std::string& extension_id, - const std::string& function_name, - const ListValue& args, - const GURL& event_url) { - if (function_name == ExtensionMessageService::kDispatchOnMessage) { - DCHECK_EQ(args.GetSize(), 2u); - - std::string message; - int source_port_id; - if (args.GetString(0, &message) && args.GetInteger(1, &source_port_id)) - OnExtensionHandleMessage(message, source_port_id); - } else if (function_name == ExtensionMessageService::kDispatchOnDisconnect) { - DCHECK_EQ(args.GetSize(), 2u); - int port_id; - if (args.GetInteger(0, &port_id)) - OnExtensionPortDisconnected(port_id); - } else if (function_name == ExtensionMessageService::kDispatchOnConnect) { - // Do nothing. - // TODO(siggi): implement - } else { - NOTREACHED() << function_name << " shouldn't be called."; - } -} - -void ExtensionPortContainer::OnExtensionHandleMessage( - const std::string& message, int source_port_id) { - // Compose the reply message and fire it away. - DictionaryValue msg_dict; - msg_dict.SetInteger(ext::kAutomationRequestIdKey, ext::POST_MESSAGE); - msg_dict.SetInteger(ext::kAutomationPortIdKey, port_id_); - msg_dict.SetString(ext::kAutomationMessageDataKey, message); - - std::string msg_json; - base::JSONWriter::Write(&msg_dict, false, &msg_json); - - PostMessageToExternalPort(msg_json); -} - -void ExtensionPortContainer::OnExtensionPortDisconnected(int source_port_id) { - // Compose the disconnect message and fire it away. - DictionaryValue msg_dict; - msg_dict.SetInteger(ext::kAutomationRequestIdKey, ext::CHANNEL_CLOSED); - msg_dict.SetInteger(ext::kAutomationPortIdKey, port_id_); - - std::string msg_json; - base::JSONWriter::Write(&msg_dict, false, &msg_json); - - PostMessageToExternalPort(msg_json); -} - -bool ExtensionPortContainer::InterceptMessageFromExternalHost( - const std::string& message, const std::string& origin, - const std::string& target, AutomationProvider* automation, - RenderViewHost *view_host, int tab_handle) { - if (target != ext::kAutomationPortRequestTarget) - return false; - - if (origin != ext::kAutomationOrigin) { - // TODO(siggi): Should we block the message on wrong origin? - LOG(WARNING) << "Wrong origin on automation port message " << origin; - } - - scoped_ptr<Value> message_value(base::JSONReader::Read(message, false)); - DCHECK(message_value->IsType(Value::TYPE_DICTIONARY)); - if (!message_value->IsType(Value::TYPE_DICTIONARY)) - return true; - - DictionaryValue* message_dict = - reinterpret_cast<DictionaryValue*>(message_value.get()); - - int command = -1; - bool got_value = message_dict->GetInteger(ext::kAutomationRequestIdKey, - &command); - DCHECK(got_value); - if (!got_value) - return true; - - if (command == ext::OPEN_CHANNEL) { - // Extract the "extension_id" and "connection_id" parameters. - std::string extension_id; - got_value = message_dict->GetString(ext::kAutomationExtensionIdKey, - &extension_id); - DCHECK(got_value); - if (!got_value) - return true; - - int connection_id; - got_value = message_dict->GetInteger(ext::kAutomationConnectionIdKey, - &connection_id); - DCHECK(got_value); - if (!got_value) - return true; - - std::string channel_name; - // Channel name is optional. - message_dict->GetString(ext::kAutomationChannelNameKey, &channel_name); - - // Tab information is optional, try to retrieve it - // and re-flatten it to a string. - std::string tab_json("null"); - DictionaryValue* tab = NULL; - if (message_dict->GetDictionary(ext::kAutomationTabJsonKey, &tab)) - base::JSONWriter::Write(tab, false, &tab_json); - - int routing_id = view_host->routing_id(); - // Create the extension port and connect it. - scoped_ptr<ExtensionPortContainer> port( - new ExtensionPortContainer(automation, tab_handle)); - - int process_id = view_host->process()->id(); - if (port->Connect(extension_id, process_id, routing_id, connection_id, - channel_name, tab_json)) { - // We have a successful connection. - automation->AddPortContainer(port.release()); - } - } else if (command == ext::POST_MESSAGE) { - int port_id = -1; - got_value = message_dict->GetInteger(ext::kAutomationPortIdKey, &port_id); - DCHECK(got_value); - if (!got_value) - return true; - - std::string data; - got_value = message_dict->GetString(ext::kAutomationMessageDataKey, &data); - DCHECK(got_value); - if (!got_value) - return true; - - ExtensionPortContainer* port = automation->GetPortContainer(port_id); - DCHECK(port); - if (port) - port->PostMessageFromExternalPort(data); - } else if (command == ext::CHANNEL_CLOSED) { - int port_id = -1; - got_value = message_dict->GetInteger(ext::kAutomationPortIdKey, &port_id); - DCHECK(got_value); - if (!got_value) - return true; - - ExtensionPortContainer* port = automation->GetPortContainer(port_id); - DCHECK(port); - if (port) { - // This will delete the port and notify the other end of the disconnect. - automation->RemovePortContainer(port); - } - } else { - // We don't expect other messages here. - NOTREACHED(); - } - - return true; -} diff --git a/chrome/browser/automation/extension_port_container.h b/chrome/browser/automation/extension_port_container.h deleted file mode 100644 index d409fee..0000000 --- a/chrome/browser/automation/extension_port_container.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_AUTOMATION_EXTENSION_PORT_CONTAINER_H_ -#define CHROME_BROWSER_AUTOMATION_EXTENSION_PORT_CONTAINER_H_ -#pragma once - -#include <string> - -#include "base/basictypes.h" -#include "base/memory/ref_counted.h" -#include "ipc/ipc_message.h" - -class AutomationProvider; -class ExtensionMessageService; -class GURL; -class ListValue; -class RenderViewHost; - -// This class represents an external port to an extension, opened -// through the automation interface. -class ExtensionPortContainer : public IPC::Message::Sender { - public: - - // Intercepts and processes a message posted through the automation interface. - // Returns true if the message was intercepted. - static bool InterceptMessageFromExternalHost(const std::string& message, - const std::string& origin, - const std::string& target, - AutomationProvider* automation, - RenderViewHost *view_host, - int tab_handle); - - ExtensionPortContainer(AutomationProvider* automation, int tab_handle); - ~ExtensionPortContainer(); - - int port_id() const { return port_id_; } - void set_port_id(int port_id) { port_id_ = port_id; } - - // IPC implementation. - virtual bool Send(IPC::Message* msg); - - private: - // Posts a message to the external host. - bool PostMessageToExternalPort(const std::string& message); - // Posts a request response message to the external host. - bool PostResponseToExternalPort(const std::string& message); - - // Forwards a message from the external port. - void PostMessageFromExternalPort(const std::string& message); - - // Attempts to connect this instance to the extension id, sends - // a response to the connecting party. - // Returns true if the connection was successful. - bool Connect(const std::string &extension_id, - int process_id, - int routing_id, - int connection_id, - const std::string& channel_name, - const std::string& tab_json); - - // Sends a connect response to the external port. - void SendConnectionResponse(int connection_id, int port_id); - - void OnExtensionMessageInvoke(const std::string& extension_id, - const std::string& function_name, - const ListValue& args, - const GURL& event_url); - void OnExtensionHandleMessage(const std::string& message, int source_port_id); - void OnExtensionPortDisconnected(int source_port_id); - - // Our automation provider. - AutomationProvider* automation_; - - // The extension message service. - scoped_refptr<ExtensionMessageService> service_; - - // Our assigned port id. - int port_id_; - // Handle to our associated tab. - int tab_handle_; - - DISALLOW_COPY_AND_ASSIGN(ExtensionPortContainer); -}; - -#endif // CHROME_BROWSER_AUTOMATION_EXTENSION_PORT_CONTAINER_H_ |