1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/extensions/extension_installed_bubble_view.h"
#include <algorithm>
#include <string>
#include "base/i18n/rtl.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/commands/command_service.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/singleton_tabs.h"
#include "chrome/browser/ui/sync/sync_promo_ui.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
#include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
#include "chrome/common/extensions/api/omnibox/omnibox_handler.h"
#include "chrome/common/extensions/sync_helper.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "extensions/common/extension.h"
#include "extensions/common/feature_switch.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/render_text.h"
#include "ui/gfx/text_elider.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/link_listener.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/layout_constants.h"
using extensions::Extension;
namespace {
const int kIconSize = 43;
const int kRightColumnWidth = 285;
// The Bubble uses a BubbleBorder which adds about 6 pixels of whitespace
// around the content view. We compensate by reducing our outer borders by this
// amount + 4px.
const int kOuterMarginInset = 10;
const int kHorizOuterMargin = views::kPanelHorizMargin - kOuterMarginInset;
const int kVertOuterMargin = views::kPanelVertMargin - kOuterMarginInset;
// Interior vertical margin is 8px smaller than standard
const int kVertInnerMargin = views::kPanelVertMargin - 8;
// We want to shift the right column (which contains the header and text) up
// 4px to align with icon.
const int kRightcolumnVerticalShift = -4;
} // namespace
namespace chrome {
void ShowExtensionInstalledBubble(const Extension* extension,
Browser* browser,
const SkBitmap& icon) {
ExtensionInstalledBubbleView::Show(extension, browser, icon);
}
} // namespace chrome
// InstalledBubbleContent is the content view which is placed in the
// ExtensionInstalledBubbleView. It displays the install icon and explanatory
// text about the installed extension.
class InstalledBubbleContent : public views::View,
public views::ButtonListener,
public views::LinkListener {
public:
InstalledBubbleContent(Browser* browser,
const Extension* extension,
ExtensionInstalledBubble::BubbleType type,
const SkBitmap* icon);
// Overridden from views::ButtonListener.
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Overriden from views::LinkListener.
void LinkClicked(views::Link* source, int event_flags) override;
private:
enum Flavors {
NONE = 0,
HOW_TO_USE = 1 << 0,
HOW_TO_MANAGE = 1 << 1,
SHOW_KEYBINDING = 1 << 2,
SIGN_IN_PROMO = 1 << 3,
};
bool GetKeybinding(extensions::Command* command);
base::string16 GetHowToUseDescription(const base::string16& key);
// Layout the signin promo at coordinates |offset_x| and |offset_y|. Returns
// the height (in pixels) of the promo UI.
int LayoutSigninPromo(int offset_x, int offset_y);
// Overriden from views::View.
gfx::Size GetPreferredSize() const override;
void Layout() override;
void OnPaint(gfx::Canvas* canvas) override;
// The browser we're associated with.
Browser* browser_;
// The id of the extension just installed.
const std::string extension_id_;
// The string that contains the link text at the beginning of the sign-in
// promo text.
base::string16 signin_promo_link_text_;
// The remaining text of the sign-in promo text.
base::string16 signin_promo_text_;
// A vector of RenderText objects representing the full sign-in promo
// paragraph as layed out within the bubble, but has the text of the link
// whited out so the link can be drawn in its place.
ScopedVector<gfx::RenderText> sign_in_promo_lines_;
// The type of the bubble to show (Browser Action, Omnibox keyword, etc).
ExtensionInstalledBubble::BubbleType type_;
// A bitmask containing the various flavors of bubble sections to show.
int flavors_;
// The height, in pixels, of the sign-in promo.
size_t height_of_signin_promo_;
views::ImageView* icon_;
views::Label* heading_;
views::Label* how_to_use_;
views::Link* sign_in_link_;
views::Label* manage_;
views::Link* manage_shortcut_;
views::ImageButton* close_button_;
DISALLOW_COPY_AND_ASSIGN(InstalledBubbleContent);
};
InstalledBubbleContent::InstalledBubbleContent(
Browser* browser,
const Extension* extension,
ExtensionInstalledBubble::BubbleType type,
const SkBitmap* icon)
: browser_(browser),
extension_id_(extension->id()),
type_(type),
flavors_(NONE),
height_of_signin_promo_(0u),
how_to_use_(NULL),
sign_in_link_(NULL),
manage_(NULL),
manage_shortcut_(NULL) {
// The Extension Installed bubble takes on various forms, depending on the
// type of extension installed. In general, though, they are all similar:
//
// -------------------------
// | | Heading [X] |
// | Icon | Info |
// | | Extra info |
// -------------------------
//
// Icon and Heading are always shown (as well as the close button).
// Info is shown for browser actions, page actions and Omnibox keyword
// extensions and might list keyboard shorcut for the former two types.
// Extra info is...
// ... for other types, either a description of how to manage the extension
// or a link to configure the keybinding shortcut (if one exists).
// Extra info can include a promo for signing into sync.
// First figure out the keybinding situation.
extensions::Command command;
bool has_keybinding = GetKeybinding(&command);
base::string16 key; // Keyboard shortcut or keyword to display in bubble.
if (extensions::sync_helper::IsSyncableExtension(extension) &&
SyncPromoUI::ShouldShowSyncPromo(browser->profile()))
flavors_ |= SIGN_IN_PROMO;
// Determine the bubble flavor we want, based on the extension type.
switch (type_) {
case ExtensionInstalledBubble::BROWSER_ACTION:
case ExtensionInstalledBubble::PAGE_ACTION: {
flavors_ |= HOW_TO_USE;
if (has_keybinding) {
flavors_ |= SHOW_KEYBINDING;
key = command.accelerator().GetShortcutText();
} else {
// The How-To-Use text makes the bubble seem a little crowded when the
// extension has a keybinding, so the How-To-Manage text is not shown
// in those cases.
flavors_ |= HOW_TO_MANAGE;
}
break;
}
case ExtensionInstalledBubble::OMNIBOX_KEYWORD: {
flavors_ |= HOW_TO_USE | HOW_TO_MANAGE;
key = base::UTF8ToUTF16(extensions::OmniboxInfo::GetKeyword(extension));
break;
}
case ExtensionInstalledBubble::GENERIC: {
break;
}
default: {
// When adding a new bubble type, the flavor needs to be set.
static_assert(ExtensionInstalledBubble::GENERIC == 3,
"kBubbleType enum has changed, this switch statement must "
"be updateed");
break;
}
}
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
const gfx::FontList& font_list =
rb.GetFontList(ui::ResourceBundle::BaseFont);
// Add the icon (for all flavors).
// Scale down to 43x43, but allow smaller icons (don't scale up).
gfx::Size size(icon->width(), icon->height());
if (size.width() > kIconSize || size.height() > kIconSize)
size = gfx::Size(kIconSize, kIconSize);
icon_ = new views::ImageView();
icon_->SetImageSize(size);
icon_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(*icon));
AddChildView(icon_);
// Add the heading (for all flavors).
base::string16 extension_name = base::UTF8ToUTF16(extension->name());
base::i18n::AdjustStringForLocaleDirection(&extension_name);
heading_ = new views::Label(l10n_util::GetStringFUTF16(
IDS_EXTENSION_INSTALLED_HEADING, extension_name));
heading_->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont));
heading_->SetMultiLine(true);
heading_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
AddChildView(heading_);
if (flavors_ & HOW_TO_USE) {
how_to_use_ = new views::Label(GetHowToUseDescription(key));
how_to_use_->SetFontList(font_list);
how_to_use_->SetMultiLine(true);
how_to_use_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
AddChildView(how_to_use_);
}
if (flavors_ & SHOW_KEYBINDING) {
manage_shortcut_ = new views::Link(
l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS));
manage_shortcut_->set_listener(this);
AddChildView(manage_shortcut_);
}
if (flavors_ & HOW_TO_MANAGE) {
manage_ = new views::Label(l10n_util::GetStringUTF16(
IDS_EXTENSION_INSTALLED_MANAGE_INFO));
manage_->SetFontList(font_list);
manage_->SetMultiLine(true);
manage_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
AddChildView(manage_);
}
if (flavors_ & SIGN_IN_PROMO) {
signin_promo_text_ =
l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_SIGNIN_PROMO);
signin_promo_link_text_ =
l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_SIGNIN_PROMO_LINK);
sign_in_link_ = new views::Link(signin_promo_link_text_);
sign_in_link_->SetFontList(font_list);
sign_in_link_->set_listener(this);
AddChildView(sign_in_link_);
}
// Add the Close button (for all flavors).
close_button_ = new views::ImageButton(this);
close_button_->SetImage(views::CustomButton::STATE_NORMAL,
rb.GetImageSkiaNamed(IDR_CLOSE_2));
close_button_->SetImage(views::CustomButton::STATE_HOVERED,
rb.GetImageSkiaNamed(IDR_CLOSE_2_H));
close_button_->SetImage(views::CustomButton::STATE_PRESSED,
rb.GetImageSkiaNamed(IDR_CLOSE_2_P));
AddChildView(close_button_);
}
void InstalledBubbleContent::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK_EQ(sender, close_button_);
GetWidget()->Close();
}
void InstalledBubbleContent::LinkClicked(views::Link* source, int event_flags) {
GetWidget()->Close();
if (source == sign_in_link_) {
chrome::ShowBrowserSignin(
browser_, signin_metrics::SOURCE_EXTENSION_INSTALL_BUBBLE);
return;
}
DCHECK_EQ(manage_shortcut_, source);
std::string configure_url = chrome::kChromeUIExtensionsURL;
configure_url += chrome::kExtensionConfigureCommandsSubPage;
chrome::NavigateParams params(chrome::GetSingletonTabNavigateParams(
browser_, GURL(configure_url)));
chrome::Navigate(¶ms);
}
bool InstalledBubbleContent::GetKeybinding(extensions::Command* command) {
extensions::CommandService* command_service =
extensions::CommandService::Get(browser_->profile());
if (type_ == ExtensionInstalledBubble::BROWSER_ACTION) {
return command_service->GetBrowserActionCommand(
extension_id_,
extensions::CommandService::ACTIVE,
command,
NULL);
} else if (type_ == ExtensionInstalledBubble::PAGE_ACTION) {
return command_service->GetPageActionCommand(
extension_id_,
extensions::CommandService::ACTIVE,
command,
NULL);
} else {
return false;
}
}
base::string16 InstalledBubbleContent::GetHowToUseDescription(
const base::string16& key) {
switch (type_) {
case ExtensionInstalledBubble::BROWSER_ACTION:
if (!key.empty()) {
return l10n_util::GetStringFUTF16(
IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO_WITH_SHORTCUT, key);
} else {
return l10n_util::GetStringUTF16(
IDS_EXTENSION_INSTALLED_BROWSER_ACTION_INFO);
}
break;
case ExtensionInstalledBubble::PAGE_ACTION:
if (!key.empty()) {
return l10n_util::GetStringFUTF16(
IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO_WITH_SHORTCUT, key);
} else {
return l10n_util::GetStringUTF16(
IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO);
}
break;
case ExtensionInstalledBubble::OMNIBOX_KEYWORD:
return l10n_util::GetStringFUTF16(
IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO, key);
break;
default:
NOTREACHED();
break;
}
return base::string16();
}
int InstalledBubbleContent::LayoutSigninPromo(int offset_x, int offset_y) {
sign_in_promo_lines_.clear();
int height = 0;
gfx::Rect contents_area = GetContentsBounds();
if (contents_area.IsEmpty())
return height;
contents_area.set_width(kRightColumnWidth);
base::string16 full_text = signin_promo_link_text_ + signin_promo_text_;
// The link is the first item in the text.
const gfx::Size link_size = sign_in_link_->GetPreferredSize();
sign_in_link_->SetBounds(
offset_x, offset_y, link_size.width(), link_size.height());
// Word-wrap the full label text.
const gfx::FontList font_list;
std::vector<base::string16> lines;
gfx::ElideRectangleText(full_text, font_list, contents_area.width(),
contents_area.height(), gfx::ELIDE_LONG_WORDS,
&lines);
gfx::Point position = gfx::Point(
contents_area.origin().x() + offset_x,
contents_area.origin().y() + offset_y + 1);
if (base::i18n::IsRTL()) {
position -= gfx::Vector2d(
2 * views::kPanelHorizMargin + kHorizOuterMargin, 0);
}
// Loop through the lines, creating a renderer for each.
for (std::vector<base::string16>::const_iterator it = lines.begin();
it != lines.end(); ++it) {
gfx::RenderText* line = gfx::RenderText::CreateInstance();
line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI);
line->SetText(*it);
const gfx::Size size(contents_area.width(),
line->GetStringSize().height());
line->SetDisplayRect(gfx::Rect(position, size));
position.set_y(position.y() + size.height());
sign_in_promo_lines_.push_back(line);
height += size.height();
}
// The link is drawn separately; make it transparent here to only draw once.
// The link always leads other text and is assumed to fit on the first line.
sign_in_promo_lines_.front()->ApplyColor(SK_ColorTRANSPARENT,
gfx::Range(0, signin_promo_link_text_.size()));
return height;
}
gfx::Size InstalledBubbleContent::GetPreferredSize() const {
int width = kHorizOuterMargin;
width += kIconSize;
width += views::kPanelHorizMargin;
width += kRightColumnWidth;
width += 2 * views::kPanelHorizMargin;
width += kHorizOuterMargin;
int height = kVertOuterMargin;
height += heading_->GetHeightForWidth(kRightColumnWidth);
height += kVertInnerMargin;
if (flavors_ & HOW_TO_USE) {
height += how_to_use_->GetHeightForWidth(kRightColumnWidth);
height += kVertInnerMargin;
}
if (flavors_ & HOW_TO_MANAGE) {
height += manage_->GetHeightForWidth(kRightColumnWidth);
height += kVertInnerMargin;
}
if (flavors_ & SIGN_IN_PROMO && height_of_signin_promo_ > 0u) {
height += height_of_signin_promo_;
height += kVertInnerMargin;
}
if (flavors_ & SHOW_KEYBINDING) {
height += manage_shortcut_->GetHeightForWidth(kRightColumnWidth);
height += kVertInnerMargin;
}
return gfx::Size(width, std::max(height, kIconSize + 2 * kVertOuterMargin));
}
void InstalledBubbleContent::Layout() {
int x = kHorizOuterMargin;
int y = kVertOuterMargin;
icon_->SetBounds(x, y, kIconSize, kIconSize);
x += kIconSize;
x += views::kPanelHorizMargin;
y += kRightcolumnVerticalShift;
heading_->SizeToFit(kRightColumnWidth);
heading_->SetX(x);
heading_->SetY(y);
y += heading_->height();
y += kVertInnerMargin;
if (flavors_ & HOW_TO_USE) {
how_to_use_->SizeToFit(kRightColumnWidth);
how_to_use_->SetX(x);
how_to_use_->SetY(y);
y += how_to_use_->height();
y += kVertInnerMargin;
}
if (flavors_ & HOW_TO_MANAGE) {
manage_->SizeToFit(kRightColumnWidth);
manage_->SetX(x);
manage_->SetY(y);
y += manage_->height();
y += kVertInnerMargin;
}
if (flavors_ & SIGN_IN_PROMO) {
height_of_signin_promo_ = LayoutSigninPromo(x, y);
y += height_of_signin_promo_;
y += kVertInnerMargin;
}
if (flavors_ & SHOW_KEYBINDING) {
gfx::Size sz = manage_shortcut_->GetPreferredSize();
manage_shortcut_->SetBounds(width() - 2 * kHorizOuterMargin - sz.width(),
y,
sz.width(),
sz.height());
y += manage_shortcut_->height();
y += kVertInnerMargin;
}
gfx::Size sz;
x += kRightColumnWidth + 2 * views::kPanelHorizMargin + kHorizOuterMargin -
close_button_->GetPreferredSize().width();
y = kVertOuterMargin;
sz = close_button_->GetPreferredSize();
// x-1 & y-1 is just slop to get the close button visually aligned with the
// title text and bubble arrow.
close_button_->SetBounds(x - 1, y - 1, sz.width(), sz.height());
}
void InstalledBubbleContent::OnPaint(gfx::Canvas* canvas) {
for (ScopedVector<gfx::RenderText>::const_iterator it =
sign_in_promo_lines_.begin();
it != sign_in_promo_lines_.end(); ++it)
(*it)->Draw(canvas);
views::View::OnPaint(canvas);
}
void ExtensionInstalledBubbleView::Show(const Extension* extension,
Browser* browser,
const SkBitmap& icon) {
new ExtensionInstalledBubbleView(extension, browser, icon);
}
ExtensionInstalledBubbleView::ExtensionInstalledBubbleView(
const Extension* extension, Browser *browser, const SkBitmap& icon)
: bubble_(this, extension, browser, icon) {
}
ExtensionInstalledBubbleView::~ExtensionInstalledBubbleView() {}
bool ExtensionInstalledBubbleView::MaybeShowNow() {
BrowserView* browser_view =
BrowserView::GetBrowserViewForBrowser(bubble_.browser());
views::View* reference_view = NULL;
if (bubble_.type() == bubble_.BROWSER_ACTION ||
extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) {
BrowserActionsContainer* container =
browser_view->GetToolbarView()->browser_actions();
if (container->animating())
return false;
reference_view = container->GetViewForId(bubble_.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.
if (!reference_view || !reference_view->visible()) {
reference_view = container->chevron();
if (!reference_view || !reference_view->visible())
reference_view = NULL; // fall back to app menu below.
}
} else if (bubble_.type() == bubble_.PAGE_ACTION) {
LocationBarView* location_bar_view = browser_view->GetLocationBarView();
ExtensionAction* page_action =
extensions::ExtensionActionManager::Get(bubble_.browser()->profile())->
GetPageAction(*bubble_.extension());
location_bar_view->SetPreviewEnabledPageAction(page_action,
true); // preview_enabled
reference_view = location_bar_view->GetPageActionView(page_action);
DCHECK(reference_view);
} else if (bubble_.type() == bubble_.OMNIBOX_KEYWORD) {
LocationBarView* location_bar_view = browser_view->GetLocationBarView();
reference_view = location_bar_view;
DCHECK(reference_view);
}
// Default case.
if (reference_view == NULL)
reference_view = browser_view->GetToolbarView()->app_menu();
SetAnchorView(reference_view);
set_arrow(bubble_.type() == bubble_.OMNIBOX_KEYWORD ?
views::BubbleBorder::TOP_LEFT :
views::BubbleBorder::TOP_RIGHT);
SetLayoutManager(new views::FillLayout());
AddChildView(new InstalledBubbleContent(
bubble_.browser(), bubble_.extension(), bubble_.type(),
&bubble_.icon()));
views::BubbleDelegateView::CreateBubble(this)->Show();
// The bubble widget is now the parent and owner of |this| and takes care of
// deletion when the bubble or browser go away.
bubble_.IgnoreBrowserClosing();
return true;
}
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 (bubble_.type() == bubble_.OMNIBOX_KEYWORD) {
const LocationBarView* location_bar_view =
BrowserView::GetBrowserViewForBrowser(bubble_.browser())->
GetLocationBarView();
return gfx::Rect(location_bar_view->GetOmniboxViewOrigin(),
gfx::Size(0, location_bar_view->omnibox_view()->height()));
}
return views::BubbleDelegateView::GetAnchorRect();
}
void ExtensionInstalledBubbleView::WindowClosing() {
if (bubble_.extension() && bubble_.type() == bubble_.PAGE_ACTION &&
!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) {
BrowserView* browser_view =
BrowserView::GetBrowserViewForBrowser(bubble_.browser());
browser_view->GetLocationBarView()->SetPreviewEnabledPageAction(
extensions::ExtensionActionManager::Get(bubble_.browser()->profile())->
GetPageAction(*bubble_.extension()),
false); // preview_enabled
}
}
|