By moving the call to Load() up in SearchProvider::Start(), we are giving a chance...
[chromium-blink-merge.git] / content / browser / plugin_process_host_mac.cc
blob5c7916a8a74d7b80ca80e8d04a8ffcd5fb7421d8
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.
5 #include <Carbon/Carbon.h>
7 #include "build/build_config.h"
9 #include <vector>
11 #include "base/bind.h"
12 #include "base/logging.h"
13 #include "base/mac/mac_util.h"
14 #include "base/process_util.h"
15 #include "content/browser/browser_child_process_host_impl.h"
16 #include "content/browser/plugin_process_host.h"
17 #include "content/common/plugin_messages.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/child_process_data.h"
20 #include "ui/gfx/rect.h"
22 namespace content {
24 void PluginProcessHost::OnPluginSelectWindow(uint32 window_id,
25 gfx::Rect window_rect,
26 bool modal) {
27 plugin_visible_windows_set_.insert(window_id);
28 if (modal)
29 plugin_modal_windows_set_.insert(window_id);
32 void PluginProcessHost::OnPluginShowWindow(uint32 window_id,
33 gfx::Rect window_rect,
34 bool modal) {
35 plugin_visible_windows_set_.insert(window_id);
36 if (modal)
37 plugin_modal_windows_set_.insert(window_id);
38 CGRect window_bounds = {
39 { window_rect.x(), window_rect.y() },
40 { window_rect.width(), window_rect.height() }
42 CGRect main_display_bounds = CGDisplayBounds(CGMainDisplayID());
43 if (CGRectEqualToRect(window_bounds, main_display_bounds) &&
44 (plugin_fullscreen_windows_set_.find(window_id) ==
45 plugin_fullscreen_windows_set_.end())) {
46 plugin_fullscreen_windows_set_.insert(window_id);
47 // If the plugin has just shown a window that's the same dimensions as
48 // the main display, hide the menubar so that it has the whole screen.
49 // (but only if we haven't already seen this fullscreen window, since
50 // otherwise our refcounting can get skewed).
51 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
52 base::Bind(base::mac::RequestFullScreen,
53 base::mac::kFullScreenModeHideAll));
57 // Must be called on the UI thread.
58 // If plugin_pid is -1, the browser will be the active process on return,
59 // otherwise that process will be given focus back before this function returns.
60 static void ReleasePluginFullScreen(pid_t plugin_pid) {
61 // Releasing full screen only works if we are the frontmost process; grab
62 // focus, but give it back to the plugin process if requested.
63 base::mac::ActivateProcess(base::GetCurrentProcId());
64 base::mac::ReleaseFullScreen(base::mac::kFullScreenModeHideAll);
65 if (plugin_pid != -1) {
66 base::mac::ActivateProcess(plugin_pid);
70 void PluginProcessHost::OnPluginHideWindow(uint32 window_id,
71 gfx::Rect window_rect) {
72 bool had_windows = !plugin_visible_windows_set_.empty();
73 plugin_visible_windows_set_.erase(window_id);
74 bool browser_needs_activation = had_windows &&
75 plugin_visible_windows_set_.empty();
77 plugin_modal_windows_set_.erase(window_id);
78 if (plugin_fullscreen_windows_set_.find(window_id) !=
79 plugin_fullscreen_windows_set_.end()) {
80 plugin_fullscreen_windows_set_.erase(window_id);
81 pid_t plugin_pid =
82 browser_needs_activation ? -1 : process_->GetData().handle;
83 browser_needs_activation = false;
84 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
85 base::Bind(ReleasePluginFullScreen, plugin_pid));
88 if (browser_needs_activation) {
89 BrowserThread::PostTask(
90 BrowserThread::UI, FROM_HERE,
91 base::Bind(base::mac::ActivateProcess, base::GetCurrentProcId()));
95 void PluginProcessHost::OnAppActivation() {
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
98 // If our plugin process has any modal windows up, we need to bring it forward
99 // so that they act more like an in-process modal window would.
100 if (!plugin_modal_windows_set_.empty()) {
101 BrowserThread::PostTask(
102 BrowserThread::UI, FROM_HERE,
103 base::Bind(base::mac::ActivateProcess, process_->GetData().handle));
107 void PluginProcessHost::OnPluginSetCursorVisibility(bool visible) {
108 if (plugin_cursor_visible_ != visible) {
109 plugin_cursor_visible_ = visible;
110 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
111 base::Bind(base::mac::SetCursorVisibility,
112 visible));
116 } // namespace content