summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorzork@google.com <zork@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-15 23:43:42 +0000
committerzork@google.com <zork@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-15 23:43:42 +0000
commita9f4d90f8a1643ccc27aba95cf60c4531b3db7b9 (patch)
tree0f6069b618b1847b12cdba7d18e2ba8326073eed /chrome
parentb2d85c6d595cd7b0b3807d2bb7849fee343d7394 (diff)
downloadchromium_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')
-rw-r--r--chrome/browser/chrome_plugin_host.cc49
-rw-r--r--chrome/browser/resource_message_filter.cc24
-rw-r--r--chrome/browser/resource_message_filter.h3
-rw-r--r--chrome/common/chrome_plugin_api.h18
-rw-r--r--chrome/common/plugin_messages_internal.h7
-rw-r--r--chrome/common/render_messages_internal.h13
-rw-r--r--chrome/plugin/chrome_plugin_host.cc24
-rw-r--r--chrome/renderer/chrome_plugin_host.cc28
-rw-r--r--chrome/renderer/render_thread.cc13
-rw-r--r--chrome/renderer/render_thread.h2
10 files changed, 163 insertions, 18 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
diff --git a/chrome/common/chrome_plugin_api.h b/chrome/common/chrome_plugin_api.h
index 9e5301a..278787c 100644
--- a/chrome/common/chrome_plugin_api.h
+++ b/chrome/common/chrome_plugin_api.h
@@ -30,7 +30,7 @@ extern "C" {
// The current version of the API, used by the 'version' field of CPPluginFuncs
// and CPBrowserFuncs.
#define CP_MAJOR_VERSION 0
-#define CP_MINOR_VERSION 6
+#define CP_MINOR_VERSION 7
#define CP_VERSION ((CP_MAJOR_VERSION << 8) | (CP_MINOR_VERSION))
#define CP_GET_MAJOR_VERSION(version) ((version & 0xff00) >> 8)
@@ -374,9 +374,23 @@ typedef CPError (STDCALL *CPB_SendMessageFunc)(CPID id,
const void *data,
uint32 data_len);
+// Asks the browser to send raw data to the other process hosting an instance of
+// this plugin. This function only works from the plugin or renderer process.
+// This function blocks until the message is processed. The memory should be
+// freed using CPB_Free when done.
+typedef CPError (STDCALL *CPB_SendSyncMessageFunc)(CPID id,
+ const void *data,
+ uint32 data_len,
+ void **retval,
+ uint32 *retval_len);
+
// Informs the plugin of raw data having been sent from another process.
typedef void (STDCALL *CPP_OnMessageFunc)(void *data, uint32 data_len);
+// Informs the plugin of raw data having been sent from another process.
+typedef void (STDCALL *CPP_OnSyncMessageFunc)(void *data, uint32 data_len,
+ void **retval, uint32 *retval_len);
+
// Function table for issuing requests using via the other side's network stack.
// For the plugin, this functions deal with issuing requests through the
// browser. For the browser, these functions deal with allowing the plugin to
@@ -419,6 +433,7 @@ typedef struct _CPPluginFuncs {
CPP_OnMessageFunc on_message;
CPP_HtmlDialogClosedFunc html_dialog_closed;
CPP_HandleCommandFunc handle_command;
+ CPP_OnSyncMessageFunc on_sync_message;
} CPPluginFuncs;
// Function table CPB functions (functions provided by host to plugin).
@@ -446,6 +461,7 @@ typedef struct _CPBrowserFuncs {
CPB_GetCommandLineArgumentsFunc get_command_line_arguments;
CPB_AddUICommandFunc add_ui_command;
CPB_HandleCommandFunc handle_command;
+ CPB_SendSyncMessageFunc send_sync_message;
} CPBrowserFuncs;
diff --git a/chrome/common/plugin_messages_internal.h b/chrome/common/plugin_messages_internal.h
index dfcffea..7b4af2a 100644
--- a/chrome/common/plugin_messages_internal.h
+++ b/chrome/common/plugin_messages_internal.h
@@ -56,6 +56,12 @@ IPC_BEGIN_MESSAGES(PluginProcessHost, 4)
IPC_MESSAGE_CONTROL1(PluginProcessHostMsg_PluginMessage,
std::vector<uint8> /* opaque data */)
+ // Allows a chrome plugin loaded in a plugin process to send arbitrary
+ // data to an instance of the same plugin loaded in the browser process.
+ IPC_SYNC_MESSAGE_CONTROL1_1(PluginProcessHostMsg_PluginSyncMessage,
+ std::vector<uint8> /* opaque data */,
+ std::vector<uint8> /* opaque data response */)
+
// Retrieve the given type of info that is associated with the given
// CPBrowsingContext. Returns the result in a string.
IPC_SYNC_MESSAGE_CONTROL0_1(PluginProcessHostMsg_GetPluginDataDir,
@@ -238,6 +244,7 @@ IPC_BEGIN_MESSAGES(PluginHost, 6)
IPC_SYNC_MESSAGE_ROUTED0_1(PluginHostMsg_GetCPBrowsingContext,
uint32 /* context */)
+
IPC_END_MESSAGES(PluginHost)
//-----------------------------------------------------------------------------
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 66941ef..faf8beb 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -45,6 +45,12 @@ IPC_BEGIN_MESSAGES(View, 1)
size_t /* max_dead_capacity */,
size_t /* capacity */)
+ // Allows a chrome plugin loaded in the browser process to send arbitrary
+ // data to an instance of the same plugin loaded in a renderer process.
+ IPC_MESSAGE_CONTROL2(ViewMsg_PluginMessage,
+ std::wstring /* dll_path of plugin */,
+ std::vector<uint8> /* opaque data */)
+
// Reply in response to ViewHostMsg_ShowView or ViewHostMsg_ShowWidget.
// similar to the new command, but used when the renderer created a view
// first, and we need to update it
@@ -653,6 +659,13 @@ IPC_BEGIN_MESSAGES(ViewHost, 2)
std::wstring /* dll_path of plugin */,
std::vector<uint8> /* opaque data */)
+ // Allows a chrome plugin loaded in a renderer process to send arbitrary
+ // data to an instance of the same plugin loaded in the browser process.
+ IPC_SYNC_MESSAGE_CONTROL2_1(ViewHostMsg_PluginSyncMessage,
+ std::wstring /* dll_path of plugin */,
+ std::vector<uint8> /* opaque data */,
+ std::vector<uint8> /* opaque data */)
+
// Requests spellcheck for a word.
IPC_SYNC_MESSAGE_ROUTED1_2(ViewHostMsg_SpellCheck,
std::wstring /* word to check */,
diff --git a/chrome/plugin/chrome_plugin_host.cc b/chrome/plugin/chrome_plugin_host.cc
index 923b11f..ecc9418 100644
--- a/chrome/plugin/chrome_plugin_host.cc
+++ b/chrome/plugin/chrome_plugin_host.cc
@@ -492,6 +492,29 @@ CPError STDCALL CPB_SendMessage(CPID id, const void *data, uint32 data_len) {
return CPERR_SUCCESS;
}
+CPError STDCALL CPB_SendSyncMessage(CPID id, const void *data, uint32 data_len,
+ void **retval, uint32 *retval_len) {
+ CHECK(ChromePluginLib::IsPluginThread());
+ const uint8* data_ptr = static_cast<const uint8*>(data);
+ std::vector<uint8> v(data_ptr, data_ptr + data_len);
+ std::vector<uint8> r;
+ if (!PluginThread::GetPluginThread()->Send(
+ new PluginProcessHostMsg_PluginSyncMessage(v, &r))) {
+ return CPERR_FAILURE;
+ }
+
+ if (r.size()) {
+ *retval_len = static_cast<uint32>(r.size());
+ *retval = CPB_Alloc(*retval_len);
+ memcpy(*retval, &(r.at(0)), r.size());
+ } else {
+ *retval = NULL;
+ *retval_len = 0;
+ }
+
+ return CPERR_SUCCESS;
+}
+
} // namespace
CPBrowserFuncs* GetCPBrowserFuncsForPlugin() {
@@ -520,6 +543,7 @@ CPBrowserFuncs* GetCPBrowserFuncsForPlugin() {
browser_funcs.get_command_line_arguments = CPB_GetCommandLineArguments;
browser_funcs.add_ui_command = CPB_AddUICommand;
browser_funcs.handle_command = CPB_HandleCommand;
+ browser_funcs.send_sync_message = CPB_SendSyncMessage;
browser_funcs.request_funcs = &request_funcs;
browser_funcs.response_funcs = &response_funcs;
diff --git a/chrome/renderer/chrome_plugin_host.cc b/chrome/renderer/chrome_plugin_host.cc
index ea370af..b087902 100644
--- a/chrome/renderer/chrome_plugin_host.cc
+++ b/chrome/renderer/chrome_plugin_host.cc
@@ -495,6 +495,32 @@ CPError STDCALL CPB_SendMessage(CPID id, const void *data, uint32 data_len) {
return CPERR_SUCCESS;
}
+CPError STDCALL CPB_SendSyncMessage(CPID id, const void *data, uint32 data_len,
+ void **retval, uint32 *retval_len) {
+ CHECK(ChromePluginLib::IsPluginThread());
+ ChromePluginLib* plugin = ChromePluginLib::FromCPID(id);
+ CHECK(plugin);
+
+ const uint8* data_ptr = static_cast<const uint8*>(data);
+ std::vector<uint8> v(data_ptr, data_ptr + data_len);
+ std::vector<uint8> r;
+ if (!RenderThread::current()->Send(new ViewHostMsg_PluginSyncMessage(
+ plugin->filename(), v, &r))) {
+ return CPERR_FAILURE;
+ }
+
+ if (r.size()) {
+ *retval_len = static_cast<uint32>(r.size());
+ *retval = CPB_Alloc(*retval_len);
+ memcpy(*retval, &(r.at(0)), r.size());
+ } else {
+ *retval = NULL;
+ *retval_len = 0;
+ }
+
+ return CPERR_SUCCESS;
+}
+
} // namespace
CPBrowserFuncs* GetCPBrowserFuncsForRenderer() {
@@ -523,6 +549,7 @@ CPBrowserFuncs* GetCPBrowserFuncsForRenderer() {
browser_funcs.get_command_line_arguments = CPB_GetCommandLineArguments;
browser_funcs.add_ui_command = CPB_AddUICommand;
browser_funcs.handle_command = CPB_HandleCommand;
+ browser_funcs.send_sync_message = CPB_SendSyncMessage;
browser_funcs.request_funcs = &request_funcs;
browser_funcs.response_funcs = &response_funcs;
@@ -546,4 +573,3 @@ CPBrowserFuncs* GetCPBrowserFuncsForRenderer() {
return &browser_funcs;
}
-
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index 97f71b5..c389860 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -10,6 +10,7 @@
#include "base/lazy_instance.h"
#include "base/shared_memory.h"
#include "base/thread_local.h"
+#include "chrome/common/chrome_plugin_lib.h"
#include "chrome/common/ipc_logging.h"
#include "chrome/common/notification_service.h"
#include "chrome/plugin/plugin_channel.h"
@@ -161,6 +162,7 @@ void RenderThread::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities)
IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats,
OnGetCacheResourceStats)
+ IPC_MESSAGE_HANDLER(ViewMsg_PluginMessage, OnPluginMessage)
// send the rest to the router
IPC_MESSAGE_UNHANDLED(router_.OnMessageReceived(msg))
IPC_END_MESSAGE_MAP()
@@ -169,6 +171,17 @@ void RenderThread::OnMessageReceived(const IPC::Message& msg) {
}
}
+void RenderThread::OnPluginMessage(const std::wstring& dll_path,
+ const std::vector<uint8>& data) {
+ CHECK(ChromePluginLib::IsPluginThread());
+ 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());
+ chrome_plugin->functions().on_message(data_ptr, data_len);
+ }
+}
+
void RenderThread::OnSetNextPageID(int32 next_page_id) {
// This should only be called at process initialization time, so we shouldn't
// have to worry about thread-safety.
diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h
index 50e022a..4dc9b99 100644
--- a/chrome/renderer/render_thread.h
+++ b/chrome/renderer/render_thread.h
@@ -75,6 +75,8 @@ class RenderThread : public IPC::Channel::Listener,
private:
void OnUpdateVisitedLinks(SharedMemoryHandle table);
+ void OnPluginMessage(const std::wstring& dll_path,
+ const std::vector<uint8>& data);
void OnSetNextPageID(int32 next_page_id);
void OnCreateNewView(HWND parent_hwnd,
HANDLE modal_dialog_event,