OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <Carbon/Carbon.h> | |
6 #include <stdint.h> | |
7 | |
8 #include "build/build_config.h" | |
9 | |
10 #include <vector> | |
11 | |
12 #include "base/bind.h" | |
13 #include "base/logging.h" | |
14 #include "base/mac/mac_util.h" | |
15 #include "content/browser/browser_child_process_host_impl.h" | |
16 #include "content/browser/plugin_process_host.h" | |
17 #include "content/public/browser/browser_thread.h" | |
18 #include "content/public/browser/child_process_data.h" | |
19 #include "ui/gfx/geometry/rect.h" | |
20 | |
21 namespace content { | |
22 | |
23 void PluginProcessHost::OnPluginShowWindow(uint32_t window_id, | |
24 gfx::Rect window_rect, | |
25 bool modal) { | |
26 plugin_visible_windows_set_.insert(window_id); | |
27 if (modal) | |
28 plugin_modal_windows_set_.insert(window_id); | |
29 CGRect window_bounds = { | |
30 { window_rect.x(), window_rect.y() }, | |
31 { window_rect.width(), window_rect.height() } | |
32 }; | |
33 CGRect main_display_bounds = CGDisplayBounds(CGMainDisplayID()); | |
34 if (CGRectEqualToRect(window_bounds, main_display_bounds) && | |
35 (plugin_fullscreen_windows_set_.find(window_id) == | |
36 plugin_fullscreen_windows_set_.end())) { | |
37 plugin_fullscreen_windows_set_.insert(window_id); | |
38 // If the plugin has just shown a window that's the same dimensions as | |
39 // the main display, hide the menubar so that it has the whole screen. | |
40 // (but only if we haven't already seen this fullscreen window, since | |
41 // otherwise our refcounting can get skewed). | |
42 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
43 base::Bind(base::mac::RequestFullScreen, | |
44 base::mac::kFullScreenModeHideAll)); | |
45 } | |
46 } | |
47 | |
48 // Must be called on the UI thread. | |
49 // If plugin_pid is -1, the browser will be the active process on return, | |
50 // otherwise that process will be given focus back before this function returns. | |
51 static void ReleasePluginFullScreen(pid_t plugin_pid) { | |
52 // Releasing full screen only works if we are the frontmost process; grab | |
53 // focus, but give it back to the plugin process if requested. | |
54 base::mac::ActivateProcess(base::GetCurrentProcId()); | |
55 base::mac::ReleaseFullScreen(base::mac::kFullScreenModeHideAll); | |
56 if (plugin_pid != -1) { | |
57 base::mac::ActivateProcess(plugin_pid); | |
58 } | |
59 } | |
60 | |
61 void PluginProcessHost::OnPluginHideWindow(uint32_t window_id, | |
62 gfx::Rect window_rect) { | |
63 bool had_windows = !plugin_visible_windows_set_.empty(); | |
64 plugin_visible_windows_set_.erase(window_id); | |
65 bool browser_needs_activation = had_windows && | |
66 plugin_visible_windows_set_.empty(); | |
67 | |
68 plugin_modal_windows_set_.erase(window_id); | |
69 if (plugin_fullscreen_windows_set_.find(window_id) != | |
70 plugin_fullscreen_windows_set_.end()) { | |
71 plugin_fullscreen_windows_set_.erase(window_id); | |
72 pid_t plugin_pid = | |
73 browser_needs_activation ? -1 : process_->GetData().handle; | |
74 browser_needs_activation = false; | |
75 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
76 base::Bind(ReleasePluginFullScreen, plugin_pid)); | |
77 } | |
78 | |
79 if (browser_needs_activation) { | |
80 BrowserThread::PostTask( | |
81 BrowserThread::UI, FROM_HERE, | |
82 base::Bind(base::mac::ActivateProcess, base::GetCurrentProcId())); | |
83 } | |
84 } | |
85 | |
86 void PluginProcessHost::OnAppActivation() { | |
87 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
88 | |
89 // If our plugin process has any modal windows up, we need to bring it forward | |
90 // so that they act more like an in-process modal window would. | |
91 if (!plugin_modal_windows_set_.empty()) { | |
92 BrowserThread::PostTask( | |
93 BrowserThread::UI, FROM_HERE, | |
94 base::Bind(base::mac::ActivateProcess, process_->GetData().handle)); | |
95 } | |
96 } | |
97 | |
98 void PluginProcessHost::OnPluginSetCursorVisibility(bool visible) { | |
99 if (plugin_cursor_visible_ != visible) { | |
100 plugin_cursor_visible_ = visible; | |
101 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
102 base::Bind(base::mac::SetCursorVisibility, | |
103 visible)); | |
104 } | |
105 } | |
106 | |
107 } // namespace content | |
OLD | NEW |