diff options
author | zork@google.com <zork@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-15 23:43:42 +0000 |
---|---|---|
committer | zork@google.com <zork@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-15 23:43:42 +0000 |
commit | a9f4d90f8a1643ccc27aba95cf60c4531b3db7b9 (patch) | |
tree | 0f6069b618b1847b12cdba7d18e2ba8326073eed /chrome/browser | |
parent | b2d85c6d595cd7b0b3807d2bb7849fee343d7394 (diff) | |
download | chromium_src-a9f4d90f8a1643ccc27aba95cf60c4531b3db7b9.zip chromium_src-a9f4d90f8a1643ccc27aba95cf60c4531b3db7b9.tar.gz chromium_src-a9f4d90f8a1643ccc27aba95cf60c4531b3db7b9.tar.bz2 |
Adding sync plugin messages, and plugin broadcasts to the renderer processes
Review URL: http://codereview.chromium.org/2411
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2246 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/chrome_plugin_host.cc | 49 | ||||
-rw-r--r-- | chrome/browser/resource_message_filter.cc | 24 | ||||
-rw-r--r-- | chrome/browser/resource_message_filter.h | 3 |
3 files changed, 60 insertions, 16 deletions
diff --git a/chrome/browser/chrome_plugin_host.cc b/chrome/browser/chrome_plugin_host.cc index 80180a6..37d8b80 100644 --- a/chrome/browser/chrome_plugin_host.cc +++ b/chrome/browser/chrome_plugin_host.cc @@ -639,28 +639,44 @@ CPProcessType STDCALL CPB_GetProcessType(CPID id) { CPError STDCALL CPB_SendMessage(CPID id, const void *data, uint32 data_len) { CommandLine cmd; if (cmd.HasSwitch(switches::kGearsInRenderer)) { - // TODO(mpcomplete): figure out what to do here. - return CPERR_FAILURE; - } + ChromePluginLib* plugin = ChromePluginLib::FromCPID(id); + CHECK(plugin); + + const unsigned char* data_ptr = static_cast<const unsigned char*>(data); + std::vector<uint8> v(data_ptr, data_ptr + data_len); + for (RenderProcessHost::iterator it = RenderProcessHost::begin(); + it != RenderProcessHost::end(); ++it) { + it->second->Send(new ViewMsg_PluginMessage(plugin->filename(), v)); + } - CHECK(ChromePluginLib::IsPluginThread()); - ChromePluginLib* plugin = ChromePluginLib::FromCPID(id); - CHECK(plugin); + return CPERR_SUCCESS; + } else { + CHECK(ChromePluginLib::IsPluginThread()); + ChromePluginLib* plugin = ChromePluginLib::FromCPID(id); + CHECK(plugin); - PluginService* service = PluginService::GetInstance(); - if (!service) + PluginService* service = PluginService::GetInstance(); + if (!service) return CPERR_FAILURE; - PluginProcessHost *host = - service->FindOrStartPluginProcess(plugin->filename(), std::string()); - if (!host) + PluginProcessHost *host = + service->FindOrStartPluginProcess(plugin->filename(), std::string()); + if (!host) return CPERR_FAILURE; - const unsigned char* data_ptr = static_cast<const unsigned char*>(data); - std::vector<uint8> v(data_ptr, data_ptr + data_len); - if (!host->Send(new PluginProcessMsg_PluginMessage(v))) - return CPERR_FAILURE; + const unsigned char* data_ptr = static_cast<const unsigned char*>(data); + std::vector<uint8> v(data_ptr, data_ptr + data_len); + if (!host->Send(new PluginProcessMsg_PluginMessage(v))) + return CPERR_FAILURE; - return CPERR_SUCCESS; + return CPERR_SUCCESS; + } +} + +CPError STDCALL CPB_SendSyncMessage(CPID id, const void *data, uint32 data_len, + void **retval, uint32 *retval_len) { + NOTREACHED() << "Sync messages should not be sent from the browser process."; + + return CPERR_FAILURE; } } @@ -694,6 +710,7 @@ CPBrowserFuncs* GetCPBrowserFuncsForBrowser() { browser_funcs.request_funcs = &request_funcs; browser_funcs.response_funcs = &response_funcs; + browser_funcs.send_sync_message = CPB_SendSyncMessage; request_funcs.size = sizeof(request_funcs); request_funcs.start_request = CPR_StartRequest; diff --git a/chrome/browser/resource_message_filter.cc b/chrome/browser/resource_message_filter.cc index 77ae6b1..3c833d8 100644 --- a/chrome/browser/resource_message_filter.cc +++ b/chrome/browser/resource_message_filter.cc @@ -17,6 +17,7 @@ #include "chrome/browser/render_widget_helper.h" #include "chrome/browser/spellchecker.h" #include "chrome/common/chrome_plugin_lib.h" +#include "chrome/common/chrome_plugin_util.h" #include "chrome/common/clipboard_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -145,6 +146,7 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewHostMsg_GetCookies, OnGetCookies) IPC_MESSAGE_HANDLER(ViewHostMsg_GetDataDir, OnGetDataDir) IPC_MESSAGE_HANDLER(ViewHostMsg_PluginMessage, OnPluginMessage) + IPC_MESSAGE_HANDLER(ViewHostMsg_PluginSyncMessage, OnPluginSyncMessage) IPC_MESSAGE_HANDLER(ViewHostMsg_LoadFont, OnLoadFont) IPC_MESSAGE_HANDLER(ViewHostMsg_GetMonitorInfoForWindow, OnGetMonitorInfoForWindow) @@ -358,6 +360,28 @@ void ResourceMessageFilter::OnPluginMessage(const std::wstring& dll_path, } } +void ResourceMessageFilter::OnPluginSyncMessage(const std::wstring& dll_path, + const std::vector<uint8>& data, + std::vector<uint8> *retval) { + DCHECK(MessageLoop::current() == + ChromeThread::GetMessageLoop(ChromeThread::IO)); + + ChromePluginLib *chrome_plugin = ChromePluginLib::Find(dll_path); + if (chrome_plugin) { + void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); + uint32 data_len = static_cast<uint32>(data.size()); + void *retval_buffer = 0; + uint32 retval_size = 0; + chrome_plugin->functions().on_sync_message(data_ptr, data_len, + &retval_buffer, &retval_size); + if (retval_buffer) { + retval->resize(retval_size); + memcpy(&(retval->at(0)), retval_buffer, retval_size); + CPB_Free(retval_buffer); + } + } +} + void ResourceMessageFilter::OnGetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { plugin_service_->GetPlugins(refresh, plugins); diff --git a/chrome/browser/resource_message_filter.h b/chrome/browser/resource_message_filter.h index 55b2056..a83a0e9 100644 --- a/chrome/browser/resource_message_filter.h +++ b/chrome/browser/resource_message_filter.h @@ -81,6 +81,9 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void OnGetDataDir(std::wstring* data_dir); void OnPluginMessage(const std::wstring& dll_path, const std::vector<uint8>& message); + void OnPluginSyncMessage(const std::wstring& dll_path, + const std::vector<uint8>& message, + std::vector<uint8> *retval); // Cache fonts for the renderer. See ResourceMessageFilter::OnLoadFont // implementation for more details |