OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/views/extensions/bookmark_app_bubble_view.h" | 5 #include "chrome/browser/ui/views/extensions/bookmark_app_bubble_view.h" |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/chrome_notification_types.h" | |
9 #include "chrome/browser/extensions/app_icon_loader_impl.h" | 10 #include "chrome/browser/extensions/app_icon_loader_impl.h" |
10 #include "chrome/browser/extensions/bookmark_app_helper.h" | 11 #include "chrome/browser/extensions/bookmark_app_helper.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/launch_util.h" | 13 #include "chrome/browser/extensions/launch_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/app_list/app_list_service.h" | |
16 #include "chrome/browser/ui/app_list/app_list_util.h" | |
17 #include "chrome/browser/ui/browser_navigator.h" | |
18 #include "chrome/browser/ui/host_desktop.h" | |
14 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
20 #include "chrome/common/url_constants.h" | |
15 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
22 #include "content/public/browser/notification_service.h" | |
23 #include "content/public/browser/web_contents.h" | |
16 #include "extensions/browser/extension_prefs.h" | 24 #include "extensions/browser/extension_prefs.h" |
17 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
19 #include "extensions/browser/pref_names.h" | 27 #include "extensions/browser/pref_names.h" |
20 #include "extensions/browser/uninstall_reason.h" | 28 #include "extensions/browser/uninstall_reason.h" |
21 #include "extensions/common/constants.h" | 29 #include "extensions/common/constants.h" |
22 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/events/keycodes/keyboard_codes.h" | 32 #include "ui/events/keycodes/keyboard_codes.h" |
25 #include "ui/views/controls/button/checkbox.h" | 33 #include "ui/views/controls/button/checkbox.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 : extensions::LAUNCH_TYPE_WINDOW; | 266 : extensions::LAUNCH_TYPE_WINDOW; |
259 profile_->GetPrefs()->SetInteger( | 267 profile_->GetPrefs()->SetInteger( |
260 extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type); | 268 extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type); |
261 extensions::SetLaunchType(GetExtensionService(profile_), | 269 extensions::SetLaunchType(GetExtensionService(profile_), |
262 extension_id_, | 270 extension_id_, |
263 launch_type); | 271 launch_type); |
264 | 272 |
265 const extensions::Extension* extension = | 273 const extensions::Extension* extension = |
266 extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( | 274 extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( |
267 extension_id_, extensions::ExtensionRegistry::EVERYTHING); | 275 extension_id_, extensions::ExtensionRegistry::EVERYTHING); |
268 if (extension && base::UTF8ToUTF16(extension->name()) == title_tf_->text()) | 276 |
277 if (!extension) | |
269 return; | 278 return; |
270 | 279 |
271 // Reinstall the app with an updated name. | 280 if (base::UTF8ToUTF16(extension->name()) != title_tf_->text()) { |
272 WebApplicationInfo install_info(web_app_info_); | 281 // Reinstall the app with an updated name. |
273 install_info.title = title_tf_->text(); | 282 WebApplicationInfo install_info(web_app_info_); |
283 install_info.title = title_tf_->text(); | |
274 | 284 |
275 extensions::CreateOrUpdateBookmarkApp(GetExtensionService(profile_), | 285 // This will asynchronously reload the extension, causing the Extension* |
276 &install_info); | 286 // we have to be destroyed. The extension ID will stay the same so that is |
287 // used later on to highlight the app. | |
Finnur
2014/12/15 14:11:29
nit: Should we explicitly set the pointer to NULL
| |
288 extensions::CreateOrUpdateBookmarkApp(GetExtensionService(profile_), | |
289 &install_info); | |
290 } | |
291 | |
292 // Show the newly installed app in the app launcher or chrome://apps. Don't | |
293 // do this on ash, as the icon will have been added to the shelf. | |
294 chrome::HostDesktopType desktop = | |
295 chrome::GetHostDesktopTypeForNativeWindow(GetWidget()->GetNativeWindow()); | |
296 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) | |
297 return; | |
298 | |
299 Profile* current_profile = profile_->GetOriginalProfile(); | |
300 if (IsAppLauncherEnabled()) { | |
301 AppListService::Get(desktop) | |
302 ->ShowForAppInstall(current_profile, extension_id_, false); | |
303 return; | |
304 } | |
305 | |
306 chrome::NavigateParams params(current_profile, | |
307 GURL(chrome::kChromeUIAppsURL), | |
308 ui::PAGE_TRANSITION_LINK); | |
309 params.disposition = NEW_FOREGROUND_TAB; | |
310 chrome::Navigate(¶ms); | |
311 | |
312 content::NotificationService::current()->Notify( | |
313 chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, | |
314 content::Source<content::WebContents>(params.target_contents), | |
315 content::Details<const std::string>(&extension_id_)); | |
277 } | 316 } |
OLD | NEW |