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/infobars/infobar.h"
13 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/browser/lifetime/application_lifetime.h"
15 #include "chrome/browser/metro_utils/metro_chrome_win.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/app_list/app_list_icon_win.h"
18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_window.h"
20 #include "chrome/browser/ui/host_desktop.h"
21 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
22 #include "chrome/common/pref_names.h"
23 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/url_constants.h"
25 #include "grit/generated_resources.h"
26 #include "grit/google_chrome_strings.h"
27 #include "ui/base/l10n/l10n_util.h"
28 #include "win8/util/win8_util.h"
31 void AppMetroInfoBarDelegateWin::Create(
34 const std::string
& extension_id
) {
35 DCHECK(win8::IsSingleWindowMetroMode());
36 DCHECK_EQ(mode
== SHOW_APP_LIST
, extension_id
.empty());
38 // Chrome should never get here via the Ash desktop, so only look for browsers
39 // on the native desktop.
40 chrome::ScopedTabbedBrowserDisplayer
displayer(
41 profile
, chrome::HOST_DESKTOP_TYPE_NATIVE
);
43 // Create a new tab at about:blank, and add the infobar.
44 content::OpenURLParams
params(GURL(content::kAboutBlankURL
),
45 content::Referrer(), NEW_FOREGROUND_TAB
, content::PAGE_TRANSITION_LINK
,
47 content::WebContents
* web_contents
= displayer
.browser()->OpenURL(params
);
48 InfoBarService::FromWebContents(web_contents
)->AddInfoBar(
49 ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr
<ConfirmInfoBarDelegate
>(
50 new AppMetroInfoBarDelegateWin(mode
, extension_id
))));
52 // Use PostTask because we can get here in a COM SendMessage, and
53 // ActivateApplication can not be sent nested (returns error
54 // RPC_E_CANTCALLOUT_ININPUTSYNCCALL).
55 base::MessageLoop::current()->PostTask(
56 FROM_HERE
, base::Bind(base::IgnoreResult(chrome::ActivateMetroChrome
)));
59 AppMetroInfoBarDelegateWin::AppMetroInfoBarDelegateWin(
61 const std::string
& extension_id
)
62 : ConfirmInfoBarDelegate(),
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 base::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 base::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 base::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));