browser_view.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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.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/tabs/tab_strip_model_observer.h"
21#include "chrome/browser/ui/views/frame/browser_frame.h"
22#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
23#include "chrome/browser/ui/views/load_complete_listener.h"
24#include "ui/base/accelerators/accelerator.h"
25#include "ui/base/models/simple_menu_model.h"
26#include "ui/gfx/native_widget_types.h"
27#include "ui/gfx/sys_color_change_listener.h"
28#include "ui/views/controls/button/button.h"
29#include "ui/views/controls/single_split_view_listener.h"
30#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
31#include "ui/views/widget/widget_delegate.h"
32#include "ui/views/widget/widget_observer.h"
33#include "ui/views/window/client_view.h"
34
35#if defined(OS_WIN)
36#include "chrome/browser/hang_monitor/hung_plugin_action.h"
37#include "chrome/browser/hang_monitor/hung_window_detector.h"
38#endif
39
40// NOTE: For more information about the objects and files in this directory,
41// view: http://dev.chromium.org/developers/design-documents/browser-window
42
43class BookmarkBarView;
44class Browser;
45class BrowserViewLayout;
46class ContentsContainer;
47class DownloadShelfView;
48class FullscreenExitBubbleViews;
49class InfoBarContainerView;
50class InstantOverlayControllerViews;
51class LocationBarView;
52class OverlayContainer;
53class StatusBubbleViews;
54class SearchViewController;
55class TabStrip;
56class TabStripModel;
57class ToolbarView;
58class TopContainerView;
59
60#if defined(OS_WIN)
61class JumpList;
62#endif
63
64#if defined(USE_ASH)
65class BrowserLauncherItemController;
66#endif
67
68namespace autofill {
69class PasswordGenerator;
70}
71
72namespace content {
73class RenderWidgetHost;
74}
75
76namespace extensions {
77class Extension;
78}
79
80namespace views {
81class AccessiblePaneView;
82class ExternalFocusTracker;
83class WebView;
84}
85
86///////////////////////////////////////////////////////////////////////////////
87// BrowserView
88//
89//  A ClientView subclass that provides the contents of a browser window,
90//  including the TabStrip, toolbars, download shelves, the content area etc.
91//
92class BrowserView : public BrowserWindow,
93                    public BrowserWindowTesting,
94                    public TabStripModelObserver,
95                    public ui::AcceleratorProvider,
96                    public views::WidgetDelegate,
97                    public views::WidgetObserver,
98                    public views::ClientView,
99                    public ImmersiveModeController::Delegate,
100                    public InfoBarContainer::Delegate,
101                    public views::SingleSplitViewListener,
102                    public gfx::SysColorChangeListener,
103                    public LoadCompleteListener::Delegate {
104 public:
105  // The browser view's class name.
106  static const char kViewClassName[];
107
108  BrowserView();
109  virtual ~BrowserView();
110
111  // Takes ownership of |browser|.
112  void Init(Browser* browser);
113
114  void set_frame(BrowserFrame* frame) { frame_ = frame; }
115  BrowserFrame* frame() const { return frame_; }
116
117  // Returns a pointer to the BrowserView* interface implementation (an
118  // instance of this object, typically) for a given native window, or NULL if
119  // there is no such association.
120  //
121  // Don't use this unless you only have a NativeWindow. In nearly all
122  // situations plumb through browser and use it.
123  static BrowserView* GetBrowserViewForNativeWindow(gfx::NativeWindow window);
124
125  // Returns the BrowserView used for the specified Browser.
126  static BrowserView* GetBrowserViewForBrowser(const Browser* browser);
127
128  // Returns a Browser instance of this view.
129  Browser* browser() { return browser_.get(); }
130
131  // Returns the apparent bounds of the toolbar, in BrowserView coordinates.
132  // These differ from |toolbar_.bounds()| in that they match where the toolbar
133  // background image is drawn -- slightly outside the "true" bounds
134  // horizontally. Note that this returns the bounds for the toolbar area.
135  gfx::Rect GetToolbarBounds() const;
136
137  // Returns the bounds of the content area, in the coordinates of the
138  // BrowserView's parent.
139  gfx::Rect GetClientAreaBounds() const;
140
141  // Returns the constraining bounding box that should be used to lay out the
142  // FindBar within. This is _not_ the size of the find bar, just the bounding
143  // box it should be laid out within. The coordinate system of the returned
144  // rect is in the coordinate system of the frame, since the FindBar is a child
145  // window.
146  gfx::Rect GetFindBarBoundingBox() const;
147
148  // Returns the preferred height of the TabStrip. Used to position the OTR
149  // avatar icon.
150  int GetTabStripHeight() const;
151
152  // Takes some view's origin (relative to this BrowserView) and offsets it such
153  // that it can be used as the source origin for seamlessly tiling the toolbar
154  // background image over that view.
155  gfx::Point OffsetPointForToolbarBackgroundImage(
156      const gfx::Point& point) const;
157
158  // Container for the tabstrip, toolbar, etc.
159  TopContainerView* top_container() { return top_container_; }
160
161  // Accessor for the TabStrip.
162  TabStrip* tabstrip() { return tabstrip_; }
163
164  // Accessor for the Toolbar.
165  ToolbarView* toolbar() { return toolbar_; }
166
167  // Bookmark bar may be NULL, for example for pop-ups.
168  BookmarkBarView* bookmark_bar() { return bookmark_bar_view_.get(); }
169
170  // Accessor for the InfobarContainer.
171  InfoBarContainerView* infobar_container() { return infobar_container_; }
172
173  // Returns true if various window components are visible.
174  bool IsTabStripVisible() const;
175
176  // Returns true if the profile associated with this Browser window is
177  // incognito.
178  bool IsOffTheRecord() const;
179
180  // Returns the resource ID to use for the OTR icon, which depends on
181  // which layout is being shown and whether we are full-screen.
182  int GetOTRIconResourceID() const;
183
184  // Returns true if the profile associated with this Browser window is
185  // a guest session.
186  bool IsGuestSession() const;
187
188  // Returns true if the non-client view should render an avatar icon.
189  bool ShouldShowAvatar() const;
190
191  // Provides the containing frame with the accelerator for the specified
192  // command id. This can be used to provide menu item shortcut hints etc.
193  // Returns true if an accelerator was found for the specified |cmd_id|, false
194  // otherwise.
195  bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator);
196
197  // Returns true if the specificed |accelerator| is registered with this view.
198  bool IsAcceleratorRegistered(const ui::Accelerator& accelerator);
199
200  // Returns the active WebContents. Used by our NonClientView's
201  // TabIconView::TabContentsProvider implementations.
202  // TODO(beng): exposing this here is a bit bogus, since it's only used to
203  // determine loading state. It'd be nicer if we could change this to be
204  // bool IsSelectedTabLoading() const; or something like that. We could even
205  // move it to a WindowDelegate subclass.
206  content::WebContents* GetActiveWebContents() const;
207
208  // Retrieves the icon to use in the frame to indicate an OTR window.
209  gfx::ImageSkia GetOTRAvatarIcon() const;
210
211  // Returns true if the Browser object associated with this BrowserView is a
212  // tabbed-type window (i.e. a browser window, not an app or popup).
213  bool IsBrowserTypeNormal() const {
214    return browser_->is_type_tabbed();
215  }
216
217  // Returns true if the specified point(BrowserView coordinates) is in
218  // in the window caption area of the browser window.
219  bool IsPositionInWindowCaption(const gfx::Point& point);
220
221  // See ImmersiveModeController for description.
222  ImmersiveModeController* immersive_mode_controller() const {
223    return immersive_mode_controller_.get();
224  }
225
226  // Restores the focused view. This is also used to set the initial focus
227  // when a new browser window is created.
228  void RestoreFocus();
229
230  void SetWindowSwitcherButton(views::Button* button);
231
232  views::Button* window_switcher_button() {
233    return window_switcher_button_;
234  }
235
236  // Called from BookmarkBarView/DownloadShelfView during their show/hide
237  // animations.
238  void ToolbarSizeChanged(bool is_animating);
239
240  // If immersive mode is enabled and we're revealing the tab strip and toolbar
241  // then stack it at the top.
242  void MaybeStackImmersiveRevealAtTop();
243
244  // Called from OverlayContainer::SetOverlay() when overlay is to be shown,
245  // expanded or hidden.  Set |repaint_infobars| to true to repaint infobars.
246  void OnOverlayStateChanged(bool repaint_infobars);
247
248#if defined(USE_ASH)
249  // Test support.
250  // Note: This is only needed to be BrowserLauncherItemController instead of
251  // LauncherItemController because of the "favicon_loader" member - to be more
252  // exact that member function is the only one being called.
253  // TODO(skuhne): Remove once per-app is default.
254  BrowserLauncherItemController* launcher_item_controller() const {
255    return launcher_item_controller_.get();
256  }
257#endif
258
259  // Overridden from BrowserWindow:
260  virtual void Show() OVERRIDE;
261  virtual void ShowInactive() OVERRIDE;
262  virtual void Hide() OVERRIDE;
263  virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
264  virtual void Close() OVERRIDE;
265  virtual void Activate() OVERRIDE;
266  virtual void Deactivate() OVERRIDE;
267  virtual bool IsActive() const OVERRIDE;
268  virtual void FlashFrame(bool flash) OVERRIDE;
269  virtual bool IsAlwaysOnTop() const OVERRIDE;
270  virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
271  virtual BrowserWindowTesting* GetBrowserWindowTesting() OVERRIDE;
272  virtual StatusBubble* GetStatusBubble() OVERRIDE;
273  virtual void UpdateTitleBar() OVERRIDE;
274  virtual void BookmarkBarStateChanged(
275      BookmarkBar::AnimateChangeType change_type) OVERRIDE;
276  virtual void UpdateDevTools() OVERRIDE;
277  virtual void UpdateLoadingAnimations(bool should_animate) OVERRIDE;
278  virtual void SetStarredState(bool is_starred) OVERRIDE;
279  virtual void ZoomChangedForActiveTab(bool can_show_bubble) OVERRIDE;
280  virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
281  virtual ui::WindowShowState GetRestoredState() const OVERRIDE;
282  virtual gfx::Rect GetBounds() const OVERRIDE;
283  virtual bool IsMaximized() const OVERRIDE;
284  virtual bool IsMinimized() const OVERRIDE;
285  virtual void Maximize() OVERRIDE;
286  virtual void Minimize() OVERRIDE;
287  virtual void Restore() OVERRIDE;
288  virtual void EnterFullscreen(
289      const GURL& url, FullscreenExitBubbleType bubble_type) OVERRIDE;
290  virtual void ExitFullscreen() OVERRIDE;
291  virtual void UpdateFullscreenExitBubbleContent(
292      const GURL& url,
293      FullscreenExitBubbleType bubble_type) OVERRIDE;
294  virtual bool ShouldHideUIForFullscreen() const OVERRIDE;
295  virtual bool IsFullscreen() const OVERRIDE;
296  virtual bool IsFullscreenBubbleVisible() const OVERRIDE;
297#if defined(OS_WIN)
298  virtual void SetMetroSnapMode(bool enable) OVERRIDE;
299  virtual bool IsInMetroSnapMode() const OVERRIDE;
300#endif
301  virtual LocationBar* GetLocationBar() const OVERRIDE;
302  virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
303  virtual void UpdateReloadStopState(bool is_loading, bool force) OVERRIDE;
304  virtual void UpdateToolbar(content::WebContents* contents,
305                             bool should_restore_state) OVERRIDE;
306  virtual void FocusToolbar() OVERRIDE;
307  virtual void FocusAppMenu() OVERRIDE;
308  virtual void FocusBookmarksToolbar() OVERRIDE;
309  virtual void FocusInfobars() OVERRIDE;
310  virtual void RotatePaneFocus(bool forwards) OVERRIDE;
311  virtual void DestroyBrowser() OVERRIDE;
312  virtual bool IsBookmarkBarVisible() const OVERRIDE;
313  virtual bool IsBookmarkBarAnimating() const OVERRIDE;
314  virtual bool IsTabStripEditable() const OVERRIDE;
315  virtual bool IsToolbarVisible() const OVERRIDE;
316  virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
317  virtual void DisableInactiveFrame() OVERRIDE;
318  virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
319                                        Profile* profile) OVERRIDE;
320  virtual void ToggleBookmarkBar() OVERRIDE;
321  virtual void ShowUpdateChromeDialog() OVERRIDE;
322  virtual void ShowBookmarkBubble(const GURL& url,
323                                  bool already_bookmarked) OVERRIDE;
324  virtual void ShowBookmarkPrompt() OVERRIDE;
325  virtual void ShowChromeToMobileBubble() OVERRIDE;
326#if defined(ENABLE_ONE_CLICK_SIGNIN)
327  virtual void ShowOneClickSigninBubble(
328      OneClickSigninBubbleType type,
329      const string16& email,
330      const string16& error_message,
331      const StartSyncCallback& start_sync_callback) OVERRIDE;
332#endif
333  // TODO(beng): Not an override, move somewhere else.
334  void SetDownloadShelfVisible(bool visible);
335  virtual bool IsDownloadShelfVisible() const OVERRIDE;
336  virtual DownloadShelf* GetDownloadShelf() OVERRIDE;
337  virtual void ConfirmBrowserCloseWithPendingDownloads() OVERRIDE;
338  virtual void UserChangedTheme() OVERRIDE;
339  virtual int GetExtraRenderViewHeight() const OVERRIDE;
340  virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE;
341  virtual void ShowWebsiteSettings(Profile* profile,
342                                   content::WebContents* web_contents,
343                                   const GURL& url,
344                                   const content::SSLStatus& ssl,
345                                   bool show_history) OVERRIDE;
346  virtual void ShowAppMenu() OVERRIDE;
347  virtual bool PreHandleKeyboardEvent(
348      const content::NativeWebKeyboardEvent& event,
349      bool* is_keyboard_shortcut) OVERRIDE;
350  virtual void HandleKeyboardEvent(
351      const content::NativeWebKeyboardEvent& event) OVERRIDE;
352  virtual void ShowCreateChromeAppShortcutsDialog(
353      Profile*, const extensions::Extension* app) OVERRIDE;
354  virtual void Cut() OVERRIDE;
355  virtual void Copy() OVERRIDE;
356  virtual void Paste() OVERRIDE;
357  virtual gfx::Rect GetInstantBounds() OVERRIDE;
358  virtual WindowOpenDisposition GetDispositionForPopupBounds(
359      const gfx::Rect& bounds) OVERRIDE;
360  virtual FindBar* CreateFindBar() OVERRIDE;
361  virtual web_modal::WebContentsModalDialogHost*
362      GetWebContentsModalDialogHost() OVERRIDE;
363  virtual void ShowAvatarBubble(content::WebContents* web_contents,
364                                const gfx::Rect& rect) OVERRIDE;
365  virtual void ShowAvatarBubbleFromAvatarButton() OVERRIDE;
366  virtual void ShowPasswordGenerationBubble(
367      const gfx::Rect& rect,
368      const content::PasswordForm& form,
369      autofill::PasswordGenerator* password_generator) OVERRIDE;
370
371  // Overridden from BrowserWindowTesting:
372  virtual BookmarkBarView* GetBookmarkBarView() const OVERRIDE;
373  virtual LocationBarView* GetLocationBarView() const OVERRIDE;
374  virtual views::View* GetTabContentsContainerView() const OVERRIDE;
375  virtual ToolbarView* GetToolbarView() const OVERRIDE;
376
377  // Overridden from TabStripModelObserver:
378  virtual void TabDetachedAt(content::WebContents* contents,
379                             int index) OVERRIDE;
380  virtual void TabDeactivated(content::WebContents* contents) OVERRIDE;
381  virtual void ActiveTabChanged(content::WebContents* old_contents,
382                                content::WebContents* new_contents,
383                                int index,
384                                int reason) OVERRIDE;
385  virtual void TabStripEmpty() OVERRIDE;
386
387  // Overridden from ui::AcceleratorProvider:
388  virtual bool GetAcceleratorForCommandId(int command_id,
389      ui::Accelerator* accelerator) OVERRIDE;
390
391  // Overridden from views::WidgetDelegate:
392  virtual bool CanResize() const OVERRIDE;
393  virtual bool CanMaximize() const OVERRIDE;
394  virtual bool CanActivate() const OVERRIDE;
395  virtual string16 GetWindowTitle() const OVERRIDE;
396  virtual string16 GetAccessibleWindowTitle() const OVERRIDE;
397  virtual views::View* GetInitiallyFocusedView() OVERRIDE;
398  virtual bool ShouldShowWindowTitle() const OVERRIDE;
399  virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE;
400  virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
401  virtual bool ShouldShowWindowIcon() const OVERRIDE;
402  virtual bool ExecuteWindowsCommand(int command_id) OVERRIDE;
403  virtual std::string GetWindowName() const OVERRIDE;
404  virtual void SaveWindowPlacement(const gfx::Rect& bounds,
405                                   ui::WindowShowState show_state) OVERRIDE;
406  virtual bool GetSavedWindowPlacement(
407      gfx::Rect* bounds,
408      ui::WindowShowState* show_state) const OVERRIDE;
409  virtual views::View* GetContentsView() OVERRIDE;
410  virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
411  virtual void OnWindowBeginUserBoundsChange() OVERRIDE;
412  virtual void OnWidgetMove() OVERRIDE;
413  virtual views::Widget* GetWidget() OVERRIDE;
414  virtual const views::Widget* GetWidget() const OVERRIDE;
415  virtual void GetAccessiblePanes(std::vector<View*>* panes) OVERRIDE;
416
417  // Overridden from views::WidgetObserver:
418  virtual void OnWidgetActivationChanged(views::Widget* widget,
419                                         bool active) OVERRIDE;
420
421  // Overridden from views::ClientView:
422  virtual bool CanClose() OVERRIDE;
423  virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
424  virtual gfx::Size GetMinimumSize() OVERRIDE;
425
426  // ImmersiveModeController::Delegate overrides:
427  virtual BookmarkBarView* GetBookmarkBar() OVERRIDE;
428  virtual FullscreenController* GetFullscreenController() OVERRIDE;
429  virtual void FocusLocationBar() OVERRIDE;
430  virtual void FullscreenStateChanged() OVERRIDE;
431  virtual void SetImmersiveStyle(bool immersive) OVERRIDE;
432
433  // InfoBarContainer::Delegate overrides
434  virtual SkColor GetInfoBarSeparatorColor() const OVERRIDE;
435  virtual void InfoBarContainerStateChanged(bool is_animating) OVERRIDE;
436  virtual bool DrawInfoBarArrows(int* x) const OVERRIDE;
437
438  // views::SingleSplitViewListener overrides:
439  virtual bool SplitHandleMoved(views::SingleSplitView* sender) OVERRIDE;
440
441  // gfx::SysColorChangeListener overrides:
442  virtual void OnSysColorChange() OVERRIDE;
443
444  // Overridden from views::View:
445  virtual const char* GetClassName() const OVERRIDE;
446  virtual void Layout() OVERRIDE;
447  virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
448  virtual void ViewHierarchyChanged(
449      const ViewHierarchyChangedDetails& details) OVERRIDE;
450  virtual void ChildPreferredSizeChanged(View* child) OVERRIDE;
451  virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
452
453  // Overridden from ui::AcceleratorTarget:
454  virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
455
456  // Testing interface:
457  views::SingleSplitView* GetContentsSplitForTest() { return contents_split_; }
458  ContentsContainer* GetContentsContainerForTest() {
459    return contents_container_;
460  }
461  OverlayContainer* GetOverlayContainerForTest() {
462    return overlay_container_;
463  }
464  views::WebView* GetContentsWebViewForTest() { return contents_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  // Layout the Status Bubble.
497  void LayoutStatusBubble();
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  void UpdateDevToolsForContents(content::WebContents* web_contents);
521
522  // Shows docked devtools.
523  void ShowDevToolsContainer();
524
525  // Hides docked devtools.
526  void HideDevToolsContainer();
527
528  // Reads split position from the current tab's devtools window and applies
529  // it to the devtools split.
530  void UpdateDevToolsSplitPosition();
531
532  // Updates various optional child Views, e.g. Bookmarks Bar, Info Bar or the
533  // Download Shelf in response to a change notification from the specified
534  // |contents|. |contents| can be NULL. In this case, all optional UI will be
535  // removed.
536  void UpdateUIForContents(content::WebContents* contents);
537
538  // Invoked to update the necessary things when our fullscreen state changes
539  // to |fullscreen|. On Windows this is invoked immediately when we toggle the
540  // full screen state. On Linux changing the fullscreen state is async, so we
541  // ask the window to change its fullscreen state, then when we get
542  // notification that it succeeded this method is invoked.
543  // If |url| is not empty, it is the URL of the page that requested fullscreen
544  // (via the fullscreen JS API).
545  // |bubble_type| determines what should be shown in the fullscreen exit
546  // bubble.
547  void ProcessFullscreen(bool fullscreen,
548                         FullscreenType fullscreen_type,
549                         const GURL& url,
550                         FullscreenExitBubbleType bubble_type);
551
552  // Copy the accelerator table from the app resources into something we can
553  // use.
554  void LoadAccelerators();
555
556  // Retrieves the command id for the specified Windows app command.
557  int GetCommandIDForAppCommandID(int app_command_id) const;
558
559  // Initialize the hung plugin detector.
560  void InitHangMonitor();
561
562  // Possibly records a user metrics action corresponding to the passed-in
563  // accelerator.  Only implemented for Chrome OS, where we're interested in
564  // learning about how frequently the top-row keys are used.
565  void UpdateAcceleratorMetrics(const ui::Accelerator& accelerator,
566                                int command_id);
567
568  // Create an icon for this window in the launcher (currently only for Ash).
569  void CreateLauncherIcon();
570
571  // Calls |method| which is either RenderWidgetHost::Cut, ::Copy, or ::Paste,
572  // first trying the content WebContents, then the devtools WebContents, and
573  // lastly the Views::Textfield if one is focused.
574  // |windows_msg_id| is temporary until Win Aura is the default on Windows,
575  // since until then the omnibox doesn't use Views::Textfield.
576  void DoCutCopyPaste(void (content::RenderWidgetHost::*method)(),
577#if defined(OS_WIN)
578                      int windows_msg_id,
579#endif
580                      int command_id);
581
582  // Calls |method| which is either RenderWidgetHost::Cut, ::Copy, or ::Paste on
583  // the given WebContents, returning true if it consumed the event.
584  bool DoCutCopyPasteForWebContents(
585      content::WebContents* contents,
586      void (content::RenderWidgetHost::*method)());
587
588  // Shows the next app-modal dialog box, if there is one to be shown, or moves
589  // an existing showing one to the front.
590  void ActivateAppModalDialog() const;
591
592  // Called when overlay is committed, i.e. made the active contents, where
593  // the overlay is reparented from |overlay_container_| to
594  // |contents_container_|.
595  void MakeOverlayContentsActiveContents();
596
597  // Return the max top arrow height for infobar.
598  int GetMaxTopInfoBarArrowHeight();
599
600  // Last focused view that issued a tab traversal.
601  int last_focused_view_storage_id_;
602
603  // The BrowserFrame that hosts this view.
604  BrowserFrame* frame_;
605
606  // The Browser object we are associated with.
607  scoped_ptr<Browser> browser_;
608
609  // BrowserView layout (LTR one is pictured here).
610  //
611  // --------------------------------------------------------------------
612  // | TopContainerView (top_container_)                                |
613  // |  --------------------------------------------------------------  |
614  // |  | Tabs (tabstrip_)                                           |  |
615  // |  |------------------------------------------------------------|  |
616  // |  | Navigation buttons, address bar, menu (toolbar_)           |  |
617  // |  --------------------------------------------------------------  |
618  // |------------------------------------------------------------------|
619  // | OverlayContainer (overlay_container_) [1]                        |
620  // |  --------------------------------------------------------------  |
621  // |  | overlay_controller_->overlay_                              |  |
622  // |  |------------------------------------------------------------|  |
623  // |  | overlay drop shadow if overlay is partial-height           |  |
624  // |  --------------------------------------------------------------  |
625  // |------------------------------------------------------------------|
626  // | All infobars (infobar_container_) [2]                            |
627  // |------------------------------------------------------------------|
628  // | Bookmarks (bookmark_bar_view_) [2]                               |
629  // |------------------------------------------------------------------|
630  // | Debugger splitter (contents_split_)                              |
631  // |  --------------------------------------------------------------  |
632  // |  | Page content (contents_container_)                         |  |
633  // |  |  --------------------------------------------------------  |  |
634  // |  |  | contents_web_view_                                   |  |  |
635  // |  |  --------------------------------------------------------  |  |
636  // |  --------------------------------------------------------------  |
637  // |  --------------------------------------------------------------  |
638  // |  | Debugger (devtools_container_)                             |  |
639  // |  |                                                            |  |
640  // |  --------------------------------------------------------------  |
641  // |------------------------------------------------------------------|
642  // | Active downloads (download_shelf_)                               |
643  // --------------------------------------------------------------------
644  //
645  // [1] Overlay container is only visible when there's an overlay; it is
646  //     directly below the toolbar in the y-axis, and appears on top the
647  //     attached bookmark and/or info bars.
648  // [2] The bookmark bar and info bar are swapped when on the new tab page.
649  //     Additionally contents_container_ is positioned on top of the bookmark
650  //     bar when the bookmark bar is detached. This is done to allow the
651  //     overlay_controller_->overlay_ to appear over the bookmark bar.
652
653  // The view that manages the tab strip, toolbar, and sometimes the bookmark
654  // bar. Stacked second in the view hiearachy behind |overlay_container_|
655  // (refer to comments for |overlay_container_|) so it can be used to slide out
656  // the top views in immersive fullscreen.
657  TopContainerView* top_container_;
658
659  // The TabStrip.
660  TabStrip* tabstrip_;
661
662  // The Toolbar containing the navigation buttons, menus and the address bar.
663  ToolbarView* toolbar_;
664
665  // This button sits next to the tabs on the right hand side and it is used
666  // only in windows metro metro mode to allow the user to flip among browser
667  // windows.
668  views::Button* window_switcher_button_;
669
670  // The Bookmark Bar View for this window. Lazily created. May be NULL for
671  // non-tabbed browsers like popups. May not be visible.
672  scoped_ptr<BookmarkBarView> bookmark_bar_view_;
673
674  // The download shelf view (view at the bottom of the page).
675  scoped_ptr<DownloadShelfView> download_shelf_;
676
677  // The InfoBarContainerView that contains InfoBars for the current tab.
678  InfoBarContainerView* infobar_container_;
679
680  // The view that contains the selected WebContents.
681  views::WebView* contents_web_view_;
682
683  // The view that contains devtools window for the selected WebContents.
684  views::WebView* devtools_container_;
685
686  // The view managing the |contents_web_view_|.
687  ContentsContainer* contents_container_;
688
689  // The view managing the |overlay_controller_->overlay_| and, if necessary,
690  // a drop shadow below the overlay in the y-axis.  Stacked at the top of the
691  // view hiearachy so it can appear over attached bookmark and/or info bars.
692  OverlayContainer* overlay_container_;
693
694  // Split view containing the contents container and devtools container.
695  views::SingleSplitView* contents_split_;
696
697  // Side to dock devtools to.
698  DevToolsDockSide devtools_dock_side_;
699
700  // Docked devtools window instance. NULL when current tab is not inspected
701  // or is inspected with undocked version of DevToolsWindow.
702  DevToolsWindow* devtools_window_;
703
704  // Tracks and stores the last focused view which is not the
705  // devtools_container_ or any of its children. Used to restore focus once
706  // the devtools_container_ is hidden.
707  scoped_ptr<views::ExternalFocusTracker> devtools_focus_tracker_;
708
709  // The Status information bubble that appears at the bottom of the window.
710  scoped_ptr<StatusBubbleViews> status_bubble_;
711
712  // A mapping between accelerators and commands.
713  std::map<ui::Accelerator, int> accelerator_table_;
714
715  // True if we have already been initialized.
716  bool initialized_;
717
718  // True if we should ignore requests to layout.  This is set while toggling
719  // fullscreen mode on and off to reduce jankiness.
720  bool ignore_layout_;
721
722  scoped_ptr<FullscreenExitBubbleViews> fullscreen_bubble_;
723
724#if defined(OS_WIN) && !defined(USE_AURA)
725  // This object is used to perform periodic actions in a worker
726  // thread. It is currently used to monitor hung plugin windows.
727  WorkerThreadTicker ticker_;
728
729  // This object is initialized with the frame window HWND. This
730  // object is also passed as a tick handler with the ticker_ object.
731  // It is used to periodically monitor for hung plugin windows
732  HungWindowDetector hung_window_detector_;
733
734  // This object is invoked by hung_window_detector_ when it detects a hung
735  // plugin window.
736  HungPluginAction hung_plugin_action_;
737
738  // Helper class to listen for completion of first page load.
739  scoped_ptr<LoadCompleteListener> load_complete_listener_;
740
741  // The custom JumpList for Windows 7.
742  scoped_refptr<JumpList> jumplist_;
743#endif
744
745#if defined(USE_ASH)
746  // Needs to be BrowserLauncerItemController for
747  // "BrowserActivationStateChanged" and "favicon_loader".
748  // TODO(skuhne): Remove once per-app is default.
749  scoped_ptr<BrowserLauncherItemController> launcher_item_controller_;
750#endif
751
752  // The timer used to update frames for the Loading Animation.
753  base::RepeatingTimer<BrowserView> loading_animation_timer_;
754
755  views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
756
757  // Used to measure the loading spinner animation rate.
758  base::TimeTicks last_animation_time_;
759
760  // If this flag is set then SetFocusToLocationBar() will set focus to the
761  // location bar even if the browser window is not active.
762  bool force_location_bar_focus_;
763
764  scoped_ptr<ImmersiveModeController> immersive_mode_controller_;
765
766  gfx::ScopedSysColorChangeListener color_change_listener_;
767
768  scoped_ptr<InstantOverlayControllerViews> overlay_controller_;
769
770  mutable base::WeakPtrFactory<BrowserView> activate_modal_dialog_factory_;
771
772  DISALLOW_COPY_AND_ASSIGN(BrowserView);
773};
774
775#endif  // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_H_
776