blob: 99e3e277b2b08b99b48f34b7f55e3b96486d1ba8 [file] [log] [blame]
[email protected]c38831a12011-10-28 12:44:491// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]1d5ac662009-10-01 19:41:562// 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]80751052011-11-12 17:10:5811#include "base/bind.h"
[email protected]1d5ac662009-10-01 19:41:5612#include "base/logging.h"
[email protected]0378bf42011-01-01 18:20:1413#include "base/mac/mac_util.h"
[email protected]a0421732011-02-23 03:55:4014#include "content/browser/plugin_process_host.h"
[email protected]105303e2011-03-14 22:16:1015#include "content/common/plugin_messages.h"
[email protected]c38831a12011-10-28 12:44:4916#include "content/public/browser/browser_thread.h"
[email protected]08397d52011-02-05 01:53:3817#include "ui/gfx/rect.h"
[email protected]1d5ac662009-10-01 19:41:5618
[email protected]631bb742011-11-02 11:29:3919using content::BrowserThread;
20
[email protected]1d5ac662009-10-01 19:41:5621void PluginProcessHost::OnPluginSelectWindow(uint32 window_id,
[email protected]a96ec6a2009-11-04 17:27:0822 gfx::Rect window_rect,
23 bool modal) {
[email protected]1d5ac662009-10-01 19:41:5624 plugin_visible_windows_set_.insert(window_id);
[email protected]a96ec6a2009-11-04 17:27:0825 if (modal)
26 plugin_modal_windows_set_.insert(window_id);
[email protected]1d5ac662009-10-01 19:41:5627}
28
29void PluginProcessHost::OnPluginShowWindow(uint32 window_id,
[email protected]a96ec6a2009-11-04 17:27:0830 gfx::Rect window_rect,
31 bool modal) {
[email protected]1d5ac662009-10-01 19:41:5632 plugin_visible_windows_set_.insert(window_id);
[email protected]a96ec6a2009-11-04 17:27:0833 if (modal)
34 plugin_modal_windows_set_.insert(window_id);
[email protected]1d5ac662009-10-01 19:41:5635 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]a3d46f72009-11-18 03:14:2040 if (CGRectEqualToRect(window_bounds, main_display_bounds) &&
41 (plugin_fullscreen_windows_set_.find(window_id) ==
42 plugin_fullscreen_windows_set_.end())) {
[email protected]b44dbd12009-10-11 19:02:1543 plugin_fullscreen_windows_set_.insert(window_id);
[email protected]1d5ac662009-10-01 19:41:5644 // 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]a3d46f72009-11-18 03:14:2046 // (but only if we haven't already seen this fullscreen window, since
47 // otherwise our refcounting can get skewed).
[email protected]80751052011-11-12 17:10:5848 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
49 base::Bind(base::mac::RequestFullScreen,
50 base::mac::kFullScreenModeHideAll));
[email protected]1d5ac662009-10-01 19:41:5651 }
52}
53
[email protected]1289b98a2009-12-08 19:41:0854// 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.
57static 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]0378bf42011-01-01 18:20:1460 base::mac::ActivateProcess(base::GetCurrentProcId());
61 base::mac::ReleaseFullScreen(base::mac::kFullScreenModeHideAll);
[email protected]1289b98a2009-12-08 19:41:0862 if (plugin_pid != -1) {
[email protected]0378bf42011-01-01 18:20:1463 base::mac::ActivateProcess(plugin_pid);
[email protected]1289b98a2009-12-08 19:41:0864 }
65}
66
[email protected]1d5ac662009-10-01 19:41:5667void PluginProcessHost::OnPluginHideWindow(uint32 window_id,
68 gfx::Rect window_rect) {
[email protected]1289b98a2009-12-08 19:41:0869 bool had_windows = !plugin_visible_windows_set_.empty();
[email protected]1d5ac662009-10-01 19:41:5670 plugin_visible_windows_set_.erase(window_id);
[email protected]1289b98a2009-12-08 19:41:0871 bool browser_needs_activation = had_windows &&
72 plugin_visible_windows_set_.empty();
73
[email protected]a96ec6a2009-11-04 17:27:0874 plugin_modal_windows_set_.erase(window_id);
[email protected]b44dbd12009-10-11 19:02:1575 if (plugin_fullscreen_windows_set_.find(window_id) !=
76 plugin_fullscreen_windows_set_.end()) {
77 plugin_fullscreen_windows_set_.erase(window_id);
[email protected]1289b98a2009-12-08 19:41:0878 pid_t plugin_pid = browser_needs_activation ? -1 : handle();
79 browser_needs_activation = false;
[email protected]80751052011-11-12 17:10:5880 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
81 base::Bind(ReleasePluginFullScreen, plugin_pid));
[email protected]b44dbd12009-10-11 19:02:1582 }
[email protected]1d5ac662009-10-01 19:41:5683
[email protected]1289b98a2009-12-08 19:41:0884 if (browser_needs_activation) {
[email protected]f8b3ef82010-10-11 02:45:5285 BrowserThread::PostTask(
86 BrowserThread::UI, FROM_HERE,
[email protected]80751052011-11-12 17:10:5887 base::Bind(base::mac::ActivateProcess, base::GetCurrentProcId()));
[email protected]1289b98a2009-12-08 19:41:0888 }
[email protected]1d5ac662009-10-01 19:41:5689}
[email protected]a96ec6a2009-11-04 17:27:0890
91void PluginProcessHost::OnAppActivation() {
[email protected]f8b3ef82010-10-11 02:45:5292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]a96ec6a2009-11-04 17:27:0893
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]80751052011-11-12 17:10:5897 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
98 base::Bind(base::mac::ActivateProcess, handle()));
[email protected]a96ec6a2009-11-04 17:27:0899 }
100}
[email protected]27f5a6c82009-11-20 18:26:16101
[email protected]18db46182010-02-02 17:04:55102void PluginProcessHost::OnPluginSetCursorVisibility(bool visible) {
103 if (plugin_cursor_visible_ != visible) {
104 plugin_cursor_visible_ = visible;
[email protected]80751052011-11-12 17:10:58105 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
106 base::Bind(base::mac::SetCursorVisibility,
107 visible));
[email protected]18db46182010-02-02 17:04:55108 }
109}