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<> |
11 #endif | 11 #endif |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/base_switches.h" | 15 #include "base/base_switches.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
| 19 #include "base/lazy_instance.h" |
19 #include "base/logging.h" | 20 #include "base/logging.h" |
20 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
21 #include "base/path_service.h" | 22 #include "base/path_service.h" |
22 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
23 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/synchronization/lock.h" |
25 #include "content/browser/browser_child_process_host_impl.h" | 27 #include "content/browser/browser_child_process_host_impl.h" |
26 #include "content/browser/loader/resource_message_filter.h" | 28 #include "content/browser/loader/resource_message_filter.h" |
27 #include "content/browser/gpu/gpu_data_manager_impl.h" | 29 #include "content/browser/gpu/gpu_data_manager_impl.h" |
28 #include "content/browser/plugin_service_impl.h" | 30 #include "content/browser/plugin_service_impl.h" |
29 #include "content/common/child_process_host_impl.h" | 31 #include "content/common/child_process_host_impl.h" |
30 #include "content/common/plugin_process_messages.h" | 32 #include "content/common/plugin_process_messages.h" |
31 #include "content/common/resource_messages.h" | 33 #include "content/common/resource_messages.h" |
32 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/content_browser_client.h" | 35 #include "content/public/browser/content_browser_client.h" |
34 #include "content/public/browser/notification_types.h" | 36 #include "content/public/browser/notification_types.h" |
(...skipping 14 matching lines...) Expand all Loading... |
49 #include "ui/gfx/rect.h" | 51 #include "ui/gfx/rect.h" |
50 #endif | 52 #endif |
51 | 53 |
52 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
53 #include "base/win/windows_version.h" | 55 #include "base/win/windows_version.h" |
54 #include "content/common/plugin_constants_win.h" | 56 #include "content/common/plugin_constants_win.h" |
55 #endif | 57 #endif |
56 | 58 |
57 namespace content { | 59 namespace content { |
58 | 60 |
| 61 namespace { |
| 62 |
| 63 base::LazyInstance<std::map<base::ProcessId, WebPluginInfo> > |
| 64 g_process_webplugin_info = LAZY_INSTANCE_INITIALIZER; |
| 65 base::LazyInstance<base::Lock>::Leaky |
| 66 g_process_webplugin_info_lock = LAZY_INSTANCE_INITIALIZER; |
| 67 } |
| 68 |
| 69 bool PluginProcessHost::GetWebPluginInfoFromPluginPid(base::ProcessId pid, |
| 70 WebPluginInfo* info) { |
| 71 base::AutoLock lock(g_process_webplugin_info_lock.Get()); |
| 72 if (!g_process_webplugin_info.Get().count(pid)) |
| 73 return false; |
| 74 |
| 75 *info = g_process_webplugin_info.Get()[pid]; |
| 76 return true; |
| 77 } |
| 78 |
59 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
60 void PluginProcessHost::OnPluginWindowDestroyed(HWND window, HWND parent) { | 80 void PluginProcessHost::OnPluginWindowDestroyed(HWND window, HWND parent) { |
61 // The window is destroyed at this point, we just care about its parent, which | 81 // The window is destroyed at this point, we just care about its parent, which |
62 // is the intermediate window we created. | 82 // is the intermediate window we created. |
63 std::set<HWND>::iterator window_index = | 83 std::set<HWND>::iterator window_index = |
64 plugin_parent_windows_set_.find(parent); | 84 plugin_parent_windows_set_.find(parent); |
65 if (window_index == plugin_parent_windows_set_.end()) | 85 if (window_index == plugin_parent_windows_set_.end()) |
66 return; | 86 return; |
67 | 87 |
68 plugin_parent_windows_set_.erase(window_index); | 88 plugin_parent_windows_set_.erase(window_index); |
(...skipping 30 matching lines...) Expand all Loading... |
99 | 119 |
100 private: | 120 private: |
101 #if defined(OS_POSIX) | 121 #if defined(OS_POSIX) |
102 int ipc_fd_; | 122 int ipc_fd_; |
103 #endif // OS_POSIX | 123 #endif // OS_POSIX |
104 | 124 |
105 DISALLOW_COPY_AND_ASSIGN(PluginSandboxedProcessLauncherDelegate); | 125 DISALLOW_COPY_AND_ASSIGN(PluginSandboxedProcessLauncherDelegate); |
106 }; | 126 }; |
107 | 127 |
108 PluginProcessHost::PluginProcessHost() | 128 PluginProcessHost::PluginProcessHost() |
| 129 : pid_(base::kNullProcessId) |
109 #if defined(OS_MACOSX) | 130 #if defined(OS_MACOSX) |
110 : plugin_cursor_visible_(true) | 131 , plugin_cursor_visible_(true) |
111 #endif | 132 #endif |
112 { | 133 { |
113 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_PLUGIN, this)); | 134 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_PLUGIN, this)); |
114 } | 135 } |
115 | 136 |
116 PluginProcessHost::~PluginProcessHost() { | 137 PluginProcessHost::~PluginProcessHost() { |
117 #if defined(OS_WIN) | 138 #if defined(OS_WIN) |
118 // We erase HWNDs from the plugin_parent_windows_set_ when we receive a | 139 // We erase HWNDs from the plugin_parent_windows_set_ when we receive a |
119 // notification that the window is being destroyed. If we don't receive this | 140 // notification that the window is being destroyed. If we don't receive this |
120 // notification and the PluginProcessHost instance is being destroyed, it | 141 // notification and the PluginProcessHost instance is being destroyed, it |
(...skipping 16 matching lines...) Expand all Loading... |
137 base::mac::kFullScreenModeHideAll)); | 158 base::mac::kFullScreenModeHideAll)); |
138 } | 159 } |
139 // If the plugin hid the cursor, reset that. | 160 // If the plugin hid the cursor, reset that. |
140 if (!plugin_cursor_visible_) { | 161 if (!plugin_cursor_visible_) { |
141 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 162 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
142 base::Bind(base::mac::SetCursorVisibility, true)); | 163 base::Bind(base::mac::SetCursorVisibility, true)); |
143 } | 164 } |
144 #endif | 165 #endif |
145 // Cancel all pending and sent requests. | 166 // Cancel all pending and sent requests. |
146 CancelRequests(); | 167 CancelRequests(); |
| 168 |
| 169 { |
| 170 base::AutoLock lock(g_process_webplugin_info_lock.Get()); |
| 171 g_process_webplugin_info.Get()[pid_] = info_; |
| 172 } |
147 } | 173 } |
148 | 174 |
149 bool PluginProcessHost::Send(IPC::Message* message) { | 175 bool PluginProcessHost::Send(IPC::Message* message) { |
150 return process_->Send(message); | 176 return process_->Send(message); |
151 } | 177 } |
152 | 178 |
153 bool PluginProcessHost::Init(const WebPluginInfo& info) { | 179 bool PluginProcessHost::Init(const WebPluginInfo& info) { |
154 info_ = info; | 180 info_ = info; |
155 process_->SetName(info_.name); | 181 process_->SetName(info_.name); |
156 | 182 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 303 |
278 return handled; | 304 return handled; |
279 } | 305 } |
280 | 306 |
281 void PluginProcessHost::OnChannelConnected(int32 peer_pid) { | 307 void PluginProcessHost::OnChannelConnected(int32 peer_pid) { |
282 for (size_t i = 0; i < pending_requests_.size(); ++i) { | 308 for (size_t i = 0; i < pending_requests_.size(); ++i) { |
283 RequestPluginChannel(pending_requests_[i]); | 309 RequestPluginChannel(pending_requests_[i]); |
284 } | 310 } |
285 | 311 |
286 pending_requests_.clear(); | 312 pending_requests_.clear(); |
| 313 |
| 314 pid_ = peer_pid; |
| 315 { |
| 316 base::AutoLock lock(g_process_webplugin_info_lock.Get()); |
| 317 g_process_webplugin_info.Get()[pid_] = info_; |
| 318 } |
287 } | 319 } |
288 | 320 |
289 void PluginProcessHost::OnChannelError() { | 321 void PluginProcessHost::OnChannelError() { |
290 CancelRequests(); | 322 CancelRequests(); |
291 } | 323 } |
292 | 324 |
293 bool PluginProcessHost::CanShutdown() { | 325 bool PluginProcessHost::CanShutdown() { |
294 return sent_requests_.empty(); | 326 return sent_requests_.empty(); |
295 } | 327 } |
296 | 328 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 | 429 |
398 void PluginProcessHost::GetContexts(const ResourceHostMsg_Request& request, | 430 void PluginProcessHost::GetContexts(const ResourceHostMsg_Request& request, |
399 ResourceContext** resource_context, | 431 ResourceContext** resource_context, |
400 net::URLRequestContext** request_context) { | 432 net::URLRequestContext** request_context) { |
401 *resource_context = | 433 *resource_context = |
402 resource_context_map_[request.origin_pid].resource_context; | 434 resource_context_map_[request.origin_pid].resource_context; |
403 *request_context = (*resource_context)->GetRequestContext(); | 435 *request_context = (*resource_context)->GetRequestContext(); |
404 } | 436 } |
405 | 437 |
406 } // namespace content | 438 } // namespace content |
OLD | NEW |