From 00f6b77b89dcd900c873ed9da13dbaa2e90fe022 Mon Sep 17 00:00:00 2001 From: "rogerta@chromium.org" Date: Fri, 23 Oct 2009 17:03:41 +0000 Subject: Add bindings to chrome frame to call the new extension automation apis. TEST=see unit tests BUG=0 Review URL: http://codereview.chromium.org/284017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29902 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome_frame/chrome_frame_automation.cc | 87 +++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'chrome_frame/chrome_frame_automation.cc') diff --git a/chrome_frame/chrome_frame_automation.cc b/chrome_frame/chrome_frame_automation.cc index 56548de..17fb43d 100644 --- a/chrome_frame/chrome_frame_automation.cc +++ b/chrome_frame/chrome_frame_automation.cc @@ -78,6 +78,14 @@ class ChromeFrameAutomationProxyImpl::CFMsgDispatcher InvokeCallback >(msg, origin); break; + case AutomationMsg_InstallExtension::ID: + InvokeCallback >(msg, + origin); + break; + case AutomationMsg_LoadExpandedExtension::ID: + InvokeCallback >(msg, + origin); + break; default: NOTREACHED(); } @@ -598,6 +606,85 @@ void ChromeFrameAutomationClient::FindInPage(const std::wstring& search_string, automation_server_->SendAsAsync(msg, NULL, this); } +// Class that maintains context during the async load/install extension +// operation. When done, InstallExtensionComplete is posted back to the UI +// thread so that the users of ChromeFrameAutomationClient can be notified. +class InstallExtensionContext { + public: + InstallExtensionContext(ChromeFrameAutomationClient* client, + const FilePath& crx_path, void* user_data) : client_(client), + crx_path_(crx_path), user_data_(user_data) { + } + + ~InstallExtensionContext() { + } + + void InstallExtensionComplete(AutomationMsg_ExtensionResponseValues res) { + client_->PostTask(FROM_HERE, NewRunnableMethod(client_, + &ChromeFrameAutomationClient::InstallExtensionComplete, crx_path_, + user_data_, res)); + delete this; + } + + private: + ChromeFrameAutomationClient* client_; + FilePath crx_path_; + void* user_data_; +}; + +void ChromeFrameAutomationClient::InstallExtension( + const FilePath& crx_path, + void* user_data) { + if (automation_server_ == NULL) { + InstallExtensionComplete(crx_path, + user_data, + AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); + return; + } + + InstallExtensionContext* ctx = new InstallExtensionContext( + this, crx_path, user_data); + + IPC::SyncMessage* msg = + new AutomationMsg_InstallExtension(0, crx_path, NULL); + + // The context will delete itself after it is called. + automation_server_->SendAsAsync(msg, NewCallback(ctx, + &InstallExtensionContext::InstallExtensionComplete), this); +} + +void ChromeFrameAutomationClient::InstallExtensionComplete( + const FilePath& crx_path, + void* user_data, + AutomationMsg_ExtensionResponseValues res) { + DCHECK(PlatformThread::CurrentId() == ui_thread_id_); + + if (chrome_frame_delegate_) { + chrome_frame_delegate_->OnExtensionInstalled(crx_path, user_data, res); + } +} + +void ChromeFrameAutomationClient::LoadExpandedExtension( + const FilePath& path, + void* user_data) { + if (automation_server_ == NULL) { + InstallExtensionComplete(path, + user_data, + AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); + return; + } + + InstallExtensionContext* ctx = new InstallExtensionContext( + this, path, user_data); + + IPC::SyncMessage* msg = + new AutomationMsg_LoadExpandedExtension(0, path, NULL); + + // The context will delete itself after it is called. + automation_server_->SendAsAsync(msg, NewCallback(ctx, + &InstallExtensionContext::InstallExtensionComplete), this); +} + void ChromeFrameAutomationClient::CreateExternalTab() { AutomationLaunchResult launch_result = AUTOMATION_SUCCESS; DCHECK(IsWindow()); -- cgit v1.1