Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/browser/ui/extensions/app_metro_infobar_delegate_win.cc

Issue 12450014: Show an InfoBar when trying to start Packaged Apps from Metro mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix another corner case Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/extensions/app_metro_infobar_delegate_win.h" 5 #include "chrome/browser/ui/extensions/app_metro_infobar_delegate_win.h"
6 6
7 #include "apps/app_launch_for_metro_restart_win.h"
7 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/host_desktop.h" 16 #include "chrome/browser/ui/host_desktop.h"
15 #include "chrome/browser/ui/metro_chrome_win.h" 17 #include "chrome/browser/ui/metro_chrome_win.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
17 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
18 #include "content/public/common/url_constants.h" 20 #include "content/public/common/url_constants.h"
19 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
20 #include "grit/google_chrome_strings.h" 22 #include "grit/google_chrome_strings.h"
21 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
22 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
24 #include "win8/util/win8_util.h" 26 #include "win8/util/win8_util.h"
25 27
26 namespace chrome { 28 namespace chrome {
27 29
28 void AppMetroInfoBarDelegateWin::CreateAndActivateMetro(Profile* profile) { 30 // static
31 void AppMetroInfoBarDelegateWin::CreateAndActivateMetroHelper(
32 Profile* profile, Mode mode, const std::string& extension_id) {
29 // Chrome should never get here via the Ash desktop, so only look for browsers 33 // Chrome should never get here via the Ash desktop, so only look for browsers
30 // on the native desktop. 34 // on the native desktop.
31 CHECK(win8::IsSingleWindowMetroMode()); 35 CHECK(win8::IsSingleWindowMetroMode());
36 if (mode == LAUNCH_PACKAGED_APP && extension_id.empty()) {
37 LOG(ERROR) << "Can not relaunch with app: extension_id is empty.";
38 return;
39 }
40
32 Browser* browser = FindOrCreateTabbedBrowser( 41 Browser* browser = FindOrCreateTabbedBrowser(
33 profile, chrome::HOST_DESKTOP_TYPE_NATIVE); 42 profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
34 43
35 // Create a new tab at about:blank, and add the infobar. 44 // Create a new tab at about:blank, and add the infobar.
36 content::OpenURLParams params( 45 content::OpenURLParams params(
37 GURL(chrome::kAboutBlankURL), 46 GURL(chrome::kAboutBlankURL),
38 content::Referrer(), 47 content::Referrer(),
39 NEW_FOREGROUND_TAB, 48 NEW_FOREGROUND_TAB,
40 content::PAGE_TRANSITION_LINK, false); 49 content::PAGE_TRANSITION_LINK, false);
41 content::WebContents* web_contents = browser->OpenURL(params); 50 content::WebContents* web_contents = browser->OpenURL(params);
42 InfoBarService* info_bar_service = 51 InfoBarService* info_bar_service =
43 InfoBarService::FromWebContents(web_contents); 52 InfoBarService::FromWebContents(web_contents);
44 info_bar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( 53 info_bar_service->AddInfoBar(scoped_ptr<AppMetroInfoBarDelegateWin>(
45 new AppMetroInfoBarDelegateWin(info_bar_service))); 54 new AppMetroInfoBarDelegateWin(info_bar_service, mode, extension_id)));
46 55
47 // Use PostTask because we can get here in a COM SendMessage, and 56 // Use PostTask because we can get here in a COM SendMessage, and
48 // ActivateApplication can not be sent nested (returns error 57 // ActivateApplication can not be sent nested (returns error
49 // RPC_E_CANTCALLOUT_ININPUTSYNCCALL). 58 // RPC_E_CANTCALLOUT_ININPUTSYNCCALL).
50 MessageLoop::current()->PostTask( 59 MessageLoop::current()->PostTask(
51 FROM_HERE, 60 FROM_HERE,
52 base::Bind(base::IgnoreResult(chrome::ActivateMetroChrome))); 61 base::Bind(base::IgnoreResult(chrome::ActivateMetroChrome)));
53 } 62 }
54 63
64 // static
65 void AppMetroInfoBarDelegateWin::CreateAndActivateMetroForAppList(
66 Profile* profile) {
67 CreateAndActivateMetroHelper(profile, SHOW_APP_LIST, std::string());
68 }
69
70 // static
71 void AppMetroInfoBarDelegateWin::CreateAndActivateMetroForApp(
72 Profile* profile, const std::string& extension_id) {
73 CreateAndActivateMetroHelper(profile, LAUNCH_PACKAGED_APP, extension_id);
74 }
75
55 AppMetroInfoBarDelegateWin::AppMetroInfoBarDelegateWin( 76 AppMetroInfoBarDelegateWin::AppMetroInfoBarDelegateWin(
56 InfoBarService* info_bar_service) 77 InfoBarService* info_bar_service,
57 : ConfirmInfoBarDelegate(info_bar_service) { 78 Mode mode,
79 const std::string& extension_id)
80 : ConfirmInfoBarDelegate(info_bar_service),
81 mode_(mode),
82 extension_id_(extension_id) {
83 CHECK_EQ(mode_ == SHOW_APP_LIST, extension_id_.empty());
58 } 84 }
59 85
60 AppMetroInfoBarDelegateWin::~AppMetroInfoBarDelegateWin() {} 86 AppMetroInfoBarDelegateWin::~AppMetroInfoBarDelegateWin() {}
61 87
62 gfx::Image* AppMetroInfoBarDelegateWin::GetIcon() const { 88 gfx::Image* AppMetroInfoBarDelegateWin::GetIcon() const {
63 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_APP_LIST); 89 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_APP_LIST);
64 } 90 }
65 91
66 string16 AppMetroInfoBarDelegateWin::GetMessageText() const { 92 string16 AppMetroInfoBarDelegateWin::GetMessageText() const {
67 return l10n_util::GetStringUTF16( 93 return l10n_util::GetStringUTF16(mode_ == SHOW_APP_LIST ?
68 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS); 94 IDS_WIN8_INFOBAR_DESKTOP_RESTART_FOR_APP_LIST :
95 IDS_WIN8_INFOBAR_DESKTOP_RESTART_FOR_PACKAGED_APP);
69 } 96 }
70 97
71 int AppMetroInfoBarDelegateWin::GetButtons() const { 98 int AppMetroInfoBarDelegateWin::GetButtons() const {
72 return BUTTON_OK | BUTTON_CANCEL; 99 return BUTTON_OK | BUTTON_CANCEL;
73 } 100 }
74 101
75 string16 AppMetroInfoBarDelegateWin::GetButtonLabel( 102 string16 AppMetroInfoBarDelegateWin::GetButtonLabel(
76 InfoBarButton button) const { 103 InfoBarButton button) const {
77 if (button == BUTTON_CANCEL) { 104 if (button == BUTTON_CANCEL) {
78 return l10n_util::GetStringUTF16( 105 return l10n_util::GetStringUTF16(
79 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_NO_BUTTON); 106 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_NO_BUTTON);
80 } 107 }
81 108
82 return l10n_util::GetStringUTF16( 109 return l10n_util::GetStringUTF16(
83 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_YES_BUTTON); 110 IDS_WIN8_INFOBAR_DESKTOP_RESTART_TO_LAUNCH_APPS_YES_BUTTON);
84 } 111 }
85 112
86 bool AppMetroInfoBarDelegateWin::Accept() { 113 bool AppMetroInfoBarDelegateWin::Accept() {
87 owner()->GetWebContents()->Close();
88 PrefService* prefs = g_browser_process->local_state(); 114 PrefService* prefs = g_browser_process->local_state();
89 prefs->SetBoolean(prefs::kRestartWithAppList, true); 115 content::WebContents* web_contents = owner()->GetWebContents();
116 if (mode_ == SHOW_APP_LIST) {
117 prefs->SetBoolean(prefs::kRestartWithAppList, true);
118 } else {
119 apps::SetAppLaunchForMetroRestart(
120 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
121 extension_id_);
122 }
123
124 web_contents->Close(); // Note: deletes |this|.
90 chrome::AttemptRestartWithModeSwitch(); 125 chrome::AttemptRestartWithModeSwitch();
91 return false; 126 return false;
92 } 127 }
93 128
94 bool AppMetroInfoBarDelegateWin::Cancel() { 129 bool AppMetroInfoBarDelegateWin::Cancel() {
95 owner()->GetWebContents()->Close(); 130 owner()->GetWebContents()->Close();
96 return false; 131 return false;
97 } 132 }
98 133
99 string16 AppMetroInfoBarDelegateWin::GetLinkText() const { 134 string16 AppMetroInfoBarDelegateWin::GetLinkText() const {
100 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); 135 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
101 } 136 }
102 137
103 bool AppMetroInfoBarDelegateWin::LinkClicked( 138 bool AppMetroInfoBarDelegateWin::LinkClicked(
104 WindowOpenDisposition disposition) { 139 WindowOpenDisposition disposition) {
105 content::OpenURLParams params( 140 content::OpenURLParams params(
106 GURL("https://support.google.com/chrome/?p=ib_redirect_to_desktop"), 141 GURL("https://support.google.com/chrome/?p=ib_redirect_to_desktop"),
107 content::Referrer(), 142 content::Referrer(),
108 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, 143 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
109 content::PAGE_TRANSITION_LINK, false); 144 content::PAGE_TRANSITION_LINK, false);
110 owner()->GetWebContents()->OpenURL(params); 145 owner()->GetWebContents()->OpenURL(params);
111 return false; 146 return false;
112 } 147 }
113 148
114 } // namespace chrome 149 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698