Commit 700d3d58 authored by evan@chromium.org's avatar evan@chromium.org

linux: OOP windowed plugins

There are still a few issues, but that's a start.
- only windowed plugins
- we can't currently create the gtksocket in background tabs, because their gtkwidgets are not yet in the hierarchy, so they can't be realized (that's what gives the XID).
- the plugin process talks to the browser process through the renderer process to create/destroy the gtksockets, because the plugin doesn't know which renderer it's talking to. We need a bit more plumbing to be able to have direct IPC.
- some code is duplicated between chrome and test_shell. We should probably refactor it, but I'm not sure where the common part should live.

Patch from Antoine Labour <piman@google.com>, with some touchups by me.

Review URL: http://codereview.chromium.org/146078

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20041 0039d316-1c4b-4281-b951-d872f2087c98
parent d1ae8544
...@@ -124,9 +124,9 @@ NativeViewId IdFromNativeView(NativeView view); ...@@ -124,9 +124,9 @@ NativeViewId IdFromNativeView(NativeView view);
typedef unsigned long PluginWindowHandle; typedef unsigned long PluginWindowHandle;
#else #else
// On OS X we don't have windowed plugins. // On OS X we don't have windowed plugins.
// Use a gfx::NativeView so the previously-compiling code still works. // We use a NULL/0 PluginWindowHandle in shared code to indicate there
// TODO(evanm): remove this and use void* instead. // is no window present, so mirror that behavior here.
typedef gfx::NativeView PluginWindowHandle; typedef bool PluginWindowHandle;
#endif #endif
} // namespace gfx } // namespace gfx
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "base/file_path.h" #include "base/file_path.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/file_version_info.h" #include "base/file_version_info.h"
#include "base/gfx/native_widget_types.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/process_util.h" #include "base/process_util.h"
...@@ -58,6 +59,10 @@ ...@@ -58,6 +59,10 @@
#include "chrome/common/ipc_channel_posix.h" #include "chrome/common/ipc_channel_posix.h"
#endif #endif
#if defined(OS_LINUX)
#include "base/gfx/gtk_native_view_id_manager.h"
#endif
static const char kDefaultPluginFinderURL[] = static const char kDefaultPluginFinderURL[] =
"http://dl.google.com/chrome/plugins/plugins2.xml"; "http://dl.google.com/chrome/plugins/plugins2.xml";
...@@ -288,6 +293,14 @@ void PluginProcessHost::AddWindow(HWND window) { ...@@ -288,6 +293,14 @@ void PluginProcessHost::AddWindow(HWND window) {
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
#if defined(OS_LINUX)
void PluginProcessHost::OnMapNativeViewId(gfx::NativeViewId id,
gfx::PluginWindowHandle* output) {
*output = 0;
Singleton<GtkNativeViewManager>()->GetXIDForId(output, id);
}
#endif // defined(OS_LINUX)
PluginProcessHost::PluginProcessHost() PluginProcessHost::PluginProcessHost()
: ChildProcessHost( : ChildProcessHost(
PLUGIN_PROCESS, PLUGIN_PROCESS,
...@@ -437,6 +450,10 @@ void PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { ...@@ -437,6 +450,10 @@ void PluginProcessHost::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed, IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed,
OnPluginWindowDestroyed) OnPluginWindowDestroyed)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_DownloadUrl, OnDownloadUrl) IPC_MESSAGE_HANDLER(PluginProcessHostMsg_DownloadUrl, OnDownloadUrl)
#endif
#if defined(OS_LINUX)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_MapNativeViewId,
OnMapNativeViewId)
#endif #endif
IPC_MESSAGE_UNHANDLED_ERROR() IPC_MESSAGE_UNHANDLED_ERROR()
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
......
...@@ -110,6 +110,10 @@ class PluginProcessHost : public ChildProcessHost, ...@@ -110,6 +110,10 @@ class PluginProcessHost : public ChildProcessHost,
gfx::NativeWindow caller_window); gfx::NativeWindow caller_window);
#endif #endif
#if defined(OS_LINUX)
void OnMapNativeViewId(gfx::NativeViewId id, gfx::PluginWindowHandle* output);
#endif
virtual bool CanShutdown() { return sent_requests_.empty(); } virtual bool CanShutdown() { return sent_requests_.empty(); }
struct ChannelRequest { struct ChannelRequest {
......
...@@ -671,6 +671,10 @@ bool RenderViewHost::SuddenTerminationAllowed() const { ...@@ -671,6 +671,10 @@ bool RenderViewHost::SuddenTerminationAllowed() const {
// RenderViewHost, IPC message handlers: // RenderViewHost, IPC message handlers:
void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { void RenderViewHost::OnMessageReceived(const IPC::Message& msg) {
#if !defined(OS_LINUX)
// On Windows there's a potential deadlock with sync messsages going in
// a circle from browser -> plugin -> renderer -> browser.
// On Linux we can avoid this by avoiding sync messages from browser->plugin.
if (msg.is_sync() && !msg.is_caller_pumping_messages()) { if (msg.is_sync() && !msg.is_caller_pumping_messages()) {
NOTREACHED() << "Can't send sync messages to UI thread without pumping " NOTREACHED() << "Can't send sync messages to UI thread without pumping "
"messages in the renderer or else deadlocks can occur if the page " "messages in the renderer or else deadlocks can occur if the page "
...@@ -680,6 +684,7 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { ...@@ -680,6 +684,7 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) {
Send(reply); Send(reply);
return; return;
} }
#endif
bool msg_is_ok = true; bool msg_is_ok = true;
IPC_BEGIN_MESSAGE_MAP_EX(RenderViewHost, msg, msg_is_ok) IPC_BEGIN_MESSAGE_MAP_EX(RenderViewHost, msg, msg_is_ok)
......
...@@ -120,6 +120,12 @@ IPC_DEFINE_MESSAGE_MAP(RenderWidgetHost) ...@@ -120,6 +120,12 @@ IPC_DEFINE_MESSAGE_MAP(RenderWidgetHost)
IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor) IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor)
IPC_MESSAGE_HANDLER(ViewHostMsg_ImeUpdateStatus, OnMsgImeUpdateStatus) IPC_MESSAGE_HANDLER(ViewHostMsg_ImeUpdateStatus, OnMsgImeUpdateStatus)
IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_ShowPopup, OnMsgShowPopup(msg)) IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_ShowPopup, OnMsgShowPopup(msg))
#if defined(OS_LINUX)
IPC_MESSAGE_HANDLER(ViewHostMsg_CreatePluginContainer,
OnMsgCreatePluginContainer)
IPC_MESSAGE_HANDLER(ViewHostMsg_DestroyPluginContainer,
OnMsgDestroyPluginContainer)
#endif
IPC_MESSAGE_UNHANDLED_ERROR() IPC_MESSAGE_UNHANDLED_ERROR()
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
...@@ -748,6 +754,18 @@ void RenderWidgetHost::OnMsgShowPopup(const IPC::Message& message) { ...@@ -748,6 +754,18 @@ void RenderWidgetHost::OnMsgShowPopup(const IPC::Message& message) {
#endif #endif
} }
#if defined(OS_LINUX)
void RenderWidgetHost::OnMsgCreatePluginContainer(
gfx::PluginWindowHandle *container) {
*container = view_->CreatePluginContainer();
}
void RenderWidgetHost::OnMsgDestroyPluginContainer(
gfx::PluginWindowHandle container) {
view_->DestroyPluginContainer(container);
}
#endif
void RenderWidgetHost::PaintBackingStoreRect(TransportDIB* bitmap, void RenderWidgetHost::PaintBackingStoreRect(TransportDIB* bitmap,
const gfx::Rect& bitmap_rect, const gfx::Rect& bitmap_rect,
const gfx::Size& view_size) { const gfx::Size& view_size) {
......
...@@ -392,6 +392,10 @@ class RenderWidgetHost : public IPC::Channel::Listener { ...@@ -392,6 +392,10 @@ class RenderWidgetHost : public IPC::Channel::Listener {
// having to bring in render_messages.h in a header file. // having to bring in render_messages.h in a header file.
void OnMsgImeUpdateStatus(int control, const gfx::Rect& caret_rect); void OnMsgImeUpdateStatus(int control, const gfx::Rect& caret_rect);
void OnMsgShowPopup(const IPC::Message& message); void OnMsgShowPopup(const IPC::Message& message);
#if defined(OS_LINUX)
void OnMsgCreatePluginContainer(gfx::PluginWindowHandle *container);
void OnMsgDestroyPluginContainer(gfx::PluginWindowHandle container);
#endif
// Paints the given bitmap to the current backing store at the given location. // Paints the given bitmap to the current backing store at the given location.
void PaintBackingStoreRect(TransportDIB* dib, void PaintBackingStoreRect(TransportDIB* dib,
......
...@@ -151,6 +151,11 @@ class RenderWidgetHostView { ...@@ -151,6 +151,11 @@ class RenderWidgetHostView {
const std::vector<WebMenuItem>& items) = 0; const std::vector<WebMenuItem>& items) = 0;
#endif #endif
#if defined(OS_LINUX)
virtual gfx::PluginWindowHandle CreatePluginContainer() = 0;
virtual void DestroyPluginContainer(gfx::PluginWindowHandle container) = 0;
#endif
void set_activatable(bool activatable) { void set_activatable(bool activatable) {
activatable_ = activatable; activatable_ = activatable;
} }
......
...@@ -34,7 +34,8 @@ using WebKit::WebInputEventFactory; ...@@ -34,7 +34,8 @@ using WebKit::WebInputEventFactory;
class RenderWidgetHostViewGtkWidget { class RenderWidgetHostViewGtkWidget {
public: public:
static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) { static GtkWidget* CreateNewWidget(RenderWidgetHostViewGtk* host_view) {
GtkWidget* widget = gtk_drawing_area_new(); GtkWidget* widget = gtk_fixed_new();
gtk_fixed_set_has_window(GTK_FIXED(widget), TRUE);
gtk_widget_set_double_buffered(widget, FALSE); gtk_widget_set_double_buffered(widget, FALSE);
#if defined(NDEBUG) #if defined(NDEBUG)
gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &gfx::kGdkWhite); gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &gfx::kGdkWhite);
...@@ -375,6 +376,7 @@ RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() { ...@@ -375,6 +376,7 @@ RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() {
void RenderWidgetHostViewGtk::InitAsChild() { void RenderWidgetHostViewGtk::InitAsChild() {
view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this)); view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this));
plugin_container_manager_.set_host_widget(view_.get());
gtk_widget_show(view_.get()); gtk_widget_show(view_.get());
} }
...@@ -384,6 +386,7 @@ void RenderWidgetHostViewGtk::InitAsPopup( ...@@ -384,6 +386,7 @@ void RenderWidgetHostViewGtk::InitAsPopup(
parent_ = parent_host_view->GetNativeView(); parent_ = parent_host_view->GetNativeView();
GtkWidget* popup = gtk_window_new(GTK_WINDOW_POPUP); GtkWidget* popup = gtk_window_new(GTK_WINDOW_POPUP);
view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this)); view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this));
plugin_container_manager_.set_host_widget(view_.get());
gtk_container_add(GTK_CONTAINER(popup), view_.get()); gtk_container_add(GTK_CONTAINER(popup), view_.get());
// If we are not activatable, we don't want to grab keyboard input, // If we are not activatable, we don't want to grab keyboard input,
...@@ -471,10 +474,9 @@ gfx::NativeView RenderWidgetHostViewGtk::GetNativeView() { ...@@ -471,10 +474,9 @@ gfx::NativeView RenderWidgetHostViewGtk::GetNativeView() {
void RenderWidgetHostViewGtk::MovePluginWindows( void RenderWidgetHostViewGtk::MovePluginWindows(
const std::vector<WebPluginGeometry>& plugin_window_moves) { const std::vector<WebPluginGeometry>& plugin_window_moves) {
if (plugin_window_moves.empty()) for (size_t i = 0; i < plugin_window_moves.size(); ++i) {
return; plugin_container_manager_.MovePluginContainer(plugin_window_moves[i]);
}
NOTIMPLEMENTED();
} }
void RenderWidgetHostViewGtk::Focus() { void RenderWidgetHostViewGtk::Focus() {
...@@ -573,6 +575,7 @@ void RenderWidgetHostViewGtk::DidScrollRect(const gfx::Rect& rect, int dx, ...@@ -573,6 +575,7 @@ void RenderWidgetHostViewGtk::DidScrollRect(const gfx::Rect& rect, int dx,
void RenderWidgetHostViewGtk::RenderViewGone() { void RenderWidgetHostViewGtk::RenderViewGone() {
Destroy(); Destroy();
plugin_container_manager_.set_host_widget(NULL);
} }
void RenderWidgetHostViewGtk::Destroy() { void RenderWidgetHostViewGtk::Destroy() {
...@@ -707,3 +710,12 @@ void RenderWidgetHostViewGtk::ReceivedSelectionText(GtkClipboard* clipboard, ...@@ -707,3 +710,12 @@ void RenderWidgetHostViewGtk::ReceivedSelectionText(GtkClipboard* clipboard,
host_view->host_->Send(new ViewMsg_InsertText(host_view->host_->routing_id(), host_view->host_->Send(new ViewMsg_InsertText(host_view->host_->routing_id(),
UTF8ToUTF16(text))); UTF8ToUTF16(text)));
} }
gfx::PluginWindowHandle RenderWidgetHostViewGtk::CreatePluginContainer() {
return plugin_container_manager_.CreatePluginContainer();
}
void RenderWidgetHostViewGtk::DestroyPluginContainer(
gfx::PluginWindowHandle container) {
plugin_container_manager_.DestroyPluginContainer(container);
}
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/common/owned_widget_gtk.h" #include "chrome/common/owned_widget_gtk.h"
#include "chrome/common/render_messages.h" #include "chrome/common/render_messages.h"
#include "webkit/glue/plugins/gtk_plugin_container_manager.h"
#include "webkit/glue/webcursor.h" #include "webkit/glue/webcursor.h"
class RenderWidgetHost; class RenderWidgetHost;
...@@ -59,6 +60,8 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView { ...@@ -59,6 +60,8 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView {
virtual void PasteFromSelectionClipboard(); virtual void PasteFromSelectionClipboard();
virtual void ShowingContextMenu(bool showing); virtual void ShowingContextMenu(bool showing);
virtual BackingStore* AllocBackingStore(const gfx::Size& size); virtual BackingStore* AllocBackingStore(const gfx::Size& size);
virtual gfx::PluginWindowHandle CreatePluginContainer();
virtual void DestroyPluginContainer(gfx::PluginWindowHandle container);
gfx::NativeView native_view() const { return view_.get(); } gfx::NativeView native_view() const { return view_.get(); }
...@@ -137,6 +140,9 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView { ...@@ -137,6 +140,9 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView {
// This state is used when GtkIMContext signal handlers create Char events // This state is used when GtkIMContext signal handlers create Char events
// because they don't use the GdkEventKey objects and cannot get the state. // because they don't use the GdkEventKey objects and cannot get the state.
int im_modifier_state_; int im_modifier_state_;
// Helper class that lets us allocate plugin containers and move them.
GtkPluginContainerManager plugin_container_manager_;
}; };
#endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_ #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_
...@@ -79,6 +79,11 @@ class TestRenderWidgetHostView : public RenderWidgetHostView { ...@@ -79,6 +79,11 @@ class TestRenderWidgetHostView : public RenderWidgetHostView {
const std::vector<WebMenuItem>& items) {} const std::vector<WebMenuItem>& items) {}
#endif #endif
#if defined(OS_LINUX)
virtual gfx::PluginWindowHandle CreatePluginContainer() { return 0; }
virtual void DestroyPluginContainer(gfx::PluginWindowHandle container) { }
#endif
bool is_showing() const { return is_showing_; } bool is_showing() const { return is_showing_; }
private: private:
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/gfx/native_widget_types.h"
#include "base/shared_memory.h" #include "base/shared_memory.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/common/ipc_message_macros.h" #include "chrome/common/ipc_message_macros.h"
...@@ -97,6 +98,16 @@ IPC_BEGIN_MESSAGES(PluginProcessHost) ...@@ -97,6 +98,16 @@ IPC_BEGIN_MESSAGES(PluginProcessHost)
HWND /* caller window */) HWND /* caller window */)
#endif #endif
#if defined(OS_LINUX)
// On Linux, the mapping between NativeViewId and X window ids
// is known only to the browser. This message lets the plugin process
// ask about a NativeViewId that was provided by the renderer.
// It will get 0 back if it's a bogus input.
IPC_SYNC_MESSAGE_CONTROL1_1(PluginProcessHostMsg_MapNativeViewId,
gfx::NativeViewId /* input: native view id */,
gfx::PluginWindowHandle /* output: X window id */)
#endif
IPC_END_MESSAGES(PluginProcessHost) IPC_END_MESSAGES(PluginProcessHost)
...@@ -219,7 +230,16 @@ IPC_BEGIN_MESSAGES(PluginHost) ...@@ -219,7 +230,16 @@ IPC_BEGIN_MESSAGES(PluginHost)
// The window parameter is a handle to the window if the plugin is a windowed // The window parameter is a handle to the window if the plugin is a windowed
// plugin. It is NULL for windowless plugins. // plugin. It is NULL for windowless plugins.
IPC_SYNC_MESSAGE_ROUTED1_0(PluginHostMsg_SetWindow, IPC_SYNC_MESSAGE_ROUTED1_0(PluginHostMsg_SetWindow,
gfx::NativeViewId /* window */) gfx::PluginWindowHandle /* window */)
#if defined(OS_LINUX)
// Asks the renderer to create a plugin container (GtkSocket).
IPC_SYNC_MESSAGE_ROUTED0_1(PluginHostMsg_CreatePluginContainer,
gfx::PluginWindowHandle /* container */)
// Asks the renderer to destroy a plugin container (GtkSocket).
IPC_SYNC_MESSAGE_ROUTED1_0(PluginHostMsg_DestroyPluginContainer,
gfx::PluginWindowHandle /* container */)
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
// The modal_loop_pump_messages_event parameter is an event handle which is // The modal_loop_pump_messages_event parameter is an event handle which is
......
...@@ -929,6 +929,13 @@ IPC_BEGIN_MESSAGES(ViewHost) ...@@ -929,6 +929,13 @@ IPC_BEGIN_MESSAGES(ViewHost)
IPC::ChannelHandle /* handle to channel */, IPC::ChannelHandle /* handle to channel */,
FilePath /* plugin_path */) FilePath /* plugin_path */)
#if defined(OS_LINUX)
IPC_SYNC_MESSAGE_ROUTED0_1(ViewHostMsg_CreatePluginContainer,
gfx::PluginWindowHandle /* container */)
IPC_SYNC_MESSAGE_ROUTED1_0(ViewHostMsg_DestroyPluginContainer,
gfx::PluginWindowHandle /* container */)
#endif
// Clipboard IPC messages // Clipboard IPC messages
// This message is used when the object list does not contain a bitmap. // This message is used when the object list does not contain a bitmap.
......
...@@ -67,6 +67,22 @@ int PluginMain(const MainFunctionParams& parameters) { ...@@ -67,6 +67,22 @@ int PluginMain(const MainFunctionParams& parameters) {
MB_OK | MB_SETFOREGROUND); MB_OK | MB_SETFOREGROUND);
} }
#else #else
#if defined(OS_LINUX)
{
// XEmbed plugins assume they are hosted in a Gtk application, so we need
// to initialize Gtk in the plugin process.
// TODO(evanm): hoist this up nearer to where we have argc/argv.
const std::vector<std::string>& args = parameters.command_line_.argv();
int argc = args.size();
scoped_array<const char *> argv(new const char *[argc + 1]);
for (int i = 0; i < argc; ++i) {
argv[i] = args[i].c_str();
}
argv[argc] = NULL;
const char **argv_pointer = argv.get();
gtk_init(&argc, const_cast<char***>(&argv_pointer));
}
#endif
NOTIMPLEMENTED() << " non-windows startup, plugin startup dialog etc."; NOTIMPLEMENTED() << " non-windows startup, plugin startup dialog etc.";
#endif #endif
......
...@@ -128,14 +128,15 @@ void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params, ...@@ -128,14 +128,15 @@ void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params,
FilePath path = FilePath::FromWStringHack( FilePath path = FilePath::FromWStringHack(
command_line.GetSwitchValue(switches::kPluginPath)); command_line.GetSwitchValue(switches::kPluginPath));
gfx::PluginWindowHandle parent = NULL;
#if defined(OS_WIN) #if defined(OS_WIN)
delegate_ = WebPluginDelegate::Create( parent = gfx::NativeViewFromId(params.containing_window);
path, mime_type_, gfx::NativeViewFromId(params.containing_window)); #elif defined(OS_LINUX)
#else PluginThread::current()->Send(new PluginProcessHostMsg_MapNativeViewId(
NOTIMPLEMENTED() << " need to figure out nativeview id business"; params.containing_window, &parent));
delegate_ = WebPluginDelegate::Create(
path, mime_type_, NULL);
#endif #endif
delegate_ = WebPluginDelegate::Create(path, mime_type_, parent);
if (delegate_) { if (delegate_) {
webplugin_ = new WebPluginProxy(channel_, instance_id_, delegate_); webplugin_ = new WebPluginProxy(channel_, instance_id_, delegate_);
......
...@@ -56,12 +56,16 @@ bool WebPluginProxy::Send(IPC::Message* msg) { ...@@ -56,12 +56,16 @@ bool WebPluginProxy::Send(IPC::Message* msg) {
return channel_->Send(msg); return channel_->Send(msg);
} }
void WebPluginProxy::SetWindow(gfx::PluginWindowHandle window) { #if defined(OS_LINUX)
#if defined(OS_WIN) gfx::PluginWindowHandle WebPluginProxy::CreatePluginContainer() {
Send(new PluginHostMsg_SetWindow(route_id_, gfx::IdFromNativeView(window))); gfx::PluginWindowHandle container;
#else Send(new PluginHostMsg_CreatePluginContainer(route_id_, &container));
NOTIMPLEMENTED(); return container;
}
#endif #endif
void WebPluginProxy::SetWindow(gfx::PluginWindowHandle window) {
Send(new PluginHostMsg_SetWindow(route_id_, window));
} }
void WebPluginProxy::WillDestroyWindow(gfx::PluginWindowHandle window) { void WebPluginProxy::WillDestroyWindow(gfx::PluginWindowHandle window) {
...@@ -69,6 +73,8 @@ void WebPluginProxy::WillDestroyWindow(gfx::PluginWindowHandle window) { ...@@ -69,6 +73,8 @@ void WebPluginProxy::WillDestroyWindow(gfx::PluginWindowHandle window) {
PluginThread::current()->Send( PluginThread::current()->Send(
new PluginProcessHostMsg_PluginWindowDestroyed( new PluginProcessHostMsg_PluginWindowDestroyed(
window, ::GetParent(window))); window, ::GetParent(window)));
#elif defined(OS_LINUX)
Send(new PluginHostMsg_DestroyPluginContainer(route_id_, window));
#else #else
NOTIMPLEMENTED(); NOTIMPLEMENTED();
#endif #endif
...@@ -275,7 +281,6 @@ void WebPluginProxy::HandleURLRequest(const char *method, ...@@ -275,7 +281,6 @@ void WebPluginProxy::HandleURLRequest(const char *method,
if (!target && (0 == base::strcasecmp(method, "GET"))) { if (!target && (0 == base::strcasecmp(method, "GET"))) {
// Please refer to https://bugzilla.mozilla.org/show_bug.cgi?id=366082 // Please refer to https://bugzilla.mozilla.org/show_bug.cgi?id=366082
// for more details on this. // for more details on this.
#if defined(OS_WIN)
if (delegate_->GetQuirks() & if (delegate_->GetQuirks() &
WebPluginDelegate::PLUGIN_QUIRK_BLOCK_NONSTANDARD_GETURL_REQUESTS) { WebPluginDelegate::PLUGIN_QUIRK_BLOCK_NONSTANDARD_GETURL_REQUESTS) {
GURL request_url(url); GURL request_url(url);
...@@ -285,10 +290,6 @@ void WebPluginProxy::HandleURLRequest(const char *method, ...@@ -285,10 +290,6 @@ void WebPluginProxy::HandleURLRequest(const char *method,
return; return;
} }
} }
#else
// TODO(port): we need a GetQuirks() on our delegate impl.
NOTIMPLEMENTED();
#endif
} }
PluginHostMsg_URLRequest_Params params; PluginHostMsg_URLRequest_Params params;
...@@ -402,7 +403,6 @@ void WebPluginProxy::UpdateGeometry( ...@@ -402,7 +403,6 @@ void WebPluginProxy::UpdateGeometry(
const gfx::Rect& clip_rect, const gfx::Rect& clip_rect,
const TransportDIB::Id& windowless_buffer_id, const TransportDIB::Id& windowless_buffer_id,
const TransportDIB::Id& background_buffer_id) { const TransportDIB::Id& background_buffer_id) {
#if defined(OS_WIN)
// TODO(port): this isn't correct usage of a TransportDIB; for now, // TODO(port): this isn't correct usage of a TransportDIB; for now,
// the caller temporarly just stuffs the handle into the HANDLE // the caller temporarly just stuffs the handle into the HANDLE
// field of the TransportDIB::Id so it should behave like the older // field of the TransportDIB::Id so it should behave like the older
...@@ -410,8 +410,9 @@ void WebPluginProxy::UpdateGeometry( ...@@ -410,8 +410,9 @@ void WebPluginProxy::UpdateGeometry(
gfx::Rect old = delegate_->GetRect(); gfx::Rect old = delegate_->GetRect();
gfx::Rect old_clip_rect = delegate_->GetClipRect(); gfx::Rect old_clip_rect = delegate_->GetClipRect();
bool moved = old.x() != window_rect.x() || old.y() != window_rect.y();
delegate_->UpdateGeometry(window_rect, clip_rect); delegate_->UpdateGeometry(window_rect, clip_rect);
#if defined(OS_WIN)
bool moved = old.x() != window_rect.x() || old.y() != window_rect.y();
if (windowless_buffer_id.handle) { if (windowless_buffer_id.handle) {
// The plugin's rect changed, so now we have a new buffer to draw into. // The plugin's rect changed, so now we have a new buffer to draw into.
SetWindowlessBuffer(windowless_buffer_id.handle, SetWindowlessBuffer(windowless_buffer_id.handle,
......
...@@ -38,9 +38,7 @@ class WebPluginProxy : public WebPlugin { ...@@ -38,9 +38,7 @@ class WebPluginProxy : public WebPlugin {
// WebPlugin overrides // WebPlugin overrides
#if defined(OS_LINUX) #if defined(OS_LINUX)
gfx::PluginWindowHandle CreatePluginContainer() { gfx::PluginWindowHandle CreatePluginContainer();
return 0; // Temporary empty stub while we restructure test_shell.
}
#endif #endif
void SetWindow(gfx::PluginWindowHandle window); void SetWindow(gfx::PluginWindowHandle window);
void WillDestroyWindow(gfx::PluginWindowHandle window); void WillDestroyWindow(gfx::PluginWindowHandle window);
......
...@@ -331,6 +331,12 @@ void WebPluginDelegateProxy::InstallMissingPlugin() { ...@@ -331,6 +331,12 @@ void WebPluginDelegateProxy::InstallMissingPlugin() {
void WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) { void WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) {
IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg) IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg)
IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow) IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow)
#if defined(OS_LINUX)
IPC_MESSAGE_HANDLER(PluginHostMsg_CreatePluginContainer,
OnCreatePluginContainer)
IPC_MESSAGE_HANDLER(PluginHostMsg_DestroyPluginContainer,
OnDestroyPluginContainer)
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessPumpEvent, IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindowlessPumpEvent,
OnSetWindowlessPumpEvent) OnSetWindowlessPumpEvent)
...@@ -634,17 +640,26 @@ int WebPluginDelegateProxy::GetProcessId() { ...@@ -634,17 +640,26 @@ int WebPluginDelegateProxy::GetProcessId() {
return channel_host_->peer_pid(); return channel_host_->peer_pid();
} }
void WebPluginDelegateProxy::OnSetWindow(gfx::NativeViewId window_id) { void WebPluginDelegateProxy::OnSetWindow(gfx::PluginWindowHandle window) {
#if defined(OS_WIN) windowless_ = !window;
gfx::NativeView window = gfx::NativeViewFromId(window_id);
windowless_ = window == NULL;
if (plugin_) if (plugin_)
plugin_->SetWindow(window); plugin_->SetWindow(window);
#else
NOTIMPLEMENTED();
#endif
} }
#if defined(OS_LINUX)
void WebPluginDelegateProxy::OnCreatePluginContainer(
gfx::PluginWindowHandle* container) {
RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
render_view_->routing_id(), container));
}
void WebPluginDelegateProxy::OnDestroyPluginContainer(
gfx::PluginWindowHandle container) {
RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
render_view_->routing_id(), container));
}
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
void WebPluginDelegateProxy::OnSetWindowlessPumpEvent( void WebPluginDelegateProxy::OnSetWindowlessPumpEvent(
HANDLE modal_loop_pump_messages_event) { HANDLE modal_loop_pump_messages_event) {
......
...@@ -106,7 +106,11 @@ class WebPluginDelegateProxy : public WebPluginDelegate, ...@@ -106,7 +106,11 @@ class WebPluginDelegateProxy : public WebPluginDelegate,
// Message handlers for messages that proxy WebPlugin methods, which // Message handlers for messages that proxy WebPlugin methods, which
// we translate into calls to the real WebPlugin. // we translate into calls to the real WebPlugin.
void OnSetWindow(gfx::NativeViewId window); void OnSetWindow(gfx::PluginWindowHandle window);
#if defined(OS_LINUX)
void OnCreatePluginContainer(gfx::PluginWindowHandle* container);
void OnDestroyPluginContainer(gfx::PluginWindowHandle container);
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
void OnSetWindowlessPumpEvent(HANDLE modal_loop_pump_messages_event); void OnSetWindowlessPumpEvent(HANDLE modal_loop_pump_messages_event);
#endif #endif
......
// 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.
#include "webkit/glue/plugins/gtk_plugin_container_manager.h"
#include <gtk/gtk.h>
#include "base/gfx/gtk_util.h"
#include "base/logging.h"
#include "webkit/glue/plugins/gtk_plugin_container.h"
#include "webkit/glue/webplugin.h"
// Helper function that always returns true. Used to prevent Gtk from
// destroying our socket when the plug goes away: we manage it ourselves.
static gboolean AlwaysTrue(void* unused) {
return TRUE;
}
gfx::PluginWindowHandle GtkPluginContainerManager::CreatePluginContainer() {
DCHECK(host_widget_);
// If the current view hasn't been attached to a top-level window (e.g. it is
// loaded in a background tab), it can't be realized without asserting in
// Gtk, so we can't get the XID for the socket. Instead, don't create one.
// We'll never see the plugin but it's better than crashing.
// TODO(piman@google.com): figure out how to add the background tab to the
// widget hierarchy, so that it can be realized. It doesn't have to be
// visible.
if (!gtk_widget_get_ancestor(host_widget_, GTK_TYPE_WINDOW)) {
NOTIMPLEMENTED() << "Can't create plugins in background tabs.";
return 0;
}
GtkWidget* plugin_container = gtk_plugin_container_new();
g_signal_connect(G_OBJECT(plugin_container), "plug-removed",
G_CALLBACK(AlwaysTrue), NULL);
// Add a connection to the "unrealize" signal so that if the parent widget
// gets destroyed before the DestroyPluginContainer gets called, bad things
// don't happen.
g_signal_connect(G_OBJECT(plugin_container), "unrealize",
G_CALLBACK(UnrealizeCallback), this);
gtk_container_add(GTK_CONTAINER(host_widget_), plugin_container);
gtk_widget_show(plugin_container);
gtk_widget_realize(plugin_container);
gfx::PluginWindowHandle id = gtk_socket_get_id(GTK_SOCKET(plugin_container));
plugin_window_to_widget_map_.insert(std::make_pair(id, plugin_container));
return id;
}
void GtkPluginContainerManager::DestroyPluginContainer(
gfx::PluginWindowHandle container) {
GtkWidget* plugin_container = MapIDToWidget(container);
if (!plugin_container)
return;
// This will call the UnrealizeCallback that will remove plugin_container
// from the map.
gtk_widget_destroy(plugin_container);
}
void GtkPluginContainerManager::MovePluginContainer(
const WebPluginGeometry& move) {
DCHECK(host_widget_);
GtkWidget *widget = MapIDToWidget(move.window);
if (!widget)
return;
DCHECK(!GTK_WIDGET_NO_WINDOW(widget));
DCHECK(GTK_WIDGET_REALIZED(widget));
if (!move.visible) {
gtk_widget_hide(widget);
return;
} else {
gtk_widget_show(widget);
}
GdkRectangle clip_rect = move.clip_rect.ToGdkRectangle();
GdkRegion* clip_region = gdk_region_rectangle(&clip_rect);
gfx::SubtractRectanglesFromRegion(clip_region, move.cutout_rects);
gdk_window_shape_combine_region(widget->window, clip_region, 0, 0);
gdk_region_destroy(clip_region);
// Update the window position. Resizing is handled by WebPluginDelegate.
// TODO(deanm): Verify that we only need to move and not resize.
// TODO(evanm): we should cache the last shape and position and skip all
// of this business in the common case where nothing has changed.
int current_x, current_y;
// Until the above TODO is resolved, we can grab the last position
// off of the GtkFixed with a bit of hackery.
GValue value = {0};
g_value_init(&value, G_TYPE_INT);
gtk_container_child_get_property(GTK_CONTAINER(host_widget_), widget,
"x", &value);
current_x = g_value_get_int(&value);
gtk_container_child_get_property(GTK_CONTAINER(host_widget_), widget,
"y", &value);
current_y = g_value_get_int(&value);
g_value_unset(&value);
if (move.window_rect.x() != current_x ||
move.window_rect.y() != current_y) {
// Calling gtk_fixed_move unnecessarily is a no-no, as it causes the
// parent window to repaint!
gtk_fixed_move(GTK_FIXED(host_widget_),
widget,
move.window_rect.x(),
move.window_rect.y());
}
gtk_plugin_container_set_size(widget,
move.window_rect.width(),
move.window_rect.height());
}
GtkWidget* GtkPluginContainerManager::MapIDToWidget(gfx::PluginWindowHandle id) {
PluginWindowToWidgetMap::const_iterator i =
plugin_window_to_widget_map_.find(id);
if (i != plugin_window_to_widget_map_.end())
return i->second;
LOG(ERROR) << "Request for widget host for unknown window id " << id;
return NULL;
}
gboolean GtkPluginContainerManager::UnrealizeCallback(GtkWidget* widget,
void* user_data) {
// This is the last chance to get the XID for the widget. Remove it from the
// map here.
GtkPluginContainerManager* plugin_container_manager =
static_cast<GtkPluginContainerManager*>(user_data);
gfx::PluginWindowHandle id = gtk_socket_get_id(GTK_SOCKET(widget));
plugin_container_manager->plugin_window_to_widget_map_.erase(id);
}
// 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.
#ifndef WEBKIT_GLUE_PLUGINS_GTK_PLUGIN_CONTAINER_MANAGER_H_
#define WEBKIT_GLUE_PLUGINS_GTK_PLUGIN_CONTAINER_MANAGER_H_
#include <gtk/gtk.h>
#include <map>
#include "base/gfx/native_widget_types.h"
typedef struct _GtkWidget GtkWidget;
struct WebPluginGeometry;
// Helper class that creates and manages plugin containers (GtkSocket).
class GtkPluginContainerManager {
public:
GtkPluginContainerManager() : host_widget_(NULL) { }
// Sets the widget that will host the plugin containers. Must be a GtkFixed.
void set_host_widget(GtkWidget *widget) { host_widget_ = widget; }
// Creates a new plugin container, returning its XID.
gfx::PluginWindowHandle CreatePluginContainer();
// Destroys a plugin container, given its XID.
void DestroyPluginContainer(gfx::PluginWindowHandle container);
// Takes an update from WebKit about a plugin's position and side and moves
// the plugin accordingly.
void MovePluginContainer(const WebPluginGeometry& move);
private:
// Maps a plugin container XID to the corresponding widget.
GtkWidget* MapIDToWidget(gfx::PluginWindowHandle id);
// Callback for when the plugin container loses its XID, so that it can be
// removed from plugin_window_to_widget_map_.
static gboolean UnrealizeCallback(GtkWidget *widget, void *user_data);
// Parent of the plugin containers.
GtkWidget* host_widget_;
// A map that associates plugin containers to their XID.
typedef std::map<gfx::PluginWindowHandle, GtkWidget*> PluginWindowToWidgetMap;
PluginWindowToWidgetMap plugin_window_to_widget_map_;
};
#endif // WEBKIT_GLUE_PLUGINS_GTK_PLUGIN_CONTAINER_MANAGER_H_
...@@ -266,6 +266,9 @@ bool WebPluginDelegateImpl::WindowedCreatePlugin() { ...@@ -266,6 +266,9 @@ bool WebPluginDelegateImpl::WindowedCreatePlugin() {
// Xembed plugins need a window created for them browser-side. // Xembed plugins need a window created for them browser-side.
// Do that now. // Do that now.
windowed_handle_ = plugin_->CreatePluginContainer(); windowed_handle_ = plugin_->CreatePluginContainer();
if (!windowed_handle_)
return false;
window_.window = reinterpret_cast<void*>(windowed_handle_); window_.window = reinterpret_cast<void*>(windowed_handle_);
if (!window_.ws_info) if (!window_.ws_info)
......
...@@ -58,7 +58,7 @@ WebPluginDelegateImpl* g_current_plugin_instance = NULL; ...@@ -58,7 +58,7 @@ WebPluginDelegateImpl* g_current_plugin_instance = NULL;
WebPluginDelegate* WebPluginDelegate::Create( WebPluginDelegate* WebPluginDelegate::Create(
const FilePath& filename, const FilePath& filename,
const std::string& mime_type, const std::string& mime_type,
gfx::NativeView containing_view) { gfx::PluginWindowHandle containing_view) {
scoped_refptr<NPAPI::PluginLib> plugin = scoped_refptr<NPAPI::PluginLib> plugin =
NPAPI::PluginLib::CreatePluginLib(filename); NPAPI::PluginLib::CreatePluginLib(filename);
if (plugin.get() == NULL) if (plugin.get() == NULL)
...@@ -73,27 +73,8 @@ WebPluginDelegate* WebPluginDelegate::Create( ...@@ -73,27 +73,8 @@ WebPluginDelegate* WebPluginDelegate::Create(
return new WebPluginDelegateImpl(containing_view, instance.get()); return new WebPluginDelegateImpl(containing_view, instance.get());
} }
bool WebPluginDelegateImpl::IsPluginDelegateWindow(gfx::NativeWindow window) {
return false;
}
bool WebPluginDelegateImpl::GetPluginNameFromWindow(
gfx::NativeWindow window, std::wstring *plugin_name) {
if (NULL == plugin_name) {
return false;
}
if (!IsPluginDelegateWindow(window)) {
return false;
}
return false;
}
bool WebPluginDelegateImpl::IsDummyActivationWindow(gfx::NativeWindow window) {
return false;
}
WebPluginDelegateImpl::WebPluginDelegateImpl( WebPluginDelegateImpl::WebPluginDelegateImpl(
gfx::NativeView containing_view, gfx::PluginWindowHandle containing_view,
NPAPI::PluginInstance *instance) NPAPI::PluginInstance *instance)
: parent_(containing_view), : parent_(containing_view),
instance_(instance), instance_(instance),
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "webkit/glue/webplugin.h" #include "webkit/glue/webplugin.h"
#include "webkit/glue/webkit_glue.h" #include "webkit/glue/webkit_glue.h"
#include "webkit/glue/webview.h" #include "webkit/glue/webview.h"
#include "webkit/glue/plugins/gtk_plugin_container.h" #include "webkit/glue/plugins/gtk_plugin_container_manager.h"
#include "webkit/glue/plugins/plugin_list.h" #include "webkit/glue/plugins/plugin_list.h"
#include "webkit/glue/window_open_disposition.h" #include "webkit/glue/window_open_disposition.h"
#include "webkit/glue/plugins/webplugin_delegate_impl.h" #include "webkit/glue/plugins/webplugin_delegate_impl.h"
...@@ -230,61 +230,9 @@ void TestWebViewDelegate::GetRootWindowResizerRect(WebWidget* webwidget, ...@@ -230,61 +230,9 @@ void TestWebViewDelegate::GetRootWindowResizerRect(WebWidget* webwidget,
void TestWebViewDelegate::DidMove(WebWidget* webwidget, void TestWebViewDelegate::DidMove(WebWidget* webwidget,
const WebPluginGeometry& move) { const WebPluginGeometry& move) {
WebWidgetHost* host = GetHostForWidget(webwidget); WebWidgetHost* host = GetHostForWidget(webwidget);
GtkPluginContainerManager* plugin_container_manager =
// The "window" on WebPluginGeometry is actually the XEmbed parent static_cast<WebViewHost*>(host)->plugin_container_manager();
// X window id. plugin_container_manager->MovePluginContainer(move);
GtkWidget* widget = ((WebViewHost*)host)->MapIDToWidget(move.window);
// If we don't know about this plugin (maybe we're shutting down the
// window?), ignore the message.
if (!widget)
return;
DCHECK(!GTK_WIDGET_NO_WINDOW(widget));
DCHECK(GTK_WIDGET_REALIZED(widget));
if (!move.visible) {
gtk_widget_hide(widget);
return;
} else {
gtk_widget_show(widget);
}
// Update the clipping region on the GdkWindow.
GdkRectangle clip_rect = move.clip_rect.ToGdkRectangle();
GdkRegion* clip_region = gdk_region_rectangle(&clip_rect);
gfx::SubtractRectanglesFromRegion(clip_region, move.cutout_rects);
gdk_window_shape_combine_region(widget->window, clip_region, 0, 0);
gdk_region_destroy(clip_region);
// Update the window position. Resizing is handled by WebPluginDelegate.
// TODO(deanm): Verify that we only need to move and not resize.
// TODO(evanm): we should cache the last shape and position and skip all
// of this business in the common case where nothing has changed.
int current_x, current_y;
// Until the above TODO is resolved, we can grab the last position
// off of the GtkFixed with a bit of hackery.
GValue value = {0};
g_value_init(&value, G_TYPE_INT);
gtk_container_child_get_property(GTK_CONTAINER(host->view_handle()), widget,
"x", &value);
current_x = g_value_get_int(&value);
gtk_container_child_get_property(GTK_CONTAINER(host->view_handle()), widget,
"y", &value);
current_y = g_value_get_int(&value);
g_value_unset(&value);
if (move.window_rect.x() != current_x || move.window_rect.y() != current_y) {
// Calling gtk_fixed_move unnecessarily is a no-no, as it causes the parent
// window to repaint!
gtk_fixed_move(GTK_FIXED(host->view_handle()),
widget,
move.window_rect.x(),
move.window_rect.y());
}
gtk_plugin_container_set_size(widget,
move.window_rect.width(),
move.window_rect.height());
} }
void TestWebViewDelegate::RunModal(WebWidget* webwidget) { void TestWebViewDelegate::RunModal(WebWidget* webwidget) {
......
...@@ -11,15 +11,14 @@ ...@@ -11,15 +11,14 @@
#include "base/gfx/native_widget_types.h" #include "base/gfx/native_widget_types.h"
#include "base/gfx/rect.h" #include "base/gfx/rect.h"
#include "webkit/tools/test_shell/webwidget_host.h" #include "webkit/tools/test_shell/webwidget_host.h"
#if defined(OS_LINUX)
#include "webkit/glue/plugins/gtk_plugin_container_manager.h"
#endif
struct WebPreferences; struct WebPreferences;
class WebView; class WebView;
class WebViewDelegate; class WebViewDelegate;
#if defined(OS_LINUX)
typedef struct _GtkSocket GtkSocket;
#endif
// This class is a simple NativeView-based host for a WebView // This class is a simple NativeView-based host for a WebView
class WebViewHost : public WebWidgetHost { class WebViewHost : public WebWidgetHost {
public: public:
...@@ -37,13 +36,12 @@ class WebViewHost : public WebWidgetHost { ...@@ -37,13 +36,12 @@ class WebViewHost : public WebWidgetHost {
// embedders to use. // embedders to use.
GdkNativeWindow CreatePluginContainer(); GdkNativeWindow CreatePluginContainer();
// Map a GdkNativeWindow returned by CreatePluginContainer() back to
// the GtkWidget hosting it. Used when we get a message back from the
// renderer indicating a plugin needs to move.
GtkWidget* MapIDToWidget(GdkNativeWindow id);
// Called when a plugin has been destroyed. Lets us clean up our side. // Called when a plugin has been destroyed. Lets us clean up our side.
void OnPluginWindowDestroyed(GdkNativeWindow id); void OnPluginWindowDestroyed(GdkNativeWindow id);
GtkPluginContainerManager* plugin_container_manager() {
return &plugin_container_manager_;
}
#endif #endif
protected: protected:
...@@ -54,16 +52,8 @@ class WebViewHost : public WebWidgetHost { ...@@ -54,16 +52,8 @@ class WebViewHost : public WebWidgetHost {
#endif #endif
#if defined(OS_LINUX) #if defined(OS_LINUX)
// A map used for MapIDToWidget() above. // Helper class that creates and moves plugin containers.
typedef std::map<GdkNativeWindow, GtkWidget*> NativeWindowToWidgetMap; GtkPluginContainerManager plugin_container_manager_;
NativeWindowToWidgetMap native_window_to_widget_map_;
// Callback for when one of our plugins goes away.
static gboolean OnPlugRemovedThunk(GtkSocket* socket,
WebViewHost* web_view_host) {
return web_view_host->OnPlugRemoved(socket);
}
gboolean OnPlugRemoved(GtkSocket* socket);
#endif #endif
}; };
......
...@@ -20,6 +20,7 @@ WebViewHost* WebViewHost::Create(GtkWidget* parent_view, ...@@ -20,6 +20,7 @@ WebViewHost* WebViewHost::Create(GtkWidget* parent_view,
WebViewHost* host = new WebViewHost(); WebViewHost* host = new WebViewHost();
host->view_ = WebWidgetHost::CreateWidget(parent_view, host); host->view_ = WebWidgetHost::CreateWidget(parent_view, host);
host->plugin_container_manager_.set_host_widget(host->view_);
g_object_set_data(G_OBJECT(host->view_), "webwidgethost", host); g_object_set_data(G_OBJECT(host->view_), "webwidgethost", host);
host->webwidget_ = WebView::Create(delegate, prefs); host->webwidget_ = WebView::Create(delegate, prefs);
...@@ -33,41 +34,9 @@ WebView* WebViewHost::webview() const { ...@@ -33,41 +34,9 @@ WebView* WebViewHost::webview() const {
} }
GdkNativeWindow WebViewHost::CreatePluginContainer() { GdkNativeWindow WebViewHost::CreatePluginContainer() {
GtkWidget* plugin_container = gtk_plugin_container_new(); return plugin_container_manager_.CreatePluginContainer();
g_signal_connect(G_OBJECT(plugin_container), "plug-removed",
G_CALLBACK(OnPlugRemovedThunk), this);
gtk_container_add(GTK_CONTAINER(view_handle()), plugin_container);
gtk_widget_show(plugin_container);
gtk_widget_realize(plugin_container);
GdkNativeWindow id = gtk_socket_get_id(GTK_SOCKET(plugin_container));
native_window_to_widget_map_.insert(std::make_pair(id, plugin_container));
return id;
}
GtkWidget* WebViewHost::MapIDToWidget(GdkNativeWindow id) {
NativeWindowToWidgetMap::const_iterator i =
native_window_to_widget_map_.find(id);
if (i != native_window_to_widget_map_.end())
return i->second;
LOG(ERROR) << "Request for widget host for unknown window id " << id;
return NULL;
} }
void WebViewHost::OnPluginWindowDestroyed(GdkNativeWindow id) { void WebViewHost::OnPluginWindowDestroyed(GdkNativeWindow id) {
GtkWidget* plugin_container = MapIDToWidget(id); plugin_container_manager_.DestroyPluginContainer(id);
if (!plugin_container)
return;
native_window_to_widget_map_.erase(id);
gtk_widget_destroy(plugin_container);
} }
gboolean WebViewHost::OnPlugRemoved(GtkSocket* socket) {
return TRUE; // Don't destroy our widget; we manage it ourselves.
}
...@@ -4469,6 +4469,8 @@ ...@@ -4469,6 +4469,8 @@
'glue/plugins/nphostapi.h', 'glue/plugins/nphostapi.h',
'glue/plugins/gtk_plugin_container.h', 'glue/plugins/gtk_plugin_container.h',
'glue/plugins/gtk_plugin_container.cc', 'glue/plugins/gtk_plugin_container.cc',
'glue/plugins/gtk_plugin_container_manager.h',
'glue/plugins/gtk_plugin_container_manager.cc',
'glue/plugins/plugin_constants_win.h', 'glue/plugins/plugin_constants_win.h',
'glue/plugins/plugin_host.cc', 'glue/plugins/plugin_host.cc',
'glue/plugins/plugin_host.h', 'glue/plugins/plugin_host.h',
...@@ -4659,7 +4661,7 @@ ...@@ -4659,7 +4661,7 @@
], ],
}, { # else: OS!="linux" }, { # else: OS!="linux"
'sources/': [['exclude', '_(linux|gtk)(_data)?\\.cc$'], 'sources/': [['exclude', '_(linux|gtk)(_data)?\\.cc$'],
['exclude', r'gtk_plugin_container\.(cc|h)']], ['exclude', r'/gtk_']],
}], }],
['OS!="mac"', { ['OS!="mac"', {
'sources/': [['exclude', '_mac\\.(cc|mm)$']] 'sources/': [['exclude', '_mac\\.(cc|mm)$']]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment