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