| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 process_->GetHost()->AddFilter(filter); | 273 process_->GetHost()->AddFilter(filter); |
| 311 } | 274 } |
| 312 | 275 |
| 313 bool PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { | 276 bool PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { |
| 314 bool handled = true; | 277 bool handled = true; |
| 315 IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg) | 278 IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg) |
| 316 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated) | 279 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated) |
| 317 #if defined(OS_WIN) | 280 #if defined(OS_WIN) |
| 318 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed, | 281 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed, |
| 319 OnPluginWindowDestroyed) | 282 OnPluginWindowDestroyed) |
| 320 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ReparentPluginWindow, | |
| 321 OnReparentPluginWindow) | |
| 322 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ReportExecutableMemory, | |
| 323 OnReportExecutableMemory) | |
| 324 #endif | 283 #endif |
| 325 #if defined(TOOLKIT_GTK) | 284 #if defined(TOOLKIT_GTK) |
| 326 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_MapNativeViewId, | 285 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_MapNativeViewId, |
| 327 OnMapNativeViewId) | 286 OnMapNativeViewId) |
| 328 #endif | 287 #endif |
| 329 #if defined(OS_MACOSX) | 288 #if defined(OS_MACOSX) |
| 330 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginSelectWindow, | 289 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginSelectWindow, |
| 331 OnPluginSelectWindow) | 290 OnPluginSelectWindow) |
| 332 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginShowWindow, | 291 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginShowWindow, |
| 333 OnPluginShowWindow) | 292 OnPluginShowWindow) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 } | 409 } |
| 451 | 410 |
| 452 void PluginProcessHost::OnChannelCreated( | 411 void PluginProcessHost::OnChannelCreated( |
| 453 const IPC::ChannelHandle& channel_handle) { | 412 const IPC::ChannelHandle& channel_handle) { |
| 454 Client* client = sent_requests_.front(); | 413 Client* client = sent_requests_.front(); |
| 455 | 414 |
| 456 if (client) | 415 if (client) |
| 457 client->OnChannelOpened(channel_handle); | 416 client->OnChannelOpened(channel_handle); |
| 458 sent_requests_.pop_front(); | 417 sent_requests_.pop_front(); |
| 459 } | 418 } |
| OLD | NEW |