1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/chrome_shell_delegate.h"
#include "ash/ash_switches.h"
#include "ash/host/root_window_host_factory.h"
#include "ash/launcher/launcher_types.h"
#include "ash/magnifier/magnifier_constants.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_util.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/ui/app_list/app_list_view_delegate.h"
#include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
#include "chrome/browser/ui/ash/user_action_handler.h"
#include "chrome/browser/ui/ash/window_positioner.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/time_format.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/user_metrics.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/aura/client/user_action_client.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
// static
ChromeShellDelegate* ChromeShellDelegate::instance_ = NULL;
ChromeShellDelegate::ChromeShellDelegate()
: window_positioner_(new ash::WindowPositioner()),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
launcher_delegate_(NULL) {
instance_ = this;
PlatformInit();
}
ChromeShellDelegate::~ChromeShellDelegate() {
if (instance_ == this)
instance_ = NULL;
}
void ChromeShellDelegate::UnlockScreen() {
// This is used only for testing thus far.
NOTIMPLEMENTED();
}
void ChromeShellDelegate::Exit() {
chrome::AttemptUserExit();
}
void ChromeShellDelegate::NewTab() {
Browser* browser = GetTargetBrowser();
// If the browser was not active, we call BrowserWindow::Show to make it
// visible. Otherwise, we let Browser::NewTab handle the active window change.
const bool was_active = browser->window()->IsActive();
chrome::NewTab(browser);
if (!was_active)
browser->window()->Show();
}
void ChromeShellDelegate::NewWindow(bool is_incognito) {
Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
chrome::NewEmptyWindow(
is_incognito ? profile->GetOffTheRecordProfile() : profile,
chrome::HOST_DESKTOP_TYPE_ASH);
}
void ChromeShellDelegate::ToggleMaximized() {
aura::Window* window = ash::wm::GetActiveWindow();
if (!window)
return;
// Get out of fullscreen when in fullscreen mode.
if (ash::wm::IsWindowFullscreen(window)) {
chrome::ToggleFullscreenMode(GetTargetBrowser());
return;
}
ash::wm::ToggleMaximizedWindow(window);
if (CommandLine::ForCurrentProcess()->
HasSwitch(ash::switches::kAshImmersiveMode)) {
// Experiment with automatically entering immersive mode when the user
// presses the F4 maximize key.
window->SetProperty(ash::internal::kImmersiveModeKey,
ash::wm::IsWindowMaximized(window));
}
}
void ChromeShellDelegate::RestoreTab() {
Browser* browser = GetTargetBrowser();
// Do not restore tabs while in the incognito mode.
if (browser->profile()->IsOffTheRecord())
return;
TabRestoreService* service =
TabRestoreServiceFactory::GetForProfile(browser->profile());
if (!service)
return;
if (service->IsLoaded()) {
chrome::RestoreTab(browser);
} else {
service->LoadTabsFromLastSession();
// LoadTabsFromLastSession is asynchronous, so TabRestoreService has not
// finished loading the entries at this point. Wait for next event cycle
// which loads the restored tab entries.
MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&ChromeShellDelegate::RestoreTab,
weak_factory_.GetWeakPtr()));
}
}
bool ChromeShellDelegate::RotatePaneFocus(ash::Shell::Direction direction) {
aura::Window* window = ash::wm::GetActiveWindow();
if (!window)
return false;
Browser* browser = chrome::FindBrowserWithWindow(window);
if (!browser)
return false;
switch (direction) {
case ash::Shell::FORWARD:
chrome::FocusNextPane(browser);
break;
case ash::Shell::BACKWARD:
chrome::FocusPreviousPane(browser);
break;
}
return true;
}
void ChromeShellDelegate::ShowTaskManager() {
Browser* browser = chrome::FindOrCreateTabbedBrowser(
ProfileManager::GetDefaultProfileOrOffTheRecord(),
chrome::HOST_DESKTOP_TYPE_ASH);
chrome::OpenTaskManager(browser, false);
}
content::BrowserContext* ChromeShellDelegate::GetCurrentBrowserContext() {
return ProfileManager::GetDefaultProfile();
}
app_list::AppListViewDelegate*
ChromeShellDelegate::CreateAppListViewDelegate() {
DCHECK(ash::Shell::HasInstance());
// Shell will own the created delegate, and the delegate will own
// the controller.
Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
return new AppListViewDelegate(new AppListControllerDelegateAsh(), profile);
}
ash::LauncherDelegate* ChromeShellDelegate::CreateLauncherDelegate(
ash::LauncherModel* model) {
// TODO(oshima): This is currently broken with multiple launchers.
// Refactor so that there is just one launcher delegate in the
// shell.
if (!launcher_delegate_) {
launcher_delegate_ = ChromeLauncherController::CreateInstance(NULL, model);
launcher_delegate_->Init();
}
return launcher_delegate_;
}
aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() {
return new UserActionHandler;
}
void ChromeShellDelegate::OpenFeedbackPage() {
chrome::OpenFeedbackDialog(GetTargetBrowser());
}
void ChromeShellDelegate::RecordUserMetricsAction(
ash::UserMetricsAction action) {
switch (action) {
case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6:
content::RecordAction(
content::UserMetricsAction("Accel_KeyboardBrightnessDown_F6"));
break;
case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7:
content::RecordAction(
content::UserMetricsAction("Accel_KeyboardBrightnessUp_F7"));
break;
case ash::UMA_ACCEL_MAXIMIZE_RESTORE_F4:
content::RecordAction(
content::UserMetricsAction("Accel_Maximize_Restore_F4"));
break;
case ash::UMA_ACCEL_NEWTAB_T:
content::RecordAction(content::UserMetricsAction("Accel_NewTab_T"));
break;
case ash::UMA_ACCEL_NEXTWINDOW_F5:
content::RecordAction(content::UserMetricsAction("Accel_NextWindow_F5"));
break;
case ash::UMA_ACCEL_NEXTWINDOW_TAB:
content::RecordAction(content::UserMetricsAction("Accel_NextWindow_Tab"));
break;
case ash::UMA_ACCEL_PREVWINDOW_F5:
content::RecordAction(content::UserMetricsAction("Accel_PrevWindow_F5"));
break;
case ash::UMA_ACCEL_PREVWINDOW_TAB:
content::RecordAction(content::UserMetricsAction("Accel_PrevWindow_Tab"));
break;
case ash::UMA_ACCEL_SEARCH_LWIN:
content::RecordAction(content::UserMetricsAction("Accel_Search_LWin"));
break;
case ash::UMA_MAXIMIZE_BUTTON_MAXIMIZE:
content::RecordAction(content::UserMetricsAction("MaxButton_Maximize"));
break;
case ash::UMA_MAXIMIZE_BUTTON_MAXIMIZE_LEFT:
content::RecordAction(content::UserMetricsAction("MaxButton_MaxLeft"));
break;
case ash::UMA_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT:
content::RecordAction(content::UserMetricsAction("MaxButton_MaxRight"));
break;
case ash::UMA_MAXIMIZE_BUTTON_MINIMIZE:
content::RecordAction(content::UserMetricsAction("MaxButton_Minimize"));
break;
case ash::UMA_MAXIMIZE_BUTTON_RESTORE:
content::RecordAction(content::UserMetricsAction("MaxButton_Restore"));
break;
case ash::UMA_MAXIMIZE_BUTTON_SHOW_BUBBLE:
content::RecordAction(content::UserMetricsAction("MaxButton_ShowBubble"));
break;
case ash::UMA_LAUNCHER_CLICK_ON_APP:
content::RecordAction(content::UserMetricsAction("Launcher_ClickOnApp"));
break;
case ash::UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON:
content::RecordAction(
content::UserMetricsAction("Launcher_ClickOnApplistButton"));
break;
case ash::UMA_MOUSE_DOWN:
content::RecordAction(content::UserMetricsAction("Mouse_Down"));
break;
case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK:
content::RecordAction(
content::UserMetricsAction("Caption_ClickTogglesMaximize"));
break;
case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE:
content::RecordAction(
content::UserMetricsAction("Caption_GestureTogglesMaximize"));
break;
case ash::UMA_TOUCHSCREEN_TAP_DOWN:
content::RecordAction(content::UserMetricsAction("Touchscreen_Down"));
break;
}
}
string16 ChromeShellDelegate::GetTimeRemainingString(base::TimeDelta delta) {
return TimeFormat::TimeRemainingLong(delta);
}
string16 ChromeShellDelegate::GetTimeDurationLongString(base::TimeDelta delta) {
return TimeFormat::TimeDurationLong(delta);
}
ui::MenuModel* ChromeShellDelegate::CreateContextMenu(aura::RootWindow* root) {
DCHECK(launcher_delegate_);
// Don't show context menu for exclusive app runtime mode.
if (chrome::IsRunningInAppMode())
return NULL;
return new LauncherContextMenu(launcher_delegate_, root);
}
ash::RootWindowHostFactory* ChromeShellDelegate::CreateRootWindowHostFactory() {
return ash::RootWindowHostFactory::Create();
}
string16 ChromeShellDelegate::GetProductName() const {
return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
}
Browser* ChromeShellDelegate::GetTargetBrowser() {
Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
if (browser)
return browser;
return chrome::FindOrCreateTabbedBrowser(
ProfileManager::GetDefaultProfileOrOffTheRecord(),
chrome::HOST_DESKTOP_TYPE_ASH);
}
|