1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/frame/browser_view.h"
9 #include "base/auto_reset.h"
10 #include "base/command_line.h"
11 #include "base/i18n/rtl.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/metrics/histogram.h"
14 #include "base/prefs/pref_service.h"
15 #include "base/profiler/scoped_tracker.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/app/chrome_dll_resource.h"
19 #include "chrome/browser/app_mode/app_mode_utils.h"
20 #include "chrome/browser/bookmarks/bookmark_stats.h"
21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/chrome_notification_types.h"
23 #include "chrome/browser/extensions/extension_util.h"
24 #include "chrome/browser/extensions/tab_helper.h"
25 #include "chrome/browser/infobars/infobar_service.h"
26 #include "chrome/browser/native_window_notification_source.h"
27 #include "chrome/browser/profiles/avatar_menu.h"
28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
30 #include "chrome/browser/profiles/profile_info_cache.h"
31 #include "chrome/browser/profiles/profile_manager.h"
32 #include "chrome/browser/profiles/profile_window.h"
33 #include "chrome/browser/profiles/profiles_state.h"
34 #include "chrome/browser/search/search.h"
35 #include "chrome/browser/sessions/tab_restore_service.h"
36 #include "chrome/browser/sessions/tab_restore_service_factory.h"
37 #include "chrome/browser/signin/signin_header_helper.h"
38 #include "chrome/browser/themes/theme_properties.h"
39 #include "chrome/browser/themes/theme_service_factory.h"
40 #include "chrome/browser/translate/chrome_translate_client.h"
41 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h"
42 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
43 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h"
44 #include "chrome/browser/ui/browser.h"
45 #include "chrome/browser/ui/browser_command_controller.h"
46 #include "chrome/browser/ui/browser_commands.h"
47 #include "chrome/browser/ui/browser_dialogs.h"
48 #include "chrome/browser/ui/browser_finder.h"
49 #include "chrome/browser/ui/browser_list.h"
50 #include "chrome/browser/ui/browser_window_state.h"
51 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
52 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
53 #include "chrome/browser/ui/omnibox/omnibox_view.h"
54 #include "chrome/browser/ui/search/search_delegate.h"
55 #include "chrome/browser/ui/search/search_model.h"
56 #include "chrome/browser/ui/search/search_ui.h"
57 #include "chrome/browser/ui/tabs/tab_menu_model.h"
58 #include "chrome/browser/ui/tabs/tab_strip_model.h"
59 #include "chrome/browser/ui/view_ids.h"
60 #include "chrome/browser/ui/views/accelerator_table.h"
61 #include "chrome/browser/ui/views/accessibility/invert_bubble_view.h"
62 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
63 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
64 #include "chrome/browser/ui/views/browser_dialogs.h"
65 #include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h"
66 #include "chrome/browser/ui/views/download/download_shelf_view.h"
67 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h"
68 #include "chrome/browser/ui/views/extensions/bookmark_app_bubble_view.h"
69 #include "chrome/browser/ui/views/frame/browser_view_layout.h"
70 #include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h"
71 #include "chrome/browser/ui/views/frame/contents_layout_manager.h"
72 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
73 #include "chrome/browser/ui/views/frame/top_container_view.h"
74 #include "chrome/browser/ui/views/frame/web_contents_close_handler.h"
75 #include "chrome/browser/ui/views/infobars/infobar_container_view.h"
76 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
77 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
78 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
79 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
80 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h"
81 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
82 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
83 #include "chrome/browser/ui/views/profiles/profile_reset_bubble_view.h"
84 #include "chrome/browser/ui/views/session_crashed_bubble_view.h"
85 #include "chrome/browser/ui/views/settings_api_bubble_helper_views.h"
86 #include "chrome/browser/ui/views/status_bubble_views.h"
87 #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
88 #include "chrome/browser/ui/views/tabs/tab.h"
89 #include "chrome/browser/ui/views/tabs/tab_strip.h"
90 #include "chrome/browser/ui/views/toolbar/reload_button.h"
91 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
92 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
93 #include "chrome/browser/ui/views/translate/translate_bubble_view.h"
94 #include "chrome/browser/ui/views/update_recommended_message_box.h"
95 #include "chrome/browser/ui/views/website_settings/permissions_bubble_view.h"
96 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h"
97 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
98 #include "chrome/browser/ui/window_sizer/window_sizer.h"
99 #include "chrome/common/chrome_switches.h"
100 #include "chrome/common/pref_names.h"
101 #include "chrome/common/url_constants.h"
102 #include "chrome/grit/chromium_strings.h"
103 #include "chrome/grit/generated_resources.h"
104 #include "chrome/grit/locale_settings.h"
105 #include "components/app_modal/app_modal_dialog.h"
106 #include "components/app_modal/app_modal_dialog_queue.h"
107 #include "components/app_modal/native_app_modal_dialog.h"
108 #include "components/signin/core/common/profile_management_switches.h"
109 #include "components/translate/core/browser/language_state.h"
110 #include "content/app/resources/grit/content_resources.h"
111 #include "content/public/browser/download_manager.h"
112 #include "content/public/browser/notification_service.h"
113 #include "content/public/browser/render_frame_host.h"
114 #include "content/public/browser/render_view_host.h"
115 #include "content/public/browser/render_widget_host_view.h"
116 #include "content/public/browser/user_metrics.h"
117 #include "content/public/browser/web_contents.h"
118 #include "content/public/common/content_switches.h"
119 #include "grit/theme_resources.h"
120 #include "ui/accessibility/ax_view_state.h"
121 #include "ui/base/accelerators/accelerator.h"
122 #include "ui/base/hit_test.h"
123 #include "ui/base/l10n/l10n_util.h"
124 #include "ui/base/resource/resource_bundle.h"
125 #include "ui/base/theme_provider.h"
126 #include "ui/content_accelerators/accelerator_util.h"
127 #include "ui/events/event_utils.h"
128 #include "ui/gfx/canvas.h"
129 #include "ui/gfx/color_utils.h"
130 #include "ui/gfx/geometry/rect_conversions.h"
131 #include "ui/gfx/screen.h"
132 #include "ui/strings/grit/ui_strings.h"
133 #include "ui/views/controls/button/menu_button.h"
134 #include "ui/views/controls/textfield/textfield.h"
135 #include "ui/views/controls/webview/webview.h"
136 #include "ui/views/focus/external_focus_tracker.h"
137 #include "ui/views/focus/view_storage.h"
138 #include "ui/views/layout/grid_layout.h"
139 #include "ui/views/widget/native_widget.h"
140 #include "ui/views/widget/root_view.h"
141 #include "ui/views/widget/widget.h"
142 #include "ui/views/window/dialog_delegate.h"
144 #if defined(USE_AURA)
145 #include "ui/aura/client/window_tree_client.h"
146 #include "ui/aura/window.h"
147 #include "ui/aura/window_tree_host.h"
151 #include "base/win/windows_version.h"
152 #include "chrome/browser/jumplist_win.h"
153 #include "ui/views/win/scoped_fullscreen_visibility.h"
156 #if defined(ENABLE_ONE_CLICK_SIGNIN)
157 #include "chrome/browser/ui/sync/one_click_signin_bubble_delegate.h"
158 #include "chrome/browser/ui/sync/one_click_signin_bubble_links_delegate.h"
159 #include "chrome/browser/ui/views/sync/one_click_signin_bubble_view.h"
162 #if defined(OS_CHROMEOS)
163 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
166 using base::TimeDelta
;
167 using base::UserMetricsAction
;
168 using content::NativeWebKeyboardEvent
;
169 using content::SSLStatus
;
170 using content::WebContents
;
171 using views::ColumnSet
;
172 using views::GridLayout
;
173 using web_modal::WebContentsModalDialogHost
;
177 // The name of a key to store on the window handle so that other code can
178 // locate this object using just the handle.
179 const char* const kBrowserViewKey
= "__BROWSER_VIEW__";
181 // The number of milliseconds between loading animation frames.
182 const int kLoadingAnimationFrameTimeMs
= 30;
184 // Paints the horizontal border separating the Bookmarks Bar from the Toolbar
185 // or page content according to |at_top| with |color|.
186 void PaintHorizontalBorder(gfx::Canvas
* canvas
,
187 BookmarkBarView
* view
,
190 int thickness
= views::NonClientFrameView::kClientEdgeThickness
;
191 int y
= at_top
? 0 : (view
->height() - thickness
);
192 canvas
->FillRect(gfx::Rect(0, y
, view
->width(), thickness
), color
);
195 // TODO(kuan): These functions are temporarily for the bookmark bar while its
196 // detached state is at the top of the page; it'll be moved to float on the
197 // content page in the very near future, at which time, these local functions
199 void PaintDetachedBookmarkBar(gfx::Canvas
* canvas
,
200 BookmarkBarView
* view
,
201 ThemeService
* theme_service
) {
202 // Paint background for detached state; if animating, this is fade in/out.
204 chrome::GetDetachedBookmarkBarBackgroundColor(theme_service
));
205 // Draw the separators above and below bookmark bar;
206 // if animating, these are fading in/out.
207 SkColor separator_color
=
208 chrome::GetDetachedBookmarkBarSeparatorColor(theme_service
);
209 PaintHorizontalBorder(canvas
, view
, true, separator_color
);
210 // The bottom border needs to be 1-px thick in both regular and retina
211 // displays, so we can't use PaintHorizontalBorder which paints a 2-px thick
212 // border in retina display.
214 paint
.setAntiAlias(false);
215 // Sets border to 1-px thick regardless of scale factor.
216 paint
.setStrokeWidth(0);
217 // Bottom border is at 50% opacity of top border.
218 paint
.setColor(SkColorSetA(separator_color
,
219 SkColorGetA(separator_color
) / 2));
220 // Calculate thickness of bottom border as per current scale factor to
221 // determine where to draw the 1-px thick border.
222 float thickness
= views::NonClientFrameView::kClientEdgeThickness
/
223 canvas
->image_scale();
224 SkScalar y
= SkIntToScalar(view
->height()) - SkFloatToScalar(thickness
);
225 canvas
->sk_canvas()->drawLine(SkIntToScalar(0), y
,
226 SkIntToScalar(view
->width()), y
, paint
);
229 // Paints the background (including the theme image behind content area) for
230 // the Bookmarks Bar when it is attached to the Toolbar into |bounds|.
231 // |background_origin| is the origin to use for painting the theme image.
232 void PaintBackgroundAttachedMode(gfx::Canvas
* canvas
,
233 ui::ThemeProvider
* theme_provider
,
234 const gfx::Rect
& bounds
,
235 const gfx::Point
& background_origin
,
236 chrome::HostDesktopType host_desktop_type
) {
237 canvas
->FillRect(bounds
,
238 theme_provider
->GetColor(ThemeProperties::COLOR_TOOLBAR
));
239 canvas
->TileImageInt(*theme_provider
->GetImageSkiaNamed(IDR_THEME_TOOLBAR
),
240 background_origin
.x(),
241 background_origin
.y(),
247 if (host_desktop_type
== chrome::HOST_DESKTOP_TYPE_ASH
) {
248 // Ash provides additional lightening at the edges of the toolbar.
249 gfx::ImageSkia
* toolbar_left
=
250 theme_provider
->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT
);
251 canvas
->TileImageInt(*toolbar_left
,
254 toolbar_left
->width(),
256 gfx::ImageSkia
* toolbar_right
=
257 theme_provider
->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT
);
258 canvas
->TileImageInt(*toolbar_right
,
259 bounds
.right() - toolbar_right
->width(),
261 toolbar_right
->width(),
266 void PaintAttachedBookmarkBar(gfx::Canvas
* canvas
,
267 BookmarkBarView
* view
,
268 BrowserView
* browser_view
,
269 chrome::HostDesktopType host_desktop_type
,
270 int toolbar_overlap
) {
271 // Paint background for attached state, this is fade in/out.
272 gfx::Point background_image_offset
=
273 browser_view
->OffsetPointForToolbarBackgroundImage(
274 gfx::Point(view
->GetMirroredX(), view
->y()));
275 PaintBackgroundAttachedMode(canvas
,
276 view
->GetThemeProvider(),
277 view
->GetLocalBounds(),
278 background_image_offset
,
280 if (view
->height() >= toolbar_overlap
) {
281 // Draw the separator below the Bookmarks Bar; this is fading in/out.
282 PaintHorizontalBorder(canvas
,
285 ThemeProperties::GetDefaultColor(
286 ThemeProperties::COLOR_TOOLBAR_SEPARATOR
));
292 ///////////////////////////////////////////////////////////////////////////////
293 // Delegate implementation for BrowserViewLayout. Usually just forwards calls
295 class BrowserViewLayoutDelegateImpl
: public BrowserViewLayoutDelegate
{
297 explicit BrowserViewLayoutDelegateImpl(BrowserView
* browser_view
)
298 : browser_view_(browser_view
) {}
299 ~BrowserViewLayoutDelegateImpl() override
{}
301 // BrowserViewLayoutDelegate overrides:
302 views::View
* GetContentsWebView() const override
{
303 return browser_view_
->contents_web_view_
;
306 bool DownloadShelfNeedsLayout() const override
{
307 DownloadShelfView
* download_shelf
= browser_view_
->download_shelf_
.get();
308 // Re-layout the shelf either if it is visible or if its close animation
309 // is currently running.
310 return download_shelf
&&
311 (download_shelf
->IsShowing() || download_shelf
->IsClosing());
314 bool IsTabStripVisible() const override
{
315 return browser_view_
->IsTabStripVisible();
318 gfx::Rect
GetBoundsForTabStripInBrowserView() const override
{
319 gfx::RectF
bounds_f(browser_view_
->frame()->GetBoundsForTabStrip(
320 browser_view_
->tabstrip()));
321 views::View::ConvertRectToTarget(browser_view_
->parent(), browser_view_
,
323 return gfx::ToEnclosingRect(bounds_f
);
326 int GetTopInsetInBrowserView() const override
{
327 return browser_view_
->frame()->GetTopInset() -
331 int GetThemeBackgroundXInset() const override
{
332 // TODO(pkotwicz): Return the inset with respect to the left edge of the
334 return browser_view_
->frame()->GetThemeBackgroundXInset();
337 bool IsToolbarVisible() const override
{
338 return browser_view_
->IsToolbarVisible();
341 bool IsBookmarkBarVisible() const override
{
342 return browser_view_
->IsBookmarkBarVisible();
345 ExclusiveAccessBubbleViews
* GetExclusiveAccessBubble() const override
{
346 return browser_view_
->exclusive_access_bubble();
350 BrowserView
* browser_view_
;
352 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayoutDelegateImpl
);
355 // This class is used to paint the background for Bookmarks Bar.
356 class BookmarkBarViewBackground
: public views::Background
{
358 BookmarkBarViewBackground(BrowserView
* browser_view
,
359 BookmarkBarView
* bookmark_bar_view
,
363 void Paint(gfx::Canvas
* canvas
, views::View
* view
) const override
;
366 BrowserView
* browser_view_
;
368 // The view hosting this background.
369 BookmarkBarView
* bookmark_bar_view_
;
373 DISALLOW_COPY_AND_ASSIGN(BookmarkBarViewBackground
);
376 BookmarkBarViewBackground::BookmarkBarViewBackground(
377 BrowserView
* browser_view
,
378 BookmarkBarView
* bookmark_bar_view
,
380 : browser_view_(browser_view
),
381 bookmark_bar_view_(bookmark_bar_view
),
385 void BookmarkBarViewBackground::Paint(gfx::Canvas
* canvas
,
386 views::View
* view
) const {
387 int toolbar_overlap
= bookmark_bar_view_
->GetToolbarOverlap();
388 if (!bookmark_bar_view_
->IsDetached()) {
389 PaintAttachedBookmarkBar(canvas
,
392 browser_
->host_desktop_type(),
397 // As 'hidden' according to the animation is the full in-tab state, we invert
398 // the value - when current_state is at '0', we expect the bar to be docked.
399 double current_state
= 1 - bookmark_bar_view_
->GetAnimationValue();
401 ThemeService
* ts
= ThemeServiceFactory::GetForProfile(browser_
->profile());
402 if (current_state
== 0.0 || current_state
== 1.0) {
403 PaintDetachedBookmarkBar(canvas
, bookmark_bar_view_
, ts
);
406 // While animating, set opacity to cross-fade between attached and detached
407 // backgrounds including their respective separators.
408 int detached_alpha
= static_cast<uint8
>(current_state
* 255);
409 int attached_alpha
= 255 - detached_alpha
;
410 if (browser_
->bookmark_bar_state() == BookmarkBar::DETACHED
) {
411 // To animate from attached to detached state:
412 // - fade out attached background
413 // - fade in detached background.
414 canvas
->SaveLayerAlpha(attached_alpha
);
415 PaintAttachedBookmarkBar(canvas
,
418 browser_
->host_desktop_type(),
421 canvas
->SaveLayerAlpha(detached_alpha
);
422 PaintDetachedBookmarkBar(canvas
, bookmark_bar_view_
, ts
);
424 // To animate from detached to attached state:
425 // - fade out detached background
426 // - fade in attached background.
427 canvas
->SaveLayerAlpha(detached_alpha
);
428 PaintDetachedBookmarkBar(canvas
, bookmark_bar_view_
, ts
);
430 canvas
->SaveLayerAlpha(attached_alpha
);
431 PaintAttachedBookmarkBar(canvas
,
434 browser_
->host_desktop_type(),
440 ///////////////////////////////////////////////////////////////////////////////
441 // BrowserView, public:
444 const char BrowserView::kViewClassName
[] = "BrowserView";
446 BrowserView::BrowserView()
447 : views::ClientView(nullptr, nullptr),
448 last_focused_view_storage_id_(
449 views::ViewStorage::GetInstance()->CreateStorageID()),
451 top_container_(nullptr),
454 find_bar_host_view_(nullptr),
455 infobar_container_(nullptr),
456 contents_web_view_(nullptr),
457 contents_container_(nullptr),
459 in_process_fullscreen_(false),
461 hung_window_detector_(&hung_plugin_action_
),
464 force_location_bar_focus_(false),
465 activate_modal_dialog_factory_(this) {
468 BrowserView::~BrowserView() {
469 // All the tabs should have been destroyed already. If we were closed by the
470 // OS with some tabs than the NativeBrowserFrame should have destroyed them.
471 DCHECK_EQ(0, browser_
->tab_strip_model()->count());
473 // Immersive mode may need to reparent views before they are removed/deleted.
474 immersive_mode_controller_
.reset();
476 browser_
->tab_strip_model()->RemoveObserver(this);
479 // Stop hung plugin monitoring.
481 ticker_
.UnregisterTickHandler(&hung_window_detector_
);
483 // Terminate the jumplist (must be called before browser_->profile() is
485 if (jumplist_
.get()) {
486 jumplist_
->Terminate();
490 // We destroy the download shelf before |browser_| to remove its child
491 // download views from the set of download observers (since the observed
492 // downloads can be destroyed along with |browser_| and the observer
493 // notifications will call back into deleted objects).
494 BrowserViewLayout
* browser_view_layout
= GetBrowserViewLayout();
495 if (browser_view_layout
)
496 browser_view_layout
->set_download_shelf(nullptr);
497 download_shelf_
.reset();
499 // The TabStrip attaches a listener to the model. Make sure we shut down the
500 // TabStrip first so that it can cleanly remove the listener.
502 tabstrip_
->parent()->RemoveChildView(tabstrip_
);
503 if (browser_view_layout
)
504 browser_view_layout
->set_tab_strip(nullptr);
508 // Child views maintain PrefMember attributes that point to
509 // OffTheRecordProfile's PrefService which gets deleted by ~Browser.
510 RemoveAllChildViews(true);
513 // Explicitly set browser_ to null.
517 void BrowserView::Init(Browser
* browser
) {
518 browser_
.reset(browser
);
519 browser_
->tab_strip_model()->AddObserver(this);
520 immersive_mode_controller_
.reset(
521 chrome::CreateImmersiveModeController(browser_
->host_desktop_type()));
525 BrowserView
* BrowserView::GetBrowserViewForNativeWindow(
526 gfx::NativeWindow window
) {
527 views::Widget
* widget
= views::Widget::GetWidgetForNativeWindow(window
);
529 reinterpret_cast<BrowserView
*>(widget
->GetNativeWindowProperty(
530 kBrowserViewKey
)) : nullptr;
534 BrowserView
* BrowserView::GetBrowserViewForBrowser(const Browser
* browser
) {
535 return static_cast<BrowserView
*>(browser
->window());
538 void BrowserView::InitStatusBubble() {
539 status_bubble_
.reset(new StatusBubbleViews(contents_web_view_
));
540 contents_web_view_
->SetStatusBubble(status_bubble_
.get());
543 gfx::Rect
BrowserView::GetToolbarBounds() const {
544 gfx::Rect
toolbar_bounds(toolbar_
->bounds());
545 if (toolbar_bounds
.IsEmpty())
546 return toolbar_bounds
;
547 // The apparent toolbar edges are outside the "real" toolbar edges.
548 toolbar_bounds
.Inset(-views::NonClientFrameView::kClientEdgeThickness
, 0);
549 return toolbar_bounds
;
552 gfx::Rect
BrowserView::GetFindBarBoundingBox() const {
553 return GetBrowserViewLayout()->GetFindBarBoundingBox();
556 int BrowserView::GetTabStripHeight() const {
557 // We want to return tabstrip_->height(), but we might be called in the midst
558 // of layout, when that hasn't yet been updated to reflect the current state.
559 // So return what the tabstrip height _ought_ to be right now.
560 return IsTabStripVisible() ? tabstrip_
->GetPreferredSize().height() : 0;
563 gfx::Point
BrowserView::OffsetPointForToolbarBackgroundImage(
564 const gfx::Point
& point
) const {
565 // The background image starts tiling horizontally at the window left edge and
566 // vertically at the top edge of the horizontal tab strip (or where it would
567 // be). We expect our parent's origin to be the window origin.
568 gfx::Point
window_point(point
+ GetMirroredPosition().OffsetFromOrigin());
569 window_point
.Offset(frame_
->GetThemeBackgroundXInset(),
570 -frame_
->GetTopInset());
574 bool BrowserView::IsTabStripVisible() const {
575 if (immersive_mode_controller_
->ShouldHideTopViews() &&
576 immersive_mode_controller_
->ShouldHideTabIndicators())
578 return browser_
->SupportsWindowFeature(Browser::FEATURE_TABSTRIP
);
581 bool BrowserView::IsOffTheRecord() const {
582 return browser_
->profile()->IsOffTheRecord();
585 bool BrowserView::IsGuestSession() const {
586 return browser_
->profile()->IsGuestSession();
589 bool BrowserView::IsRegularOrGuestSession() const {
590 return profiles::IsRegularOrGuestSession(browser_
.get());
593 bool BrowserView::ShouldShowAvatar() const {
594 #if defined(OS_CHROMEOS)
595 if (!browser_
->is_type_tabbed() && !browser_
->is_app())
597 // Don't show incognito avatar in the guest session.
598 if (IsOffTheRecord() && !IsGuestSession())
600 // This function is called via BrowserNonClientFrameView::UpdateAvatarInfo
601 // during the creation of the BrowserWindow, so browser->window() will not
602 // yet be set. In this case we can safely return false.
603 if (!browser_
->window())
605 return chrome::MultiUserWindowManager::ShouldShowAvatar(
606 browser_
->window()->GetNativeWindow());
608 if (!IsBrowserTypeNormal())
610 if (IsOffTheRecord()) // Desktop guest is incognito and needs avatar.
612 // Tests may not have a profile manager.
613 if (!g_browser_process
->profile_manager())
615 ProfileInfoCache
& cache
=
616 g_browser_process
->profile_manager()->GetProfileInfoCache();
617 if (cache
.GetIndexOfProfileWithPath(browser_
->profile()->GetPath()) ==
622 return AvatarMenu::ShouldShowAvatarMenu();
626 bool BrowserView::GetAccelerator(int cmd_id
,
627 ui::Accelerator
* accelerator
) const {
628 // We retrieve the accelerator information for standard accelerators
629 // for cut, copy and paste.
630 if (chrome::GetStandardAcceleratorForCommandId(cmd_id
, accelerator
))
632 // Else, we retrieve the accelerator information from the accelerator table.
633 for (std::map
<ui::Accelerator
, int>::const_iterator it
=
634 accelerator_table_
.begin(); it
!= accelerator_table_
.end(); ++it
) {
635 if (it
->second
== cmd_id
) {
636 *accelerator
= it
->first
;
640 // Else, we retrieve the accelerator information from Ash (if applicable).
641 return chrome::GetAshAcceleratorForCommandId(
642 cmd_id
, browser_
->host_desktop_type(), accelerator
);
645 bool BrowserView::IsAcceleratorRegistered(const ui::Accelerator
& accelerator
) {
646 return accelerator_table_
.find(accelerator
) != accelerator_table_
.end();
649 WebContents
* BrowserView::GetActiveWebContents() const {
650 return browser_
->tab_strip_model()->GetActiveWebContents();
653 gfx::ImageSkia
BrowserView::GetOTRAvatarIcon() const {
654 return *GetThemeProvider()->GetImageSkiaNamed(IDR_OTR_ICON
);
657 ///////////////////////////////////////////////////////////////////////////////
658 // BrowserView, BrowserWindow implementation:
660 void BrowserView::Show() {
662 // The Browser associated with this browser window must become the active
663 // browser at the time |Show()| is called. This is the natural behavior under
664 // Windows and Ash, but other platforms will not trigger
665 // OnWidgetActivationChanged() until we return to the runloop. Therefore any
666 // calls to Browser::GetLastActive() will return the wrong result if we do not
667 // explicitly set it here.
668 // A similar block also appears in BrowserWindowCocoa::Show().
669 if (browser()->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH
)
670 BrowserList::SetLastActive(browser());
673 // If the window is already visible, just activate it.
674 if (frame_
->IsVisible()) {
679 // Showing the window doesn't make the browser window active right away.
680 // This can cause SetFocusToLocationBar() to skip setting focus to the
681 // location bar. To avoid this we explicilty let SetFocusToLocationBar()
682 // know that it's ok to steal focus.
683 force_location_bar_focus_
= true;
685 // Setting the focus doesn't work when the window is invisible, so any focus
686 // initialization that happened before this will be lost.
688 // We really "should" restore the focus whenever the window becomes unhidden,
689 // but I think initializing is the only time where this can happen where
690 // there is some focus change we need to pick up, and this is easier than
691 // plumbing through an un-hide message all the way from the frame.
693 // If we do find there are cases where we need to restore the focus on show,
694 // that should be added and this should be removed.
699 force_location_bar_focus_
= false;
701 browser()->OnWindowDidShow();
703 chrome::MaybeShowInvertBubbleView(this);
706 void BrowserView::ShowInactive() {
707 if (!frame_
->IsVisible())
708 frame_
->ShowInactive();
711 void BrowserView::Hide() {
715 void BrowserView::SetBounds(const gfx::Rect
& bounds
) {
717 GetWidget()->SetBounds(bounds
);
720 void BrowserView::Close() {
724 void BrowserView::Activate() {
728 void BrowserView::Deactivate() {
729 frame_
->Deactivate();
732 bool BrowserView::IsActive() const {
733 return frame_
->IsActive();
736 void BrowserView::FlashFrame(bool flash
) {
737 frame_
->FlashFrame(flash
);
740 bool BrowserView::IsAlwaysOnTop() const {
744 void BrowserView::SetAlwaysOnTop(bool always_on_top
) {
745 // Not implemented for browser windows.
749 gfx::NativeWindow
BrowserView::GetNativeWindow() const {
750 // While the browser destruction is going on, the widget can already be gone,
751 // but utility functions like FindBrowserWithWindow will come here and crash.
752 // We short circuit therefore.
755 return GetWidget()->GetTopLevelWidget()->GetNativeWindow();
758 StatusBubble
* BrowserView::GetStatusBubble() {
759 return status_bubble_
.get();
763 // Only used by ToolbarSizeChanged() below, but placed here because template
764 // arguments (to base::AutoReset<>) must have external linkage.
765 enum CallState
{ NORMAL
, REENTRANT
, REENTRANT_FORCE_FAST_RESIZE
};
768 void BrowserView::UpdateTitleBar() {
769 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185 is
771 tracked_objects::ScopedTracker
tracking_profile1(
772 FROM_HERE_WITH_EXPLICIT_FUNCTION("467185 BrowserView::UpdateTitleBar1"));
773 frame_
->UpdateWindowTitle();
774 if (ShouldShowWindowIcon() && !loading_animation_timer_
.IsRunning()) {
775 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/467185
777 tracked_objects::ScopedTracker
tracking_profile2(
778 FROM_HERE_WITH_EXPLICIT_FUNCTION(
779 "467185 BrowserView::UpdateTitleBar2"));
780 frame_
->UpdateWindowIcon();
784 void BrowserView::BookmarkBarStateChanged(
785 BookmarkBar::AnimateChangeType change_type
) {
786 if (bookmark_bar_view_
.get()) {
787 BookmarkBar::State new_state
= browser_
->bookmark_bar_state();
789 // We don't properly support animating the bookmark bar to and from the
790 // detached state in immersive fullscreen.
791 bool detached_changed
= (new_state
== BookmarkBar::DETACHED
) ||
792 bookmark_bar_view_
->IsDetached();
793 if (detached_changed
&& immersive_mode_controller_
->IsEnabled())
794 change_type
= BookmarkBar::DONT_ANIMATE_STATE_CHANGE
;
796 bookmark_bar_view_
->SetBookmarkBarState(new_state
, change_type
);
798 if (MaybeShowBookmarkBar(GetActiveWebContents()))
802 void BrowserView::UpdateDevTools() {
803 UpdateDevToolsForContents(GetActiveWebContents(), true);
807 void BrowserView::UpdateLoadingAnimations(bool should_animate
) {
808 if (should_animate
) {
809 if (!loading_animation_timer_
.IsRunning()) {
810 // Loads are happening, and the timer isn't running, so start it.
811 last_animation_time_
= base::TimeTicks::Now();
812 loading_animation_timer_
.Start(FROM_HERE
,
813 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs
), this,
814 &BrowserView::LoadingAnimationCallback
);
817 if (loading_animation_timer_
.IsRunning()) {
818 last_animation_time_
= base::TimeTicks();
819 loading_animation_timer_
.Stop();
820 // Loads are now complete, update the state if a task was scheduled.
821 LoadingAnimationCallback();
826 void BrowserView::SetStarredState(bool is_starred
) {
827 GetLocationBarView()->SetStarToggled(is_starred
);
830 void BrowserView::SetTranslateIconToggled(bool is_lit
) {
831 GetLocationBarView()->SetTranslateIconToggled(is_lit
);
834 void BrowserView::OnActiveTabChanged(content::WebContents
* old_contents
,
835 content::WebContents
* new_contents
,
838 DCHECK(new_contents
);
840 // If |contents_container_| already has the correct WebContents, we can save
841 // some work. This also prevents extra events from being reported by the
842 // Visibility API under Windows, as ChangeWebContents will briefly hide
843 // the WebContents window.
844 bool change_tab_contents
=
845 contents_web_view_
->web_contents() != new_contents
;
847 // Update various elements that are interested in knowing the current
850 // When we toggle the NTP floating bookmarks bar and/or the info bar,
851 // we don't want any WebContents to be attached, so that we
852 // avoid an unnecessary resize and re-layout of a WebContents.
853 if (change_tab_contents
) {
854 contents_web_view_
->SetWebContents(nullptr);
855 devtools_web_view_
->SetWebContents(nullptr);
858 // Do this before updating InfoBarContainer as the InfoBarContainer may
859 // callback to us and trigger layout.
860 if (bookmark_bar_view_
.get()) {
861 bookmark_bar_view_
->SetBookmarkBarState(
862 browser_
->bookmark_bar_state(),
863 BookmarkBar::DONT_ANIMATE_STATE_CHANGE
);
866 infobar_container_
->ChangeInfoBarManager(
867 InfoBarService::FromWebContents(new_contents
));
869 if (old_contents
&& PermissionBubbleManager::FromWebContents(old_contents
))
870 PermissionBubbleManager::FromWebContents(old_contents
)->SetView(nullptr);
872 if (new_contents
&& PermissionBubbleManager::FromWebContents(new_contents
)) {
873 if (!permission_bubble_
.get())
874 permission_bubble_
.reset(new PermissionBubbleViewViews(browser_
.get()));
876 PermissionBubbleManager::FromWebContents(new_contents
)->SetView(
877 permission_bubble_
.get());
880 UpdateUIForContents(new_contents
);
882 // Layout for DevTools _before_ setting the both main and devtools WebContents
883 // to avoid toggling the size of any of them.
884 UpdateDevToolsForContents(new_contents
, !change_tab_contents
);
886 if (change_tab_contents
) {
887 web_contents_close_handler_
->ActiveTabChanged();
888 contents_web_view_
->SetWebContents(new_contents
);
889 // The second layout update should be no-op. It will just set the
890 // DevTools WebContents.
891 UpdateDevToolsForContents(new_contents
, true);
894 if (!browser_
->tab_strip_model()->closing_all() && GetWidget()->IsActive() &&
895 GetWidget()->IsVisible()) {
896 // We only restore focus if our window is visible, to avoid invoking blur
897 // handlers when we are eventually shown.
898 new_contents
->RestoreFocus();
901 // Update all the UI bits.
904 TranslateBubbleView::CloseBubble();
905 ZoomBubbleView::CloseBubble();
908 void BrowserView::ZoomChangedForActiveTab(bool can_show_bubble
) {
909 GetLocationBarView()->ZoomChangedForActiveTab(
910 can_show_bubble
&& !toolbar_
->IsWrenchMenuShowing());
913 gfx::Rect
BrowserView::GetRestoredBounds() const {
915 ui::WindowShowState state
;
916 frame_
->GetWindowPlacement(&bounds
, &state
);
920 ui::WindowShowState
BrowserView::GetRestoredState() const {
922 ui::WindowShowState state
;
923 frame_
->GetWindowPlacement(&bounds
, &state
);
927 gfx::Rect
BrowserView::GetBounds() const {
928 return frame_
->GetWindowBoundsInScreen();
931 bool BrowserView::IsMaximized() const {
932 return frame_
->IsMaximized();
935 bool BrowserView::IsMinimized() const {
936 return frame_
->IsMinimized();
939 void BrowserView::Maximize() {
943 void BrowserView::Minimize() {
947 void BrowserView::Restore() {
951 void BrowserView::EnterFullscreen(const GURL
& url
,
952 ExclusiveAccessBubbleType bubble_type
,
955 return; // Nothing to do.
957 ProcessFullscreen(true, NORMAL_FULLSCREEN
, url
, bubble_type
);
960 void BrowserView::ExitFullscreen() {
962 return; // Nothing to do.
964 ProcessFullscreen(false, NORMAL_FULLSCREEN
, GURL(),
965 EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE
);
968 void BrowserView::UpdateExclusiveAccessExitBubbleContent(
970 ExclusiveAccessBubbleType bubble_type
) {
971 // Immersive mode has no exit bubble because it has a visible strip at the
972 // top that gives the user a hover target.
973 // TODO(jamescook): Figure out what to do with mouse-lock.
974 if (bubble_type
== EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE
||
975 ShouldUseImmersiveFullscreenForUrl(url
)) {
976 exclusive_access_bubble_
.reset();
977 } else if (exclusive_access_bubble_
.get()) {
978 exclusive_access_bubble_
->UpdateContent(url
, bubble_type
);
980 exclusive_access_bubble_
.reset(
981 new ExclusiveAccessBubbleViews(this, url
, bubble_type
));
985 bool BrowserView::ShouldHideUIForFullscreen() const {
986 // Immersive mode needs UI for the slide-down top panel.
987 if (immersive_mode_controller_
->IsEnabled())
990 return IsFullscreen();
993 bool BrowserView::IsFullscreen() const {
994 return frame_
->IsFullscreen();
997 bool BrowserView::IsFullscreenBubbleVisible() const {
998 return exclusive_access_bubble_
!= nullptr;
1001 bool BrowserView::SupportsFullscreenWithToolbar() const {
1005 void BrowserView::UpdateFullscreenWithToolbar(bool with_toolbar
) {
1006 // This is currently a Mac only feature.
1010 bool BrowserView::IsFullscreenWithToolbar() const {
1015 void BrowserView::SetMetroSnapMode(bool enable
) {
1016 LOCAL_HISTOGRAM_COUNTS("Metro.SnapModeToggle", enable
);
1017 ProcessFullscreen(enable
, METRO_SNAP_FULLSCREEN
, GURL(),
1018 EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE
);
1021 bool BrowserView::IsInMetroSnapMode() const {
1024 #endif // defined(OS_WIN)
1026 void BrowserView::RestoreFocus() {
1027 WebContents
* selected_web_contents
= GetActiveWebContents();
1028 if (selected_web_contents
)
1029 selected_web_contents
->RestoreFocus();
1032 void BrowserView::FullscreenStateChanged() {
1033 CHECK(!IsFullscreen());
1034 ProcessFullscreen(false, NORMAL_FULLSCREEN
, GURL(),
1035 EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE
);
1038 void BrowserView::ToolbarSizeChanged(bool is_animating
) {
1039 // The call to SetMaxTopArrowHeight() below can result in reentrancy;
1040 // |call_state| tracks whether we're reentrant. We can't just early-return in
1041 // this case because we need to layout again so the infobar container's bounds
1042 // are set correctly.
1043 static CallState call_state
= NORMAL
;
1045 // A reentrant call can (and should) use the fast resize path unless both it
1046 // and the normal call are both non-animating.
1047 bool use_fast_resize
=
1048 is_animating
|| (call_state
== REENTRANT_FORCE_FAST_RESIZE
);
1049 if (use_fast_resize
)
1050 contents_web_view_
->SetFastResize(true);
1051 UpdateUIForContents(GetActiveWebContents());
1052 if (use_fast_resize
)
1053 contents_web_view_
->SetFastResize(false);
1055 // Inform the InfoBarContainer that the distance to the location icon may have
1056 // changed. We have to do this after the block above so that the toolbars are
1057 // laid out correctly for calculating the maximum arrow height below.
1059 base::AutoReset
<CallState
> resetter(&call_state
,
1060 is_animating
? REENTRANT_FORCE_FAST_RESIZE
: REENTRANT
);
1061 SetMaxTopArrowHeight(GetMaxTopInfoBarArrowHeight(), infobar_container_
);
1064 // When transitioning from animating to not animating we need to make sure the
1065 // contents_container_ gets layed out. If we don't do this and the bounds
1066 // haven't changed contents_container_ won't get a Layout out and we'll end up
1067 // with a gray rect because the clip wasn't updated. Note that a reentrant
1068 // call never needs to do this, because after it returns, the normal call
1069 // wrapping it will do it.
1070 if ((call_state
== NORMAL
) && !is_animating
) {
1071 contents_web_view_
->InvalidateLayout();
1072 contents_container_
->Layout();
1076 LocationBar
* BrowserView::GetLocationBar() const {
1077 return GetLocationBarView();
1080 void BrowserView::SetFocusToLocationBar(bool select_all
) {
1081 // On Windows, changing focus to the location bar causes the browser
1082 // window to become active. This can steal focus if the user has
1083 // another window open already. On ChromeOS, changing focus makes a
1084 // view believe it has a focus even if the widget doens't have a
1085 // focus. Either cases, we need to ignore this when the browser
1086 // window isn't active.
1087 if (!force_location_bar_focus_
&& !IsActive())
1090 // Temporarily reveal the top-of-window views (if not already revealed) so
1091 // that the location bar view is visible and is considered focusable. If the
1092 // location bar view gains focus, |immersive_mode_controller_| will keep the
1093 // top-of-window views revealed.
1094 scoped_ptr
<ImmersiveRevealedLock
> focus_reveal_lock(
1095 immersive_mode_controller_
->GetRevealedLock(
1096 ImmersiveModeController::ANIMATE_REVEAL_YES
));
1098 LocationBarView
* location_bar
= GetLocationBarView();
1099 if (location_bar
->omnibox_view()->IsFocusable()) {
1100 // Location bar got focus.
1101 location_bar
->FocusLocation(select_all
);
1103 // If none of location bar got focus, then clear focus.
1104 views::FocusManager
* focus_manager
= GetFocusManager();
1105 DCHECK(focus_manager
);
1106 focus_manager
->ClearFocus();
1110 void BrowserView::UpdateReloadStopState(bool is_loading
, bool force
) {
1111 toolbar_
->reload_button()->ChangeMode(
1112 is_loading
? ReloadButton::MODE_STOP
: ReloadButton::MODE_RELOAD
, force
);
1115 void BrowserView::UpdateToolbar(content::WebContents
* contents
) {
1116 // We may end up here during destruction.
1118 toolbar_
->Update(contents
);
1119 frame_
->UpdateToolbar();
1122 void BrowserView::ResetToolbarTabState(content::WebContents
* contents
) {
1123 // We may end up here during destruction.
1125 toolbar_
->ResetTabState(contents
);
1128 void BrowserView::FocusToolbar() {
1129 // Temporarily reveal the top-of-window views (if not already revealed) so
1130 // that the toolbar is visible and is considered focusable. If the
1131 // toolbar gains focus, |immersive_mode_controller_| will keep the
1132 // top-of-window views revealed.
1133 scoped_ptr
<ImmersiveRevealedLock
> focus_reveal_lock(
1134 immersive_mode_controller_
->GetRevealedLock(
1135 ImmersiveModeController::ANIMATE_REVEAL_YES
));
1137 // Start the traversal within the main toolbar. SetPaneFocus stores
1138 // the current focused view before changing focus.
1139 toolbar_
->SetPaneFocus(nullptr);
1142 void BrowserView::FocusBookmarksToolbar() {
1143 DCHECK(!immersive_mode_controller_
->IsEnabled());
1144 if (bookmark_bar_view_
.get() &&
1145 bookmark_bar_view_
->visible() &&
1146 bookmark_bar_view_
->GetPreferredSize().height() != 0) {
1147 bookmark_bar_view_
->SetPaneFocusAndFocusDefault();
1151 void BrowserView::FocusInfobars() {
1152 if (infobar_container_
->child_count() > 0)
1153 infobar_container_
->SetPaneFocusAndFocusDefault();
1156 void BrowserView::FocusAppMenu() {
1157 // Chrome doesn't have a traditional menu bar, but it has a menu button in the
1158 // main toolbar that plays the same role. If the user presses a key that
1159 // would typically focus the menu bar, tell the toolbar to focus the menu
1160 // button. If the user presses the key again, return focus to the previous
1163 // Not used on the Mac, which has a normal menu bar.
1164 if (toolbar_
->IsAppMenuFocused()) {
1167 DCHECK(!immersive_mode_controller_
->IsEnabled());
1168 toolbar_
->SetPaneFocusAndFocusAppMenu();
1172 void BrowserView::RotatePaneFocus(bool forwards
) {
1173 GetWidget()->GetFocusManager()->RotatePaneFocus(
1175 views::FocusManager::kForward
: views::FocusManager::kBackward
,
1176 views::FocusManager::kWrap
);
1179 void BrowserView::DestroyBrowser() {
1180 // After this returns other parts of Chrome are going to be shutdown. Close
1181 // the window now so that we are deleted immediately and aren't left holding
1182 // references to deleted objects.
1183 GetWidget()->RemoveObserver(this);
1184 GetLocationBar()->GetOmniboxView()->model()->popup_model()->RemoveObserver(
1189 bool BrowserView::IsBookmarkBarVisible() const {
1190 if (!browser_
->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR
))
1192 if (!bookmark_bar_view_
.get())
1194 if (bookmark_bar_view_
->GetPreferredSize().height() == 0)
1196 // New tab page needs visible bookmarks even when top-views are hidden.
1197 if (immersive_mode_controller_
->ShouldHideTopViews() &&
1198 !bookmark_bar_view_
->IsDetached())
1203 bool BrowserView::IsBookmarkBarAnimating() const {
1204 return bookmark_bar_view_
.get() && bookmark_bar_view_
->is_animating();
1207 bool BrowserView::IsTabStripEditable() const {
1208 return tabstrip_
->IsTabStripEditable();
1211 bool BrowserView::IsToolbarVisible() const {
1212 if (immersive_mode_controller_
->ShouldHideTopViews())
1214 return browser_
->SupportsWindowFeature(Browser::FEATURE_TOOLBAR
) ||
1215 browser_
->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR
);
1218 gfx::Rect
BrowserView::GetRootWindowResizerRect() const {
1219 // Views does not support resizer rects because they caused page cycler
1220 // performance regressions when they were added. See crrev.com/9654
1224 void BrowserView::ConfirmAddSearchProvider(TemplateURL
* template_url
,
1226 chrome::EditSearchEngine(GetWidget()->GetNativeWindow(), template_url
,
1230 void BrowserView::ShowUpdateChromeDialog() {
1231 UpdateRecommendedMessageBox::Show(GetWidget()->GetNativeWindow());
1234 void BrowserView::ShowBookmarkBubble(const GURL
& url
, bool already_bookmarked
) {
1235 scoped_ptr
<BookmarkBubbleDelegate
> delegate
;
1236 delegate
.reset(new BookmarkBubbleSignInDelegate(browser_
.get()));
1238 BookmarkBubbleView::ShowBubble(GetToolbarView()->GetBookmarkBubbleAnchor(),
1239 bookmark_bar_view_
.get(),
1241 browser_
->profile(),
1243 !already_bookmarked
);
1246 void BrowserView::ShowBookmarkAppBubble(
1247 const WebApplicationInfo
& web_app_info
,
1248 const ShowBookmarkAppBubbleCallback
& callback
) {
1249 BookmarkAppBubbleView::ShowBubble(GetToolbarView(), web_app_info
, callback
);
1252 void BrowserView::ShowTranslateBubble(
1253 content::WebContents
* web_contents
,
1254 translate::TranslateStep step
,
1255 translate::TranslateErrors::Type error_type
,
1256 bool is_user_gesture
) {
1257 if (contents_web_view_
->HasFocus() &&
1258 !GetLocationBarView()->IsMouseHovered()) {
1259 content::RenderViewHost
* rvh
= web_contents
->GetRenderViewHost();
1260 if (rvh
->IsFocusedElementEditable())
1264 ChromeTranslateClient
* chrome_translate_client
=
1265 ChromeTranslateClient::FromWebContents(web_contents
);
1266 translate::LanguageState
& language_state
=
1267 chrome_translate_client
->GetLanguageState();
1268 language_state
.SetTranslateEnabled(true);
1273 TranslateBubbleView::ShowBubble(
1274 GetToolbarView()->GetTranslateBubbleAnchor(), web_contents
, step
,
1275 error_type
, is_user_gesture
);
1278 bool BrowserView::ShowSessionCrashedBubble() {
1279 return SessionCrashedBubbleView::Show(browser_
.get());
1282 bool BrowserView::IsProfileResetBubbleSupported() const {
1286 GlobalErrorBubbleViewBase
* BrowserView::ShowProfileResetBubble(
1287 const base::WeakPtr
<ProfileResetGlobalError
>& global_error
) {
1288 return ProfileResetBubbleView::ShowBubble(global_error
, browser_
.get());
1291 #if defined(ENABLE_ONE_CLICK_SIGNIN)
1292 void BrowserView::ShowOneClickSigninBubble(
1293 OneClickSigninBubbleType type
,
1294 const base::string16
& email
,
1295 const base::string16
& error_message
,
1296 const StartSyncCallback
& start_sync_callback
) {
1297 scoped_ptr
<OneClickSigninBubbleDelegate
> delegate
;
1298 delegate
.reset(new OneClickSigninBubbleLinksDelegate(browser()));
1300 views::View
* anchor_view
;
1301 if (type
== BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE
)
1302 anchor_view
= toolbar_
->app_menu();
1304 anchor_view
= toolbar_
->location_bar();
1306 OneClickSigninBubbleView::ShowBubble(type
, email
, error_message
,
1307 delegate
.Pass(), anchor_view
,
1308 start_sync_callback
);
1312 void BrowserView::SetDownloadShelfVisible(bool visible
) {
1313 // This can be called from the superclass destructor, when it destroys our
1314 // child views. At that point, browser_ is already gone.
1318 if (visible
&& IsDownloadShelfVisible() != visible
) {
1319 // Invoke GetDownloadShelf to force the shelf to be created.
1323 browser_
->UpdateDownloadShelfVisibility(visible
);
1325 // SetDownloadShelfVisible can force-close the shelf, so make sure we lay out
1326 // everything correctly, as if the animation had finished. This doesn't
1327 // matter for showing the shelf, as the show animation will do it.
1328 ToolbarSizeChanged(false);
1331 bool BrowserView::IsDownloadShelfVisible() const {
1332 return download_shelf_
.get() && download_shelf_
->IsShowing();
1335 DownloadShelf
* BrowserView::GetDownloadShelf() {
1336 if (!download_shelf_
.get()) {
1337 download_shelf_
.reset(new DownloadShelfView(browser_
.get(), this));
1338 download_shelf_
->set_owned_by_client();
1339 GetBrowserViewLayout()->set_download_shelf(download_shelf_
.get());
1341 return download_shelf_
.get();
1344 void BrowserView::ConfirmBrowserCloseWithPendingDownloads(
1346 Browser::DownloadClosePreventionType dialog_type
,
1348 const base::Callback
<void(bool)>& callback
) {
1349 DownloadInProgressDialogView::Show(
1350 GetNativeWindow(), download_count
, dialog_type
, app_modal
, callback
);
1353 void BrowserView::UserChangedTheme() {
1354 frame_
->FrameTypeChanged();
1357 int BrowserView::GetExtraRenderViewHeight() const {
1358 // Currently this is only used on linux.
1362 void BrowserView::WebContentsFocused(WebContents
* contents
) {
1363 if (contents_web_view_
->GetWebContents() == contents
)
1364 contents_web_view_
->OnWebContentsFocused(contents
);
1366 devtools_web_view_
->OnWebContentsFocused(contents
);
1369 void BrowserView::ShowWebsiteSettings(Profile
* profile
,
1370 content::WebContents
* web_contents
,
1372 const content::SSLStatus
& ssl
) {
1373 // Some browser windows have a location icon embedded in the frame. Try to
1374 // use that if it exists. If it doesn't exist, use the location icon from
1375 // the location bar.
1376 views::View
* popup_anchor
= frame_
->GetLocationIconView();
1378 popup_anchor
= GetLocationBarView()->location_icon_view();
1380 WebsiteSettingsPopupView::ShowPopup(popup_anchor
, profile
, web_contents
, url
,
1381 ssl
, browser_
.get());
1384 void BrowserView::ShowAppMenu() {
1385 // Keep the top-of-window views revealed as long as the app menu is visible.
1386 scoped_ptr
<ImmersiveRevealedLock
> revealed_lock(
1387 immersive_mode_controller_
->GetRevealedLock(
1388 ImmersiveModeController::ANIMATE_REVEAL_NO
));
1390 toolbar_
->app_menu()->Activate();
1393 bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent
& event
,
1394 bool* is_keyboard_shortcut
) {
1395 *is_keyboard_shortcut
= false;
1397 if ((event
.type
!= blink::WebInputEvent::RawKeyDown
) &&
1398 (event
.type
!= blink::WebInputEvent::KeyUp
)) {
1402 views::FocusManager
* focus_manager
= GetFocusManager();
1403 DCHECK(focus_manager
);
1405 if (focus_manager
->shortcut_handling_suspended())
1408 ui::Accelerator accelerator
=
1409 ui::GetAcceleratorFromNativeWebKeyboardEvent(event
);
1411 // What we have to do here is as follows:
1412 // - If the |browser_| is for an app, do nothing.
1413 // - If the |browser_| is not for an app, and the |accelerator| is not
1414 // associated with the browser (e.g. an Ash shortcut), process it.
1415 // - If the |browser_| is not for an app, and the |accelerator| is associated
1416 // with the browser, and it is a reserved one (e.g. Ctrl+w), process it.
1417 // - If the |browser_| is not for an app, and the |accelerator| is associated
1418 // with the browser, and it is not a reserved one, do nothing.
1420 if (browser_
->is_app()) {
1421 // Let all keys fall through to a v1 app's web content, even accelerators.
1422 // We don't have to flip |is_keyboard_shortcut| here. If we do that, the app
1423 // might not be able to see a subsequent Char event. See OnHandleInputEvent
1424 // in content/renderer/render_widget.cc for details.
1428 chrome::BrowserCommandController
* controller
= browser_
->command_controller();
1430 // Here we need to retrieve the command id (if any) associated to the
1431 // keyboard event. Instead of looking up the command id in the
1432 // |accelerator_table_| by ourselves, we block the command execution of
1433 // the |browser_| object then send the keyboard event to the
1434 // |focus_manager| as if we are activating an accelerator key.
1435 // Then we can retrieve the command id from the |browser_| object.
1436 bool original_block_command_state
= controller
->block_command_execution();
1437 controller
->SetBlockCommandExecution(true);
1438 // If the |accelerator| is a non-browser shortcut (e.g. Ash shortcut), the
1439 // command execution cannot be blocked and true is returned. However, it is
1440 // okay as long as is_app() is false. See comments in this function.
1441 const bool processed
= focus_manager
->ProcessAccelerator(accelerator
);
1442 const int id
= controller
->GetLastBlockedCommand(nullptr);
1443 controller
->SetBlockCommandExecution(original_block_command_state
);
1445 // Executing the command may cause |this| object to be destroyed.
1446 if (controller
->IsReservedCommandOrKey(id
, event
)) {
1447 UpdateAcceleratorMetrics(accelerator
, id
);
1448 return chrome::ExecuteCommand(browser_
.get(), id
);
1452 // |accelerator| is a non-reserved browser shortcut (e.g. Ctrl+f).
1453 if (event
.type
== blink::WebInputEvent::RawKeyDown
)
1454 *is_keyboard_shortcut
= true;
1455 } else if (processed
) {
1456 // |accelerator| is a non-browser shortcut (e.g. F4-F10 on Ash). Report
1457 // that we handled it.
1464 void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent
& event
) {
1465 unhandled_keyboard_event_handler_
.HandleKeyboardEvent(event
,
1469 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always
1470 // enabled in the page menu regardless of whether the command will do
1471 // anything. When someone selects the menu item, we just act as if they hit
1472 // the keyboard shortcut for the command by sending the associated key press
1473 // to windows. The real fix to this bug is to disable the commands when they
1474 // won't do anything. We'll need something like an overall clipboard command
1475 // manager to do that.
1476 void BrowserView::Cut() {
1477 // If a WebContent is focused, call WebContents::Cut. Otherwise, e.g. if
1478 // Omnibox is focused, send a Ctrl+x key event to Chrome. Using RWH interface
1479 // rather than the fake key event for a WebContent is important since the fake
1480 // event might be consumed by the web content (crbug.com/137908).
1481 DoCutCopyPaste(&content::WebContents::Cut
, IDS_APP_CUT
);
1484 void BrowserView::Copy() {
1485 DoCutCopyPaste(&content::WebContents::Copy
, IDS_APP_COPY
);
1488 void BrowserView::Paste() {
1489 DoCutCopyPaste(&content::WebContents::Paste
, IDS_APP_PASTE
);
1492 WindowOpenDisposition
BrowserView::GetDispositionForPopupBounds(
1493 const gfx::Rect
& bounds
) {
1497 FindBar
* BrowserView::CreateFindBar() {
1498 return chrome::CreateFindBar(this);
1501 WebContentsModalDialogHost
* BrowserView::GetWebContentsModalDialogHost() {
1502 return GetBrowserViewLayout()->GetWebContentsModalDialogHost();
1505 BookmarkBarView
* BrowserView::GetBookmarkBarView() const {
1506 return bookmark_bar_view_
.get();
1509 LocationBarView
* BrowserView::GetLocationBarView() const {
1510 return toolbar_
? toolbar_
->location_bar() : nullptr;
1513 views::View
* BrowserView::GetTabContentsContainerView() const {
1514 return contents_web_view_
;
1517 ToolbarView
* BrowserView::GetToolbarView() const {
1521 ///////////////////////////////////////////////////////////////////////////////
1522 // BrowserView, TabStripModelObserver implementation:
1524 void BrowserView::TabInsertedAt(WebContents
* contents
,
1527 #if defined(USE_AURA)
1528 // WebContents inserted in tabs might not have been added to the root
1529 // window yet. Per http://crbug/342672 add them now since drawing the
1530 // WebContents requires root window specific data - information about
1531 // the screen the WebContents is drawn on, for example.
1532 if (!contents
->GetNativeView()->GetRootWindow()) {
1533 aura::Window
* window
= contents
->GetNativeView();
1534 aura::Window
* root_window
= GetNativeWindow()->GetRootWindow();
1535 aura::client::ParentWindowWithContext(
1536 window
, root_window
, root_window
->GetBoundsInScreen());
1537 DCHECK(contents
->GetNativeView()->GetRootWindow());
1540 web_contents_close_handler_
->TabInserted();
1543 extensions::MaybeShowExtensionControlledNewTabPage(browser(), contents
);
1546 void BrowserView::TabDetachedAt(WebContents
* contents
, int index
) {
1547 if (PermissionBubbleManager::FromWebContents(contents
))
1548 PermissionBubbleManager::FromWebContents(contents
)->SetView(nullptr);
1550 // We use index here rather than comparing |contents| because by this time
1551 // the model has already removed |contents| from its list, so
1552 // browser_->GetActiveWebContents() will return null or something else.
1553 if (index
== browser_
->tab_strip_model()->active_index()) {
1554 // We need to reset the current tab contents to null before it gets
1555 // freed. This is because the focus manager performs some operations
1556 // on the selected WebContents when it is removed.
1557 web_contents_close_handler_
->ActiveTabChanged();
1558 contents_web_view_
->SetWebContents(nullptr);
1559 infobar_container_
->ChangeInfoBarManager(nullptr);
1560 UpdateDevToolsForContents(nullptr, true);
1564 void BrowserView::TabDeactivated(WebContents
* contents
) {
1565 if (PermissionBubbleManager::FromWebContents(contents
))
1566 PermissionBubbleManager::FromWebContents(contents
)->SetView(nullptr);
1568 // We do not store the focus when closing the tab to work-around bug 4633.
1569 // Some reports seem to show that the focus manager and/or focused view can
1570 // be garbage at that point, it is not clear why.
1571 if (!contents
->IsBeingDestroyed())
1572 contents
->StoreFocus();
1575 void BrowserView::TabStripEmpty() {
1576 // Make sure all optional UI is removed before we are destroyed, otherwise
1577 // there will be consequences (since our view hierarchy will still have
1578 // references to freed views).
1579 UpdateUIForContents(nullptr);
1582 void BrowserView::WillCloseAllTabs() {
1583 web_contents_close_handler_
->WillCloseAllTabs();
1586 void BrowserView::CloseAllTabsCanceled() {
1587 web_contents_close_handler_
->CloseAllTabsCanceled();
1590 ///////////////////////////////////////////////////////////////////////////////
1591 // BrowserView, ui::AcceleratorProvider implementation:
1593 bool BrowserView::GetAcceleratorForCommandId(int command_id
,
1594 ui::Accelerator
* accelerator
) {
1595 // Let's let the ToolbarView own the canonical implementation of this method.
1596 return toolbar_
->GetAcceleratorForCommandId(command_id
, accelerator
);
1599 ///////////////////////////////////////////////////////////////////////////////
1600 // BrowserView, views::WidgetDelegate implementation:
1602 bool BrowserView::CanResize() const {
1606 bool BrowserView::CanMaximize() const {
1610 bool BrowserView::CanMinimize() const {
1614 bool BrowserView::CanActivate() const {
1615 app_modal::AppModalDialogQueue
* queue
=
1616 app_modal::AppModalDialogQueue::GetInstance();
1617 if (!queue
->active_dialog() || !queue
->active_dialog()->native_dialog() ||
1618 !queue
->active_dialog()->native_dialog()->IsShowing()) {
1622 #if defined(USE_AURA) && defined(OS_CHROMEOS)
1623 // On Aura window manager controls all windows so settings focus via PostTask
1624 // will make only worse because posted task will keep trying to steal focus.
1625 queue
->ActivateModalDialog();
1627 // If another browser is app modal, flash and activate the modal browser. This
1628 // has to be done in a post task, otherwise if the user clicked on a window
1629 // that doesn't have the modal dialog the windows keep trying to get the focus
1630 // from each other on Windows. http://crbug.com/141650.
1631 base::MessageLoop::current()->PostTask(
1633 base::Bind(&BrowserView::ActivateAppModalDialog
,
1634 activate_modal_dialog_factory_
.GetWeakPtr()));
1639 base::string16
BrowserView::GetWindowTitle() const {
1640 return browser_
->GetWindowTitleForCurrentTab();
1643 base::string16
BrowserView::GetAccessibleWindowTitle() const {
1644 if (IsOffTheRecord()) {
1645 return l10n_util::GetStringFUTF16(
1646 IDS_ACCESSIBLE_INCOGNITO_WINDOW_TITLE_FORMAT
,
1649 return GetWindowTitle();
1652 views::View
* BrowserView::GetInitiallyFocusedView() {
1656 bool BrowserView::ShouldShowWindowTitle() const {
1657 // For Ash only, trusted windows (apps and settings) do not show a title,
1658 // crbug.com/119411. Child windows (i.e. popups) do show a title.
1659 if (browser_
->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH
&&
1660 browser_
->is_trusted_source() &&
1661 !browser_
->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME
))
1664 return browser_
->SupportsWindowFeature(Browser::FEATURE_TITLEBAR
);
1667 gfx::ImageSkia
BrowserView::GetWindowAppIcon() {
1668 if (browser_
->is_app()) {
1669 WebContents
* contents
= browser_
->tab_strip_model()->GetActiveWebContents();
1670 extensions::TabHelper
* extensions_tab_helper
=
1671 contents
? extensions::TabHelper::FromWebContents(contents
) : nullptr;
1672 if (extensions_tab_helper
&& extensions_tab_helper
->GetExtensionAppIcon())
1673 return gfx::ImageSkia::CreateFrom1xBitmap(
1674 *extensions_tab_helper
->GetExtensionAppIcon());
1677 return GetWindowIcon();
1680 gfx::ImageSkia
BrowserView::GetWindowIcon() {
1681 if (browser_
->is_app() || browser_
->is_type_popup())
1682 return browser_
->GetCurrentPageIcon().AsImageSkia();
1683 return gfx::ImageSkia();
1686 bool BrowserView::ShouldShowWindowIcon() const {
1687 // For Ash only, trusted windows (apps and settings) do not show an icon,
1688 // crbug.com/119411. Child windows (i.e. popups) do show an icon.
1689 if (browser_
->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH
&&
1690 browser_
->is_trusted_source() &&
1691 !browser_
->SupportsWindowFeature(Browser::FEATURE_WEBAPPFRAME
))
1694 return browser_
->SupportsWindowFeature(Browser::FEATURE_TITLEBAR
);
1697 bool BrowserView::ExecuteWindowsCommand(int command_id
) {
1698 // This function handles WM_SYSCOMMAND, WM_APPCOMMAND, and WM_COMMAND.
1700 if (command_id
== IDC_DEBUG_FRAME_TOGGLE
)
1701 GetWidget()->DebugToggleFrameType();
1703 // Translate WM_APPCOMMAND command ids into a command id that the browser
1704 // knows how to handle.
1705 int command_id_from_app_command
= GetCommandIDForAppCommandID(command_id
);
1706 if (command_id_from_app_command
!= -1)
1707 command_id
= command_id_from_app_command
;
1709 return chrome::ExecuteCommand(browser_
.get(), command_id
);
1712 std::string
BrowserView::GetWindowName() const {
1713 return chrome::GetWindowName(browser_
.get());
1716 void BrowserView::SaveWindowPlacement(const gfx::Rect
& bounds
,
1717 ui::WindowShowState show_state
) {
1718 // If IsFullscreen() is true, we've just changed into fullscreen mode, and
1719 // we're catching the going-into-fullscreen sizing and positioning calls,
1720 // which we want to ignore.
1721 if (!IsFullscreen() && frame_
->ShouldSaveWindowPlacement() &&
1722 chrome::ShouldSaveWindowPlacement(browser_
.get())) {
1723 WidgetDelegate::SaveWindowPlacement(bounds
, show_state
);
1724 chrome::SaveWindowPlacement(browser_
.get(), bounds
, show_state
);
1728 bool BrowserView::GetSavedWindowPlacement(
1729 const views::Widget
* widget
,
1731 ui::WindowShowState
* show_state
) const {
1732 chrome::GetSavedWindowBoundsAndShowState(browser_
.get(), bounds
, show_state
);
1734 if (browser_
->is_type_popup() &&
1735 !browser_
->is_app() &&
1736 !browser_
->is_trusted_source()) {
1737 // This is normal non-app popup window. The value passed in |bounds|
1738 // represents two pieces of information:
1739 // - the position of the window, in screen coordinates (outer position).
1740 // - the size of the content area (inner size).
1741 // We need to use these values to determine the appropriate size and
1742 // position of the resulting window.
1743 if (IsToolbarVisible()) {
1744 // If we're showing the toolbar, we need to adjust |*bounds| to include
1745 // its desired height, since the toolbar is considered part of the
1746 // window's client area as far as GetWindowBoundsForClientBounds is
1749 bounds
->height() + toolbar_
->GetPreferredSize().height());
1752 gfx::Rect window_rect
= frame_
->non_client_view()->
1753 GetWindowBoundsForClientBounds(*bounds
);
1754 window_rect
.set_origin(bounds
->origin());
1756 // When we are given x/y coordinates of 0 on a created popup window,
1757 // assume none were given by the window.open() command.
1758 if (window_rect
.x() == 0 && window_rect
.y() == 0) {
1759 gfx::Size size
= window_rect
.size();
1760 window_rect
.set_origin(
1761 WindowSizer::GetDefaultPopupOrigin(size
,
1762 browser_
->host_desktop_type()));
1765 *bounds
= window_rect
;
1766 *show_state
= ui::SHOW_STATE_NORMAL
;
1769 // We return true because we can _always_ locate reasonable bounds using the
1770 // WindowSizer, and we don't want to trigger the Window's built-in "size to
1771 // default" handling because the browser window has no default preferred
1776 views::View
* BrowserView::GetContentsView() {
1777 return contents_web_view_
;
1780 views::ClientView
* BrowserView::CreateClientView(views::Widget
* widget
) {
1784 void BrowserView::OnWidgetActivationChanged(views::Widget
* widget
,
1787 BrowserList::SetLastActive(browser_
.get());
1790 void BrowserView::OnWindowBeginUserBoundsChange() {
1791 WebContents
* web_contents
= GetActiveWebContents();
1794 web_contents
->GetRenderViewHost()->NotifyMoveOrResizeStarted();
1797 void BrowserView::OnWidgetMove() {
1798 if (!initialized_
) {
1799 // Creating the widget can trigger a move. Ignore it until we've initialized
1804 // Cancel any tabstrip animations, some of them may be invalidated by the
1805 // window being repositioned.
1806 // Comment out for one cycle to see if this fixes dist tests.
1807 // tabstrip_->DestroyDragController();
1809 // status_bubble_ may be null if this is invoked during construction.
1810 if (status_bubble_
.get())
1811 status_bubble_
->Reposition();
1813 BookmarkBubbleView::Hide();
1815 // Close the omnibox popup, if any.
1816 LocationBarView
* location_bar_view
= GetLocationBarView();
1817 if (location_bar_view
)
1818 location_bar_view
->GetOmniboxView()->CloseOmniboxPopup();
1821 views::Widget
* BrowserView::GetWidget() {
1822 return View::GetWidget();
1825 const views::Widget
* BrowserView::GetWidget() const {
1826 return View::GetWidget();
1829 void BrowserView::GetAccessiblePanes(std::vector
<views::View
*>* panes
) {
1830 // This should be in the order of pane traversal of the panes using F6
1831 // (Windows) or Ctrl+Back/Forward (Chrome OS). If one of these is
1832 // invisible or has no focusable children, it will be automatically
1834 panes
->push_back(toolbar_
);
1835 if (bookmark_bar_view_
.get())
1836 panes
->push_back(bookmark_bar_view_
.get());
1837 if (infobar_container_
)
1838 panes
->push_back(infobar_container_
);
1839 if (download_shelf_
.get())
1840 panes
->push_back(download_shelf_
.get());
1841 panes
->push_back(GetTabContentsContainerView());
1842 if (devtools_web_view_
->visible())
1843 panes
->push_back(devtools_web_view_
);
1846 ///////////////////////////////////////////////////////////////////////////////
1847 // BrowserView, views::ClientView overrides:
1849 bool BrowserView::CanClose() {
1850 // You cannot close a frame for which there is an active originating drag
1852 if (tabstrip_
&& !tabstrip_
->IsTabStripCloseable())
1855 // Give beforeunload handlers the chance to cancel the close before we hide
1856 // the window below.
1857 if (!browser_
->ShouldCloseWindow())
1860 bool fast_tab_closing_enabled
=
1861 base::CommandLine::ForCurrentProcess()->HasSwitch(
1862 switches::kEnableFastUnload
);
1864 if (!browser_
->tab_strip_model()->empty()) {
1865 // Tab strip isn't empty. Hide the frame (so it appears to have closed
1866 // immediately) and close all the tabs, allowing the renderers to shut
1867 // down. When the tab strip is empty we'll be called back again.
1869 browser_
->OnWindowClosing();
1870 if (fast_tab_closing_enabled
)
1871 browser_
->tab_strip_model()->CloseAllTabs();
1873 } else if (fast_tab_closing_enabled
&&
1874 !browser_
->HasCompletedUnloadProcessing()) {
1875 // The browser needs to finish running unload handlers.
1876 // Hide the frame (so it appears to have closed immediately), and
1877 // the browser will call us back again when it is ready to close.
1882 // Empty TabStripModel, it's now safe to allow the Window to be closed.
1883 content::NotificationService::current()->Notify(
1884 chrome::NOTIFICATION_WINDOW_CLOSED
,
1885 content::Source
<gfx::NativeWindow
>(frame_
->GetNativeWindow()),
1886 content::NotificationService::NoDetails());
1890 int BrowserView::NonClientHitTest(const gfx::Point
& point
) {
1891 return GetBrowserViewLayout()->NonClientHitTest(point
);
1894 gfx::Size
BrowserView::GetMinimumSize() const {
1895 return GetBrowserViewLayout()->GetMinimumSize();
1898 ///////////////////////////////////////////////////////////////////////////////
1899 // BrowserView, views::View overrides:
1901 const char* BrowserView::GetClassName() const {
1902 return kViewClassName
;
1905 void BrowserView::Layout() {
1906 if (!initialized_
|| in_process_fullscreen_
)
1909 views::View::Layout();
1911 // TODO(jamescook): Why was this in the middle of layout code?
1912 toolbar_
->location_bar()->omnibox_view()->SetFocusable(IsToolbarVisible());
1915 void BrowserView::PaintChildren(const PaintContext
& context
) {
1916 // Paint the |infobar_container_| last so that it may paint its
1917 // overlapping tabs.
1918 for (int i
= 0; i
< child_count(); ++i
) {
1919 View
* child
= child_at(i
);
1920 if (child
!= infobar_container_
&& !child
->layer())
1921 child
->Paint(context
);
1924 infobar_container_
->Paint(context
);
1927 void BrowserView::ViewHierarchyChanged(
1928 const ViewHierarchyChangedDetails
& details
) {
1929 if (!initialized_
&& details
.is_add
&& details
.child
== this && GetWidget()) {
1931 initialized_
= true;
1935 void BrowserView::ChildPreferredSizeChanged(View
* child
) {
1939 void BrowserView::GetAccessibleState(ui::AXViewState
* state
) {
1940 state
->role
= ui::AX_ROLE_CLIENT
;
1943 void BrowserView::OnNativeThemeChanged(const ui::NativeTheme
* theme
) {
1944 // Do not handle native theme changes before the browser view is initialized.
1947 ClientView::OnNativeThemeChanged(theme
);
1949 chrome::MaybeShowInvertBubbleView(this);
1952 ///////////////////////////////////////////////////////////////////////////////
1953 // BrowserView, ui::AcceleratorTarget overrides:
1955 bool BrowserView::AcceleratorPressed(const ui::Accelerator
& accelerator
) {
1956 std::map
<ui::Accelerator
, int>::const_iterator iter
=
1957 accelerator_table_
.find(accelerator
);
1958 DCHECK(iter
!= accelerator_table_
.end());
1959 int command_id
= iter
->second
;
1961 chrome::BrowserCommandController
* controller
= browser_
->command_controller();
1962 if (!controller
->block_command_execution())
1963 UpdateAcceleratorMetrics(accelerator
, command_id
);
1964 return chrome::ExecuteCommand(browser_
.get(), command_id
);
1967 ///////////////////////////////////////////////////////////////////////////////
1968 // BrowserView, OmniboxPopupModelObserver overrides:
1969 void BrowserView::OnOmniboxPopupShownOrHidden() {
1970 SetMaxTopArrowHeight(GetMaxTopInfoBarArrowHeight(), infobar_container_
);
1973 ///////////////////////////////////////////////////////////////////////////////
1974 // BrowserView, InfoBarContainerDelegate overrides:
1976 SkColor
BrowserView::GetInfoBarSeparatorColor() const {
1977 // NOTE: Keep this in sync with ToolbarView::OnPaint()!
1978 return (IsTabStripVisible() || !frame_
->ShouldUseNativeFrame()) ?
1979 ThemeProperties::GetDefaultColor(
1980 ThemeProperties::COLOR_TOOLBAR_SEPARATOR
) :
1984 void BrowserView::InfoBarContainerStateChanged(bool is_animating
) {
1985 ToolbarSizeChanged(is_animating
);
1988 bool BrowserView::DrawInfoBarArrows(int* x
) const {
1990 gfx::Point
anchor(toolbar_
->location_bar()->GetLocationBarAnchorPoint());
1991 ConvertPointToTarget(toolbar_
->location_bar(), this, &anchor
);
1997 void BrowserView::InitViews() {
1998 GetWidget()->AddObserver(this);
2000 // Stow a pointer to this object onto the window handle so that we can get at
2001 // it later when all we have is a native view.
2002 GetWidget()->SetNativeWindowProperty(kBrowserViewKey
, this);
2004 // Stow a pointer to the browser's profile onto the window handle so that we
2005 // can get it later when all we have is a native view.
2006 GetWidget()->SetNativeWindowProperty(Profile::kProfileKey
,
2007 browser_
->profile());
2009 // Start a hung plugin window detector for this browser object (as long as
2010 // hang detection is not disabled).
2011 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
2012 switches::kDisableHangMonitor
)) {
2018 infobar_container_
= new InfoBarContainerView(this);
2019 AddChildView(infobar_container_
);
2021 contents_web_view_
= new ContentsWebView(browser_
->profile());
2022 contents_web_view_
->set_id(VIEW_ID_TAB_CONTAINER
);
2023 contents_web_view_
->SetEmbedFullscreenWidgetMode(true);
2025 web_contents_close_handler_
.reset(
2026 new WebContentsCloseHandler(contents_web_view_
));
2028 devtools_web_view_
= new views::WebView(browser_
->profile());
2029 devtools_web_view_
->set_id(VIEW_ID_DEV_TOOLS_DOCKED
);
2030 devtools_web_view_
->SetVisible(false);
2032 contents_container_
= new views::View();
2033 contents_container_
->set_background(views::Background::CreateSolidBackground(
2034 ThemeProperties::GetDefaultColor(
2035 ThemeProperties::COLOR_CONTROL_BACKGROUND
)));
2036 contents_container_
->AddChildView(devtools_web_view_
);
2037 contents_container_
->AddChildView(contents_web_view_
);
2038 contents_container_
->SetLayoutManager(new ContentsLayoutManager(
2039 devtools_web_view_
, contents_web_view_
));
2040 AddChildView(contents_container_
);
2041 set_contents_view(contents_container_
);
2043 // Top container holds tab strip and toolbar and lives at the front of the
2045 top_container_
= new TopContainerView(this);
2046 AddChildView(top_container_
);
2048 // TabStrip takes ownership of the controller.
2049 BrowserTabStripController
* tabstrip_controller
=
2050 new BrowserTabStripController(browser_
.get(),
2051 browser_
->tab_strip_model());
2052 tabstrip_
= new TabStrip(tabstrip_controller
);
2053 top_container_
->AddChildView(tabstrip_
);
2054 tabstrip_controller
->InitFromModel(tabstrip_
);
2056 toolbar_
= new ToolbarView(browser_
.get());
2057 top_container_
->AddChildView(toolbar_
);
2062 // Create do-nothing view for the sake of controlling the z-order of the find
2064 find_bar_host_view_
= new View();
2065 AddChildView(find_bar_host_view_
);
2067 immersive_mode_controller_
->Init(this);
2069 BrowserViewLayout
* browser_view_layout
= new BrowserViewLayout
;
2070 browser_view_layout
->Init(new BrowserViewLayoutDelegateImpl(this),
2077 contents_container_
,
2078 GetContentsLayoutManager(),
2079 immersive_mode_controller_
.get());
2080 SetLayoutManager(browser_view_layout
);
2083 // Create a custom JumpList and add it to an observer of TabRestoreService
2084 // so we can update the custom JumpList when a tab is added or removed.
2085 if (JumpList::Enabled()) {
2086 load_complete_listener_
.reset(new LoadCompleteListener(this));
2090 GetLocationBar()->GetOmniboxView()->model()->popup_model()->AddObserver(this);
2093 void BrowserView::LoadingAnimationCallback() {
2094 base::TimeTicks now
= base::TimeTicks::Now();
2095 if (!last_animation_time_
.is_null()) {
2096 UMA_HISTOGRAM_TIMES(
2097 "Tabs.LoadingAnimationTime",
2098 now
- last_animation_time_
);
2100 last_animation_time_
= now
;
2101 if (browser_
->is_type_tabbed()) {
2102 // Loading animations are shown in the tab for tabbed windows. We check the
2103 // browser type instead of calling IsTabStripVisible() because the latter
2104 // will return false for fullscreen windows, but we still need to update
2105 // their animations (so that when they come out of fullscreen mode they'll
2107 tabstrip_
->UpdateLoadingAnimations();
2108 } else if (ShouldShowWindowIcon()) {
2109 // ... or in the window icon area for popups and app windows.
2110 WebContents
* web_contents
=
2111 browser_
->tab_strip_model()->GetActiveWebContents();
2112 // GetActiveWebContents can return null for example under Purify when
2113 // the animations are running slowly and this function is called on a timer
2114 // through LoadingAnimationCallback.
2115 frame_
->UpdateThrobber(web_contents
&& web_contents
->IsLoading());
2119 void BrowserView::OnLoadCompleted() {
2121 DCHECK(!jumplist_
.get());
2122 jumplist_
= new JumpList(browser_
->profile());
2126 BrowserViewLayout
* BrowserView::GetBrowserViewLayout() const {
2127 return static_cast<BrowserViewLayout
*>(GetLayoutManager());
2130 ContentsLayoutManager
* BrowserView::GetContentsLayoutManager() const {
2131 return static_cast<ContentsLayoutManager
*>(
2132 contents_container_
->GetLayoutManager());
2135 bool BrowserView::MaybeShowBookmarkBar(WebContents
* contents
) {
2136 bool show_bookmark_bar
= contents
&&
2137 browser_
->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR
);
2138 if (!show_bookmark_bar
&& !bookmark_bar_view_
.get())
2140 if (!bookmark_bar_view_
.get()) {
2141 bookmark_bar_view_
.reset(new BookmarkBarView(browser_
.get(), this));
2142 bookmark_bar_view_
->set_owned_by_client();
2143 bookmark_bar_view_
->set_background(new BookmarkBarViewBackground(
2144 this, bookmark_bar_view_
.get(), browser_
.get()));
2145 bookmark_bar_view_
->SetBookmarkBarState(
2146 browser_
->bookmark_bar_state(),
2147 BookmarkBar::DONT_ANIMATE_STATE_CHANGE
);
2148 GetBrowserViewLayout()->set_bookmark_bar(bookmark_bar_view_
.get());
2150 // Don't change the visibility of the BookmarkBarView. BrowserViewLayout
2152 bookmark_bar_view_
->SetPageNavigator(GetActiveWebContents());
2154 // Update parenting for the bookmark bar. This may detach it from all views.
2155 bool needs_layout
= false;
2156 views::View
* new_parent
= nullptr;
2157 if (show_bookmark_bar
) {
2158 if (bookmark_bar_view_
->IsDetached())
2161 new_parent
= top_container_
;
2163 if (new_parent
!= bookmark_bar_view_
->parent()) {
2164 SetBookmarkBarParent(new_parent
);
2165 needs_layout
= true;
2168 // Check for updates to the desired size.
2169 if (bookmark_bar_view_
->GetPreferredSize().height() !=
2170 bookmark_bar_view_
->height())
2171 needs_layout
= true;
2173 return needs_layout
;
2176 void BrowserView::SetBookmarkBarParent(views::View
* new_parent
) {
2177 if (new_parent
== this) {
2178 // Add it underneath |top_container_| or at the end if top container isn't
2180 int top_container_index
= GetIndexOf(top_container_
);
2181 if (top_container_index
>= 0)
2182 AddChildViewAt(bookmark_bar_view_
.get(), top_container_index
);
2184 AddChildView(bookmark_bar_view_
.get());
2185 } else if (new_parent
) {
2186 // No special stacking is required for other parents.
2187 new_parent
->AddChildView(bookmark_bar_view_
.get());
2189 // Bookmark bar is being detached from all views because it is hidden.
2190 bookmark_bar_view_
->parent()->RemoveChildView(bookmark_bar_view_
.get());
2194 bool BrowserView::MaybeShowInfoBar(WebContents
* contents
) {
2195 // TODO(beng): Remove this function once the interface between
2196 // InfoBarContainer, DownloadShelfView and WebContents and this
2197 // view is sorted out.
2201 void BrowserView::UpdateDevToolsForContents(
2202 WebContents
* web_contents
, bool update_devtools_web_contents
) {
2203 DevToolsContentsResizingStrategy strategy
;
2204 WebContents
* devtools
= DevToolsWindow::GetInTabWebContents(
2205 web_contents
, &strategy
);
2207 if (!devtools_web_view_
->web_contents() && devtools
&&
2208 !devtools_focus_tracker_
.get()) {
2209 // Install devtools focus tracker when dev tools window is shown for the
2211 devtools_focus_tracker_
.reset(
2212 new views::ExternalFocusTracker(devtools_web_view_
,
2213 GetFocusManager()));
2216 // Restore focus to the last focused view when hiding devtools window.
2217 if (devtools_web_view_
->web_contents() && !devtools
&&
2218 devtools_focus_tracker_
.get()) {
2219 devtools_focus_tracker_
->FocusLastFocusedExternalView();
2220 devtools_focus_tracker_
.reset();
2223 // Replace devtools WebContents.
2224 if (devtools_web_view_
->web_contents() != devtools
&&
2225 update_devtools_web_contents
) {
2226 devtools_web_view_
->SetWebContents(devtools
);
2230 devtools_web_view_
->SetVisible(true);
2231 GetContentsLayoutManager()->SetContentsResizingStrategy(strategy
);
2233 devtools_web_view_
->SetVisible(false);
2234 GetContentsLayoutManager()->SetContentsResizingStrategy(
2235 DevToolsContentsResizingStrategy());
2237 contents_container_
->Layout();
2240 // When strategy.hide_inspected_contents() returns true, we are hiding
2241 // contents_web_view_ behind the devtools_web_view_. Otherwise,
2242 // contents_web_view_ should be right above the devtools_web_view_.
2243 int devtools_index
= contents_container_
->GetIndexOf(devtools_web_view_
);
2244 int contents_index
= contents_container_
->GetIndexOf(contents_web_view_
);
2245 bool devtools_is_on_top
= devtools_index
> contents_index
;
2246 if (strategy
.hide_inspected_contents() != devtools_is_on_top
)
2247 contents_container_
->ReorderChildView(contents_web_view_
, devtools_index
);
2251 void BrowserView::UpdateUIForContents(WebContents
* contents
) {
2252 bool needs_layout
= MaybeShowBookmarkBar(contents
);
2253 // TODO(jamescook): This function always returns true. Remove it and figure
2254 // out when layout is actually required.
2255 needs_layout
|= MaybeShowInfoBar(contents
);
2260 void BrowserView::ProcessFullscreen(bool fullscreen
,
2261 FullscreenMode mode
,
2263 ExclusiveAccessBubbleType bubble_type
) {
2264 if (in_process_fullscreen_
)
2266 in_process_fullscreen_
= true;
2268 // Reduce jankiness during the following position changes by:
2269 // * Hiding the window until it's in the final position
2270 // * Ignoring all intervening Layout() calls, which resize the webpage and
2271 // thus are slow and look ugly (enforced via |in_process_fullscreen_|).
2272 LocationBarView
* location_bar
= GetLocationBarView();
2274 if (mode
== METRO_SNAP_FULLSCREEN
|| !fullscreen
) {
2275 // Hide the fullscreen bubble as soon as possible, since the mode toggle can
2276 // take enough time for the user to notice.
2277 exclusive_access_bubble_
.reset();
2281 // Move focus out of the location bar if necessary.
2282 views::FocusManager
* focus_manager
= GetFocusManager();
2283 DCHECK(focus_manager
);
2284 // Look for focus in the location bar itself or any child view.
2285 if (location_bar
->Contains(focus_manager
->GetFocusedView()))
2286 focus_manager
->ClearFocus();
2289 // Toggle fullscreen mode.
2290 frame_
->SetFullscreen(fullscreen
);
2292 // Enable immersive before the browser refreshes its list of enabled commands.
2293 if (mode
!= METRO_SNAP_FULLSCREEN
&& ShouldUseImmersiveFullscreenForUrl(url
))
2294 immersive_mode_controller_
->SetEnabled(fullscreen
);
2296 browser_
->WindowFullscreenStateChanged();
2298 if (fullscreen
&& !chrome::IsRunningInAppMode() &&
2299 mode
!= METRO_SNAP_FULLSCREEN
) {
2300 UpdateExclusiveAccessExitBubbleContent(url
, bubble_type
);
2303 // Undo our anti-jankiness hacks and force a re-layout. We also need to
2304 // recompute the height of the infobar top arrow because toggling in and out
2305 // of fullscreen changes it. Calling ToolbarSizeChanged() will do both these
2306 // things since it computes the arrow height directly and forces a layout
2307 // indirectly via UpdateUIForContents(). Reset |in_process_fullscreen_| in
2308 // order to let the layout occur.
2309 in_process_fullscreen_
= false;
2310 ToolbarSizeChanged(false);
2312 if (permission_bubble_
.get())
2313 permission_bubble_
->UpdateAnchorPosition();
2316 bool BrowserView::ShouldUseImmersiveFullscreenForUrl(const GURL
& url
) const {
2317 // Kiosk mode needs the whole screen, and if we're not in an Ash desktop
2318 // immersive fullscreen doesn't exist.
2319 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode
) ||
2320 browser()->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH
) {
2324 return url
.is_empty();
2327 void BrowserView::LoadAccelerators() {
2328 views::FocusManager
* focus_manager
= GetFocusManager();
2329 DCHECK(focus_manager
);
2331 // Let's fill our own accelerator table.
2332 const bool is_app_mode
= chrome::IsRunningInForcedAppMode();
2333 const std::vector
<chrome::AcceleratorMapping
> accelerator_list(
2334 chrome::GetAcceleratorList());
2335 for (std::vector
<chrome::AcceleratorMapping
>::const_iterator it
=
2336 accelerator_list
.begin(); it
!= accelerator_list
.end(); ++it
) {
2337 // In app mode, only allow accelerators of white listed commands to pass
2339 if (is_app_mode
&& !chrome::IsCommandAllowedInAppMode(it
->command_id
))
2342 ui::Accelerator
accelerator(it
->keycode
, it
->modifiers
);
2343 accelerator_table_
[accelerator
] = it
->command_id
;
2345 // Also register with the focus manager.
2346 focus_manager
->RegisterAccelerator(
2347 accelerator
, ui::AcceleratorManager::kNormalPriority
, this);
2351 int BrowserView::GetCommandIDForAppCommandID(int app_command_id
) const {
2353 switch (app_command_id
) {
2354 // NOTE: The order here matches the APPCOMMAND declaration order in the
2356 case APPCOMMAND_BROWSER_BACKWARD
: return IDC_BACK
;
2357 case APPCOMMAND_BROWSER_FORWARD
: return IDC_FORWARD
;
2358 case APPCOMMAND_BROWSER_REFRESH
: return IDC_RELOAD
;
2359 case APPCOMMAND_BROWSER_HOME
: return IDC_HOME
;
2360 case APPCOMMAND_BROWSER_STOP
: return IDC_STOP
;
2361 case APPCOMMAND_BROWSER_SEARCH
: return IDC_FOCUS_SEARCH
;
2362 case APPCOMMAND_HELP
: return IDC_HELP_PAGE_VIA_KEYBOARD
;
2363 case APPCOMMAND_NEW
: return IDC_NEW_TAB
;
2364 case APPCOMMAND_OPEN
: return IDC_OPEN_FILE
;
2365 case APPCOMMAND_CLOSE
: return IDC_CLOSE_TAB
;
2366 case APPCOMMAND_SAVE
: return IDC_SAVE_PAGE
;
2367 case APPCOMMAND_PRINT
: return IDC_PRINT
;
2368 case APPCOMMAND_COPY
: return IDC_COPY
;
2369 case APPCOMMAND_CUT
: return IDC_CUT
;
2370 case APPCOMMAND_PASTE
: return IDC_PASTE
;
2372 // TODO(pkasting): http://b/1113069 Handle these.
2373 case APPCOMMAND_UNDO
:
2374 case APPCOMMAND_REDO
:
2375 case APPCOMMAND_SPELL_CHECK
:
2379 // App commands are Windows-specific so there's nothing to do here.
2384 void BrowserView::InitHangMonitor() {
2386 PrefService
* pref_service
= g_browser_process
->local_state();
2390 int plugin_message_response_timeout
=
2391 pref_service
->GetInteger(prefs::kPluginMessageResponseTimeout
);
2392 int hung_plugin_detect_freq
=
2393 pref_service
->GetInteger(prefs::kHungPluginDetectFrequency
);
2394 HWND window
= GetWidget()->GetNativeView()->GetHost()->
2395 GetAcceleratedWidget();
2396 if ((hung_plugin_detect_freq
> 0) &&
2397 hung_window_detector_
.Initialize(window
,
2398 plugin_message_response_timeout
)) {
2399 ticker_
.set_tick_interval(hung_plugin_detect_freq
);
2400 ticker_
.RegisterTickHandler(&hung_window_detector_
);
2403 pref_service
->SetInteger(prefs::kPluginMessageResponseTimeout
,
2404 plugin_message_response_timeout
);
2405 pref_service
->SetInteger(prefs::kHungPluginDetectFrequency
,
2406 hung_plugin_detect_freq
);
2411 void BrowserView::UpdateAcceleratorMetrics(const ui::Accelerator
& accelerator
,
2413 const ui::KeyboardCode key_code
= accelerator
.key_code();
2414 if (command_id
== IDC_HELP_PAGE_VIA_KEYBOARD
&& key_code
== ui::VKEY_F1
)
2415 content::RecordAction(UserMetricsAction("ShowHelpTabViaF1"));
2417 if (command_id
== IDC_BOOKMARK_PAGE
)
2418 UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
2419 BOOKMARK_ENTRY_POINT_ACCELERATOR
,
2420 BOOKMARK_ENTRY_POINT_LIMIT
);
2422 #if defined(OS_CHROMEOS)
2423 // Collect information about the relative popularity of various accelerators
2425 switch (command_id
) {
2427 if (key_code
== ui::VKEY_BACK
)
2428 content::RecordAction(UserMetricsAction("Accel_Back_Backspace"));
2429 else if (key_code
== ui::VKEY_BROWSER_BACK
)
2430 content::RecordAction(UserMetricsAction("Accel_Back_F1"));
2431 else if (key_code
== ui::VKEY_LEFT
)
2432 content::RecordAction(UserMetricsAction("Accel_Back_Left"));
2435 if (key_code
== ui::VKEY_BACK
)
2436 content::RecordAction(UserMetricsAction("Accel_Forward_Backspace"));
2437 else if (key_code
== ui::VKEY_BROWSER_FORWARD
)
2438 content::RecordAction(UserMetricsAction("Accel_Forward_F2"));
2439 else if (key_code
== ui::VKEY_RIGHT
)
2440 content::RecordAction(UserMetricsAction("Accel_Forward_Right"));
2443 case IDC_RELOAD_IGNORING_CACHE
:
2444 if (key_code
== ui::VKEY_R
)
2445 content::RecordAction(UserMetricsAction("Accel_Reload_R"));
2446 else if (key_code
== ui::VKEY_BROWSER_REFRESH
)
2447 content::RecordAction(UserMetricsAction("Accel_Reload_F3"));
2449 case IDC_FOCUS_LOCATION
:
2450 if (key_code
== ui::VKEY_D
)
2451 content::RecordAction(UserMetricsAction("Accel_FocusLocation_D"));
2452 else if (key_code
== ui::VKEY_L
)
2453 content::RecordAction(UserMetricsAction("Accel_FocusLocation_L"));
2455 case IDC_FOCUS_SEARCH
:
2456 if (key_code
== ui::VKEY_E
)
2457 content::RecordAction(UserMetricsAction("Accel_FocusSearch_E"));
2458 else if (key_code
== ui::VKEY_K
)
2459 content::RecordAction(UserMetricsAction("Accel_FocusSearch_K"));
2468 void BrowserView::ShowAvatarBubbleFromAvatarButton(
2469 AvatarBubbleMode mode
,
2470 const signin::ManageAccountsParams
& manage_accounts_params
) {
2471 views::BubbleBorder::Arrow arrow
= views::BubbleBorder::TOP_RIGHT
;
2472 views::BubbleBorder::BubbleAlignment alignment
=
2473 views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR
;
2474 views::View
* anchor_view
= frame_
->GetAvatarMenuButton();
2476 anchor_view
= toolbar_
->app_menu();
2477 else if (!frame_
->GetAvatarMenuButton()->button_on_right())
2478 arrow
= views::BubbleBorder::TOP_LEFT
;
2480 if (switches::IsNewAvatarMenu()) {
2481 NewAvatarButton
* button
= frame_
->GetNewAvatarMenuButton();
2483 anchor_view
= button
;
2484 arrow
= views::BubbleBorder::TOP_RIGHT
;
2485 alignment
= views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE
;
2488 profiles::BubbleViewMode bubble_view_mode
;
2489 profiles::TutorialMode tutorial_mode
;
2490 profiles::BubbleViewModeFromAvatarBubbleMode(
2491 mode
, &bubble_view_mode
, &tutorial_mode
);
2492 ProfileChooserView::ShowBubble(
2493 bubble_view_mode
, tutorial_mode
,
2494 manage_accounts_params
, anchor_view
, arrow
, alignment
, browser());
2497 views::View::ConvertPointToScreen(anchor_view
, &origin
);
2498 gfx::Rect
bounds(origin
, anchor_view
->size());
2499 views::BubbleBorder::ArrowPaintType arrow_paint_type
=
2500 ShouldHideUIForFullscreen() ? views::BubbleBorder::PAINT_TRANSPARENT
:
2501 views::BubbleBorder::PAINT_NORMAL
;
2502 AvatarMenuBubbleView::ShowBubble(anchor_view
, arrow
, arrow_paint_type
,
2503 alignment
, bounds
, browser());
2505 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE
);
2508 int BrowserView::GetRenderViewHeightInsetWithDetachedBookmarkBar() {
2509 if (browser_
->bookmark_bar_state() != BookmarkBar::DETACHED
||
2510 !bookmark_bar_view_
.get() || !bookmark_bar_view_
->IsDetached()) {
2513 // Don't use bookmark_bar_view_->height() which won't be the final height if
2514 // the bookmark bar is animating.
2515 return chrome::kNTPBookmarkBarHeight
-
2516 bookmark_bar_view_
->GetFullyDetachedToolbarOverlap();
2519 void BrowserView::ExecuteExtensionCommand(
2520 const extensions::Extension
* extension
,
2521 const extensions::Command
& command
) {
2522 toolbar_
->ExecuteExtensionCommand(extension
, command
);
2525 ExclusiveAccessContext
* BrowserView::GetExclusiveAccessContext() {
2529 void BrowserView::DoCutCopyPaste(void (WebContents::*method
)(),
2531 WebContents
* contents
= browser_
->tab_strip_model()->GetActiveWebContents();
2534 if (DoCutCopyPasteForWebContents(contents
, method
))
2537 WebContents
* devtools
= DevToolsWindow::GetInTabWebContents(contents
,
2539 if (devtools
&& DoCutCopyPasteForWebContents(devtools
, method
))
2542 views::FocusManager
* focus_manager
= GetFocusManager();
2543 views::View
* focused
= focus_manager
->GetFocusedView();
2545 (!strcmp(focused
->GetClassName(), views::Textfield::kViewClassName
) ||
2546 !strcmp(focused
->GetClassName(), OmniboxViewViews::kViewClassName
))) {
2547 views::Textfield
* textfield
= static_cast<views::Textfield
*>(focused
);
2548 textfield
->ExecuteCommand(command_id
);
2552 bool BrowserView::DoCutCopyPasteForWebContents(
2553 WebContents
* contents
,
2554 void (WebContents::*method
)()) {
2555 if (contents
->GetRenderWidgetHostView()->HasFocus()) {
2556 (contents
->*method
)();
2563 void BrowserView::ActivateAppModalDialog() const {
2564 // If another browser is app modal, flash and activate the modal browser.
2565 app_modal::AppModalDialog
* active_dialog
=
2566 app_modal::AppModalDialogQueue::GetInstance()->active_dialog();
2570 Browser
* modal_browser
=
2571 chrome::FindBrowserWithWebContents(active_dialog
->web_contents());
2572 if (modal_browser
&& (browser_
!= modal_browser
)) {
2573 modal_browser
->window()->FlashFrame(true);
2574 modal_browser
->window()->Activate();
2577 app_modal::AppModalDialogQueue::GetInstance()->ActivateModalDialog();
2580 int BrowserView::GetMaxTopInfoBarArrowHeight() {
2581 int top_arrow_height
= 0;
2582 // Only show the arrows when not in fullscreen and when there's no omnibox
2584 if (!IsFullscreen() &&
2585 !GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) {
2586 gfx::Point
icon_bottom(
2587 toolbar_
->location_bar()->GetLocationBarAnchorPoint());
2588 ConvertPointToTarget(toolbar_
->location_bar(), this, &icon_bottom
);
2589 gfx::Point
infobar_top(0, infobar_container_
->GetVerticalOverlap(nullptr));
2590 ConvertPointToTarget(infobar_container_
, this, &infobar_top
);
2591 top_arrow_height
= infobar_top
.y() - icon_bottom
.y();
2593 return top_arrow_height
;
2596 ///////////////////////////////////////////////////////////////////////////////
2597 // BrowserView, ExclusiveAccessContext overrides
2598 Profile
* BrowserView::GetProfile() {
2599 return browser_
->profile();
2602 WebContents
* BrowserView::GetActiveWebContents() {
2603 return browser_
->tab_strip_model()->GetActiveWebContents();
2606 void BrowserView::UnhideDownloadShelf() {
2607 GetDownloadShelf()->Unhide();
2610 void BrowserView::HideDownloadShelf() {
2611 GetDownloadShelf()->Hide();
2612 StatusBubble
* statusBubble
= GetStatusBubble();
2614 statusBubble
->Hide();
2617 ///////////////////////////////////////////////////////////////////////////////
2618 // BrowserView, ExclusiveAccessBubbleViewsContext overrides
2619 ExclusiveAccessManager
* BrowserView::GetExclusiveAccessManager() {
2620 return browser_
->exclusive_access_manager();
2623 bool BrowserView::IsImmersiveModeEnabled() {
2624 return immersive_mode_controller()->IsEnabled();
2627 views::Widget
* BrowserView::GetBubbleAssociatedWidget() {
2631 gfx::Rect
BrowserView::GetTopContainerBoundsInScreen() {
2632 return top_container_
->GetBoundsInScreen();