Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / ash / chrome_new_window_delegate_chromeos.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_new_window_delegate_chromeos.h"
6
7 #include "ash/keyboard_overlay/keyboard_overlay_view.h"
8 #include "chrome/browser/chromeos/file_manager/app_id.h"
9 #include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_util.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/extensions/application_launch.h"
16 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
17 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
18 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/web_contents.h"
20 #include "extensions/browser/extension_system.h"
21
22 ChromeNewWindowDelegateChromeos::ChromeNewWindowDelegateChromeos() {}
23 ChromeNewWindowDelegateChromeos::~ChromeNewWindowDelegateChromeos() {}
24
25 void ChromeNewWindowDelegateChromeos::OpenFileManager() {
26   using file_manager::kFileManagerAppId;
27   Profile* const profile = ProfileManager::GetActiveUserProfile();
28   const ExtensionService* const service =
29       extensions::ExtensionSystem::Get(profile)->extension_service();
30   if (!service ||
31       !extensions::util::IsAppLaunchableWithoutEnabling(kFileManagerAppId,
32                                                         profile)) {
33     return;
34   }
35
36   const extensions::Extension* const extension =
37       service->GetInstalledExtension(kFileManagerAppId);
38   // event_flags = 0 means this invokes the same behavior as the launcher
39   // item is clicked without any keyboard modifiers.
40   OpenApplication(AppLaunchParams(profile,
41                                   extension,
42                                   0 /* event_flags */,
43                                   chrome::HOST_DESKTOP_TYPE_ASH));
44 }
45
46 void ChromeNewWindowDelegateChromeos::OpenCrosh() {
47   Profile* profile = ProfileManager::GetActiveUserProfile();
48   GURL crosh_url = extensions::TerminalExtensionHelper::GetCroshExtensionURL(
49       profile);
50   if (!crosh_url.is_valid())
51     return;
52   chrome::ScopedTabbedBrowserDisplayer displayer(
53       profile,
54       chrome::HOST_DESKTOP_TYPE_ASH);
55   Browser* browser = displayer.browser();
56   content::WebContents* page = browser->OpenURL(
57       content::OpenURLParams(crosh_url,
58                              content::Referrer(),
59                              NEW_FOREGROUND_TAB,
60                              ui::PAGE_TRANSITION_GENERATED,
61                              false));
62   browser->window()->Show();
63   browser->window()->Activate();
64   page->Focus();
65 }
66
67 void ChromeNewWindowDelegateChromeos::ShowKeyboardOverlay() {
68   // TODO(mazda): Move the show logic to ash (http://crbug.com/124222).
69   Profile* profile = ProfileManager::GetActiveUserProfile();
70   std::string url(chrome::kChromeUIKeyboardOverlayURL);
71   ash::KeyboardOverlayView::ShowDialog(profile,
72                                        new ChromeWebContentsHandler,
73                                        GURL(url));
74 }