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

Unified Diff: chrome/browser/ui/views/extensions/extension_installed_bubble_view.cc

Issue 1807793003: Convert ExtensionInstalledBubble to BubbleDialogDelegateView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: iwyu Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_installed_bubble_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/extensions/extension_installed_bubble_view.cc
diff --git a/chrome/browser/ui/views/extensions/extension_installed_bubble_view.cc b/chrome/browser/ui/views/extensions/extension_installed_bubble_view.cc
index 9e86a81c0141750b39a8315af535117870dc91b5..30047bbcf3a215529d91d4f47177df15eac66dd1 100644
--- a/chrome/browser/ui/views/extensions/extension_installed_bubble_view.cc
+++ b/chrome/browser/ui/views/extensions/extension_installed_bubble_view.cc
@@ -113,31 +113,25 @@ class HeadingAndCloseButtonView : public views::View {
} // namespace
ExtensionInstalledBubbleView::ExtensionInstalledBubbleView(
- ExtensionInstalledBubble* bubble,
- BubbleReference bubble_reference)
- : bubble_(bubble),
- bubble_reference_(bubble_reference),
- extension_(bubble->extension()),
- browser_(bubble->browser()),
- type_(bubble->type()),
- anchor_position_(bubble->anchor_position()),
+ ExtensionInstalledBubble* controller)
+ : BubbleDialogDelegateView(nullptr, views::BubbleBorder::TOP_RIGHT),
close_(nullptr),
manage_shortcut_(nullptr) {}
ExtensionInstalledBubbleView::~ExtensionInstalledBubbleView() {}
void ExtensionInstalledBubbleView::UpdateAnchorView() {
- BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
+ BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
views::View* reference_view = nullptr;
- switch (anchor_position_) {
+ switch (controller_->anchor_position()) {
case ExtensionInstalledBubble::ANCHOR_BROWSER_ACTION: {
BrowserActionsContainer* container =
browser_view->GetToolbarView()->browser_actions();
// Hitting this DCHECK means |ShouldShow| failed.
DCHECK(!container->animating());
- reference_view = container->GetViewForId(extension_->id());
+ reference_view = container->GetViewForId(controller_->extension()->id());
// If the view is not visible then it is in the chevron, so point the
// install bubble to the chevron instead. If this is an incognito window,
// both could be invisible.
@@ -151,8 +145,8 @@ void ExtensionInstalledBubbleView::UpdateAnchorView() {
case ExtensionInstalledBubble::ANCHOR_PAGE_ACTION: {
LocationBarView* location_bar_view = browser_view->GetLocationBarView();
ExtensionAction* page_action =
- extensions::ExtensionActionManager::Get(browser_->profile())
- ->GetPageAction(*extension_);
+ extensions::ExtensionActionManager::Get(browser()->profile())
+ ->GetPageAction(*controller_->extension());
location_bar_view->SetPreviewEnabledPageAction(page_action,
true); // preview_enabled
reference_view = location_bar_view->GetPageActionView(page_action);
@@ -160,9 +154,8 @@ void ExtensionInstalledBubbleView::UpdateAnchorView() {
break;
}
case ExtensionInstalledBubble::ANCHOR_OMNIBOX: {
- LocationBarView* location_bar_view = browser_view->GetLocationBarView();
- reference_view = location_bar_view;
- DCHECK(reference_view);
+ // TODO(estade): remove ANCHOR_OMNIBOX.
+ NOTREACHED();
break;
}
case ExtensionInstalledBubble::ANCHOR_APP_MENU:
@@ -177,7 +170,7 @@ void ExtensionInstalledBubbleView::UpdateAnchorView() {
}
views::View* ExtensionInstalledBubbleView::CreateFootnoteView() {
- if (!(bubble_->options() & ExtensionInstalledBubble::SIGN_IN_PROMO))
+ if (!(controller_->options() & ExtensionInstalledBubble::SIGN_IN_PROMO))
return nullptr;
return new BubbleSyncPromoView(this,
@@ -185,58 +178,26 @@ views::View* ExtensionInstalledBubbleView::CreateFootnoteView() {
IDS_EXTENSION_INSTALLED_SYNC_PROMO_NEW);
}
+int ExtensionInstalledBubbleView::GetDialogButtons() const {
+ return ui::DIALOG_BUTTON_NONE;
+}
+
void ExtensionInstalledBubbleView::WindowClosing() {
- if (anchor_position_ == ExtensionInstalledBubble::ANCHOR_PAGE_ACTION) {
- BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
+ if (controller_->anchor_position() ==
+ ExtensionInstalledBubble::ANCHOR_PAGE_ACTION) {
+ BrowserView* browser_view =
+ BrowserView::GetBrowserViewForBrowser(browser());
browser_view->GetLocationBarView()->SetPreviewEnabledPageAction(
- extensions::ExtensionActionManager::Get(browser_->profile())
- ->GetPageAction(*extension_),
+ extensions::ExtensionActionManager::Get(browser()->profile())
+ ->GetPageAction(*controller_->extension()),
false); // preview_enabled
}
}
-gfx::Rect ExtensionInstalledBubbleView::GetAnchorRect() const {
- // For omnibox keyword bubbles, move the arrow to point to the left edge
- // of the omnibox, just to the right of the icon.
- if (type_ == ExtensionInstalledBubble::OMNIBOX_KEYWORD) {
- const LocationBarView* location_bar_view =
- BrowserView::GetBrowserViewForBrowser(browser_)->GetLocationBarView();
- return gfx::Rect(location_bar_view->GetOmniboxViewOrigin(),
- gfx::Size(0, location_bar_view->omnibox_view()->height()));
- }
- return views::BubbleDelegateView::GetAnchorRect();
-}
-
-void ExtensionInstalledBubbleView::OnWidgetClosing(views::Widget* widget) {
- if (bubble_reference_) {
- DCHECK_EQ(widget, GetWidget());
- // A more specific close reason should already be recorded.
- // This is the catch-all close reason for this bubble.
- bubble_reference_->CloseBubble(BUBBLE_CLOSE_FOCUS_LOST);
- }
-}
-
-void ExtensionInstalledBubbleView::OnWidgetActivationChanged(
- views::Widget* widget,
- bool active) {
- if (!active && bubble_reference_ && widget == GetWidget())
- bubble_reference_->CloseBubble(BUBBLE_CLOSE_FOCUS_LOST);
-}
-
-bool ExtensionInstalledBubbleView::AcceleratorPressed(
- const ui::Accelerator& accelerator) {
- if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE)
- return false;
- DCHECK(bubble_reference_);
- bool did_close = bubble_reference_->CloseBubble(BUBBLE_CLOSE_USER_DISMISSED);
- DCHECK(did_close);
- return true;
-}
-
void ExtensionInstalledBubbleView::OnSignInLinkClicked() {
GetWidget()->Close();
chrome::ShowBrowserSignin(
- browser_,
+ browser(),
signin_metrics::AccessPoint::ACCESS_POINT_EXTENSION_INSTALL_BUBBLE);
}
@@ -254,11 +215,13 @@ void ExtensionInstalledBubbleView::LinkClicked(views::Link* source,
std::string configure_url = chrome::kChromeUIExtensionsURL;
configure_url += chrome::kExtensionConfigureCommandsSubPage;
chrome::NavigateParams params(
- chrome::GetSingletonTabNavigateParams(browser_, GURL(configure_url)));
+ chrome::GetSingletonTabNavigateParams(browser(), GURL(configure_url)));
chrome::Navigate(&params);
}
-void ExtensionInstalledBubbleView::InitLayout() {
+void ExtensionInstalledBubbleView::Init() {
+ UpdateAnchorView();
+
// The Extension Installed bubble takes on various forms, depending on the
// type of extension installed. In general, though, they are all similar:
//
@@ -276,14 +239,13 @@ void ExtensionInstalledBubbleView::InitLayout() {
// or a link to configure the keybinding shortcut (if one exists).
// Extra info can include a promo for signing into sync.
- const ExtensionInstalledBubble& bubble = *bubble_;
// The number of rows in the content section of the bubble.
int main_content_row_count = 1;
- if (bubble.options() & ExtensionInstalledBubble::HOW_TO_USE)
+ if (controller_->options() & ExtensionInstalledBubble::HOW_TO_USE)
++main_content_row_count;
- if (bubble.options() & ExtensionInstalledBubble::SHOW_KEYBINDING)
+ if (controller_->options() & ExtensionInstalledBubble::SHOW_KEYBINDING)
++main_content_row_count;
- if (bubble.options() & ExtensionInstalledBubble::HOW_TO_MANAGE)
+ if (controller_->options() & ExtensionInstalledBubble::HOW_TO_MANAGE)
++main_content_row_count;
views::GridLayout* layout = new views::GridLayout(this);
@@ -303,7 +265,7 @@ void ExtensionInstalledBubbleView::InitLayout() {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
const gfx::FontList& font_list = rb.GetFontList(ui::ResourceBundle::BaseFont);
- const SkBitmap& bitmap = bubble.icon();
+ const SkBitmap& bitmap = controller_->icon();
// Add the icon (for all options).
// Scale down to 43x43, but allow smaller icons (don't scale up).
gfx::Size size(bitmap.width(), bitmap.height());
@@ -317,7 +279,8 @@ void ExtensionInstalledBubbleView::InitLayout() {
layout->AddView(icon, 1, main_content_row_count);
// Add the heading (for all options).
- base::string16 extension_name = base::UTF8ToUTF16(extension_->name());
+ base::string16 extension_name =
+ base::UTF8ToUTF16(controller_->extension()->name());
base::i18n::AdjustStringForLocaleDirection(&extension_name);
views::Label* heading =
CreateLabel(l10n_util::GetStringFUTF16(IDS_EXTENSION_INSTALLED_HEADING,
@@ -340,11 +303,12 @@ void ExtensionInstalledBubbleView::InitLayout() {
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
};
- if (bubble.options() & ExtensionInstalledBubble::HOW_TO_USE) {
- add_content_view(CreateLabel(bubble.GetHowToUseDescription(), font_list));
+ if (controller_->options() & ExtensionInstalledBubble::HOW_TO_USE) {
+ add_content_view(
+ CreateLabel(controller_->GetHowToUseDescription(), font_list));
}
- if (bubble.options() & ExtensionInstalledBubble::SHOW_KEYBINDING) {
+ if (controller_->options() & ExtensionInstalledBubble::SHOW_KEYBINDING) {
manage_shortcut_ = new views::Link(
l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS));
manage_shortcut_->set_listener(this);
@@ -352,7 +316,7 @@ void ExtensionInstalledBubbleView::InitLayout() {
add_content_view(manage_shortcut_);
}
- if (bubble.options() & ExtensionInstalledBubble::HOW_TO_MANAGE) {
+ if (controller_->options() & ExtensionInstalledBubble::HOW_TO_MANAGE) {
add_content_view(CreateLabel(
l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_INFO),
font_list));
@@ -371,6 +335,8 @@ bool ExtensionInstalledBubble::ShouldShow() {
return true;
}
+// NB: This bubble is using the temporarily-deprecated bubble manager interface
Devlin 2016/04/07 19:02:51 This is deprecated now? I thought it was just add
Evan Stade 2016/04/07 20:02:50 Yes, but it's already been de-staffed (at least te
+// BubbleUi. Do not copy this pattern.
class ExtensionInstalledBubbleUi : public BubbleUi {
public:
explicit ExtensionInstalledBubbleUi(ExtensionInstalledBubble* bubble);
@@ -383,7 +349,7 @@ class ExtensionInstalledBubbleUi : public BubbleUi {
void UpdateAnchorPosition() override;
ExtensionInstalledBubble* bubble_;
- ExtensionInstalledBubbleView* delegate_view_;
+ ExtensionInstalledBubbleView* bubble_view_;
DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleUi);
};
@@ -395,36 +361,28 @@ scoped_ptr<BubbleUi> ExtensionInstalledBubble::BuildBubbleUi() {
ExtensionInstalledBubbleUi::ExtensionInstalledBubbleUi(
ExtensionInstalledBubble* bubble)
- : bubble_(bubble), delegate_view_(nullptr) {
+ : bubble_(bubble), bubble_view_(nullptr) {
DCHECK(bubble_);
}
ExtensionInstalledBubbleUi::~ExtensionInstalledBubbleUi() {}
-void ExtensionInstalledBubbleUi::Show(BubbleReference bubble_reference) {
- // Owned by widget.
- delegate_view_ = new ExtensionInstalledBubbleView(bubble_, bubble_reference);
- delegate_view_->UpdateAnchorView();
-
- delegate_view_->set_arrow(bubble_->type() == bubble_->OMNIBOX_KEYWORD
- ? views::BubbleBorder::TOP_LEFT
- : views::BubbleBorder::TOP_RIGHT);
-
- delegate_view_->InitLayout();
+void ExtensionInstalledBubbleUi::Show(BubbleReference /*bubble_reference*/) {
Devlin 2016/04/07 19:02:50 nit: is this part of the styleguide? I don't see
Evan Stade 2016/04/07 20:02:50 yes, it's in the style guide but not commonly done
+ bubble_view_ = new ExtensionInstalledBubbleView(bubble_);
- views::BubbleDelegateView::CreateBubble(delegate_view_)->Show();
+ views::BubbleDialogDelegateView::CreateBubble(bubble_view_)->Show();
content::RecordAction(
base::UserMetricsAction("Signin_Impression_FromExtensionInstallBubble"));
}
void ExtensionInstalledBubbleUi::Close() {
- if (delegate_view_) {
- delegate_view_->GetWidget()->Close();
- delegate_view_ = nullptr;
+ if (bubble_view_) {
+ bubble_view_->GetWidget()->Close();
+ bubble_view_ = nullptr;
}
}
void ExtensionInstalledBubbleUi::UpdateAnchorPosition() {
- DCHECK(delegate_view_);
- delegate_view_->UpdateAnchorView();
+ DCHECK(bubble_view_);
+ bubble_view_->UpdateAnchorView();
}
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_installed_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698