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.
5 #include "chrome/browser/ui/apps/app_metro_infobar_delegate_win.h"
7 #include "base/bind_helpers.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/apps/app_launch_for_metro_restart_win.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/lifetime/application_lifetime.h"
13 #include "chrome/browser/metro_utils/metro_chrome_win.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/app_list/app_list_icon_win.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/host_desktop.h"
19 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
20 #include "chrome/common/pref_names.h"
21 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/url_constants.h"
23 #include "grit/generated_resources.h"
24 #include "grit/google_chrome_strings.h"
25 #include "ui/base/l10n/l10n_util.h"
26 #include "win8/util/win8_util.h"
29 void AppMetroInfoBarDelegateWin::Create(
32 const std::string& extension_id) {
33 DCHECK(win8::IsSingleWindowMetroMode());
34 DCHECK_EQ(mode == SHOW_APP_LIST, extension_id.empty());
36 // Chrome should never get here via the Ash desktop, so only look for browsers
37 // on the native desktop.
38 chrome::ScopedTabbedBrowserDisplayer displayer(
39 profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
41 // Create a new tab at about:blank, and add the infobar.
42 content::OpenURLParams params(GURL(content::kAboutBlankURL),
43 content::Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK,
45 content::WebContents* web_contents = displayer.browser()->OpenURL(params);
46 InfoBarService* info_bar_service =
47 InfoBarService::FromWebContents(web_contents);
48 info_bar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
49 new AppMetroInfoBarDelegateWin(info_bar_service, mode, extension_id)));
51 // Use PostTask because we can get here in a COM SendMessage, and
52 // ActivateApplication can not be sent nested (returns error
53 // RPC_E_CANTCALLOUT_ININPUTSYNCCALL).
54 base::MessageLoop::current()->PostTask(
55 FROM_HERE, base::Bind(base::IgnoreResult(chrome::ActivateMetroChrome)));
58 AppMetroInfoBarDelegateWin::AppMetroInfoBarDelegateWin(
59 InfoBarService* info_bar_service,
61 const std::string& extension_id)
62 : ConfirmInfoBarDelegate(info_bar_service),
64 extension_id_(extension_id) {
65 DCHECK_EQ(mode_ == SHOW_APP_LIST, extension_id_.empty());
68 AppMetroInfoBarDelegateWin::~AppMetroInfoBarDelegateWin() {}
70 int AppMetroInfoBarDelegateWin::GetIconID() const {
71 return GetAppListIconResourceId();
74 string16 AppMetroInfoBarDelegateWin::GetMessageText() const {
75 return l10n_util::GetStringUTF16(mode_ == SHOW_APP_LIST ?
76 IDS_WIN8_INFOBAR_DESKTOP_RESTART_FOR_APP_LIST :
77 IDS_WIN8_INFOBAR_DESKTOP_RESTART_FOR_PACKAGED_APP);
80 string16 AppMetroInfoBarDelegateWin::GetButtonLabel(
81 InfoBarButton button) const {
82 return l10n_util::GetStringUTF16(button == BUTTON_CANCEL ?
83 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_NO_BUTTON :
84 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_YES_BUTTON);
87 bool AppMetroInfoBarDelegateWin::Accept() {
88 PrefService* prefs = g_browser_process->local_state();
89 if (mode_ == SHOW_APP_LIST) {
90 prefs->SetBoolean(prefs::kRestartWithAppList, true);
92 app_metro_launch::SetAppLaunchForMetroRestart(
93 Profile::FromBrowserContext(web_contents()->GetBrowserContext()),
97 web_contents()->Close(); // Note: deletes |this|.
98 chrome::AttemptRestartToDesktopMode();
102 bool AppMetroInfoBarDelegateWin::Cancel() {
103 web_contents()->Close();
107 string16 AppMetroInfoBarDelegateWin::GetLinkText() const {
108 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
111 bool AppMetroInfoBarDelegateWin::LinkClicked(
112 WindowOpenDisposition disposition) {
113 web_contents()->OpenURL(content::OpenURLParams(
114 GURL("https://support.google.com/chrome/?p=ib_redirect_to_desktop"),
116 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
117 content::PAGE_TRANSITION_LINK, false));