OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/plugin_process_host.h" | 5 #include "content/browser/plugin_process_host.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
10 #include <utility> // for pair<> | 10 #include <utility> // for pair<> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "base/mac/mac_util.h" | 51 #include "base/mac/mac_util.h" |
52 #include "content/common/plugin_carbon_interpose_constants_mac.h" | 52 #include "content/common/plugin_carbon_interpose_constants_mac.h" |
53 #include "ui/gfx/rect.h" | 53 #include "ui/gfx/rect.h" |
54 #endif | 54 #endif |
55 | 55 |
56 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
57 #include "base/win/windows_version.h" | 57 #include "base/win/windows_version.h" |
58 #include "webkit/plugins/npapi/plugin_constants_win.h" | 58 #include "webkit/plugins/npapi/plugin_constants_win.h" |
59 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" | 59 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
60 | 60 |
61 namespace { | |
62 | |
63 void ReparentPluginWindowHelper(HWND window, HWND parent) { | |
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
65 | |
66 int window_style = WS_CHILD; | |
67 if (!webkit::npapi::WebPluginDelegateImpl::IsDummyActivationWindow(window)) | |
68 window_style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS; | |
69 | |
70 ::SetWindowLongPtr(window, GWL_STYLE, window_style); | |
71 ::SetParent(window, parent); | |
72 // Allow the Flash plugin to forward some messages back to Chrome. | |
73 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | |
74 ::SetPropW(parent, webkit::npapi::kNativeWindowClassFilterProp, HANDLE(-1)); | |
75 } | |
76 | |
77 } // namespace | |
78 | |
79 void PluginProcessHost::OnPluginWindowDestroyed(HWND window, HWND parent) { | 61 void PluginProcessHost::OnPluginWindowDestroyed(HWND window, HWND parent) { |
80 // The window is destroyed at this point, we just care about its parent, which | 62 // The window is destroyed at this point, we just care about its parent, which |
81 // is the intermediate window we created. | 63 // is the intermediate window we created. |
82 std::set<HWND>::iterator window_index = | 64 std::set<HWND>::iterator window_index = |
83 plugin_parent_windows_set_.find(parent); | 65 plugin_parent_windows_set_.find(parent); |
84 if (window_index == plugin_parent_windows_set_.end()) | 66 if (window_index == plugin_parent_windows_set_.end()) |
85 return; | 67 return; |
86 | 68 |
87 plugin_parent_windows_set_.erase(window_index); | 69 plugin_parent_windows_set_.erase(window_index); |
88 PostMessage(parent, WM_CLOSE, 0, 0); | 70 PostMessage(parent, WM_CLOSE, 0, 0); |
89 } | 71 } |
90 | 72 |
91 void PluginProcessHost::AddWindow(HWND window) { | 73 void PluginProcessHost::AddWindow(HWND window) { |
92 plugin_parent_windows_set_.insert(window); | 74 plugin_parent_windows_set_.insert(window); |
93 } | 75 } |
94 | 76 |
95 void PluginProcessHost::OnReparentPluginWindow(HWND window, HWND parent) { | |
96 // Reparent only from the plugin process to our process. | |
97 DWORD process_id = 0; | |
98 ::GetWindowThreadProcessId(window, &process_id); | |
99 if (process_id != ::GetProcessId(process_->GetHandle())) | |
100 return; | |
101 ::GetWindowThreadProcessId(parent, &process_id); | |
102 if (process_id != ::GetCurrentProcessId()) | |
103 return; | |
104 | |
105 BrowserThread::PostTask( | |
106 BrowserThread::UI, FROM_HERE, | |
107 base::Bind(ReparentPluginWindowHelper, window, parent)); | |
108 } | |
109 | |
110 void PluginProcessHost::OnReportExecutableMemory(size_t size) { | |
111 // TODO(jschuh): move this into the plugin process once it supports UMA. | |
112 UMA_HISTOGRAM_MEMORY_KB("Plugin.ExecPageSizeKB", size / 1024); | |
113 } | |
114 #endif // defined(OS_WIN) | 77 #endif // defined(OS_WIN) |
115 | 78 |
116 #if defined(TOOLKIT_GTK) | 79 #if defined(TOOLKIT_GTK) |
117 void PluginProcessHost::OnMapNativeViewId(gfx::NativeViewId id, | 80 void PluginProcessHost::OnMapNativeViewId(gfx::NativeViewId id, |
118 gfx::PluginWindowHandle* output) { | 81 gfx::PluginWindowHandle* output) { |
119 *output = 0; | 82 *output = 0; |
120 #if !defined(USE_AURA) | 83 #if !defined(USE_AURA) |
121 GtkNativeViewManager::GetInstance()->GetXIDForId(output, id); | 84 GtkNativeViewManager::GetInstance()->GetXIDForId(output, id); |
122 #endif | 85 #endif |
123 } | 86 } |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 process_->GetHost()->AddFilter(filter); | 270 process_->GetHost()->AddFilter(filter); |
308 } | 271 } |
309 | 272 |
310 bool PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { | 273 bool PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { |
311 bool handled = true; | 274 bool handled = true; |
312 IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg) | 275 IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg) |
313 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated) | 276 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated) |
314 #if defined(OS_WIN) | 277 #if defined(OS_WIN) |
315 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed, | 278 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed, |
316 OnPluginWindowDestroyed) | 279 OnPluginWindowDestroyed) |
317 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ReparentPluginWindow, | |
318 OnReparentPluginWindow) | |
319 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ReportExecutableMemory, | |
320 OnReportExecutableMemory) | |
321 #endif | 280 #endif |
322 #if defined(TOOLKIT_GTK) | 281 #if defined(TOOLKIT_GTK) |
323 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_MapNativeViewId, | 282 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_MapNativeViewId, |
324 OnMapNativeViewId) | 283 OnMapNativeViewId) |
325 #endif | 284 #endif |
326 #if defined(OS_MACOSX) | 285 #if defined(OS_MACOSX) |
327 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginSelectWindow, | 286 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginSelectWindow, |
328 OnPluginSelectWindow) | 287 OnPluginSelectWindow) |
329 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginShowWindow, | 288 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginShowWindow, |
330 OnPluginShowWindow) | 289 OnPluginShowWindow) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 } | 406 } |
448 | 407 |
449 void PluginProcessHost::OnChannelCreated( | 408 void PluginProcessHost::OnChannelCreated( |
450 const IPC::ChannelHandle& channel_handle) { | 409 const IPC::ChannelHandle& channel_handle) { |
451 Client* client = sent_requests_.front(); | 410 Client* client = sent_requests_.front(); |
452 | 411 |
453 if (client) | 412 if (client) |
454 client->OnChannelOpened(channel_handle); | 413 client->OnChannelOpened(channel_handle); |
455 sent_requests_.pop_front(); | 414 sent_requests_.pop_front(); |
456 } | 415 } |
OLD | NEW |