db4feb3a186fd86bb54c71cc3ae6a89bdf9acf8a
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / ash / chrome_shell_delegate_views.cc
1 // Copyright 2013 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.
4
5 #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
6
7 #include "ash/accessibility_delegate.h"
8 #include "ash/magnifier/magnifier_constants.h"
9 #include "ash/media_delegate.h"
10 #include "ash/system/tray/default_system_tray_delegate.h"
11 #include "ash/wm/window_util.h"
12 #include "base/command_line.h"
13 #include "chrome/browser/accessibility/accessibility_events.h"
14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/prefs/session_startup_pref.h"
16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/ui/ash/caps_lock_delegate_views.h"
18 #include "chrome/browser/ui/ash/chrome_new_window_delegate.h"
19 #include "chrome/browser/ui/ash/session_state_delegate_views.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/browser_list.h"
23 #include "chrome/browser/ui/browser_tabstrip.h"
24 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/host_desktop.h"
26 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
27 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
28 #include "chrome/common/chrome_switches.h"
29 #include "content/public/browser/notification_service.h"
30
31 #if defined(OS_WIN)
32 #include "chrome/browser/ui/ash/system_tray_delegate_win.h"
33 #include "chrome/browser/ui/ash/user_wallpaper_delegate_win.h"
34 #endif
35
36 namespace {
37
38 class NewWindowDelegateImpl : public ChromeNewWindowDelegate {
39  public:
40   NewWindowDelegateImpl() {}
41   virtual ~NewWindowDelegateImpl() {}
42
43   // Overridden from ash::NewWindowDelegate:
44   virtual void OpenFileManager() OVERRIDE {}
45   virtual void OpenCrosh() OVERRIDE {}
46   virtual void ShowKeyboardOverlay() OVERRIDE {}
47
48  private:
49   DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
50 };
51
52 class MediaDelegateImpl : public ash::MediaDelegate {
53  public:
54   MediaDelegateImpl() {}
55   virtual ~MediaDelegateImpl() {}
56   virtual void HandleMediaNextTrack() OVERRIDE {}
57   virtual void HandleMediaPlayPause() OVERRIDE {}
58   virtual void HandleMediaPrevTrack() OVERRIDE {}
59
60  private:
61   DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
62 };
63
64 class EmptyAccessibilityDelegate : public ash::AccessibilityDelegate {
65  public:
66   EmptyAccessibilityDelegate() {}
67   virtual ~EmptyAccessibilityDelegate() {}
68
69   virtual void ToggleHighContrast() OVERRIDE {
70   }
71
72   virtual bool IsHighContrastEnabled() const OVERRIDE {
73     return false;
74   }
75
76   virtual bool IsSpokenFeedbackEnabled() const OVERRIDE {
77     return false;
78   }
79
80   virtual void ToggleSpokenFeedback(
81       ash::AccessibilityNotificationVisibility notify) OVERRIDE {
82   }
83
84   virtual void SetLargeCursorEnabled(bool enalbed) OVERRIDE {
85   }
86
87   virtual bool IsLargeCursorEnabled() const OVERRIDE {
88     return false;
89   }
90
91   virtual void SetMagnifierEnabled(bool enabled) OVERRIDE {
92   }
93
94   virtual void SetMagnifierType(ash::MagnifierType type) OVERRIDE {
95   }
96
97   virtual bool IsMagnifierEnabled() const OVERRIDE {
98     return false;
99   }
100
101   virtual void SetAutoclickEnabled(bool enabled) OVERRIDE {
102   }
103
104   virtual bool IsAutoclickEnabled() const OVERRIDE {
105     return false;
106   }
107
108   virtual ash::MagnifierType GetMagnifierType() const OVERRIDE {
109     return ash::kDefaultMagnifierType;
110   }
111
112   virtual void SaveScreenMagnifierScale(double scale) OVERRIDE {
113   }
114
115   virtual double GetSavedScreenMagnifierScale() OVERRIDE {
116     return std::numeric_limits<double>::min();
117   }
118
119   virtual bool ShouldShowAccessibilityMenu() const OVERRIDE {
120     return false;
121   }
122
123   virtual void SilenceSpokenFeedback() const OVERRIDE {
124   }
125
126   virtual void TriggerAccessibilityAlert(
127       ash::AccessibilityAlert alert) OVERRIDE {
128   }
129
130   virtual ash::AccessibilityAlert GetLastAccessibilityAlert() OVERRIDE {
131     return ash::A11Y_ALERT_NONE;
132   }
133
134   base::TimeDelta PlayShutdownSound() const OVERRIDE {
135     return base::TimeDelta();
136   }
137
138  private:
139   DISALLOW_COPY_AND_ASSIGN(EmptyAccessibilityDelegate);
140 };
141
142 }  // namespace
143
144 bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
145   return false;
146 }
147
148 void ChromeShellDelegate::PreInit() {
149 }
150
151 void ChromeShellDelegate::Shutdown() {
152 }
153
154 ash::NewWindowDelegate* ChromeShellDelegate::CreateNewWindowDelegate() {
155   return new NewWindowDelegateImpl;
156 }
157
158 ash::MediaDelegate* ChromeShellDelegate::CreateMediaDelegate() {
159   return new MediaDelegateImpl;
160 }
161
162 ash::CapsLockDelegate* ChromeShellDelegate::CreateCapsLockDelegate() {
163   return new CapsLockDelegate();
164 }
165
166 ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() {
167   return new SessionStateDelegate;
168 }
169
170 ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate() {
171 #if defined(OS_WIN)
172   return CreateWindowsSystemTrayDelegate();
173 #else
174   return new ash::DefaultSystemTrayDelegate;
175 #endif
176 }
177
178 ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() {
179   return new EmptyAccessibilityDelegate;
180 }
181
182 ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
183 #if defined(OS_WIN)
184   return ::CreateUserWallpaperDelegate();
185 #else
186   return NULL;
187 #endif
188 }
189
190 void ChromeShellDelegate::Observe(int type,
191                                   const content::NotificationSource& source,
192                                   const content::NotificationDetails& details) {
193   switch (type) {
194     case chrome::NOTIFICATION_ASH_SESSION_STARTED: {
195       // If we are launched to service a windows 8 search request then let the
196       // IPC which carries the search string create the browser and initiate
197       // the navigation.
198       if (CommandLine::ForCurrentProcess()->HasSwitch(
199           switches::kWindows8Search))
200         break;
201       // If Chrome ASH is launched when no browser is open in the desktop,
202       // we should execute the startup code.
203       // If there are browsers open in the desktop, we create a browser window
204       // and open a new tab page, if session restore is not on.
205       BrowserList* desktop_list = BrowserList::GetInstance(
206           chrome::HOST_DESKTOP_TYPE_NATIVE);
207       if (desktop_list->empty()) {
208         // We pass a dummy command line here, because the browser is launched in
209         // silent-mode by the metro viewer process, which causes the
210         // StartupBrowserCreatorImpl class to not create any browsers which is
211         // not the behavior we want.
212         CommandLine dummy(CommandLine::NO_PROGRAM);
213         StartupBrowserCreatorImpl startup_impl(
214             base::FilePath(),
215             dummy,
216             chrome::startup::IS_NOT_FIRST_RUN);
217         startup_impl.Launch(
218             ProfileManager::GetActiveUserProfile(),
219             std::vector<GURL>(),
220             true,
221             chrome::HOST_DESKTOP_TYPE_ASH);
222       } else {
223         Browser* browser =
224             chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
225         if (browser && browser->is_type_tabbed()) {
226           chrome::AddTabAt(browser, GURL(), -1, true);
227           return;
228         }
229
230         chrome::ScopedTabbedBrowserDisplayer displayer(
231             ProfileManager::GetActiveUserProfile(),
232             chrome::HOST_DESKTOP_TYPE_ASH);
233         chrome::AddTabAt(displayer.browser(), GURL(), -1, true);
234       }
235       break;
236     }
237     case chrome::NOTIFICATION_ASH_SESSION_ENDED:
238       break;
239     default:
240       NOTREACHED() << "Unexpected notification " << type;
241   }
242 }
243
244 void ChromeShellDelegate::PlatformInit() {
245 #if defined(OS_WIN)
246   registrar_.Add(this,
247                  chrome::NOTIFICATION_ASH_SESSION_STARTED,
248                  content::NotificationService::AllSources());
249   registrar_.Add(this,
250                  chrome::NOTIFICATION_ASH_SESSION_ENDED,
251                  content::NotificationService::AllSources());
252 #endif
253 }