OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 <Carbon/Carbon.h> | 5 #include <Carbon/Carbon.h> |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "base/bind.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
13 #include "content/browser/plugin_process_host.h" | 14 #include "content/browser/plugin_process_host.h" |
14 #include "content/common/plugin_messages.h" | 15 #include "content/common/plugin_messages.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
17 | 18 |
18 using content::BrowserThread; | 19 using content::BrowserThread; |
19 | 20 |
20 void PluginProcessHost::OnPluginSelectWindow(uint32 window_id, | 21 void PluginProcessHost::OnPluginSelectWindow(uint32 window_id, |
(...skipping 16 matching lines...) Expand all Loading... |
37 }; | 38 }; |
38 CGRect main_display_bounds = CGDisplayBounds(CGMainDisplayID()); | 39 CGRect main_display_bounds = CGDisplayBounds(CGMainDisplayID()); |
39 if (CGRectEqualToRect(window_bounds, main_display_bounds) && | 40 if (CGRectEqualToRect(window_bounds, main_display_bounds) && |
40 (plugin_fullscreen_windows_set_.find(window_id) == | 41 (plugin_fullscreen_windows_set_.find(window_id) == |
41 plugin_fullscreen_windows_set_.end())) { | 42 plugin_fullscreen_windows_set_.end())) { |
42 plugin_fullscreen_windows_set_.insert(window_id); | 43 plugin_fullscreen_windows_set_.insert(window_id); |
43 // If the plugin has just shown a window that's the same dimensions as | 44 // If the plugin has just shown a window that's the same dimensions as |
44 // the main display, hide the menubar so that it has the whole screen. | 45 // the main display, hide the menubar so that it has the whole screen. |
45 // (but only if we haven't already seen this fullscreen window, since | 46 // (but only if we haven't already seen this fullscreen window, since |
46 // otherwise our refcounting can get skewed). | 47 // otherwise our refcounting can get skewed). |
47 BrowserThread::PostTask( | 48 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
48 BrowserThread::UI, FROM_HERE, | 49 base::Bind(base::mac::RequestFullScreen, |
49 NewRunnableFunction(base::mac::RequestFullScreen, | 50 base::mac::kFullScreenModeHideAll)); |
50 base::mac::kFullScreenModeHideAll)); | |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 // Must be called on the UI thread. | 54 // Must be called on the UI thread. |
55 // If plugin_pid is -1, the browser will be the active process on return, | 55 // If plugin_pid is -1, the browser will be the active process on return, |
56 // otherwise that process will be given focus back before this function returns. | 56 // otherwise that process will be given focus back before this function returns. |
57 static void ReleasePluginFullScreen(pid_t plugin_pid) { | 57 static void ReleasePluginFullScreen(pid_t plugin_pid) { |
58 // Releasing full screen only works if we are the frontmost process; grab | 58 // Releasing full screen only works if we are the frontmost process; grab |
59 // focus, but give it back to the plugin process if requested. | 59 // focus, but give it back to the plugin process if requested. |
60 base::mac::ActivateProcess(base::GetCurrentProcId()); | 60 base::mac::ActivateProcess(base::GetCurrentProcId()); |
61 base::mac::ReleaseFullScreen(base::mac::kFullScreenModeHideAll); | 61 base::mac::ReleaseFullScreen(base::mac::kFullScreenModeHideAll); |
62 if (plugin_pid != -1) { | 62 if (plugin_pid != -1) { |
63 base::mac::ActivateProcess(plugin_pid); | 63 base::mac::ActivateProcess(plugin_pid); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 void PluginProcessHost::OnPluginHideWindow(uint32 window_id, | 67 void PluginProcessHost::OnPluginHideWindow(uint32 window_id, |
68 gfx::Rect window_rect) { | 68 gfx::Rect window_rect) { |
69 bool had_windows = !plugin_visible_windows_set_.empty(); | 69 bool had_windows = !plugin_visible_windows_set_.empty(); |
70 plugin_visible_windows_set_.erase(window_id); | 70 plugin_visible_windows_set_.erase(window_id); |
71 bool browser_needs_activation = had_windows && | 71 bool browser_needs_activation = had_windows && |
72 plugin_visible_windows_set_.empty(); | 72 plugin_visible_windows_set_.empty(); |
73 | 73 |
74 plugin_modal_windows_set_.erase(window_id); | 74 plugin_modal_windows_set_.erase(window_id); |
75 if (plugin_fullscreen_windows_set_.find(window_id) != | 75 if (plugin_fullscreen_windows_set_.find(window_id) != |
76 plugin_fullscreen_windows_set_.end()) { | 76 plugin_fullscreen_windows_set_.end()) { |
77 plugin_fullscreen_windows_set_.erase(window_id); | 77 plugin_fullscreen_windows_set_.erase(window_id); |
78 pid_t plugin_pid = browser_needs_activation ? -1 : handle(); | 78 pid_t plugin_pid = browser_needs_activation ? -1 : handle(); |
79 browser_needs_activation = false; | 79 browser_needs_activation = false; |
80 BrowserThread::PostTask( | 80 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
81 BrowserThread::UI, FROM_HERE, | 81 base::Bind(ReleasePluginFullScreen, plugin_pid)); |
82 NewRunnableFunction(ReleasePluginFullScreen, plugin_pid)); | |
83 } | 82 } |
84 | 83 |
85 if (browser_needs_activation) { | 84 if (browser_needs_activation) { |
86 BrowserThread::PostTask( | 85 BrowserThread::PostTask( |
87 BrowserThread::UI, FROM_HERE, | 86 BrowserThread::UI, FROM_HERE, |
88 NewRunnableFunction(base::mac::ActivateProcess, | 87 base::Bind(base::mac::ActivateProcess, base::GetCurrentProcId())); |
89 base::GetCurrentProcId())); | |
90 } | 88 } |
91 } | 89 } |
92 | 90 |
93 void PluginProcessHost::OnAppActivation() { | 91 void PluginProcessHost::OnAppActivation() { |
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
95 | 93 |
96 // If our plugin process has any modal windows up, we need to bring it forward | 94 // If our plugin process has any modal windows up, we need to bring it forward |
97 // so that they act more like an in-process modal window would. | 95 // so that they act more like an in-process modal window would. |
98 if (!plugin_modal_windows_set_.empty()) { | 96 if (!plugin_modal_windows_set_.empty()) { |
99 BrowserThread::PostTask( | 97 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
100 BrowserThread::UI, FROM_HERE, | 98 base::Bind(base::mac::ActivateProcess, handle())); |
101 NewRunnableFunction(base::mac::ActivateProcess, handle())); | |
102 } | 99 } |
103 } | 100 } |
104 | 101 |
105 void PluginProcessHost::OnPluginSetCursorVisibility(bool visible) { | 102 void PluginProcessHost::OnPluginSetCursorVisibility(bool visible) { |
106 if (plugin_cursor_visible_ != visible) { | 103 if (plugin_cursor_visible_ != visible) { |
107 plugin_cursor_visible_ = visible; | 104 plugin_cursor_visible_ = visible; |
108 BrowserThread::PostTask( | 105 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
109 BrowserThread::UI, FROM_HERE, | 106 base::Bind(base::mac::SetCursorVisibility, |
110 NewRunnableFunction(base::mac::SetCursorVisibility, | 107 visible)); |
111 visible)); | |
112 } | 108 } |
113 } | 109 } |
OLD | NEW |