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/exclusive_access/exclusive_access_manager.h"
28 #include "chrome/browser/ui/host_desktop.h"
29 #include "chrome/browser/ui/search/search_tab_helper_delegate.h"
30 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h"
31 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
32 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
33 #include "chrome/browser/ui/toolbar/toolbar_model.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 "components/translate/content/browser/content_translate_driver.h"
38 #include "components/ui/zoom/zoom_observer.h"
39 #include "content/public/browser/notification_observer.h"
40 #include "content/public/browser/notification_registrar.h"
41 #include "content/public/browser/page_navigator.h"
42 #include "content/public/browser/web_contents_delegate.h"
43 #include "content/public/common/page_zoom.h"
44 #include "ui/base/page_transition_types.h"
45 #include "ui/base/ui_base_types.h"
46 #include "ui/base/window_open_disposition.h"
47 #include "ui/gfx/geometry/rect.h"
48 #include "ui/shell_dialogs/select_file_dialog.h"
50 #if defined(ENABLE_EXTENSIONS)
51 #include "extensions/browser/extension_registry_observer.h"
54 class BrowserContentSettingBubbleModelDelegate
;
55 class BrowserInstantController
;
56 class BrowserSyncedWindowDelegate
;
57 class BrowserToolbarModelDelegate
;
58 class BrowserTabRestoreServiceDelegate
;
60 class FindBarController
;
67 class TabStripModelDelegate
;
68 class ValidationMessageBubble
;
69 struct WebApplicationInfo
;
72 class BrowserCommandController
;
73 class FastUnloadController
;
74 class UnloadController
;
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
,
111 public ui_zoom::ZoomObserver
,
112 public content::PageNavigator
,
113 public content::NotificationObserver
,
114 #if defined(ENABLE_EXTENSIONS)
115 public extensions::ExtensionRegistryObserver
,
117 public translate::ContentTranslateDriver::Observer
,
118 public ui::SelectFileDialog::Listener
{
120 // SessionService::WindowType mirrors these values. If you add to this
121 // enum, look at SessionService::WindowType to see if it needs to be
124 // If you add a new type, consider updating the test
125 // BrowserTest.StartMaximized.
130 // Possible elements of the Browser window.
133 FEATURE_TITLEBAR
= 1,
134 FEATURE_TABSTRIP
= 2,
136 FEATURE_LOCATIONBAR
= 8,
137 FEATURE_BOOKMARKBAR
= 16,
138 FEATURE_INFOBAR
= 32,
139 FEATURE_DOWNLOADSHELF
= 64,
140 FEATURE_WEBAPPFRAME
= 128
143 // The context for a download blocked notification from
144 // OkToCloseWithInProgressDownloads.
145 enum DownloadClosePreventionType
{
146 // Browser close is not blocked by download state.
149 // The browser is shutting down and there are active downloads
150 // that would be cancelled.
151 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN
,
153 // There are active downloads associated with this incognito profile
154 // that would be canceled.
155 DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE
,
158 struct CreateParams
{
159 CreateParams(Profile
* profile
, chrome::HostDesktopType host_desktop_type
);
160 CreateParams(Type type
,
162 chrome::HostDesktopType host_desktop_type
);
164 static CreateParams
CreateForApp(const std::string
& app_name
,
166 const gfx::Rect
& window_bounds
,
168 chrome::HostDesktopType host_desktop_type
);
170 static CreateParams
CreateForDevTools(
172 chrome::HostDesktopType host_desktop_type
);
177 // The associated profile.
180 // The host desktop the browser is created on.
181 chrome::HostDesktopType host_desktop_type
;
183 // Specifies the browser is_trusted_source_ value.
186 // The bounds of the window to open.
187 gfx::Rect initial_bounds
;
189 ui::WindowShowState initial_show_state
;
191 bool is_session_restore
;
193 // Supply a custom BrowserWindow implementation, to be used instead of the
194 // default. Intended for testing.
195 BrowserWindow
* window
;
198 friend class Browser
;
200 // The application name that is also the name of the window to the shell.
201 // Do not set this value directly, use CreateForApp.
202 // This name will be set for:
203 // 1) v1 applications launched via an application shortcut or extension API.
204 // 2) undocked devtool windows.
205 // 3) popup windows spawned from v1 applications.
206 std::string app_name
;
209 // Constructors, Creation, Showing //////////////////////////////////////////
211 explicit Browser(const CreateParams
& params
);
214 // Set overrides for the initial window bounds and maximized state.
215 void set_override_bounds(const gfx::Rect
& bounds
) {
216 override_bounds_
= bounds
;
218 ui::WindowShowState
initial_show_state() const { return initial_show_state_
; }
219 void set_initial_show_state(ui::WindowShowState initial_show_state
) {
220 initial_show_state_
= initial_show_state
;
222 // Return true if the initial window bounds have been overridden.
223 bool bounds_overridden() const {
224 return !override_bounds_
.IsEmpty();
226 // Set indicator that this browser is being created via session restore.
227 // This is used on the Mac (only) to determine animation style when the
228 // browser window is shown.
229 void set_is_session_restore(bool is_session_restore
) {
230 is_session_restore_
= is_session_restore
;
232 bool is_session_restore() const {
233 return is_session_restore_
;
235 chrome::HostDesktopType
host_desktop_type() const {
236 return host_desktop_type_
;
239 // Accessors ////////////////////////////////////////////////////////////////
241 Type
type() const { return type_
; }
242 const std::string
& app_name() const { return app_name_
; }
243 bool is_trusted_source() const { return is_trusted_source_
; }
244 Profile
* profile() const { return profile_
; }
245 gfx::Rect
override_bounds() const { return override_bounds_
; }
247 // |window()| will return NULL if called before |CreateBrowserWindow()|
249 BrowserWindow
* window() const { return window_
; }
250 ToolbarModel
* toolbar_model() { return toolbar_model_
.get(); }
251 const ToolbarModel
* toolbar_model() const { return toolbar_model_
.get(); }
252 #if defined(UNIT_TEST)
253 void swap_toolbar_models(scoped_ptr
<ToolbarModel
>* toolbar_model
) {
254 toolbar_model
->swap(toolbar_model_
);
257 web_modal::PopupManager
* popup_manager() {
258 return popup_manager_
.get();
260 TabStripModel
* tab_strip_model() const { return tab_strip_model_
.get(); }
261 chrome::BrowserCommandController
* command_controller() {
262 return command_controller_
.get();
264 SearchModel
* search_model() { return search_model_
.get(); }
265 const SearchModel
* search_model() const {
266 return search_model_
.get();
268 SearchDelegate
* search_delegate() {
269 return search_delegate_
.get();
271 const SessionID
& session_id() const { return session_id_
; }
272 BrowserContentSettingBubbleModelDelegate
*
273 content_setting_bubble_model_delegate() {
274 return content_setting_bubble_model_delegate_
.get();
276 BrowserTabRestoreServiceDelegate
* tab_restore_service_delegate() {
277 return tab_restore_service_delegate_
.get();
279 BrowserSyncedWindowDelegate
* synced_window_delegate() {
280 return synced_window_delegate_
.get();
282 BrowserInstantController
* instant_controller() {
283 return instant_controller_
.get();
286 // Get the FindBarController for this browser, creating it if it does not
288 FindBarController
* GetFindBarController();
290 // Returns true if a FindBarController exists for this browser.
291 bool HasFindBarController() const;
293 // Returns the state of the bookmark bar.
294 BookmarkBar::State
bookmark_bar_state() const { return bookmark_bar_state_
; }
296 // State Storage and Retrieval for UI ///////////////////////////////////////
298 // Gets the Favicon of the page in the selected tab.
299 gfx::Image
GetCurrentPageIcon() const;
301 // Gets the title of the window based on the selected tab's title.
302 base::string16
GetWindowTitleForCurrentTab() const;
304 // Prepares a title string for display (removes embedded newlines, etc).
305 static void FormatTitleForDisplay(base::string16
* title
);
307 // OnBeforeUnload handling //////////////////////////////////////////////////
309 // Gives beforeunload handlers the chance to cancel the close. Returns whether
310 // to proceed with the close. If called while the process begun by
311 // CallBeforeUnloadHandlers is in progress, returns false without taking
313 bool ShouldCloseWindow();
315 // Begins the process of confirming whether the associated browser can be
316 // closed. If there are no tabs with beforeunload handlers it will immediately
317 // return false. Otherwise, it starts prompting the user, returns true and
318 // will call |on_close_confirmed| with the result of the user's decision.
319 // After calling this function, if the window will not be closed, call
320 // ResetBeforeUnloadHandlers() to reset all beforeunload handlers; calling
321 // this function multiple times without an intervening call to
322 // ResetBeforeUnloadHandlers() will run only the beforeunload handlers
323 // registered since the previous call.
324 bool CallBeforeUnloadHandlers(
325 const base::Callback
<void(bool)>& on_close_confirmed
);
327 // Clears the results of any beforeunload confirmation dialogs triggered by a
328 // CallBeforeUnloadHandlers call.
329 void ResetBeforeUnloadHandlers();
331 // Figure out if there are tabs that have beforeunload handlers.
332 // It starts beforeunload/unload processing as a side-effect.
333 bool TabsNeedBeforeUnloadFired();
335 // Returns true if all tabs' beforeunload/unload events have fired.
336 bool HasCompletedUnloadProcessing() const;
338 bool IsAttemptingToCloseBrowser() const;
340 // Invoked when the window containing us is closing. Performs the necessary
342 void OnWindowClosing();
344 // In-progress download termination handling /////////////////////////////////
346 // Called when the user has decided whether to proceed or not with the browser
347 // closure. |cancel_downloads| is true if the downloads should be canceled
348 // and the browser closed, false if the browser should stay open and the
349 // downloads running.
350 void InProgressDownloadResponse(bool cancel_downloads
);
352 // Indicates whether or not this browser window can be closed, or
353 // would be blocked by in-progress downloads.
354 // If executing downloads would be cancelled by this window close,
355 // then |*num_downloads_blocking| is updated with how many downloads
356 // would be canceled if the close continued.
357 DownloadClosePreventionType
OkToCloseWithInProgressDownloads(
358 int* num_downloads_blocking
) const;
360 // External state change handling ////////////////////////////////////////////
362 // Invoked when the fullscreen state of the window changes.
363 // BrowserWindow::EnterFullscreen invokes this after the window has become
365 void WindowFullscreenStateChanged();
367 // Assorted browser commands ////////////////////////////////////////////////
369 // NOTE: Within each of the following sections, the IDs are ordered roughly by
370 // how they appear in the GUI/menus (left to right, top to bottom, etc.).
372 // See the description of
373 // FullscreenController::ToggleFullscreenModeWithExtension.
374 void ToggleFullscreenModeWithExtension(const GURL
& extension_url
);
377 // See the description of FullscreenController::ToggleMetroSnapMode.
378 void SetMetroSnapMode(bool enable
);
381 // Returns true if the Browser supports the specified feature. The value of
382 // this varies during the lifetime of the browser. For example, if the window
383 // is fullscreen this may return a different value. If you only care about
384 // whether or not it's possible for the browser to support a particular
385 // feature use |CanSupportWindowFeature|.
386 bool SupportsWindowFeature(WindowFeature feature
) const;
388 // Returns true if the Browser can support the specified feature. See comment
389 // in |SupportsWindowFeature| for details on this.
390 bool CanSupportWindowFeature(WindowFeature feature
) const;
392 // TODO(port): port these, and re-merge the two function declaration lists.
393 // Page-related commands.
394 void ToggleEncodingAutoDetect();
395 void OverrideEncoding(int encoding_id
);
397 // Show various bits of UI
400 void UpdateDownloadShelfVisibility(bool visible
);
402 /////////////////////////////////////////////////////////////////////////////
404 // Called by chrome::Navigate() when a navigation has occurred in a tab in
405 // this Browser. Updates the UI for the start of this navigation.
406 void UpdateUIForNavigationInTab(content::WebContents
* contents
,
407 ui::PageTransition transition
,
408 bool user_initiated
);
410 // Interface implementations ////////////////////////////////////////////////
412 // Overridden from content::PageNavigator:
413 content::WebContents
* OpenURL(const content::OpenURLParams
& params
) override
;
415 // Overridden from TabStripModelObserver:
416 void TabInsertedAt(content::WebContents
* contents
,
418 bool foreground
) override
;
419 void TabClosingAt(TabStripModel
* tab_strip_model
,
420 content::WebContents
* contents
,
422 void TabDetachedAt(content::WebContents
* contents
, int index
) override
;
423 void TabDeactivated(content::WebContents
* contents
) override
;
424 void ActiveTabChanged(content::WebContents
* old_contents
,
425 content::WebContents
* new_contents
,
427 int reason
) override
;
428 void TabMoved(content::WebContents
* contents
,
430 int to_index
) override
;
431 void TabReplacedAt(TabStripModel
* tab_strip_model
,
432 content::WebContents
* old_contents
,
433 content::WebContents
* new_contents
,
435 void TabPinnedStateChanged(content::WebContents
* contents
,
437 void TabStripEmpty() override
;
439 // Overridden from content::WebContentsDelegate:
440 bool CanOverscrollContent() const override
;
441 bool ShouldPreserveAbortedURLs(content::WebContents
* source
) override
;
442 bool PreHandleKeyboardEvent(content::WebContents
* source
,
443 const content::NativeWebKeyboardEvent
& event
,
444 bool* is_keyboard_shortcut
) override
;
445 void HandleKeyboardEvent(
446 content::WebContents
* source
,
447 const content::NativeWebKeyboardEvent
& event
) override
;
448 void ShowValidationMessage(content::WebContents
* web_contents
,
449 const gfx::Rect
& anchor_in_root_view
,
450 const base::string16
& main_text
,
451 const base::string16
& sub_text
) override
;
452 void HideValidationMessage(content::WebContents
* web_contents
) override
;
453 void MoveValidationMessage(content::WebContents
* web_contents
,
454 const gfx::Rect
& anchor_in_root_view
) override
;
455 bool PreHandleGestureEvent(content::WebContents
* source
,
456 const blink::WebGestureEvent
& event
) override
;
457 bool CanDragEnter(content::WebContents
* source
,
458 const content::DropData
& data
,
459 blink::WebDragOperationsMask operations_allowed
) override
;
461 bool is_type_tabbed() const { return type_
== TYPE_TABBED
; }
462 bool is_type_popup() const { return type_
== TYPE_POPUP
; }
465 bool is_devtools() const;
467 // True when the mouse cursor is locked.
468 bool IsMouseLocked() const;
470 // Called each time the browser window is shown.
471 void OnWindowDidShow();
473 // Show the first run search engine bubble on the location bar.
474 void ShowFirstRunBubble();
476 // Show a download on the download shelf.
477 void ShowDownload(content::DownloadItem
* download
);
479 ExclusiveAccessManager
* exclusive_access_manager() {
480 return exclusive_access_manager_
.get();
483 extensions::WindowController
* extension_window_controller() const {
484 return extension_window_controller_
.get();
488 friend class BrowserTest
;
489 friend class FullscreenControllerInteractiveTest
;
490 friend class FullscreenControllerTest
;
491 FRIEND_TEST_ALL_PREFIXES(AppModeTest
, EnableAppModeTest
);
492 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest
,
493 IsReservedCommandOrKeyIsApp
);
494 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest
, AppFullScreen
);
495 FRIEND_TEST_ALL_PREFIXES(BrowserTest
, NoTabsInPopups
);
496 FRIEND_TEST_ALL_PREFIXES(BrowserTest
, ConvertTabToAppShortcut
);
497 FRIEND_TEST_ALL_PREFIXES(BrowserTest
, OpenAppWindowLikeNtp
);
498 FRIEND_TEST_ALL_PREFIXES(BrowserTest
, AppIdSwitch
);
499 FRIEND_TEST_ALL_PREFIXES(BrowserTest
, ShouldShowLocationBar
);
500 FRIEND_TEST_ALL_PREFIXES(ExclusiveAccessBubbleWindowControllerTest
,
501 DenyExitsFullscreen
);
502 FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest
,
503 TabEntersPresentationModeFromWindowed
);
504 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest
, OpenAppShortcutNoPref
);
505 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest
,
506 OpenAppShortcutWindowPref
);
507 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest
, OpenAppShortcutTabPref
);
509 class InterstitialObserver
;
511 // Used to describe why a tab is being detached. This is used by
512 // TabDetachedAtImpl.
514 // Result of TabDetachedAt.
517 // Result of TabReplacedAt.
520 // Result of the tab strip not having any significant tabs.
524 // Describes where the bookmark bar state change originated from.
525 enum BookmarkBarStateChangeReason
{
526 // From the constructor.
527 BOOKMARK_BAR_STATE_CHANGE_INIT
,
529 // Change is the result of the active tab changing.
530 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH
,
532 // Change is the result of the bookmark bar pref changing.
533 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE
,
535 // Change is the result of a state change in the active tab.
536 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE
,
538 // Change is the result of window toggling in/out of fullscreen mode.
539 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN
,
542 // Overridden from content::WebContentsDelegate:
543 content::WebContents
* OpenURLFromTab(
544 content::WebContents
* source
,
545 const content::OpenURLParams
& params
) override
;
546 void NavigationStateChanged(content::WebContents
* source
,
547 content::InvalidateTypes changed_flags
) override
;
548 void VisibleSSLStateChanged(const content::WebContents
* source
) override
;
549 void AddNewContents(content::WebContents
* source
,
550 content::WebContents
* new_contents
,
551 WindowOpenDisposition disposition
,
552 const gfx::Rect
& initial_rect
,
554 bool* was_blocked
) override
;
555 void ActivateContents(content::WebContents
* contents
) override
;
556 void DeactivateContents(content::WebContents
* contents
) override
;
557 void LoadingStateChanged(content::WebContents
* source
,
558 bool to_different_document
) override
;
559 void CloseContents(content::WebContents
* source
) override
;
560 void MoveContents(content::WebContents
* source
,
561 const gfx::Rect
& pos
) override
;
562 bool IsPopupOrPanel(const content::WebContents
* source
) const override
;
563 void UpdateTargetURL(content::WebContents
* source
, const GURL
& url
) override
;
564 void ContentsMouseEvent(content::WebContents
* source
,
565 const gfx::Point
& location
,
566 bool motion
) override
;
567 void ContentsZoomChange(bool zoom_in
) override
;
568 void WebContentsFocused(content::WebContents
* content
) override
;
569 bool TakeFocus(content::WebContents
* source
, bool reverse
) override
;
570 gfx::Rect
GetRootWindowResizerRect() const override
;
571 void BeforeUnloadFired(content::WebContents
* source
,
573 bool* proceed_to_fire_unload
) override
;
574 bool ShouldFocusLocationBarByDefault(content::WebContents
* source
) override
;
575 void SetFocusToLocationBar(bool select_all
) override
;
576 int GetExtraRenderViewHeight() const override
;
577 void ViewSourceForTab(content::WebContents
* source
,
578 const GURL
& page_url
) override
;
579 void ViewSourceForFrame(content::WebContents
* source
,
580 const GURL
& frame_url
,
581 const content::PageState
& frame_page_state
) override
;
582 void ShowRepostFormWarningDialog(content::WebContents
* source
) override
;
583 bool ShouldCreateWebContents(
584 content::WebContents
* web_contents
,
586 int main_frame_route_id
,
587 WindowContainerType window_container_type
,
588 const base::string16
& frame_name
,
589 const GURL
& target_url
,
590 const std::string
& partition_id
,
591 content::SessionStorageNamespace
* session_storage_namespace
) override
;
592 void WebContentsCreated(content::WebContents
* source_contents
,
593 int opener_render_frame_id
,
594 const base::string16
& frame_name
,
595 const GURL
& target_url
,
596 content::WebContents
* new_contents
) override
;
597 void RendererUnresponsive(content::WebContents
* source
) override
;
598 void RendererResponsive(content::WebContents
* source
) override
;
599 void WorkerCrashed(content::WebContents
* source
) override
;
600 void DidNavigateMainFramePostCommit(
601 content::WebContents
* web_contents
) override
;
602 content::JavaScriptDialogManager
* GetJavaScriptDialogManager(
603 content::WebContents
* source
) override
;
604 content::ColorChooser
* OpenColorChooser(
605 content::WebContents
* web_contents
,
607 const std::vector
<content::ColorSuggestion
>& suggestions
) override
;
608 void RunFileChooser(content::WebContents
* web_contents
,
609 const content::FileChooserParams
& params
) override
;
610 void EnumerateDirectory(content::WebContents
* web_contents
,
612 const base::FilePath
& path
) override
;
613 bool EmbedsFullscreenWidget() const override
;
614 void EnterFullscreenModeForTab(content::WebContents
* web_contents
,
615 const GURL
& origin
) override
;
616 void ExitFullscreenModeForTab(content::WebContents
* web_contents
) override
;
617 bool IsFullscreenForTabOrPending(
618 const content::WebContents
* web_contents
) const override
;
619 void RegisterProtocolHandler(content::WebContents
* web_contents
,
620 const std::string
& protocol
,
622 bool user_gesture
) override
;
623 void UnregisterProtocolHandler(content::WebContents
* web_contents
,
624 const std::string
& protocol
,
626 bool user_gesture
) override
;
627 void UpdatePreferredSize(content::WebContents
* source
,
628 const gfx::Size
& pref_size
) override
;
629 void ResizeDueToAutoResize(content::WebContents
* source
,
630 const gfx::Size
& new_size
) override
;
631 void FindReply(content::WebContents
* web_contents
,
633 int number_of_matches
,
634 const gfx::Rect
& selection_rect
,
635 int active_match_ordinal
,
636 bool final_update
) override
;
637 void RequestToLockMouse(content::WebContents
* web_contents
,
639 bool last_unlocked_by_target
) override
;
640 void LostMouseLock() override
;
641 void RequestMediaAccessPermission(
642 content::WebContents
* web_contents
,
643 const content::MediaStreamRequest
& request
,
644 const content::MediaResponseCallback
& callback
) override
;
645 bool CheckMediaAccessPermission(content::WebContents
* web_contents
,
646 const GURL
& security_origin
,
647 content::MediaStreamType type
) override
;
648 bool RequestPpapiBrokerPermission(
649 content::WebContents
* web_contents
,
651 const base::FilePath
& plugin_path
,
652 const base::Callback
<void(bool)>& callback
) override
;
653 gfx::Size
GetSizeForNewRenderView(
654 content::WebContents
* web_contents
) const override
;
656 // Overridden from CoreTabHelperDelegate:
657 // Note that the caller is responsible for deleting |old_contents|.
658 void SwapTabContents(content::WebContents
* old_contents
,
659 content::WebContents
* new_contents
,
661 bool did_finish_load
) override
;
662 bool CanReloadContents(content::WebContents
* web_contents
) const override
;
663 bool CanSaveContents(content::WebContents
* web_contents
) const override
;
665 // Overridden from SearchEngineTabHelperDelegate:
666 void ConfirmAddSearchProvider(TemplateURL
* template_url
,
667 Profile
* profile
) override
;
669 // Overridden from SearchTabHelperDelegate:
670 void NavigateOnThumbnailClick(const GURL
& url
,
671 WindowOpenDisposition disposition
,
672 content::WebContents
* source_contents
) override
;
673 void OnWebContentsInstantSupportDisabled(
674 const content::WebContents
* web_contents
) override
;
675 OmniboxView
* GetOmniboxView() override
;
676 std::set
<std::string
> GetOpenUrls() override
;
678 // Overridden from WebContentsModalDialogManagerDelegate:
679 void SetWebContentsBlocked(content::WebContents
* web_contents
,
680 bool blocked
) override
;
681 web_modal::WebContentsModalDialogHost
* GetWebContentsModalDialogHost()
684 // Overridden from BookmarkTabHelperDelegate:
685 void URLStarredChanged(content::WebContents
* web_contents
,
686 bool starred
) override
;
688 // Overridden from ZoomObserver:
690 const ui_zoom::ZoomController::ZoomChangedEventData
& data
) override
;
692 // Overridden from SelectFileDialog::Listener:
693 void FileSelected(const base::FilePath
& path
,
695 void* params
) override
;
696 void FileSelectedWithExtraInfo(const ui::SelectedFileInfo
& file_info
,
698 void* params
) override
;
700 // Overridden from content::NotificationObserver:
701 void Observe(int type
,
702 const content::NotificationSource
& source
,
703 const content::NotificationDetails
& details
) override
;
705 #if defined(ENABLE_EXTENSIONS)
706 // Overridden from extensions::ExtensionRegistryObserver:
707 void OnExtensionUninstalled(content::BrowserContext
* browser_context
,
708 const extensions::Extension
* extension
,
709 extensions::UninstallReason reason
) override
;
710 void OnExtensionLoaded(content::BrowserContext
* browser_context
,
711 const extensions::Extension
* extension
) override
;
712 void OnExtensionUnloaded(
713 content::BrowserContext
* browser_context
,
714 const extensions::Extension
* extension
,
715 extensions::UnloadedExtensionInfo::Reason reason
) override
;
718 // Overridden from translate::ContentTranslateDriver::Observer:
719 void OnIsPageTranslatedChanged(content::WebContents
* source
) override
;
720 void OnTranslateEnabledChanged(content::WebContents
* source
) override
;
722 // Command and state updating ///////////////////////////////////////////////
724 // Handle changes to kDevTools preference.
725 void OnDevToolsDisabledChanged();
727 // UI update coalescing and handling ////////////////////////////////////////
729 // Asks the toolbar (and as such the location bar) to update its state to
730 // reflect the current tab's current URL, security state, etc.
731 // If |should_restore_state| is true, we're switching (back?) to this tab and
732 // should restore any previous location bar state (such as user editing) as
734 void UpdateToolbar(bool should_restore_state
);
736 // Does one or both of the following for each bit in |changed_flags|:
737 // . If the update should be processed immediately, it is.
738 // . If the update should processed asynchronously (to avoid lots of ui
739 // updates), then scheduled_updates_ is updated for the |source| and update
740 // pair and a task is scheduled (assuming it isn't running already)
741 // that invokes ProcessPendingUIUpdates.
742 void ScheduleUIUpdate(content::WebContents
* source
,
743 unsigned changed_flags
);
745 // Processes all pending updates to the UI that have been scheduled by
746 // ScheduleUIUpdate in scheduled_updates_.
747 void ProcessPendingUIUpdates();
749 // Removes all entries from scheduled_updates_ whose source is contents.
750 void RemoveScheduledUpdatesFor(content::WebContents
* contents
);
752 // Getters for UI ///////////////////////////////////////////////////////////
754 // TODO(beng): remove, and provide AutomationProvider a better way to access
755 // the LocationBarView's edit.
756 friend class AutomationProvider
;
757 friend class BrowserProxy
;
759 // Returns the StatusBubble from the current toolbar. It is possible for
760 // this to return NULL if called before the toolbar has initialized.
761 // TODO(beng): remove this.
762 StatusBubble
* GetStatusBubble();
764 // Session restore functions ////////////////////////////////////////////////
766 // Notifies the history database of the index for all tabs whose index is
768 void SyncHistoryWithTabs(int index
);
770 // In-progress download termination handling /////////////////////////////////
772 // Called when the window is closing to check if potential in-progress
773 // downloads should prevent it from closing.
774 // Returns true if the window can close, false otherwise.
775 bool CanCloseWithInProgressDownloads();
777 // Assorted utility functions ///////////////////////////////////////////////
779 // Sets the specified browser as the delegate of the WebContents and all the
780 // associated tab helpers that are needed. If |set_delegate| is true, this
781 // browser object is set as a delegate for |web_contents| components, else
782 // is is removed as a delegate.
783 void SetAsDelegate(content::WebContents
* web_contents
, bool set_delegate
);
785 // Shows the Find Bar, optionally selecting the next entry that matches the
786 // existing search string for that Tab. |forward_direction| controls the
788 void FindInPage(bool find_next
, bool forward_direction
);
791 // TODO(beng): figure out if we need this now that the frame itself closes
792 // after a return to the message loop.
795 void TabDetachedAtImpl(content::WebContents
* contents
,
799 // Shared code between Reload() and ReloadIgnoringCache().
800 void ReloadInternal(WindowOpenDisposition disposition
, bool ignore_cache
);
802 // Returns true if the Browser window should show the location bar.
803 bool ShouldShowLocationBar() const;
805 // Returns true if the Browser window should use a web app style frame.
806 bool ShouldUseWebAppFrame() const;
808 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
809 // |check_fullscreen| is true, the set of features reflect the actual state of
810 // the browser, otherwise the set of features reflect the possible state of
812 bool SupportsWindowFeatureImpl(WindowFeature feature
,
813 bool check_fullscreen
) const;
815 // Resets |bookmark_bar_state_| based on the active tab. Notifies the
816 // BrowserWindow if necessary.
817 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason
);
819 bool ShouldHideUIForFullscreen() const;
821 // Creates a BackgroundContents if appropriate; return true if one was
823 bool MaybeCreateBackgroundContents(
825 int main_frame_route_id
,
826 content::WebContents
* opener_web_contents
,
827 const base::string16
& frame_name
,
828 const GURL
& target_url
,
829 const std::string
& partition_id
,
830 content::SessionStorageNamespace
* session_storage_namespace
);
832 // Data members /////////////////////////////////////////////////////////////
834 std::vector
<InterstitialObserver
*> interstitial_observers_
;
836 content::NotificationRegistrar registrar_
;
838 #if defined(ENABLE_EXTENSIONS)
839 ScopedObserver
<extensions::ExtensionRegistry
,
840 extensions::ExtensionRegistryObserver
>
841 extension_registry_observer_
;
844 PrefChangeRegistrar profile_pref_registrar_
;
846 // This Browser's type.
849 // This Browser's profile.
850 Profile
* const profile_
;
852 // This Browser's window.
853 BrowserWindow
* window_
;
855 // Manages popup windows (bubbles, tab-modals) visible overlapping this
856 // window. JS alerts are not handled by this manager.
857 scoped_ptr
<web_modal::PopupManager
> popup_manager_
;
859 scoped_ptr
<TabStripModelDelegate
> tab_strip_model_delegate_
;
860 scoped_ptr
<TabStripModel
> tab_strip_model_
;
862 // The application name that is also the name of the window to the shell.
863 // This name should be set when:
864 // 1) we launch an application via an application shortcut or extension API.
865 // 2) we launch an undocked devtool window.
866 std::string app_name_
;
868 // True if the source is trusted (i.e. we do not need to show the URL in a
869 // a popup window). Also used to determine which app windows to save and
870 // restore on Chrome OS.
871 bool is_trusted_source_
;
873 // Unique identifier of this browser for session restore. This id is only
874 // unique within the current session, and is not guaranteed to be unique
876 const SessionID session_id_
;
878 // The model for the toolbar view.
879 scoped_ptr
<ToolbarModel
> toolbar_model_
;
881 // The model for the "active" search state. There are per-tab search models
882 // as well. When a tab is active its model is kept in sync with this one.
883 // When a new tab is activated its model state is propagated to this active
884 // model. This way, observers only have to attach to this single model for
885 // updates, and don't have to worry about active tab changes directly.
886 scoped_ptr
<SearchModel
> search_model_
;
888 // UI update coalescing and handling ////////////////////////////////////////
890 typedef std::map
<const content::WebContents
*, int> UpdateMap
;
892 // Maps from WebContents to pending UI updates that need to be processed.
893 // We don't update things like the URL or tab title right away to avoid
894 // flickering and extra painting.
895 // See ScheduleUIUpdate and ProcessPendingUIUpdates.
896 UpdateMap scheduled_updates_
;
898 // In-progress download termination handling /////////////////////////////////
900 enum CancelDownloadConfirmationState
{
901 NOT_PROMPTED
, // We have not asked the user.
902 WAITING_FOR_RESPONSE
, // We have asked the user and have not received a
904 RESPONSE_RECEIVED
// The user was prompted and made a decision already.
907 // State used to figure-out whether we should prompt the user for confirmation
908 // when the browser is closed with in-progress downloads.
909 CancelDownloadConfirmationState cancel_download_confirmation_state_
;
911 /////////////////////////////////////////////////////////////////////////////
913 // Override values for the bounds of the window and its maximized or minimized
915 // These are supplied by callers that don't want to use the default values.
916 // The default values are typically loaded from local state (last session),
917 // obtained from the last window of the same type, or obtained from the
918 // shell shortcut's startup info.
919 gfx::Rect override_bounds_
;
920 ui::WindowShowState initial_show_state_
;
922 // Tracks when this browser is being created by session restore.
923 bool is_session_restore_
;
925 const chrome::HostDesktopType host_desktop_type_
;
927 scoped_ptr
<chrome::UnloadController
> unload_controller_
;
928 scoped_ptr
<chrome::FastUnloadController
> fast_unload_controller_
;
930 // The Find Bar. This may be NULL if there is no Find Bar, and if it is
931 // non-NULL, it may or may not be visible.
932 scoped_ptr
<FindBarController
> find_bar_controller_
;
934 // Dialog box used for opening and saving files.
935 scoped_refptr
<ui::SelectFileDialog
> select_file_dialog_
;
937 // Keep track of the encoding auto detect pref.
938 BooleanPrefMember encoding_auto_detect_
;
940 // Helper which implements the ContentSettingBubbleModel interface.
941 scoped_ptr
<BrowserContentSettingBubbleModelDelegate
>
942 content_setting_bubble_model_delegate_
;
944 // Helper which implements the ToolbarModelDelegate interface.
945 scoped_ptr
<BrowserToolbarModelDelegate
> toolbar_model_delegate_
;
947 // A delegate that handles the details of updating the "active"
948 // |search_model_| state with the tab's state.
949 scoped_ptr
<SearchDelegate
> search_delegate_
;
951 // Helper which implements the TabRestoreServiceDelegate interface.
952 scoped_ptr
<BrowserTabRestoreServiceDelegate
> tab_restore_service_delegate_
;
954 // Helper which implements the SyncedWindowDelegate interface.
955 scoped_ptr
<BrowserSyncedWindowDelegate
> synced_window_delegate_
;
957 scoped_ptr
<BrowserInstantController
> instant_controller_
;
959 BookmarkBar::State bookmark_bar_state_
;
961 scoped_ptr
<ExclusiveAccessManager
> exclusive_access_manager_
;
963 scoped_ptr
<extensions::WindowController
> extension_window_controller_
;
965 scoped_ptr
<chrome::BrowserCommandController
> command_controller_
;
967 // True if the browser window has been shown at least once.
968 bool window_has_shown_
;
970 scoped_ptr
<ValidationMessageBubble
> validation_message_bubble_
;
972 // The following factory is used for chrome update coalescing.
973 base::WeakPtrFactory
<Browser
> chrome_updater_factory_
;
975 // The following factory is used to close the frame at a later time.
976 base::WeakPtrFactory
<Browser
> weak_factory_
;
978 DISALLOW_COPY_AND_ASSIGN(Browser
);
981 #endif // CHROME_BROWSER_UI_BROWSER_H_