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. |
| 288 extensions::CreateOrUpdateBookmarkApp(GetExtensionService(profile_), |
| 289 &install_info); |
| 290 } |
| 291 |
| 292 // As the extension could be destroyed after this point, set it to null to |
| 293 // prevent anyone trying to use it in future. |
| 294 extension = nullptr; |
| 295 |
| 296 // Show the newly installed app in the app launcher or chrome://apps. Don't |
| 297 // do this on ash, as the icon will have been added to the shelf. |
| 298 chrome::HostDesktopType desktop = |
| 299 chrome::GetHostDesktopTypeForNativeWindow(GetWidget()->GetNativeWindow()); |
| 300 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH) |
| 301 return; |
| 302 |
| 303 Profile* current_profile = profile_->GetOriginalProfile(); |
| 304 if (IsAppLauncherEnabled()) { |
| 305 AppListService::Get(desktop) |
| 306 ->ShowForAppInstall(current_profile, extension_id_, false); |
| 307 return; |
| 308 } |
| 309 |
| 310 chrome::NavigateParams params(current_profile, |
| 311 GURL(chrome::kChromeUIAppsURL), |
| 312 ui::PAGE_TRANSITION_LINK); |
| 313 params.disposition = NEW_FOREGROUND_TAB; |
| 314 chrome::Navigate(¶ms); |
| 315 |
| 316 content::NotificationService::current()->Notify( |
| 317 chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, |
| 318 content::Source<content::WebContents>(params.target_contents), |
| 319 content::Details<const std::string>(&extension_id_)); |
277 } | 320 } |
OLD | NEW |