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.
5 #ifndef CHROME_BROWSER_UI_BROWSER_H_
6 #define CHROME_BROWSER_UI_BROWSER_H_
13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/prefs/pref_change_registrar.h"
19 #include "base/prefs/pref_member.h"
20 #include "base/scoped_observer.h"
21 #include "base/strings/string16.h"
22 #include "chrome/browser/devtools/devtools_toggle_action.h"
23 #include "chrome/browser/ui/bookmarks/bookmark_bar.h"
24 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h"
25 #include "chrome/browser/ui/browser_navigator.h"
26 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
27 #include "chrome/browser/ui/host_desktop.h"
28 #include "chrome/browser/ui/search/search_tab_helper_delegate.h"
29 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h"
30 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
31 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
32 #include "chrome/browser/ui/toolbar/toolbar_model.h"
33 #include "chrome/browser/ui/zoom/zoom_observer.h"
34 #include "components/content_settings/core/common/content_settings.h"
35 #include "components/content_settings/core/common/content_settings_types.h"
36 #include "components/sessions/session_id.h"
37 #include "content/public/browser/notification_observer.h"
38 #include "content/public/browser/notification_registrar.h"
39 #include "content/public/browser/page_navigator.h"
40 #include "content/public/browser/web_contents_delegate.h"
41 #include "content/public/common/page_zoom.h"
42 #include "ui/base/page_transition_types.h"
43 #include "ui/base/ui_base_types.h"
44 #include "ui/base/window_open_disposition.h"
45 #include "ui/gfx/rect.h"
46 #include "ui/shell_dialogs/select_file_dialog.h"
48 #if defined(ENABLE_EXTENSIONS)
49 #include "extensions/browser/extension_registry_observer.h"
52 class BrowserContentSettingBubbleModelDelegate
;
53 class BrowserContentTranslateDriverObserver
;
54 class BrowserInstantController
;
55 class BrowserSyncedWindowDelegate
;
56 class BrowserToolbarModelDelegate
;
57 class BrowserTabRestoreServiceDelegate
;
59 class FindBarController
;
60 class FullscreenController
;
67 class TabStripModelDelegate
;
68 struct WebApplicationInfo
;
71 class BrowserCommandController
;
72 class FastUnloadController
;
73 class UnloadController
;
74 class ValidationMessageBubble
;
78 class NavigationController
;
80 class SessionStorageNamespace
;
83 namespace extensions
{
85 class ExtensionRegistry
;
86 class WindowController
;
95 struct SelectedFileInfo
;
96 class WebDialogDelegate
;
101 class WebContentsModalDialogHost
;
104 class Browser
: public TabStripModelObserver
,
105 public content::WebContentsDelegate
,
106 public CoreTabHelperDelegate
,
107 public SearchEngineTabHelperDelegate
,
108 public SearchTabHelperDelegate
,
109 public ChromeWebModalDialogManagerDelegate
,
110 public BookmarkTabHelperDelegate
,
112 public content::PageNavigator
,
113 public content::NotificationObserver
,
114 #if defined(ENABLE_EXTENSIONS)
115 public extensions::ExtensionRegistryObserver
,
117 public ui::SelectFileDialog::Listener
{
119 // SessionService::WindowType mirrors these values. If you add to this
120 // enum, look at SessionService::WindowType to see if it needs to be
123 // If you add a new type, consider updating the test
124 // BrowserTest.StartMaximized.
129 // Possible elements of the Browser window.
132 FEATURE_TITLEBAR
= 1,
133 FEATURE_TABSTRIP
= 2,
135 FEATURE_LOCATIONBAR
= 8,
136 FEATURE_BOOKMARKBAR
= 16,
137 FEATURE_INFOBAR
= 32,
138 FEATURE_DOWNLOADSHELF
= 64
141 // The context for a download blocked notification from
142 // OkToCloseWithInProgressDownloads.
143 enum DownloadClosePreventionType
{
144 // Browser close is not blocked by download state.
147 // The browser is shutting down and there are active downloads
148 // that would be cancelled.
149 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN
,
151 // There are active downloads associated with this incognito profile
152 // that would be canceled.
153 DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE
,
156 struct CreateParams
{
157 CreateParams(Profile
* profile
, chrome::HostDesktopType host_desktop_type
);
158 CreateParams(Type type
,
160 chrome::HostDesktopType host_desktop_type
);
162 static CreateParams
CreateForApp(const std::string
& app_name
,
164 const gfx::Rect
& window_bounds
,
166 chrome::HostDesktopType host_desktop_type
);
168 static CreateParams
CreateForDevTools(
170 chrome::HostDesktopType host_desktop_type
);
175 // The associated profile.
178 // The host desktop the browser is created on.
179 chrome::HostDesktopType host_desktop_type
;
181 // Specifies the browser is_trusted_source_ value.
184 // The bounds of the window to open.
185 gfx::Rect initial_bounds
;
187 ui::WindowShowState initial_show_state
;
189 bool is_session_restore
;
191 // Supply a custom BrowserWindow implementation, to be used instead of the
192 // default. Intended for testing.
193 BrowserWindow
* window
;
196 friend class Browser
;
198 // The application name that is also the name of the window to the shell.
199 // Do not set this value directly, use CreateForApp.
200 // This name will be set for:
201 // 1) v1 applications launched via an application shortcut or extension API.
202 // 2) undocked devtool windows.
203 // 3) popup windows spawned from v1 applications.
204 std::string app_name
;
207 // Constructors, Creation, Showing //////////////////////////////////////////
209 explicit Browser(const CreateParams
& params
);
212 // Set overrides for the initial window bounds and maximized state.
213 void set_override_bounds(const gfx::Rect
& bounds
) {
214 override_bounds_
= bounds
;
216 ui::WindowShowState
initial_show_state() const { return initial_show_state_
; }
217 void set_initial_show_state(ui::WindowShowState initial_show_state
) {
218 initial_show_state_
= initial_show_state
;
220 // Return true if the initial window bounds have been overridden.
221 bool bounds_overridden() const {
222 return !override_bounds_
.IsEmpty();
224 // Set indicator that this browser is being created via session restore.
225 // This is used on the Mac (only) to determine animation style when the
226 // browser window is shown.
227 void set_is_session_restore(bool is_session_restore
) {
228 is_session_restore_
= is_session_restore
;
230 bool is_session_restore() const {
231 return is_session_restore_
;
233 chrome::HostDesktopType
host_desktop_type() const {
234 return host_desktop_type_
;
237 // Accessors ////////////////////////////////////////////////////////////////
239 Type
type() const { return type_
; }
240 const std::string
& app_name() const { return app_name_
; }
241 bool is_trusted_source() const { return is_trusted_source_
; }
242 Profile
* profile() const { return profile_
; }
243 gfx::Rect
override_bounds() const { return override_bounds_
; }
245 // |window()| will return NULL if called before |CreateBrowserWindow()|
247 BrowserWindow
* window() const { return window_
; }
248 ToolbarModel
* toolbar_model() { return toolbar_model_
.get(); }
249 const ToolbarModel
* toolbar_model() const { return toolbar_model_
.get(); }
250 #if defined(UNIT_TEST)
251 void swap_toolbar_models(scoped_ptr
<ToolbarModel
>* toolbar_model
) {
252 toolbar_model
->swap(toolbar_model_
);
255 web_modal::PopupManager
* popup_manager() {
256 return popup_manager_
.get();
258 TabStripModel
* tab_strip_model() const { return tab_strip_model_
.get(); }
259 chrome::BrowserCommandController
* command_controller() {
260 return command_controller_
.get();
262 SearchModel
* search_model() { return search_model_
.get(); }
263 const SearchModel
* search_model() const {
264 return search_model_
.get();
266 SearchDelegate
* search_delegate() {
267 return search_delegate_
.get();
269 const SessionID
& session_id() const { return session_id_
; }
270 BrowserContentSettingBubbleModelDelegate
*
271 content_setting_bubble_model_delegate() {
272 return content_setting_bubble_model_delegate_
.get();
274 BrowserTabRestoreServiceDelegate
* tab_restore_service_delegate() {
275 return tab_restore_service_delegate_
.get();
277 BrowserSyncedWindowDelegate
* synced_window_delegate() {
278 return synced_window_delegate_
.get();
280 BrowserInstantController
* instant_controller() {
281 return instant_controller_
.get();
284 // Get the FindBarController for this browser, creating it if it does not
286 FindBarController
* GetFindBarController();
288 // Returns true if a FindBarController exists for this browser.
289 bool HasFindBarController() const;
291 // Returns the state of the bookmark bar.
292 BookmarkBar::State
bookmark_bar_state() const { return bookmark_bar_state_
; }
294 // State Storage and Retrieval for UI ///////////////////////////////////////
296 // Gets the Favicon of the page in the selected tab.
297 gfx::Image
GetCurrentPageIcon() const;
299 // Gets the title of the window based on the selected tab's title.
300 base::string16
GetWindowTitleForCurrentTab() const;
302 // Prepares a title string for display (removes embedded newlines, etc).
303 static void FormatTitleForDisplay(base::string16
* title
);
305 // OnBeforeUnload handling //////////////////////////////////////////////////
307 // Gives beforeunload handlers the chance to cancel the close. Returns whether
308 // to proceed with the close. If called while the process begun by
309 // CallBeforeUnloadHandlers is in progress, returns false without taking
311 bool ShouldCloseWindow();
313 // Begins the process of confirming whether the associated browser can be
314 // closed. If there are no tabs with beforeunload handlers it will immediately
315 // return false. Otherwise, it starts prompting the user, returns true and
316 // will call |on_close_confirmed| with the result of the user's decision.
317 // After calling this function, if the window will not be closed, call
318 // ResetBeforeUnloadHandlers() to reset all beforeunload handlers; calling
319 // this function multiple times without an intervening call to
320 // ResetBeforeUnloadHandlers() will run only the beforeunload handlers
321 // registered since the previous call.
322 bool CallBeforeUnloadHandlers(
323 const base::Callback
<void(bool)>& on_close_confirmed
);
325 // Clears the results of any beforeunload confirmation dialogs triggered by a
326 // CallBeforeUnloadHandlers call.
327 void ResetBeforeUnloadHandlers();
329 // Figure out if there are tabs that have beforeunload handlers.
330 // It starts beforeunload/unload processing as a side-effect.
331 bool TabsNeedBeforeUnloadFired();
333 // Returns true if all tabs' beforeunload/unload events have fired.
334 bool HasCompletedUnloadProcessing() const;
336 bool IsAttemptingToCloseBrowser() const;
338 // Invoked when the window containing us is closing. Performs the necessary
340 void OnWindowClosing();
342 // In-progress download termination handling /////////////////////////////////
344 // Called when the user has decided whether to proceed or not with the browser
345 // closure. |cancel_downloads| is true if the downloads should be canceled
346 // and the browser closed, false if the browser should stay open and the
347 // downloads running.
348 void InProgressDownloadResponse(bool cancel_downloads
);
350 // Indicates whether or not this browser window can be closed, or
351 // would be blocked by in-progress downloads.
352 // If executing downloads would be cancelled by this window close,
353 // then |*num_downloads_blocking| is updated with how many downloads
354 // would be canceled if the close continued.
355 DownloadClosePreventionType
OkToCloseWithInProgressDownloads(
356 int* num_downloads_blocking
) const;
358 // External state change handling ////////////////////////////////////////////
360 // Invoked when the fullscreen state of the window changes.
361 // BrowserWindow::EnterFullscreen invokes this after the window has become
363 void WindowFullscreenStateChanged();
365 // Assorted browser commands ////////////////////////////////////////////////
367 // NOTE: Within each of the following sections, the IDs are ordered roughly by
368 // how they appear in the GUI/menus (left to right, top to bottom, etc.).
370 // See the description of
371 // FullscreenController::ToggleFullscreenModeWithExtension.
372 void ToggleFullscreenModeWithExtension(const GURL
& extension_url
);
375 // See the description of FullscreenController::ToggleMetroSnapMode.
376 void SetMetroSnapMode(bool enable
);
379 // Returns true if the Browser supports the specified feature. The value of
380 // this varies during the lifetime of the browser. For example, if the window
381 // is fullscreen this may return a different value. If you only care about
382 // whether or not it's possible for the browser to support a particular
383 // feature use |CanSupportWindowFeature|.
384 bool SupportsWindowFeature(WindowFeature feature
) const;
386 // Returns true if the Browser can support the specified feature. See comment
387 // in |SupportsWindowFeature| for details on this.
388 bool CanSupportWindowFeature(WindowFeature feature
) const;
390 // TODO(port): port these, and re-merge the two function declaration lists.
391 // Page-related commands.
392 void ToggleEncodingAutoDetect();
393 void OverrideEncoding(int encoding_id
);
395 // Show various bits of UI
398 void UpdateDownloadShelfVisibility(bool visible
);
400 /////////////////////////////////////////////////////////////////////////////
402 // Called by chrome::Navigate() when a navigation has occurred in a tab in
403 // this Browser. Updates the UI for the start of this navigation.
404 void UpdateUIForNavigationInTab(content::WebContents
* contents
,
405 ui::PageTransition transition
,
406 bool user_initiated
);
408 // Interface implementations ////////////////////////////////////////////////
410 // Overridden from content::PageNavigator:
411 virtual content::WebContents
* OpenURL(
412 const content::OpenURLParams
& params
) override
;
414 // Overridden from TabStripModelObserver:
415 virtual void TabInsertedAt(content::WebContents
* contents
,
417 bool foreground
) override
;
418 virtual void TabClosingAt(TabStripModel
* tab_strip_model
,
419 content::WebContents
* contents
,
421 virtual void TabDetachedAt(content::WebContents
* contents
,
423 virtual void TabDeactivated(content::WebContents
* contents
) override
;
424 virtual void ActiveTabChanged(content::WebContents
* old_contents
,
425 content::WebContents
* new_contents
,
427 int reason
) override
;
428 virtual void TabMoved(content::WebContents
* contents
,
430 int to_index
) override
;
431 virtual void TabReplacedAt(TabStripModel
* tab_strip_model
,
432 content::WebContents
* old_contents
,
433 content::WebContents
* new_contents
,
435 virtual void TabPinnedStateChanged(content::WebContents
* contents
,
437 virtual void TabStripEmpty() override
;
439 // Overridden from content::WebContentsDelegate:
440 virtual bool CanOverscrollContent() const override
;
441 virtual bool ShouldPreserveAbortedURLs(content::WebContents
* source
) override
;
442 virtual bool PreHandleKeyboardEvent(
443 content::WebContents
* source
,
444 const content::NativeWebKeyboardEvent
& event
,
445 bool* is_keyboard_shortcut
) override
;
446 virtual void HandleKeyboardEvent(
447 content::WebContents
* source
,
448 const content::NativeWebKeyboardEvent
& event
) override
;
449 virtual void OverscrollUpdate(float delta_y
) override
;
450 virtual void ShowValidationMessage(content::WebContents
* web_contents
,
451 const gfx::Rect
& anchor_in_root_view
,
452 const base::string16
& main_text
,
453 const base::string16
& sub_text
) override
;
454 virtual void HideValidationMessage(
455 content::WebContents
* web_contents
) override
;
456 virtual void MoveValidationMessage(
457 content::WebContents
* web_contents
,
458 const gfx::Rect
& anchor_in_root_view
) override
;
459 virtual bool PreHandleGestureEvent(
460 content::WebContents
* source
,
461 const blink::WebGestureEvent
& event
) override
;
462 virtual bool CanDragEnter(
463 content::WebContents
* source
,
464 const content::DropData
& data
,
465 blink::WebDragOperationsMask operations_allowed
) override
;
467 bool is_type_tabbed() const { return type_
== TYPE_TABBED
; }
468 bool is_type_popup() const { return type_
== TYPE_POPUP
; }
471 bool is_devtools() const;
473 // True when the mouse cursor is locked.
474 bool IsMouseLocked() const;
476 // Called each time the browser window is shown.
477 void OnWindowDidShow();
479 // Show the first run search engine bubble on the location bar.
480 void ShowFirstRunBubble();
482 // Show a download on the download shelf.
483 void ShowDownload(content::DownloadItem
* download
);
485 FullscreenController
* fullscreen_controller() const {
486 return fullscreen_controller_
.get();
489 extensions::WindowController
* extension_window_controller() const {
490 return extension_window_controller_
.get();
494 friend class BrowserTest
;
495 friend class FullscreenControllerInteractiveTest
;
496 friend class FullscreenControllerTest
;
497 FRIEND_TEST_ALL_PREFIXES(AppModeTest
, EnableAppModeTest
);
498 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest
,
499 IsReservedCommandOrKeyIsApp
);
500 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest
, AppFullScreen
);
501 FRIEND_TEST_ALL_PREFIXES(BrowserTest
, NoTabsInPopups
);
502 FRIEND_TEST_ALL_PREFIXES(BrowserTest
, ConvertTabToAppShortcut
);
503 FRIEND_TEST_ALL_PREFIXES(BrowserTest
, OpenAppWindowLikeNtp
);
504 FRIEND_TEST_ALL_PREFIXES(BrowserTest
, AppIdSwitch
);
505 FRIEND_TEST_ALL_PREFIXES(BrowserTest
, ShouldShowLocationBar
);
506 FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest
,
507 TabEntersPresentationModeFromWindowed
);
508 FRIEND_TEST_ALL_PREFIXES(FullscreenExitBubbleControllerTest
,
509 DenyExitsFullscreen
);
510 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest
, OpenAppShortcutNoPref
);
511 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest
,
512 OpenAppShortcutWindowPref
);
513 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest
, OpenAppShortcutTabPref
);
515 class InterstitialObserver
;
517 // Used to describe why a tab is being detached. This is used by
518 // TabDetachedAtImpl.
520 // Result of TabDetachedAt.
523 // Result of TabReplacedAt.
526 // Result of the tab strip not having any significant tabs.
530 // Describes where the bookmark bar state change originated from.
531 enum BookmarkBarStateChangeReason
{
532 // From the constructor.
533 BOOKMARK_BAR_STATE_CHANGE_INIT
,
535 // Change is the result of the active tab changing.
536 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH
,
538 // Change is the result of the bookmark bar pref changing.
539 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE
,
541 // Change is the result of a state change in the active tab.
542 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE
,
544 // Change is the result of window toggling in/out of fullscreen mode.
545 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN
,
548 // Overridden from content::WebContentsDelegate:
549 virtual content::WebContents
* OpenURLFromTab(
550 content::WebContents
* source
,
551 const content::OpenURLParams
& params
) override
;
552 virtual void NavigationStateChanged(
553 const content::WebContents
* source
,
554 content::InvalidateTypes changed_flags
) override
;
555 virtual void VisibleSSLStateChanged(
556 const content::WebContents
* source
) override
;
557 virtual void AddNewContents(content::WebContents
* source
,
558 content::WebContents
* new_contents
,
559 WindowOpenDisposition disposition
,
560 const gfx::Rect
& initial_pos
,
562 bool* was_blocked
) override
;
563 virtual void ActivateContents(content::WebContents
* contents
) override
;
564 virtual void DeactivateContents(content::WebContents
* contents
) override
;
565 virtual void LoadingStateChanged(content::WebContents
* source
,
566 bool to_different_document
) override
;
567 virtual void CloseContents(content::WebContents
* source
) override
;
568 virtual void MoveContents(content::WebContents
* source
,
569 const gfx::Rect
& pos
) override
;
570 virtual bool IsPopupOrPanel(
571 const content::WebContents
* source
) const override
;
572 virtual void UpdateTargetURL(content::WebContents
* source
,
573 const GURL
& url
) override
;
574 virtual void ContentsMouseEvent(content::WebContents
* source
,
575 const gfx::Point
& location
,
576 bool motion
) override
;
577 virtual void ContentsZoomChange(bool zoom_in
) override
;
578 virtual void WebContentsFocused(content::WebContents
* content
) override
;
579 virtual bool TakeFocus(content::WebContents
* source
, bool reverse
) override
;
580 virtual gfx::Rect
GetRootWindowResizerRect() const override
;
581 virtual void BeforeUnloadFired(content::WebContents
* source
,
583 bool* proceed_to_fire_unload
) override
;
584 virtual bool ShouldFocusLocationBarByDefault(
585 content::WebContents
* source
) override
;
586 virtual void SetFocusToLocationBar(bool select_all
) override
;
587 virtual int GetExtraRenderViewHeight() const override
;
588 virtual void ViewSourceForTab(content::WebContents
* source
,
589 const GURL
& page_url
) override
;
590 virtual void ViewSourceForFrame(
591 content::WebContents
* source
,
592 const GURL
& frame_url
,
593 const content::PageState
& frame_page_state
) override
;
594 virtual void ShowRepostFormWarningDialog(
595 content::WebContents
* source
) override
;
596 virtual bool ShouldCreateWebContents(
597 content::WebContents
* web_contents
,
599 WindowContainerType window_container_type
,
600 const base::string16
& frame_name
,
601 const GURL
& target_url
,
602 const std::string
& partition_id
,
603 content::SessionStorageNamespace
* session_storage_namespace
) override
;
604 virtual void WebContentsCreated(content::WebContents
* source_contents
,
605 int opener_render_frame_id
,
606 const base::string16
& frame_name
,
607 const GURL
& target_url
,
608 content::WebContents
* new_contents
) override
;
609 virtual void RendererUnresponsive(content::WebContents
* source
) override
;
610 virtual void RendererResponsive(content::WebContents
* source
) override
;
611 virtual void WorkerCrashed(content::WebContents
* source
) override
;
612 virtual void DidNavigateMainFramePostCommit(
613 content::WebContents
* web_contents
) override
;
614 virtual void DidNavigateToPendingEntry(
615 content::WebContents
* web_contents
) override
;
616 virtual content::JavaScriptDialogManager
*
617 GetJavaScriptDialogManager() override
;
618 virtual content::ColorChooser
* OpenColorChooser(
619 content::WebContents
* web_contents
,
621 const std::vector
<content::ColorSuggestion
>& suggestions
) override
;
622 virtual void RunFileChooser(
623 content::WebContents
* web_contents
,
624 const content::FileChooserParams
& params
) override
;
625 virtual void EnumerateDirectory(content::WebContents
* web_contents
,
627 const base::FilePath
& path
) override
;
628 virtual bool EmbedsFullscreenWidget() const override
;
629 virtual void ToggleFullscreenModeForTab(content::WebContents
* web_contents
,
630 bool enter_fullscreen
) override
;
631 virtual bool IsFullscreenForTabOrPending(
632 const content::WebContents
* web_contents
) const override
;
633 virtual void RegisterProtocolHandler(content::WebContents
* web_contents
,
634 const std::string
& protocol
,
636 bool user_gesture
) override
;
637 virtual void UnregisterProtocolHandler(content::WebContents
* web_contents
,
638 const std::string
& protocol
,
640 bool user_gesture
) override
;
641 virtual void UpdatePreferredSize(content::WebContents
* source
,
642 const gfx::Size
& pref_size
) override
;
643 virtual void ResizeDueToAutoResize(content::WebContents
* source
,
644 const gfx::Size
& new_size
) override
;
645 virtual void FindReply(content::WebContents
* web_contents
,
647 int number_of_matches
,
648 const gfx::Rect
& selection_rect
,
649 int active_match_ordinal
,
650 bool final_update
) override
;
651 virtual void RequestToLockMouse(content::WebContents
* web_contents
,
653 bool last_unlocked_by_target
) override
;
654 virtual void LostMouseLock() override
;
655 virtual void RequestMediaAccessPermission(
656 content::WebContents
* web_contents
,
657 const content::MediaStreamRequest
& request
,
658 const content::MediaResponseCallback
& callback
) override
;
659 virtual bool CheckMediaAccessPermission(
660 content::WebContents
* web_contents
,
661 const GURL
& security_origin
,
662 content::MediaStreamType type
) override
;
663 virtual bool RequestPpapiBrokerPermission(
664 content::WebContents
* web_contents
,
666 const base::FilePath
& plugin_path
,
667 const base::Callback
<void(bool)>& callback
) override
;
668 virtual gfx::Size
GetSizeForNewRenderView(
669 content::WebContents
* web_contents
) const override
;
671 // Overridden from CoreTabHelperDelegate:
672 // Note that the caller is responsible for deleting |old_contents|.
673 virtual void SwapTabContents(content::WebContents
* old_contents
,
674 content::WebContents
* new_contents
,
676 bool did_finish_load
) override
;
677 virtual bool CanReloadContents(
678 content::WebContents
* web_contents
) const override
;
679 virtual bool CanSaveContents(
680 content::WebContents
* web_contents
) const override
;
682 // Overridden from SearchEngineTabHelperDelegate:
683 virtual void ConfirmAddSearchProvider(TemplateURL
* template_url
,
684 Profile
* profile
) override
;
686 // Overridden from SearchTabHelperDelegate:
687 virtual void NavigateOnThumbnailClick(
689 WindowOpenDisposition disposition
,
690 content::WebContents
* source_contents
) override
;
691 virtual void OnWebContentsInstantSupportDisabled(
692 const content::WebContents
* web_contents
) override
;
693 virtual OmniboxView
* GetOmniboxView() override
;
694 virtual std::set
<std::string
> GetOpenUrls() override
;
696 // Overridden from WebContentsModalDialogManagerDelegate:
697 virtual void SetWebContentsBlocked(content::WebContents
* web_contents
,
698 bool blocked
) override
;
699 virtual web_modal::WebContentsModalDialogHost
*
700 GetWebContentsModalDialogHost() override
;
702 // Overridden from BookmarkTabHelperDelegate:
703 virtual void URLStarredChanged(content::WebContents
* web_contents
,
704 bool starred
) override
;
706 // Overridden from ZoomObserver:
707 virtual void OnZoomChanged(
708 const ZoomController::ZoomChangedEventData
& data
) override
;
710 // Overridden from SelectFileDialog::Listener:
711 virtual void FileSelected(const base::FilePath
& path
,
713 void* params
) override
;
714 virtual void FileSelectedWithExtraInfo(
715 const ui::SelectedFileInfo
& file_info
,
717 void* params
) override
;
719 // Overridden from content::NotificationObserver:
720 virtual void Observe(int type
,
721 const content::NotificationSource
& source
,
722 const content::NotificationDetails
& details
) override
;
724 #if defined(ENABLE_EXTENSIONS)
725 // Overridden from extensions::ExtensionRegistryObserver:
726 virtual void OnExtensionUninstalled(
727 content::BrowserContext
* browser_context
,
728 const extensions::Extension
* extension
,
729 extensions::UninstallReason reason
) override
;
730 virtual void OnExtensionLoaded(
731 content::BrowserContext
* browser_context
,
732 const extensions::Extension
* extension
) override
;
733 virtual void OnExtensionUnloaded(
734 content::BrowserContext
* browser_context
,
735 const extensions::Extension
* extension
,
736 extensions::UnloadedExtensionInfo::Reason reason
) override
;
739 // Command and state updating ///////////////////////////////////////////////
741 // Handle changes to kDevTools preference.
742 void OnDevToolsDisabledChanged();
744 // UI update coalescing and handling ////////////////////////////////////////
746 // Asks the toolbar (and as such the location bar) to update its state to
747 // reflect the current tab's current URL, security state, etc.
748 // If |should_restore_state| is true, we're switching (back?) to this tab and
749 // should restore any previous location bar state (such as user editing) as
751 void UpdateToolbar(bool should_restore_state
);
753 // Does one or both of the following for each bit in |changed_flags|:
754 // . If the update should be processed immediately, it is.
755 // . If the update should processed asynchronously (to avoid lots of ui
756 // updates), then scheduled_updates_ is updated for the |source| and update
757 // pair and a task is scheduled (assuming it isn't running already)
758 // that invokes ProcessPendingUIUpdates.
759 void ScheduleUIUpdate(const content::WebContents
* source
,
760 unsigned changed_flags
);
762 // Processes all pending updates to the UI that have been scheduled by
763 // ScheduleUIUpdate in scheduled_updates_.
764 void ProcessPendingUIUpdates();
766 // Removes all entries from scheduled_updates_ whose source is contents.
767 void RemoveScheduledUpdatesFor(content::WebContents
* contents
);
769 // Getters for UI ///////////////////////////////////////////////////////////
771 // TODO(beng): remove, and provide AutomationProvider a better way to access
772 // the LocationBarView's edit.
773 friend class AutomationProvider
;
774 friend class BrowserProxy
;
776 // Returns the StatusBubble from the current toolbar. It is possible for
777 // this to return NULL if called before the toolbar has initialized.
778 // TODO(beng): remove this.
779 StatusBubble
* GetStatusBubble();
781 // Session restore functions ////////////////////////////////////////////////
783 // Notifies the history database of the index for all tabs whose index is
785 void SyncHistoryWithTabs(int index
);
787 // In-progress download termination handling /////////////////////////////////
789 // Called when the window is closing to check if potential in-progress
790 // downloads should prevent it from closing.
791 // Returns true if the window can close, false otherwise.
792 bool CanCloseWithInProgressDownloads();
794 // Assorted utility functions ///////////////////////////////////////////////
796 // Sets the specified browser as the delegate of the WebContents and all the
797 // associated tab helpers that are needed. If |set_delegate| is true, this
798 // browser object is set as a delegate for |web_contents| components, else
799 // is is removed as a delegate.
800 void SetAsDelegate(content::WebContents
* web_contents
, bool set_delegate
);
802 // Shows the Find Bar, optionally selecting the next entry that matches the
803 // existing search string for that Tab. |forward_direction| controls the
805 void FindInPage(bool find_next
, bool forward_direction
);
808 // TODO(beng): figure out if we need this now that the frame itself closes
809 // after a return to the message loop.
812 void TabDetachedAtImpl(content::WebContents
* contents
,
816 // Shared code between Reload() and ReloadIgnoringCache().
817 void ReloadInternal(WindowOpenDisposition disposition
, bool ignore_cache
);
819 // Returns true if the Browser window should show the location bar.
820 bool ShouldShowLocationBar() const;
822 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
823 // |check_fullscreen| is true, the set of features reflect the actual state of
824 // the browser, otherwise the set of features reflect the possible state of
826 bool SupportsWindowFeatureImpl(WindowFeature feature
,
827 bool check_fullscreen
) const;
829 // Resets |bookmark_bar_state_| based on the active tab. Notifies the
830 // BrowserWindow if necessary.
831 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason
);
833 bool ShouldHideUIForFullscreen() const;
835 // Creates a BackgroundContents if appropriate; return true if one was
837 bool MaybeCreateBackgroundContents(
839 content::WebContents
* opener_web_contents
,
840 const base::string16
& frame_name
,
841 const GURL
& target_url
,
842 const std::string
& partition_id
,
843 content::SessionStorageNamespace
* session_storage_namespace
);
845 // Data members /////////////////////////////////////////////////////////////
847 std::vector
<InterstitialObserver
*> interstitial_observers_
;
849 content::NotificationRegistrar registrar_
;
851 #if defined(ENABLE_EXTENSIONS)
852 ScopedObserver
<extensions::ExtensionRegistry
,
853 extensions::ExtensionRegistryObserver
>
854 extension_registry_observer_
;
857 PrefChangeRegistrar profile_pref_registrar_
;
859 // This Browser's type.
862 // This Browser's profile.
863 Profile
* const profile_
;
865 // This Browser's window.
866 BrowserWindow
* window_
;
868 // Manages popup windows (bubbles, tab-modals) visible overlapping this
869 // window. JS alerts are not handled by this manager.
870 scoped_ptr
<web_modal::PopupManager
> popup_manager_
;
872 scoped_ptr
<TabStripModelDelegate
> tab_strip_model_delegate_
;
873 scoped_ptr
<TabStripModel
> tab_strip_model_
;
875 // The application name that is also the name of the window to the shell.
876 // This name should be set when:
877 // 1) we launch an application via an application shortcut or extension API.
878 // 2) we launch an undocked devtool window.
879 std::string app_name_
;
881 // True if the source is trusted (i.e. we do not need to show the URL in a
882 // a popup window). Also used to determine which app windows to save and
883 // restore on Chrome OS.
884 bool is_trusted_source_
;
886 // Unique identifier of this browser for session restore. This id is only
887 // unique within the current session, and is not guaranteed to be unique
889 const SessionID session_id_
;
891 // The model for the toolbar view.
892 scoped_ptr
<ToolbarModel
> toolbar_model_
;
894 // The model for the "active" search state. There are per-tab search models
895 // as well. When a tab is active its model is kept in sync with this one.
896 // When a new tab is activated its model state is propagated to this active
897 // model. This way, observers only have to attach to this single model for
898 // updates, and don't have to worry about active tab changes directly.
899 scoped_ptr
<SearchModel
> search_model_
;
901 // UI update coalescing and handling ////////////////////////////////////////
903 typedef std::map
<const content::WebContents
*, int> UpdateMap
;
905 // Maps from WebContents to pending UI updates that need to be processed.
906 // We don't update things like the URL or tab title right away to avoid
907 // flickering and extra painting.
908 // See ScheduleUIUpdate and ProcessPendingUIUpdates.
909 UpdateMap scheduled_updates_
;
911 // In-progress download termination handling /////////////////////////////////
913 enum CancelDownloadConfirmationState
{
914 NOT_PROMPTED
, // We have not asked the user.
915 WAITING_FOR_RESPONSE
, // We have asked the user and have not received a
917 RESPONSE_RECEIVED
// The user was prompted and made a decision already.
920 // State used to figure-out whether we should prompt the user for confirmation
921 // when the browser is closed with in-progress downloads.
922 CancelDownloadConfirmationState cancel_download_confirmation_state_
;
924 /////////////////////////////////////////////////////////////////////////////
926 // Override values for the bounds of the window and its maximized or minimized
928 // These are supplied by callers that don't want to use the default values.
929 // The default values are typically loaded from local state (last session),
930 // obtained from the last window of the same type, or obtained from the
931 // shell shortcut's startup info.
932 gfx::Rect override_bounds_
;
933 ui::WindowShowState initial_show_state_
;
935 // Tracks when this browser is being created by session restore.
936 bool is_session_restore_
;
938 const chrome::HostDesktopType host_desktop_type_
;
940 scoped_ptr
<chrome::UnloadController
> unload_controller_
;
941 scoped_ptr
<chrome::FastUnloadController
> fast_unload_controller_
;
943 // The Find Bar. This may be NULL if there is no Find Bar, and if it is
944 // non-NULL, it may or may not be visible.
945 scoped_ptr
<FindBarController
> find_bar_controller_
;
947 // Dialog box used for opening and saving files.
948 scoped_refptr
<ui::SelectFileDialog
> select_file_dialog_
;
950 // Keep track of the encoding auto detect pref.
951 BooleanPrefMember encoding_auto_detect_
;
953 // Helper which implements the ContentSettingBubbleModel interface.
954 scoped_ptr
<BrowserContentSettingBubbleModelDelegate
>
955 content_setting_bubble_model_delegate_
;
957 // Helper which implements the ToolbarModelDelegate interface.
958 scoped_ptr
<BrowserToolbarModelDelegate
> toolbar_model_delegate_
;
960 // A delegate that handles the details of updating the "active"
961 // |search_model_| state with the tab's state.
962 scoped_ptr
<SearchDelegate
> search_delegate_
;
964 // Helper which implements the TabRestoreServiceDelegate interface.
965 scoped_ptr
<BrowserTabRestoreServiceDelegate
> tab_restore_service_delegate_
;
967 // Helper which implements the SyncedWindowDelegate interface.
968 scoped_ptr
<BrowserSyncedWindowDelegate
> synced_window_delegate_
;
970 scoped_ptr
<BrowserInstantController
> instant_controller_
;
972 BookmarkBar::State bookmark_bar_state_
;
974 scoped_ptr
<FullscreenController
> fullscreen_controller_
;
976 scoped_ptr
<extensions::WindowController
> extension_window_controller_
;
978 scoped_ptr
<chrome::BrowserCommandController
> command_controller_
;
980 // True if the browser window has been shown at least once.
981 bool window_has_shown_
;
983 // The following factory is used for chrome update coalescing.
984 base::WeakPtrFactory
<Browser
> chrome_updater_factory_
;
986 scoped_ptr
<BrowserContentTranslateDriverObserver
> translate_driver_observer_
;
988 scoped_ptr
<chrome::ValidationMessageBubble
> validation_message_bubble_
;
990 // The following factory is used to close the frame at a later time.
991 base::WeakPtrFactory
<Browser
> weak_factory_
;
993 DISALLOW_COPY_AND_ASSIGN(Browser
);
996 #endif // CHROME_BROWSER_UI_BROWSER_H_