browser_view.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_H_
7
8#include <map>
9#include <string>
10#include <vector>
11
12#include "base/compiler_specific.h"
13#include "base/memory/scoped_ptr.h"
14#include "base/timer/timer.h"
15#include "build/build_config.h"
16#include "chrome/browser/devtools/devtools_window.h"
17#include "chrome/browser/infobars/infobar_container.h"
18#include "chrome/browser/ui/browser.h"
19#include "chrome/browser/ui/browser_window.h"
20#include "chrome/browser/ui/omnibox/omnibox_popup_model_observer.h"
21#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
22#include "chrome/browser/ui/views/frame/browser_frame.h"
23#include "chrome/browser/ui/views/frame/contents_web_view.h"
24#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
25#include "chrome/browser/ui/views/frame/scroll_end_effect_controller.h"
26#include "chrome/browser/ui/views/load_complete_listener.h"
27#include "ui/base/accelerators/accelerator.h"
28#include "ui/base/models/simple_menu_model.h"
29#include "ui/gfx/native_widget_types.h"
30#include "ui/gfx/sys_color_change_listener.h"
31#include "ui/views/controls/button/button.h"
32#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
33#include "ui/views/widget/widget_delegate.h"
34#include "ui/views/widget/widget_observer.h"
35#include "ui/views/window/client_view.h"
36
37#if defined(OS_WIN)
38#include "chrome/browser/hang_monitor/hung_plugin_action.h"
39#include "chrome/browser/hang_monitor/hung_window_detector.h"
40#endif
41
42// NOTE: For more information about the objects and files in this directory,
43// view: http://dev.chromium.org/developers/design-documents/browser-window
44
45class BookmarkBarView;
46class Browser;
47class BrowserViewLayout;
48class ContentsLayoutManager;
49class DownloadShelfView;
50class FullscreenExitBubbleViews;
51class InfoBarContainerView;
52class LocationBarView;
53class PermissionBubbleViewViews;
54class StatusBubbleViews;
55class SearchViewController;
56class TabStrip;
57class TabStripModel;
58class ToolbarView;
59class TopContainerView;
60
61#if defined(OS_WIN)
62class JumpList;
63#endif
64
65namespace autofill {
66class PasswordGenerator;
67}
68
69namespace content {
70class RenderWidgetHost;
71}
72
73namespace extensions {
74class Extension;
75}
76
77namespace views {
78class AccessiblePaneView;
79class ExternalFocusTracker;
80class WebView;
81}
82
83///////////////////////////////////////////////////////////////////////////////
84// BrowserView
85//
86//  A ClientView subclass that provides the contents of a browser window,
87//  including the TabStrip, toolbars, download shelves, the content area etc.
88//
89class BrowserView : public BrowserWindow,
90                    public BrowserWindowTesting,
91                    public TabStripModelObserver,
92                    public ui::AcceleratorProvider,
93                    public views::WidgetDelegate,
94                    public views::WidgetObserver,
95                    public views::ClientView,
96                    public InfoBarContainer::Delegate,
97                    public gfx::SysColorChangeListener,
98                    public LoadCompleteListener::Delegate,
99                    public OmniboxPopupModelObserver {
100 public:
101  // The browser view's class name.
102  static const char kViewClassName[];
103
104  BrowserView();
105  virtual ~BrowserView();
106
107  // Takes ownership of |browser|.
108  void Init(Browser* browser);
109
110  void set_frame(BrowserFrame* frame) { frame_ = frame; }
111  BrowserFrame* frame() const { return frame_; }
112
113  // Returns a pointer to the BrowserView* interface implementation (an
114  // instance of this object, typically) for a given native window, or NULL if
115  // there is no such association.
116  //
117  // Don't use this unless you only have a NativeWindow. In nearly all
118  // situations plumb through browser and use it.
119  static BrowserView* GetBrowserViewForNativeWindow(gfx::NativeWindow window);
120
121  // Returns the BrowserView used for the specified Browser.
122  static BrowserView* GetBrowserViewForBrowser(const Browser* browser);
123
124  // Returns a Browser instance of this view.
125  Browser* browser() { return browser_.get(); }
126
127  // Initializes (or re-initializes) the status bubble.  We try to only create
128  // the bubble once and re-use it for the life of the browser, but certain
129  // events (such as changing enabling/disabling Aero on Win) can force a need
130  // to change some of the bubble's creation parameters.
131  void InitStatusBubble();
132
133  // Initializes the permission bubble view. This class is intended to be
134  // created once and then re-used for the life of the browser window. The
135  // bubbles it creates will be associated with a single visible tab.
136  void InitPermissionBubbleView();
137
138  // Returns the apparent bounds of the toolbar, in BrowserView coordinates.
139  // These differ from |toolbar_.bounds()| in that they match where the toolbar
140  // background image is drawn -- slightly outside the "true" bounds
141  // horizontally. Note that this returns the bounds for the toolbar area.
142  gfx::Rect GetToolbarBounds() const;
143
144  // Returns the constraining bounding box that should be used to lay out the
145  // FindBar within. This is _not_ the size of the find bar, just the bounding
146  // box it should be laid out within. The coordinate system of the returned
147  // rect is in the coordinate system of the frame, since the FindBar is a child
148  // window.
149  gfx::Rect GetFindBarBoundingBox() const;
150
151  // Returns the preferred height of the TabStrip. Used to position the OTR
152  // avatar icon.
153  int GetTabStripHeight() const;
154
155  // Takes some view's origin (relative to this BrowserView) and offsets it such
156  // that it can be used as the source origin for seamlessly tiling the toolbar
157  // background image over that view.
158  gfx::Point OffsetPointForToolbarBackgroundImage(
159      const gfx::Point& point) const;
160
161  // Container for the tabstrip, toolbar, etc.
162  TopContainerView* top_container() { return top_container_; }
163
164  // Accessor for the TabStrip.
165  TabStrip* tabstrip() { return tabstrip_; }
166
167  // Accessor for the Toolbar.
168  ToolbarView* toolbar() { return toolbar_; }
169
170  // Bookmark bar may be NULL, for example for pop-ups.
171  BookmarkBarView* bookmark_bar() { return bookmark_bar_view_.get(); }
172
173  // Returns the do-nothing view which controls the z-order of the find bar
174  // widget relative to views which paint into layers and views which have an
175  // associated NativeView. The presence / visibility of this view is not
176  // indicative of the visibility of the find bar widget or even whether
177  // FindBarController is initialized.
178  View* find_bar_host_view() { return find_bar_host_view_; }
179
180  // Accessor for the InfobarContainer.
181  InfoBarContainerView* infobar_container() { return infobar_container_; }
182
183  // Accessor for the FullscreenExitBubbleViews.
184  FullscreenExitBubbleViews* fullscreen_exit_bubble() {
185    return fullscreen_bubble_.get();
186  }
187
188  // Returns true if various window components are visible.
189  bool IsTabStripVisible() const;
190
191  // Returns true if the profile associated with this Browser window is
192  // incognito.
193  bool IsOffTheRecord() const;
194
195  // Returns true if the profile associated with this Browser window is
196  // a guest session.
197  bool IsGuestSession() const;
198
199  // Returns true if the profile associated with this Browser window is
200  // not off the record or a guest session.
201  bool IsRegularOrGuestSession() const;
202
203  // Returns the resource ID to use for the OTR icon, which depends on
204  // which layout is being shown and whether we are full-screen.
205  int GetOTRIconResourceID() const;
206
207  // Returns the resource ID to use for the Guest icon, which may depend on
208  // which layout is being shown and whether we are full-screen.
209  int GetGuestIconResourceID() const;
210
211  // Returns true if the non-client view should render an avatar icon.
212  bool ShouldShowAvatar() const;
213
214  // Provides the containing frame with the accelerator for the specified
215  // command id. This can be used to provide menu item shortcut hints etc.
216  // Returns true if an accelerator was found for the specified |cmd_id|, false
217  // otherwise.
218  bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator);
219
220  // Returns true if the specificed |accelerator| is registered with this view.
221  bool IsAcceleratorRegistered(const ui::Accelerator& accelerator);
222
223  // Returns the active WebContents. Used by our NonClientView's
224  // TabIconView::TabContentsProvider implementations.
225  // TODO(beng): exposing this here is a bit bogus, since it's only used to
226  // determine loading state. It'd be nicer if we could change this to be
227  // bool IsSelectedTabLoading() const; or something like that. We could even
228  // move it to a WindowDelegate subclass.
229  content::WebContents* GetActiveWebContents() const;
230
231  // Retrieves the icon to use in the frame to indicate an OTR window.
232  gfx::ImageSkia GetOTRAvatarIcon() const;
233
234  // Returns true if the Browser object associated with this BrowserView is a
235  // tabbed-type window (i.e. a browser window, not an app or popup).
236  bool IsBrowserTypeNormal() const {
237    return browser_->is_type_tabbed();
238  }
239
240  // See ImmersiveModeController for description.
241  ImmersiveModeController* immersive_mode_controller() const {
242    return immersive_mode_controller_.get();
243  }
244
245  // Restores the focused view. This is also used to set the initial focus
246  // when a new browser window is created.
247  void RestoreFocus();
248
249  void SetWindowSwitcherButton(views::Button* button);
250
251  views::Button* window_switcher_button() {
252    return window_switcher_button_;
253  }
254
255  // Called after the widget's fullscreen state is changed without going through
256  // FullscreenController. This method does any processing which was skipped.
257  // Only exiting fullscreen in this way is currently supported.
258  void FullscreenStateChanged();
259
260  // Called from BookmarkBarView/DownloadShelfView during their show/hide
261  // animations.
262  void ToolbarSizeChanged(bool is_animating);
263
264  // Overridden from BrowserWindow:
265  virtual void Show() OVERRIDE;
266  virtual void ShowInactive() OVERRIDE;
267  virtual void Hide() OVERRIDE;
268  virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
269  virtual void Close() OVERRIDE;
270  virtual void Activate() OVERRIDE;
271  virtual void Deactivate() OVERRIDE;
272  virtual bool IsActive() const OVERRIDE;
273  virtual void FlashFrame(bool flash) OVERRIDE;
274  virtual bool IsAlwaysOnTop() const OVERRIDE;
275  virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
276  virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
277  virtual BrowserWindowTesting* GetBrowserWindowTesting() OVERRIDE;
278  virtual StatusBubble* GetStatusBubble() OVERRIDE;
279  virtual void UpdateTitleBar() OVERRIDE;
280  virtual void BookmarkBarStateChanged(
281      BookmarkBar::AnimateChangeType change_type) OVERRIDE;
282  virtual void UpdateDevTools() OVERRIDE;
283  virtual void UpdateLoadingAnimations(bool should_animate) OVERRIDE;
284  virtual void SetStarredState(bool is_starred) OVERRIDE;
285  virtual void SetTranslateIconToggled(bool is_lit) OVERRIDE;
286  virtual void OnActiveTabChanged(content::WebContents* old_contents,
287                                  content::WebContents* new_contents,
288                                  int index,
289                                  int reason) OVERRIDE;
290  virtual void ZoomChangedForActiveTab(bool can_show_bubble) OVERRIDE;
291  virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
292  virtual ui::WindowShowState GetRestoredState() const OVERRIDE;
293  virtual gfx::Rect GetBounds() const OVERRIDE;
294  virtual bool IsMaximized() const OVERRIDE;
295  virtual bool IsMinimized() const OVERRIDE;
296  virtual void Maximize() OVERRIDE;
297  virtual void Minimize() OVERRIDE;
298  virtual void Restore() OVERRIDE;
299  virtual void EnterFullscreen(
300      const GURL& url, FullscreenExitBubbleType bubble_type) OVERRIDE;
301  virtual void ExitFullscreen() OVERRIDE;
302  virtual void UpdateFullscreenExitBubbleContent(
303      const GURL& url,
304      FullscreenExitBubbleType bubble_type) OVERRIDE;
305  virtual bool ShouldHideUIForFullscreen() const OVERRIDE;
306  virtual bool IsFullscreen() const OVERRIDE;
307  virtual bool IsFullscreenBubbleVisible() const OVERRIDE;
308#if defined(OS_WIN)
309  virtual void SetMetroSnapMode(bool enable) OVERRIDE;
310  virtual bool IsInMetroSnapMode() const OVERRIDE;
311#endif
312  virtual LocationBar* GetLocationBar() const OVERRIDE;
313  virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
314  virtual void UpdateReloadStopState(bool is_loading, bool force) OVERRIDE;
315  virtual void UpdateToolbar(content::WebContents* contents) OVERRIDE;
316  virtual void FocusToolbar() OVERRIDE;
317  virtual void FocusAppMenu() OVERRIDE;
318  virtual void FocusBookmarksToolbar() OVERRIDE;
319  virtual void FocusInfobars() OVERRIDE;
320  virtual void RotatePaneFocus(bool forwards) OVERRIDE;
321  virtual void DestroyBrowser() OVERRIDE;
322  virtual bool IsBookmarkBarVisible() const OVERRIDE;
323  virtual bool IsBookmarkBarAnimating() const OVERRIDE;
324  virtual bool IsTabStripEditable() const OVERRIDE;
325  virtual bool IsToolbarVisible() const OVERRIDE;
326  virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
327  virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
328                                        Profile* profile) OVERRIDE;
329  virtual void ShowUpdateChromeDialog() OVERRIDE;
330  virtual void ShowBookmarkBubble(const GURL& url,
331                                  bool already_bookmarked) OVERRIDE;
332  virtual void ShowBookmarkAppBubble(
333      const WebApplicationInfo& web_app_info,
334      const std::string& extension_id) OVERRIDE;
335  virtual void ShowBookmarkPrompt() OVERRIDE;
336  virtual void ShowTranslateBubble(content::WebContents* contents,
337                                   TranslateTabHelper::TranslateStep step,
338                                   TranslateErrors::Type error_type) OVERRIDE;
339#if defined(ENABLE_ONE_CLICK_SIGNIN)
340  virtual void ShowOneClickSigninBubble(
341      OneClickSigninBubbleType type,
342      const base::string16& email,
343      const base::string16& error_message,
344      const StartSyncCallback& start_sync_callback) OVERRIDE;
345#endif
346  // TODO(beng): Not an override, move somewhere else.
347  void SetDownloadShelfVisible(bool visible);
348  virtual bool IsDownloadShelfVisible() const OVERRIDE;
349  virtual DownloadShelf* GetDownloadShelf() OVERRIDE;
350  virtual void ConfirmBrowserCloseWithPendingDownloads(
351      int download_count,
352      Browser::DownloadClosePreventionType dialog_type,
353      bool app_modal,
354      const base::Callback<void(bool)>& callback) OVERRIDE;
355  virtual void UserChangedTheme() OVERRIDE;
356  virtual int GetExtraRenderViewHeight() const OVERRIDE;
357  virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE;
358  virtual void ShowWebsiteSettings(Profile* profile,
359                                   content::WebContents* web_contents,
360                                   const GURL& url,
361                                   const content::SSLStatus& ssl) OVERRIDE;
362  virtual void ShowAppMenu() OVERRIDE;
363  virtual bool PreHandleKeyboardEvent(
364      const content::NativeWebKeyboardEvent& event,
365      bool* is_keyboard_shortcut) OVERRIDE;
366  virtual void HandleKeyboardEvent(
367      const content::NativeWebKeyboardEvent& event) OVERRIDE;
368  virtual void Cut() OVERRIDE;
369  virtual void Copy() OVERRIDE;
370  virtual void Paste() OVERRIDE;
371  virtual WindowOpenDisposition GetDispositionForPopupBounds(
372      const gfx::Rect& bounds) OVERRIDE;
373  virtual FindBar* CreateFindBar() OVERRIDE;
374  virtual web_modal::WebContentsModalDialogHost*
375      GetWebContentsModalDialogHost() OVERRIDE;
376  virtual void ShowAvatarBubble(content::WebContents* web_contents,
377                                const gfx::Rect& rect) OVERRIDE;
378  virtual void ShowAvatarBubbleFromAvatarButton() OVERRIDE;
379  virtual void ShowPasswordGenerationBubble(
380      const gfx::Rect& rect,
381      const autofill::PasswordForm& form,
382      autofill::PasswordGenerator* password_generator) OVERRIDE;
383  virtual void OverscrollUpdate(int delta_y) OVERRIDE;
384  virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() OVERRIDE;
385
386  // Overridden from BrowserWindowTesting:
387  virtual BookmarkBarView* GetBookmarkBarView() const OVERRIDE;
388  virtual LocationBarView* GetLocationBarView() const OVERRIDE;
389  virtual views::View* GetTabContentsContainerView() const OVERRIDE;
390  virtual ToolbarView* GetToolbarView() const OVERRIDE;
391
392  // Overridden from TabStripModelObserver:
393  virtual void TabDetachedAt(content::WebContents* contents,
394                             int index) OVERRIDE;
395  virtual void TabDeactivated(content::WebContents* contents) OVERRIDE;
396  virtual void TabStripEmpty() OVERRIDE;
397
398  // Overridden from ui::AcceleratorProvider:
399  virtual bool GetAcceleratorForCommandId(int command_id,
400      ui::Accelerator* accelerator) OVERRIDE;
401
402  // Overridden from views::WidgetDelegate:
403  virtual bool CanResize() const OVERRIDE;
404  virtual bool CanMaximize() const OVERRIDE;
405  virtual bool CanActivate() const OVERRIDE;
406  virtual base::string16 GetWindowTitle() const OVERRIDE;
407  virtual base::string16 GetAccessibleWindowTitle() const OVERRIDE;
408  virtual views::View* GetInitiallyFocusedView() OVERRIDE;
409  virtual bool ShouldShowWindowTitle() const OVERRIDE;
410  virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE;
411  virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
412  virtual bool ShouldShowWindowIcon() const OVERRIDE;
413  virtual bool ExecuteWindowsCommand(int command_id) OVERRIDE;
414  virtual std::string GetWindowName() const OVERRIDE;
415  virtual void SaveWindowPlacement(const gfx::Rect& bounds,
416                                   ui::WindowShowState show_state) OVERRIDE;
417  virtual bool GetSavedWindowPlacement(
418      const views::Widget* widget,
419      gfx::Rect* bounds,
420      ui::WindowShowState* show_state) const OVERRIDE;
421  virtual views::View* GetContentsView() OVERRIDE;
422  virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
423  virtual void OnWindowBeginUserBoundsChange() OVERRIDE;
424  virtual void OnWidgetMove() OVERRIDE;
425  virtual views::Widget* GetWidget() OVERRIDE;
426  virtual const views::Widget* GetWidget() const OVERRIDE;
427  virtual void GetAccessiblePanes(std::vector<View*>* panes) OVERRIDE;
428
429  // Overridden from views::WidgetObserver:
430  virtual void OnWidgetActivationChanged(views::Widget* widget,
431                                         bool active) OVERRIDE;
432
433  // Overridden from views::ClientView:
434  virtual bool CanClose() OVERRIDE;
435  virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
436  virtual gfx::Size GetMinimumSize() OVERRIDE;
437
438  // InfoBarContainer::Delegate overrides
439  virtual SkColor GetInfoBarSeparatorColor() const OVERRIDE;
440  virtual void InfoBarContainerStateChanged(bool is_animating) OVERRIDE;
441  virtual bool DrawInfoBarArrows(int* x) const OVERRIDE;
442
443  // gfx::SysColorChangeListener overrides:
444  virtual void OnSysColorChange() OVERRIDE;
445
446  // Overridden from views::View:
447  virtual const char* GetClassName() const OVERRIDE;
448  virtual void Layout() OVERRIDE;
449  virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
450  virtual void ViewHierarchyChanged(
451      const ViewHierarchyChangedDetails& details) OVERRIDE;
452  virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
453  virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
454
455  // Overridden from ui::AcceleratorTarget:
456  virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
457
458  // OmniboxPopupModelObserver overrides
459  virtual void OnOmniboxPopupShownOrHidden() OVERRIDE;
460
461  // Testing interface:
462  views::View* GetContentsContainerForTest() { return contents_container_; }
463  views::WebView* GetContentsWebViewForTest() { return contents_web_view_; }
464  views::WebView* GetDevToolsWebViewForTest() { return devtools_web_view_; }
465
466 private:
467  // Do not friend BrowserViewLayout. Use the BrowserViewLayoutDelegate
468  // interface to keep these two classes decoupled and testable.
469  friend class BrowserViewLayoutDelegateImpl;
470  FRIEND_TEST_ALL_PREFIXES(BrowserViewTest, BrowserView);
471  FRIEND_TEST_ALL_PREFIXES(BrowserViewsAccessibilityTest,
472                           TestAboutChromeViewAccObj);
473
474  enum FullscreenType {
475    FOR_DESKTOP,
476    FOR_METRO
477  };
478
479  // Appends to |toolbars| a pointer to each AccessiblePaneView that
480  // can be traversed using F6, in the order they should be traversed.
481  void GetAccessiblePanes(std::vector<views::AccessiblePaneView*>* panes);
482
483  // Constructs and initializes the child views.
484  void InitViews();
485
486  // Callback for the loading animation(s) associated with this view.
487  void LoadingAnimationCallback();
488
489  // LoadCompleteListener::Delegate implementation. Creates and initializes the
490  // |jumplist_| after the first page load.
491  virtual void OnLoadCompleted() OVERRIDE;
492
493  // Returns the BrowserViewLayout.
494  BrowserViewLayout* GetBrowserViewLayout() const;
495
496  // Returns the ContentsLayoutManager.
497  ContentsLayoutManager* GetContentsLayoutManager() const;
498
499  // Prepare to show the Bookmark Bar for the specified WebContents.
500  // Returns true if the Bookmark Bar can be shown (i.e. it's supported for this
501  // Browser type) and there should be a subsequent re-layout to show it.
502  // |contents| can be NULL.
503  bool MaybeShowBookmarkBar(content::WebContents* contents);
504
505  // Moves the bookmark bar view to the specified parent, which may be NULL,
506  // |this|, or |top_container_|. Ensures that |top_container_| stays in front
507  // of |bookmark_bar_view_|.
508  void SetBookmarkBarParent(views::View* new_parent);
509
510  // Prepare to show an Info Bar for the specified WebContents. Returns
511  // true if there is an Info Bar to show and one is supported for this Browser
512  // type, and there should be a subsequent re-layout to show it.
513  // |contents| can be NULL.
514  bool MaybeShowInfoBar(content::WebContents* contents);
515
516  // Updates devtools window for given contents. This method will show docked
517  // devtools window for inspected |web_contents| that has docked devtools
518  // and hide it for NULL or not inspected |web_contents|. It will also make
519  // sure devtools window size and position are restored for given tab.
520  // This method will not update actual DevTools WebContents, if not
521  // |update_devtools_web_contents|. In this case, manual update is required.
522  void UpdateDevToolsForContents(content::WebContents* web_contents,
523                                 bool update_devtools_web_contents);
524
525  // Updates various optional child Views, e.g. Bookmarks Bar, Info Bar or the
526  // Download Shelf in response to a change notification from the specified
527  // |contents|. |contents| can be NULL. In this case, all optional UI will be
528  // removed.
529  void UpdateUIForContents(content::WebContents* contents);
530
531  // Invoked to update the necessary things when our fullscreen state changes
532  // to |fullscreen|. On Windows this is invoked immediately when we toggle the
533  // full screen state. On Linux changing the fullscreen state is async, so we
534  // ask the window to change its fullscreen state, then when we get
535  // notification that it succeeded this method is invoked.
536  // If |url| is not empty, it is the URL of the page that requested fullscreen
537  // (via the fullscreen JS API).
538  // |bubble_type| determines what should be shown in the fullscreen exit
539  // bubble.
540  void ProcessFullscreen(bool fullscreen,
541                         FullscreenType fullscreen_type,
542                         const GURL& url,
543                         FullscreenExitBubbleType bubble_type);
544
545  // Returns whether immmersive fullscreen should replace fullscreen. This
546  // should only occur for "browser-fullscreen" for tabbed-typed windows (not
547  // for tab-fullscreen and not for app/popup type windows).
548  bool ShouldUseImmersiveFullscreenForUrl(const GURL& url) const;
549
550  // Copy the accelerator table from the app resources into something we can
551  // use.
552  void LoadAccelerators();
553
554  // Retrieves the command id for the specified Windows app command.
555  int GetCommandIDForAppCommandID(int app_command_id) const;
556
557  // Initialize the hung plugin detector.
558  void InitHangMonitor();
559
560  // Possibly records a user metrics action corresponding to the passed-in
561  // accelerator.  Only implemented for Chrome OS, where we're interested in
562  // learning about how frequently the top-row keys are used.
563  void UpdateAcceleratorMetrics(const ui::Accelerator& accelerator,
564                                int command_id);
565
566  // Calls |method| which is either RenderWidgetHost::Cut, ::Copy, or ::Paste,
567  // first trying the content WebContents, then the devtools WebContents, and
568  // lastly the Views::Textfield if one is focused.
569  void DoCutCopyPaste(void (content::RenderWidgetHost::*method)(),
570                      int command_id);
571
572  // Calls |method| which is either RenderWidgetHost::Cut, ::Copy, or ::Paste on
573  // the given WebContents, returning true if it consumed the event.
574  bool DoCutCopyPasteForWebContents(
575      content::WebContents* contents,
576      void (content::RenderWidgetHost::*method)());
577
578  // Shows the next app-modal dialog box, if there is one to be shown, or moves
579  // an existing showing one to the front.
580  void ActivateAppModalDialog() const;
581
582  // Returns the max top arrow height for infobar.
583  int GetMaxTopInfoBarArrowHeight();
584
585  // Last focused view that issued a tab traversal.
586  int last_focused_view_storage_id_;
587
588  // The BrowserFrame that hosts this view.
589  BrowserFrame* frame_;
590
591  // The Browser object we are associated with.
592  scoped_ptr<Browser> browser_;
593
594  // BrowserView layout (LTR one is pictured here).
595  //
596  // --------------------------------------------------------------------
597  // | TopContainerView (top_container_)                                |
598  // |  --------------------------------------------------------------  |
599  // |  | Tabs (tabstrip_)                                           |  |
600  // |  |------------------------------------------------------------|  |
601  // |  | Navigation buttons, address bar, menu (toolbar_)           |  |
602  // |  --------------------------------------------------------------  |
603  // |------------------------------------------------------------------|
604  // | All infobars (infobar_container_) [1]                            |
605  // |------------------------------------------------------------------|
606  // | Bookmarks (bookmark_bar_view_) [1]                               |
607  // |------------------------------------------------------------------|
608  // | Contents container (contents_container_)                         |
609  // |  --------------------------------------------------------------  |
610  // |  |  devtools_web_view_                                        |  |
611  // |  |------------------------------------------------------------|  |
612  // |  |  contents_web_view_                                        |  |
613  // |  --------------------------------------------------------------  |
614  // |------------------------------------------------------------------|
615  // | Active downloads (download_shelf_)                               |
616  // --------------------------------------------------------------------
617  //
618  // [1] The bookmark bar and info bar are swapped when on the new tab page.
619  //     Additionally when the bookmark bar is detached, contents_container_ is
620  //     positioned on top of the bar while the tab's contents are placed below
621  //     the bar.  This allows the find bar to always align with the top of
622  //     contents_container_ regardless if there's bookmark or info bars.
623
624  // The view that manages the tab strip, toolbar, and sometimes the bookmark
625  // bar. Stacked top in the view hiearachy so it can be used to slide out
626  // the top views in immersive fullscreen.
627  TopContainerView* top_container_;
628
629  // The TabStrip.
630  TabStrip* tabstrip_;
631
632  // The Toolbar containing the navigation buttons, menus and the address bar.
633  ToolbarView* toolbar_;
634
635  // This button sits next to the tabs on the right hand side and it is used
636  // only in windows metro metro mode to allow the user to flip among browser
637  // windows.
638  views::Button* window_switcher_button_;
639
640  // The Bookmark Bar View for this window. Lazily created. May be NULL for
641  // non-tabbed browsers like popups. May not be visible.
642  scoped_ptr<BookmarkBarView> bookmark_bar_view_;
643
644  // The do-nothing view which controls the z-order of the find bar widget
645  // relative to views which paint into layers and views with an associated
646  // NativeView.
647  View* find_bar_host_view_;
648
649  // The download shelf view (view at the bottom of the page).
650  scoped_ptr<DownloadShelfView> download_shelf_;
651
652  // The InfoBarContainerView that contains InfoBars for the current tab.
653  InfoBarContainerView* infobar_container_;
654
655  // The view that contains the selected WebContents.
656  ContentsWebView* contents_web_view_;
657
658  // The view that contains devtools window for the selected WebContents.
659  views::WebView* devtools_web_view_;
660
661  // The view managing the devtools and contents positions.
662  // Handled by ContentsLayoutManager.
663  views::View* contents_container_;
664
665  // Docked devtools window instance. NULL when current tab is not inspected
666  // or is inspected with undocked version of DevToolsWindow.
667  DevToolsWindow* devtools_window_;
668
669  // Tracks and stores the last focused view which is not the
670  // devtools_web_view_ or any of its children. Used to restore focus once
671  // the devtools_web_view_ is hidden.
672  scoped_ptr<views::ExternalFocusTracker> devtools_focus_tracker_;
673
674  // The Status information bubble that appears at the bottom of the window.
675  scoped_ptr<StatusBubbleViews> status_bubble_;
676
677  // The permission bubble view is the toolkit-specific implementation of the
678  // interface used by the manager to display permissions bubbles.
679  scoped_ptr<PermissionBubbleViewViews> permission_bubble_view_;
680
681  // A mapping between accelerators and commands.
682  std::map<ui::Accelerator, int> accelerator_table_;
683
684  // True if we have already been initialized.
685  bool initialized_;
686
687  // True when in ProcessFullscreen(). The flag is used to avoid reentrance and
688  // to ignore requests to layout while in ProcessFullscreen() to reduce
689  // jankiness.
690  bool in_process_fullscreen_;
691
692  scoped_ptr<FullscreenExitBubbleViews> fullscreen_bubble_;
693
694#if defined(OS_WIN)
695  // This object is used to perform periodic actions in a worker
696  // thread. It is currently used to monitor hung plugin windows.
697  WorkerThreadTicker ticker_;
698
699  // This object is initialized with the frame window HWND. This
700  // object is also passed as a tick handler with the ticker_ object.
701  // It is used to periodically monitor for hung plugin windows
702  HungWindowDetector hung_window_detector_;
703
704  // This object is invoked by hung_window_detector_ when it detects a hung
705  // plugin window.
706  HungPluginAction hung_plugin_action_;
707
708  // Helper class to listen for completion of first page load.
709  scoped_ptr<LoadCompleteListener> load_complete_listener_;
710
711  // The custom JumpList for Windows 7.
712  scoped_refptr<JumpList> jumplist_;
713#endif
714
715  // The timer used to update frames for the Loading Animation.
716  base::RepeatingTimer<BrowserView> loading_animation_timer_;
717
718  views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
719
720  // Used to measure the loading spinner animation rate.
721  base::TimeTicks last_animation_time_;
722
723  // If this flag is set then SetFocusToLocationBar() will set focus to the
724  // location bar even if the browser window is not active.
725  bool force_location_bar_focus_;
726
727  scoped_ptr<ImmersiveModeController> immersive_mode_controller_;
728
729  scoped_ptr<ScrollEndEffectController> scroll_end_effect_controller_;
730
731  gfx::ScopedSysColorChangeListener color_change_listener_;
732
733  mutable base::WeakPtrFactory<BrowserView> activate_modal_dialog_factory_;
734
735  DISALLOW_COPY_AND_ASSIGN(BrowserView);
736};
737
738#endif  // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_H_
739