[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 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 | |
| 7 | #include "build/build_config.h" |
| 8 | |
| 9 | #include <vector> |
| 10 | |
[email protected] | 8075105 | 2011-11-12 17:10:58 | [diff] [blame] | 11 | #include "base/bind.h" |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 12 | #include "base/logging.h" |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 13 | #include "base/mac/mac_util.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 14 | #include "content/browser/plugin_process_host.h" |
[email protected] | 105303e | 2011-03-14 22:16:10 | [diff] [blame] | 15 | #include "content/common/plugin_messages.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 16 | #include "content/public/browser/browser_thread.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 17 | #include "ui/gfx/rect.h" |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 18 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 19 | using content::BrowserThread; |
| 20 | |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 21 | void PluginProcessHost::OnPluginSelectWindow(uint32 window_id, |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 22 | gfx::Rect window_rect, |
| 23 | bool modal) { |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 24 | plugin_visible_windows_set_.insert(window_id); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 25 | if (modal) |
| 26 | plugin_modal_windows_set_.insert(window_id); |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void PluginProcessHost::OnPluginShowWindow(uint32 window_id, |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 30 | gfx::Rect window_rect, |
| 31 | bool modal) { |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 32 | plugin_visible_windows_set_.insert(window_id); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 33 | if (modal) |
| 34 | plugin_modal_windows_set_.insert(window_id); |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 35 | CGRect window_bounds = { |
| 36 | { window_rect.x(), window_rect.y() }, |
| 37 | { window_rect.width(), window_rect.height() } |
| 38 | }; |
| 39 | CGRect main_display_bounds = CGDisplayBounds(CGMainDisplayID()); |
[email protected] | a3d46f7 | 2009-11-18 03:14:20 | [diff] [blame] | 40 | if (CGRectEqualToRect(window_bounds, main_display_bounds) && |
| 41 | (plugin_fullscreen_windows_set_.find(window_id) == |
| 42 | plugin_fullscreen_windows_set_.end())) { |
[email protected] | b44dbd1 | 2009-10-11 19:02:15 | [diff] [blame] | 43 | plugin_fullscreen_windows_set_.insert(window_id); |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 44 | // If the plugin has just shown a window that's the same dimensions as |
| 45 | // the main display, hide the menubar so that it has the whole screen. |
[email protected] | a3d46f7 | 2009-11-18 03:14:20 | [diff] [blame] | 46 | // (but only if we haven't already seen this fullscreen window, since |
| 47 | // otherwise our refcounting can get skewed). |
[email protected] | 8075105 | 2011-11-12 17:10:58 | [diff] [blame] | 48 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 49 | base::Bind(base::mac::RequestFullScreen, |
| 50 | base::mac::kFullScreenModeHideAll)); |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | |
[email protected] | 1289b98a | 2009-12-08 19:41:08 | [diff] [blame] | 54 | // Must be called on the UI thread. |
| 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. |
| 57 | static void ReleasePluginFullScreen(pid_t plugin_pid) { |
| 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. |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 60 | base::mac::ActivateProcess(base::GetCurrentProcId()); |
| 61 | base::mac::ReleaseFullScreen(base::mac::kFullScreenModeHideAll); |
[email protected] | 1289b98a | 2009-12-08 19:41:08 | [diff] [blame] | 62 | if (plugin_pid != -1) { |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 63 | base::mac::ActivateProcess(plugin_pid); |
[email protected] | 1289b98a | 2009-12-08 19:41:08 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 67 | void PluginProcessHost::OnPluginHideWindow(uint32 window_id, |
| 68 | gfx::Rect window_rect) { |
[email protected] | 1289b98a | 2009-12-08 19:41:08 | [diff] [blame] | 69 | bool had_windows = !plugin_visible_windows_set_.empty(); |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 70 | plugin_visible_windows_set_.erase(window_id); |
[email protected] | 1289b98a | 2009-12-08 19:41:08 | [diff] [blame] | 71 | bool browser_needs_activation = had_windows && |
| 72 | plugin_visible_windows_set_.empty(); |
| 73 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 74 | plugin_modal_windows_set_.erase(window_id); |
[email protected] | b44dbd1 | 2009-10-11 19:02:15 | [diff] [blame] | 75 | if (plugin_fullscreen_windows_set_.find(window_id) != |
| 76 | plugin_fullscreen_windows_set_.end()) { |
| 77 | plugin_fullscreen_windows_set_.erase(window_id); |
[email protected] | 1289b98a | 2009-12-08 19:41:08 | [diff] [blame] | 78 | pid_t plugin_pid = browser_needs_activation ? -1 : handle(); |
| 79 | browser_needs_activation = false; |
[email protected] | 8075105 | 2011-11-12 17:10:58 | [diff] [blame] | 80 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 81 | base::Bind(ReleasePluginFullScreen, plugin_pid)); |
[email protected] | b44dbd1 | 2009-10-11 19:02:15 | [diff] [blame] | 82 | } |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 83 | |
[email protected] | 1289b98a | 2009-12-08 19:41:08 | [diff] [blame] | 84 | if (browser_needs_activation) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 85 | BrowserThread::PostTask( |
| 86 | BrowserThread::UI, FROM_HERE, |
[email protected] | 8075105 | 2011-11-12 17:10:58 | [diff] [blame] | 87 | base::Bind(base::mac::ActivateProcess, base::GetCurrentProcId())); |
[email protected] | 1289b98a | 2009-12-08 19:41:08 | [diff] [blame] | 88 | } |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 89 | } |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 90 | |
| 91 | void PluginProcessHost::OnAppActivation() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 92 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 93 | |
| 94 | // If our plugin process has any modal windows up, we need to bring it forward |
| 95 | // so that they act more like an in-process modal window would. |
| 96 | if (!plugin_modal_windows_set_.empty()) { |
[email protected] | 8075105 | 2011-11-12 17:10:58 | [diff] [blame] | 97 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 98 | base::Bind(base::mac::ActivateProcess, handle())); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 99 | } |
| 100 | } |
[email protected] | 27f5a6c8 | 2009-11-20 18:26:16 | [diff] [blame] | 101 | |
[email protected] | 18db4618 | 2010-02-02 17:04:55 | [diff] [blame] | 102 | void PluginProcessHost::OnPluginSetCursorVisibility(bool visible) { |
| 103 | if (plugin_cursor_visible_ != visible) { |
| 104 | plugin_cursor_visible_ = visible; |
[email protected] | 8075105 | 2011-11-12 17:10:58 | [diff] [blame] | 105 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 106 | base::Bind(base::mac::SetCursorVisibility, |
| 107 | visible)); |
[email protected] | 18db4618 | 2010-02-02 17:04:55 | [diff] [blame] | 108 | } |
| 109 | } |