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

Side by Side Diff: chrome/browser/ui/views/location_bar/zoom_bubble_view.cc

Issue 712993004: Don't re-use a zoom bubble unless it has the same web-contents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test. Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/location_bar/zoom_bubble_view.h" 5 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/chrome_page_zoom.h" 10 #include "chrome/browser/chrome_page_zoom.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 bool anchor_to_view = !is_fullscreen || 56 bool anchor_to_view = !is_fullscreen ||
57 browser_view->immersive_mode_controller()->IsRevealed(); 57 browser_view->immersive_mode_controller()->IsRevealed();
58 views::View* anchor_view = anchor_to_view ? 58 views::View* anchor_view = anchor_to_view ?
59 browser_view->GetLocationBarView()->zoom_view() : NULL; 59 browser_view->GetLocationBarView()->zoom_view() : NULL;
60 60
61 // Find the extension that initiated the zoom change, if any. 61 // Find the extension that initiated the zoom change, if any.
62 ZoomController* zoom_controller = 62 ZoomController* zoom_controller =
63 ZoomController::FromWebContents(web_contents); 63 ZoomController::FromWebContents(web_contents);
64 const extensions::Extension* extension = zoom_controller->last_extension(); 64 const extensions::Extension* extension = zoom_controller->last_extension();
65 65
66 // If the bubble is already showing in this window and the zoom change was not
67 // initiated by an extension, then the bubble can be reused and only the label
68 // text needs to be updated.
69 if (zoom_bubble_ && 66 if (zoom_bubble_ &&
70 zoom_bubble_->GetAnchorView() == anchor_view && 67 zoom_bubble_->GetAnchorView() == anchor_view &&
71 !extension) { 68 !extension) {
69 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_);
72 zoom_bubble_->Refresh(); 70 zoom_bubble_->Refresh();
73 return; 71 return;
74 } 72 }
75 73
76 // If the bubble is already showing but in a different tab, the current 74 // If the bubble is already showing but in a different tab, the current
77 // bubble must be closed and a new one created. 75 // bubble must be closed and a new one created.
78 CloseBubble(); 76 CloseBubble();
79 77
80 zoom_bubble_ = new ZoomBubbleView(anchor_view, 78 zoom_bubble_ = new ZoomBubbleView(anchor_view,
81 web_contents, 79 web_contents,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 void ZoomBubbleView::Refresh() { 165 void ZoomBubbleView::Refresh() {
168 ZoomController* zoom_controller = 166 ZoomController* zoom_controller =
169 ZoomController::FromWebContents(web_contents_); 167 ZoomController::FromWebContents(web_contents_);
170 int zoom_percent = zoom_controller->GetZoomPercent(); 168 int zoom_percent = zoom_controller->GetZoomPercent();
171 label_->SetText( 169 label_->SetText(
172 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); 170 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent));
173 StartTimerIfNecessary(); 171 StartTimerIfNecessary();
174 } 172 }
175 173
176 void ZoomBubbleView::Close() { 174 void ZoomBubbleView::Close() {
175 // Prevent inadvertent re-use of this bubble.
sky 2014/11/12 21:48:55 This isn't entirely clear. Maybe something like Cl
wjmaclean 2014/11/12 22:00:00 Done. I assume you meant "Widget's Close() is asy
176 zoom_bubble_ = NULL;
177 web_contents_ = NULL;
177 GetWidget()->Close(); 178 GetWidget()->Close();
178 } 179 }
179 180
180 void ZoomBubbleView::SetExtensionInfo(const extensions::Extension* extension) { 181 void ZoomBubbleView::SetExtensionInfo(const extensions::Extension* extension) {
181 DCHECK(extension); 182 DCHECK(extension);
182 extension_info_.id = extension->id(); 183 extension_info_.id = extension->id();
183 extension_info_.name = extension->name(); 184 extension_info_.name = extension->name();
184 185
185 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 186 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
186 const gfx::ImageSkia& default_extension_icon_image = 187 const gfx::ImageSkia& default_extension_icon_image =
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 344 }
344 345
345 void ZoomBubbleView::OnImmersiveRevealStarted() { 346 void ZoomBubbleView::OnImmersiveRevealStarted() {
346 CloseBubble(); 347 CloseBubble();
347 } 348 }
348 349
349 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() { 350 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() {
350 immersive_mode_controller_ = NULL; 351 immersive_mode_controller_ = NULL;
351 } 352 }
352 353
353 void ZoomBubbleView::WindowClosing() {
sky 2014/11/12 21:48:55 You should still keep this. The reason you want th
wjmaclean 2014/11/12 22:00:01 Sounds fair ... didn't realize that would happen.
354 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't
355 // call this right away). Only set to NULL when it's this bubble.
356 if (zoom_bubble_ == this)
357 zoom_bubble_ = NULL;
358 }
359
360 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} 354 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {}
361 355
362 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} 356 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698