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

Side by Side Diff: chrome/browser/extensions/extension_install_ui_default.cc

Issue 12095052: Move app_launcher.* out of chrome/browser/extensions and into apps/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Beserk Q. More rebase Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/extensions/extension_install_ui_default.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
11 #include "chrome/browser/api/infobars/infobar_service.h"
12 #include "chrome/browser/extensions/app_launcher.h"
13 #include "chrome/browser/extensions/extension_install_prompt.h"
14 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/themes/theme_service.h"
17 #include "chrome/browser/themes/theme_service_factory.h"
18 #include "chrome/browser/ui/app_list/app_list_util.h"
19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_dialogs.h"
21 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/browser_navigator.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/simple_message_box.h"
27 #include "chrome/browser/ui/singleton_tabs.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
30 #include "chrome/common/chrome_notification_types.h"
31 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/extensions/extension.h"
33 #include "chrome/common/url_constants.h"
34 #include "content/public/browser/browser_thread.h"
35 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/web_contents.h"
37 #include "grit/generated_resources.h"
38 #include "grit/theme_resources.h"
39 #include "ui/base/l10n/l10n_util.h"
40 #include "ui/base/resource/resource_bundle.h"
41
42 #if defined(USE_ASH)
43 #include "ash/shell.h"
44 #endif
45
46 using content::BrowserThread;
47 using content::WebContents;
48 using extensions::Extension;
49
50 namespace {
51
52 bool disable_failure_ui_for_tests = false;
53
54 // Helper class to put up an infobar when installation fails.
55 class ErrorInfobarDelegate : public ConfirmInfoBarDelegate {
56 public:
57 // Creates an error delegate and adds it to |infobar_service|.
58 static void Create(InfoBarService* infobar_service,
59 Browser* browser,
60 const extensions::CrxInstallerError& error);
61
62 private:
63 ErrorInfobarDelegate(InfoBarService* infobar_service,
64 Browser* browser,
65 const extensions::CrxInstallerError& error)
66 : ConfirmInfoBarDelegate(infobar_service),
67 browser_(browser),
68 error_(error) {
69 }
70
71 virtual string16 GetMessageText() const OVERRIDE {
72 return error_.message();
73 }
74
75 virtual int GetButtons() const OVERRIDE {
76 return BUTTON_OK;
77 }
78
79 virtual string16 GetLinkText() const OVERRIDE {
80 return error_.type() == extensions::CrxInstallerError::ERROR_OFF_STORE ?
81 l10n_util::GetStringUTF16(IDS_LEARN_MORE) : ASCIIToUTF16("");
82 }
83
84 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE {
85 chrome::NavigateParams params(
86 browser_,
87 GURL("http://support.google.com/chrome_webstore/?p=crx_warning"),
88 content::PAGE_TRANSITION_LINK);
89 params.disposition = NEW_FOREGROUND_TAB;
90 chrome::Navigate(&params);
91 return false;
92 }
93
94 Browser* browser_;
95 extensions::CrxInstallerError error_;
96 };
97
98 // static
99 void ErrorInfobarDelegate::Create(InfoBarService* infobar_service,
100 Browser* browser,
101 const extensions::CrxInstallerError& error) {
102 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
103 new ErrorInfobarDelegate(infobar_service, browser, error)));
104 }
105
106 void OnAppLauncherEnabledCompleted(const extensions::Extension* extension,
107 Browser* browser,
108 SkBitmap* icon,
109 bool use_bubble,
110 bool use_launcher) {
111 #if defined(ENABLE_APP_LIST)
112 if (use_launcher) {
113 chrome::ShowAppList(browser->profile());
114
115 content::NotificationService::current()->Notify(
116 chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST,
117 content::Source<Profile>(browser->profile()),
118 content::Details<const std::string>(&extension->id()));
119 return;
120 }
121 #endif
122
123 if (use_bubble) {
124 chrome::ShowExtensionInstalledBubble(extension, browser, *icon);
125 return;
126 }
127
128 ExtensionInstallUI::OpenAppInstalledUI(browser, extension->id());
129 }
130
131 } // namespace
132
133 ExtensionInstallUIDefault::ExtensionInstallUIDefault(Profile* profile)
134 : skip_post_install_ui_(false),
135 previous_using_native_theme_(false),
136 use_app_installed_bubble_(false) {
137 profile_ = profile;
138
139 // |profile_| can be NULL during tests.
140 if (profile_) {
141 // Remember the current theme in case the user presses undo.
142 const Extension* previous_theme =
143 ThemeServiceFactory::GetThemeForProfile(profile);
144 if (previous_theme)
145 previous_theme_id_ = previous_theme->id();
146 previous_using_native_theme_ =
147 ThemeServiceFactory::GetForProfile(profile)->UsingNativeTheme();
148 }
149 }
150
151 ExtensionInstallUIDefault::~ExtensionInstallUIDefault() {
152 }
153
154 void ExtensionInstallUIDefault::OnInstallSuccess(const Extension* extension,
155 SkBitmap* icon) {
156 if (skip_post_install_ui_)
157 return;
158
159 if (!profile_) {
160 // TODO(zelidrag): Figure out what exact conditions cause crash
161 // http://crbug.com/159437 and write browser test to cover it.
162 NOTREACHED();
163 return;
164 }
165
166 if (extension->is_theme()) {
167 ThemeInstalledInfoBarDelegate::Create(
168 extension, profile_, previous_theme_id_, previous_using_native_theme_);
169 return;
170 }
171
172 // Extensions aren't enabled by default in incognito so we confirm
173 // the install in a normal window.
174 Profile* current_profile = profile_->GetOriginalProfile();
175 Browser* browser =
176 chrome::FindOrCreateTabbedBrowser(current_profile,
177 chrome::GetActiveDesktop());
178 if (browser->tab_strip_model()->count() == 0)
179 chrome::AddBlankTabAt(browser, -1, true);
180 browser->window()->Show();
181
182 if (extension->is_app()) {
183 bool use_bubble = false;
184
185 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)
186 CommandLine* cmdline = CommandLine::ForCurrentProcess();
187 use_bubble = (use_app_installed_bubble_ ||
188 cmdline->HasSwitch(switches::kAppsNewInstallBubble));
189 #endif
190
191 extensions::UpdateIsAppLauncherEnabled(
192 base::Bind(&OnAppLauncherEnabledCompleted, extension, browser, icon,
193 use_bubble));
194 return;
195 }
196
197 chrome::ShowExtensionInstalledBubble(extension, browser, *icon);
198 }
199
200 void ExtensionInstallUIDefault::OnInstallFailure(
201 const extensions::CrxInstallerError& error) {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
203 if (disable_failure_ui_for_tests || skip_post_install_ui_)
204 return;
205
206 Browser* browser = chrome::FindLastActiveWithProfile(profile_,
207 chrome::GetActiveDesktop());
208 WebContents* web_contents =
209 browser->tab_strip_model()->GetActiveWebContents();
210 if (!web_contents)
211 return;
212 ErrorInfobarDelegate::Create(InfoBarService::FromWebContents(web_contents),
213 browser, error);
214 }
215
216 void ExtensionInstallUIDefault::SetSkipPostInstallUI(bool skip_ui) {
217 skip_post_install_ui_ = skip_ui;
218 }
219
220 void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) {
221 use_app_installed_bubble_ = use_bubble;
222 }
223
224 // static
225 ExtensionInstallUI* ExtensionInstallUI::Create(Profile* profile) {
226 return new ExtensionInstallUIDefault(profile);
227 }
228
229 // static
230 void ExtensionInstallUI::OpenAppInstalledUI(Browser* browser,
231 const std::string& app_id) {
232 #if defined(OS_CHROMEOS)
233 chrome::ShowAppList(browser->profile());
234
235 content::NotificationService::current()->Notify(
236 chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST,
237 content::Source<Profile>(browser->profile()),
238 content::Details<const std::string>(&app_id));
239 #else
240 chrome::NavigateParams params(chrome::GetSingletonTabNavigateParams(
241 browser, GURL(chrome::kChromeUINewTabURL)));
242 chrome::Navigate(&params);
243
244 content::NotificationService::current()->Notify(
245 chrome::NOTIFICATION_APP_INSTALLED_TO_NTP,
246 content::Source<WebContents>(params.target_contents),
247 content::Details<const std::string>(&app_id));
248 #endif
249 }
250
251 // static
252 void ExtensionInstallUI::DisableFailureUIForTests() {
253 disable_failure_ui_for_tests = true;
254 }
255
256 // static
257 ExtensionInstallPrompt* ExtensionInstallUI::CreateInstallPromptWithBrowser(
258 Browser* browser) {
259 content::WebContents* web_contents = NULL;
260 if (browser)
261 web_contents = browser->tab_strip_model()->GetActiveWebContents();
262 return new ExtensionInstallPrompt(web_contents);
263 }
264
265 // static
266 ExtensionInstallPrompt* ExtensionInstallUI::CreateInstallPromptWithProfile(
267 Profile* profile) {
268 Browser* browser = chrome::FindLastActiveWithProfile(profile,
269 chrome::GetActiveDesktop());
270 return CreateInstallPromptWithBrowser(browser);
271 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_install_ui_default.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698