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