Index: chrome/browser/ui/views/extensions/bookmark_app_bubble_view.cc |
diff --git a/chrome/browser/ui/views/extensions/bookmark_app_bubble_view.cc b/chrome/browser/ui/views/extensions/bookmark_app_bubble_view.cc |
index 934e8a941f1571d570635b432076e7b4c4da8487..15f1c4085d3290aa5287229e66427cc19697edb2 100644 |
--- a/chrome/browser/ui/views/extensions/bookmark_app_bubble_view.cc |
+++ b/chrome/browser/ui/views/extensions/bookmark_app_bubble_view.cc |
@@ -6,30 +6,14 @@ |
#include "base/strings/string16.h" |
#include "base/strings/utf_string_conversions.h" |
-#include "chrome/browser/chrome_notification_types.h" |
-#include "chrome/browser/extensions/app_icon_loader_impl.h" |
-#include "chrome/browser/extensions/bookmark_app_helper.h" |
-#include "chrome/browser/extensions/extension_service.h" |
-#include "chrome/browser/extensions/launch_util.h" |
-#include "chrome/browser/profiles/profile.h" |
-#include "chrome/browser/ui/app_list/app_list_service.h" |
-#include "chrome/browser/ui/app_list/app_list_util.h" |
-#include "chrome/browser/ui/browser_navigator.h" |
-#include "chrome/browser/ui/host_desktop.h" |
-#include "chrome/common/extensions/extension_constants.h" |
-#include "chrome/common/url_constants.h" |
#include "chrome/grit/generated_resources.h" |
-#include "content/public/browser/notification_service.h" |
#include "content/public/browser/web_contents.h" |
-#include "extensions/browser/extension_prefs.h" |
-#include "extensions/browser/extension_registry.h" |
-#include "extensions/browser/extension_system.h" |
-#include "extensions/browser/pref_names.h" |
-#include "extensions/browser/uninstall_reason.h" |
#include "extensions/common/constants.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/resource/resource_bundle.h" |
#include "ui/events/keycodes/keyboard_codes.h" |
+#include "ui/gfx/image/image_skia.h" |
+#include "ui/gfx/image/image_skia_source.h" |
#include "ui/views/controls/button/checkbox.h" |
#include "ui/views/controls/button/label_button.h" |
#include "ui/views/controls/image_view.h" |
@@ -51,50 +35,57 @@ const int kMinTextfieldWidth = 200; |
// Size of the icon. |
const int kIconSize = extension_misc::EXTENSION_ICON_MEDIUM; |
-ExtensionService* GetExtensionService(Profile* profile) { |
- return extensions::ExtensionSystem::Get(profile)->extension_service(); |
-} |
+class WebAppInfoImageSource : public gfx::ImageSkiaSource { |
+ public: |
+ WebAppInfoImageSource(int dip_size, const WebApplicationInfo& info) |
+ : dip_size_(dip_size), info_(info) {} |
+ ~WebAppInfoImageSource() override {} |
+ |
+ private: |
+ gfx::ImageSkiaRep GetImageForScale(float scale) override { |
+ int size = static_cast<int>(dip_size_ * scale); |
Lei Zhang
2015/02/03 18:37:49
Can this overflow? I'm guessing no because the two
benwells
2015/02/04 16:01:00
That's right, but I've changed it to use the safe
|
+ for (auto icon_info : info_.icons) { |
Lei Zhang
2015/02/03 18:37:49
const auto& ?
benwells
2015/02/04 16:01:00
Done.
|
+ if (icon_info.width == size) { |
+ return gfx::ImageSkiaRep(icon_info.data, scale); |
+ } |
+ } |
+ return gfx::ImageSkiaRep(); |
+ } |
-} // namespace |
+ int dip_size_; |
+ WebApplicationInfo info_; |
+}; |
-BookmarkAppBubbleView* BookmarkAppBubbleView::bookmark_app_bubble_ = NULL; |
+} // namespace |
BookmarkAppBubbleView::~BookmarkAppBubbleView() { |
} |
// static |
-void BookmarkAppBubbleView::ShowBubble(views::View* anchor_view, |
- Profile* profile, |
- const WebApplicationInfo& web_app_info, |
- const std::string& extension_id) { |
- if (bookmark_app_bubble_ != NULL) |
- return; |
- |
- bookmark_app_bubble_ = new BookmarkAppBubbleView( |
- anchor_view, profile, web_app_info, extension_id); |
- views::BubbleDelegateView::CreateBubble(bookmark_app_bubble_)->Show(); |
+void BookmarkAppBubbleView::ShowBubble( |
+ views::View* anchor_view, |
+ const WebApplicationInfo& web_app_info, |
+ const BrowserWindow::ShowBookmarkAppBubbleCallback& callback) { |
+ BookmarkAppBubbleView* bookmark_app_bubble = |
Lei Zhang
2015/02/03 18:37:49
Who frees this? Can you add a comment to explain t
benwells
2015/02/04 16:01:00
Comment added.
|
+ new BookmarkAppBubbleView(anchor_view, web_app_info, callback); |
+ views::BubbleDelegateView::CreateBubble(bookmark_app_bubble)->Show(); |
// Select the entire title textfield contents when the bubble is first shown. |
- bookmark_app_bubble_->title_tf_->SelectAll(true); |
- bookmark_app_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
+ bookmark_app_bubble->title_tf_->SelectAll(true); |
+ bookmark_app_bubble->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
} |
BookmarkAppBubbleView::BookmarkAppBubbleView( |
views::View* anchor_view, |
- Profile* profile, |
const WebApplicationInfo& web_app_info, |
- const std::string& extension_id) |
+ const BrowserWindow::ShowBookmarkAppBubbleCallback& callback) |
: BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
- profile_(profile), |
web_app_info_(web_app_info), |
- extension_id_(extension_id), |
+ user_accepted_(false), |
+ callback_(callback), |
add_button_(NULL), |
cancel_button_(NULL), |
open_as_window_checkbox_(NULL), |
- title_tf_(NULL), |
- remove_app_(true), |
- app_icon_loader_(new extensions::AppIconLoaderImpl(profile, |
- kIconSize, |
- this)) { |
+ title_tf_(NULL) { |
const SkColor background_color = GetNativeTheme()->GetSystemColor( |
ui::NativeTheme::kColorId_DialogBackground); |
set_arrow(views::BubbleBorder::TOP_CENTER); |
@@ -171,29 +162,25 @@ void BookmarkAppBubbleView::Init() { |
layout->AddView(title_label); |
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
- const extensions::Extension* extension = |
- extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( |
- extension_id_, extensions::ExtensionRegistry::EVERYTHING); |
- |
layout->StartRow(0, TITLE_TEXT_COLUMN_SET_ID); |
icon_image_view_ = new views::ImageView(); |
- icon_image_view_->SetImageSize(gfx::Size(kIconSize, kIconSize)); |
+ |
+ gfx::Size image_size(kIconSize, kIconSize); |
+ gfx::ImageSkia image(new WebAppInfoImageSource(kIconSize, web_app_info_), |
+ image_size); |
+ icon_image_view_->SetImageSize(image_size); |
+ icon_image_view_->SetImage(image); |
layout->AddView(icon_image_view_); |
- app_icon_loader_->FetchImage(extension_id_); |
title_tf_ = new views::Textfield(); |
- title_tf_->SetText(extension ? base::UTF8ToUTF16(extension->name()) |
- : web_app_info_.title); |
+ title_tf_->SetText(web_app_info_.title); |
layout->AddView(title_tf_); |
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
layout->StartRow(0, CONTENT_COLUMN_SET_ID); |
open_as_window_checkbox_ = new views::Checkbox( |
l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_WINDOW)); |
- open_as_window_checkbox_->SetChecked( |
- profile_->GetPrefs()->GetInteger( |
- extensions::pref_names::kBookmarkAppCreationLaunchType) == |
- extensions::LAUNCH_TYPE_WINDOW); |
+ open_as_window_checkbox_->SetChecked(web_app_info_.open_as_window); |
layout->AddView(open_as_window_checkbox_); |
layout->AddView(add_button_); |
layout->AddView(cancel_button_); |
@@ -207,21 +194,7 @@ views::View* BookmarkAppBubbleView::GetInitiallyFocusedView() { |
} |
void BookmarkAppBubbleView::WindowClosing() { |
- // We have to reset |bookmark_app_bubble_| here, not in our destructor, |
- // because we'll be destroyed asynchronously and the shown state will be |
- // checked before then. |
- DCHECK_EQ(bookmark_app_bubble_, this); |
- bookmark_app_bubble_ = NULL; |
- |
- if (remove_app_) { |
- GetExtensionService(profile_) |
- ->UninstallExtension(extension_id_, |
- extensions::UNINSTALL_REASON_INSTALL_CANCELED, |
- base::Bind(&base::DoNothing), |
- NULL); |
- } else { |
- ApplyEdits(); |
- } |
+ callback_.Run(user_accepted_, web_app_info_); |
} |
bool BookmarkAppBubbleView::AcceleratorPressed( |
@@ -244,71 +217,12 @@ void BookmarkAppBubbleView::ButtonPressed(views::Button* sender, |
HandleButtonPressed(sender); |
} |
-void BookmarkAppBubbleView::SetAppImage(const std::string& id, |
- const gfx::ImageSkia& image) { |
- DCHECK_EQ(extension_id_, id); |
- icon_image_view_->SetImage(image); |
-} |
- |
void BookmarkAppBubbleView::HandleButtonPressed(views::Button* sender) { |
- // Unset |remove_app_| so we don't delete the bookmark after the window |
- // closes. |
- if (sender == add_button_) |
- remove_app_ = false; |
- |
- GetWidget()->Close(); |
-} |
- |
-void BookmarkAppBubbleView::ApplyEdits() { |
- // Set the launch type based on the checkbox. |
- extensions::LaunchType launch_type = open_as_window_checkbox_->checked() |
- ? extensions::LAUNCH_TYPE_WINDOW |
- : extensions::LAUNCH_TYPE_REGULAR; |
- profile_->GetPrefs()->SetInteger( |
- extensions::pref_names::kBookmarkAppCreationLaunchType, launch_type); |
- extensions::SetLaunchType(profile_, extension_id_, launch_type); |
- |
- const extensions::Extension* extension = |
- extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( |
- extension_id_, extensions::ExtensionRegistry::EVERYTHING); |
- |
- if (!extension) |
- return; |
- |
- if (base::UTF8ToUTF16(extension->name()) != title_tf_->text()) { |
- // Reinstall the app with an updated name. |
- WebApplicationInfo install_info(web_app_info_); |
- install_info.title = title_tf_->text(); |
- |
- // This will asynchronously reload the extension, causing the Extension* |
- // we have to be destroyed. The extension ID will stay the same so that is |
- // used later on to highlight the app. |
- extensions::CreateOrUpdateBookmarkApp(GetExtensionService(profile_), |
- &install_info); |
- } |
- |
- // As the extension could be destroyed after this point, set it to null to |
- // prevent anyone trying to use it in future. |
- extension = nullptr; |
- |
- // Show the newly installed app in the app launcher or chrome://apps. |
- Profile* current_profile = profile_->GetOriginalProfile(); |
- if (IsAppLauncherEnabled()) { |
- chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( |
- GetWidget()->GetNativeWindow()); |
- AppListService::Get(desktop) |
- ->ShowForAppInstall(current_profile, extension_id_, false); |
- return; |
+ if (sender == add_button_) { |
+ user_accepted_ = true; |
+ web_app_info_.title = title_tf_->text(); |
+ web_app_info_.open_as_window = open_as_window_checkbox_->checked(); |
} |
- chrome::NavigateParams params(current_profile, |
- GURL(chrome::kChromeUIAppsURL), |
- ui::PAGE_TRANSITION_LINK); |
- params.disposition = SINGLETON_TAB; |
- chrome::Navigate(¶ms); |
- |
- content::NotificationService::current()->Notify( |
- chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, |
- content::Source<content::WebContents>(params.target_contents), |
- content::Details<const std::string>(&extension_id_)); |
+ GetWidget()->Close(); |
} |