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/strings/string16.h"
21 #include "chrome/browser/devtools/devtools_toggle_action.h"
22 #include "chrome/browser/sessions/session_id.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_engines/search_engine_tab_helper_delegate.h"
29 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
31 #include "chrome/browser/ui/toolbar/toolbar_model.h"
32 #include "chrome/browser/ui/zoom/zoom_observer.h"
33 #include "chrome/common/content_settings.h"
34 #include "chrome/common/content_settings_types.h"
35 #include "chrome/common/extensions/extension_constants.h"
36 #include "content/public/browser/notification_observer.h"
37 #include "content/public/browser/notification_registrar.h"
38 #include "content/public/browser/page_navigator.h"
39 #include "content/public/browser/web_contents_delegate.h"
40 #include "content/public/common/page_transition_types.h"
41 #include "content/public/common/page_zoom.h"
42 #include "ui/base/ui_base_types.h"
43 #include "ui/base/window_open_disposition.h"
44 #include "ui/gfx/rect.h"
45 #include "ui/shell_dialogs/select_file_dialog.h"
47 class BrowserContentSettingBubbleModelDelegate;
48 class BrowserInstantController;
49 class BrowserLanguageStateObserver;
50 class BrowserSyncedWindowDelegate;
51 class BrowserToolbarModelDelegate;
52 class BrowserTabRestoreServiceDelegate;
54 class FindBarController;
55 class FullscreenController;
62 class TabStripModelDelegate;
63 struct WebApplicationInfo;
66 class BrowserCommandController;
67 class FastUnloadController;
68 class UnloadController;
72 class NavigationController;
74 class SessionStorageNamespace;
77 namespace extensions {
79 class WindowController;
88 struct SelectedFileInfo;
89 class WebDialogDelegate;
93 class WebContentsModalDialogHost;
96 class Browser : public TabStripModelObserver,
97 public content::WebContentsDelegate,
98 public CoreTabHelperDelegate,
99 public SearchEngineTabHelperDelegate,
100 public ChromeWebModalDialogManagerDelegate,
101 public BookmarkTabHelperDelegate,
103 public content::PageNavigator,
104 public content::NotificationObserver,
105 public ui::SelectFileDialog::Listener {
107 // SessionService::WindowType mirrors these values. If you add to this
108 // enum, look at SessionService::WindowType to see if it needs to be
111 // If you add a new type, consider updating the test
112 // BrowserTest.StartMaximized.
117 // Distinguishes between browsers that host an app (opened from
118 // ApplicationLauncher::OpenApplication), and child browsers created by an app
119 // from Browser::CreateForApp (e.g. by windows.open or the extension API).
125 // Possible elements of the Browser window.
128 FEATURE_TITLEBAR = 1,
129 FEATURE_TABSTRIP = 2,
131 FEATURE_LOCATIONBAR = 8,
132 FEATURE_BOOKMARKBAR = 16,
133 FEATURE_INFOBAR = 32,
134 FEATURE_DOWNLOADSHELF = 64
137 // The context for a download blocked notification from
138 // OkToCloseWithInProgressDownloads.
139 enum DownloadClosePreventionType {
140 // Browser close is not blocked by download state.
143 // The browser is shutting down and there are active downloads
144 // that would be cancelled.
145 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN,
147 // There are active downloads associated with this incognito profile
148 // that would be canceled.
149 DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE,
152 struct CreateParams {
153 CreateParams(Profile* profile, chrome::HostDesktopType host_desktop_type);
154 CreateParams(Type type,
156 chrome::HostDesktopType host_desktop_type);
158 static CreateParams CreateForApp(Type type,
159 const std::string& app_name,
160 const gfx::Rect& window_bounds,
162 chrome::HostDesktopType host_desktop_type);
164 static CreateParams CreateForDevTools(
166 chrome::HostDesktopType host_desktop_type);
171 // The associated profile.
174 // The host desktop the browser is created on.
175 chrome::HostDesktopType host_desktop_type;
177 // The application name that is also the name of the window to the shell.
178 // This name should be set when:
179 // 1) we launch an application via an application shortcut or extension API.
180 // 2) we launch an undocked devtool window.
181 std::string app_name;
183 // Type of app (host or child). See description of AppType.
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 // Constructors, Creation, Showing //////////////////////////////////////////
200 explicit Browser(const CreateParams& params);
203 // Set overrides for the initial window bounds and maximized state.
204 void set_override_bounds(const gfx::Rect& bounds) {
205 override_bounds_ = bounds;
207 ui::WindowShowState initial_show_state() const { return initial_show_state_; }
208 void set_initial_show_state(ui::WindowShowState initial_show_state) {
209 initial_show_state_ = initial_show_state;
211 // Return true if the initial window bounds have been overridden.
212 bool bounds_overridden() const {
213 return !override_bounds_.IsEmpty();
215 // Set indicator that this browser is being created via session restore.
216 // This is used on the Mac (only) to determine animation style when the
217 // browser window is shown.
218 void set_is_session_restore(bool is_session_restore) {
219 is_session_restore_ = is_session_restore;
221 bool is_session_restore() const {
222 return is_session_restore_;
224 chrome::HostDesktopType host_desktop_type() const {
225 return host_desktop_type_;
228 // Accessors ////////////////////////////////////////////////////////////////
230 Type type() const { return type_; }
231 const std::string& app_name() const { return app_name_; }
232 AppType app_type() const { return app_type_; }
233 Profile* profile() const { return profile_; }
234 gfx::Rect override_bounds() const { return override_bounds_; }
236 // |window()| will return NULL if called before |CreateBrowserWindow()|
238 BrowserWindow* window() const { return window_; }
239 ToolbarModel* toolbar_model() { return toolbar_model_.get(); }
240 const ToolbarModel* toolbar_model() const { return toolbar_model_.get(); }
241 #if defined(UNIT_TEST)
242 void swap_toolbar_models(scoped_ptr<ToolbarModel>* toolbar_model) {
243 toolbar_model->swap(toolbar_model_);
246 TabStripModel* tab_strip_model() const { return tab_strip_model_.get(); }
247 chrome::BrowserCommandController* command_controller() {
248 return command_controller_.get();
250 SearchModel* search_model() { return search_model_.get(); }
251 const SearchModel* search_model() const {
252 return search_model_.get();
254 SearchDelegate* search_delegate() {
255 return search_delegate_.get();
257 const SessionID& session_id() const { return session_id_; }
258 BrowserContentSettingBubbleModelDelegate*
259 content_setting_bubble_model_delegate() {
260 return content_setting_bubble_model_delegate_.get();
262 BrowserTabRestoreServiceDelegate* tab_restore_service_delegate() {
263 return tab_restore_service_delegate_.get();
265 BrowserSyncedWindowDelegate* synced_window_delegate() {
266 return synced_window_delegate_.get();
268 BrowserInstantController* instant_controller() {
269 return instant_controller_.get();
272 // Get the FindBarController for this browser, creating it if it does not
274 FindBarController* GetFindBarController();
276 // Returns true if a FindBarController exists for this browser.
277 bool HasFindBarController() const;
279 // Returns the state of the bookmark bar.
280 BookmarkBar::State bookmark_bar_state() const { return bookmark_bar_state_; }
282 // State Storage and Retrieval for UI ///////////////////////////////////////
284 // Gets the Favicon of the page in the selected tab.
285 gfx::Image GetCurrentPageIcon() const;
287 // Gets the title of the window based on the selected tab's title.
288 string16 GetWindowTitleForCurrentTab() const;
290 // Prepares a title string for display (removes embedded newlines, etc).
291 static void FormatTitleForDisplay(string16* title);
293 // OnBeforeUnload handling //////////////////////////////////////////////////
295 // Gives beforeunload handlers the chance to cancel the close. Returns whether
296 // to proceed with the close. If called while the process begun by
297 // CallBeforeUnloadHandlers is in progress, returns false without taking
299 bool ShouldCloseWindow();
301 // Begins the process of confirming whether the associated browser can be
302 // closed. If there are no tabs with beforeunload handlers it will immediately
303 // return false. Otherwise, it starts prompting the user, returns true and
304 // will call |on_close_confirmed| with the result of the user's decision.
305 // After calling this function, if the window will not be closed, call
306 // ResetBeforeUnloadHandlers() to reset all beforeunload handlers; calling
307 // this function multiple times without an intervening call to
308 // ResetBeforeUnloadHandlers() will run only the beforeunload handlers
309 // registered since the previous call.
310 bool CallBeforeUnloadHandlers(
311 const base::Callback<void(bool)>& on_close_confirmed);
313 // Clears the results of any beforeunload confirmation dialogs triggered by a
314 // CallBeforeUnloadHandlers call.
315 void ResetBeforeUnloadHandlers();
317 // Figure out if there are tabs that have beforeunload handlers.
318 // It starts beforeunload/unload processing as a side-effect.
319 bool TabsNeedBeforeUnloadFired();
321 // Returns true if all tabs' beforeunload/unload events have fired.
322 bool HasCompletedUnloadProcessing() const;
324 bool IsAttemptingToCloseBrowser() const;
326 // Invoked when the window containing us is closing. Performs the necessary
328 void OnWindowClosing();
330 // In-progress download termination handling /////////////////////////////////
332 // Called when the user has decided whether to proceed or not with the browser
333 // closure. |cancel_downloads| is true if the downloads should be canceled
334 // and the browser closed, false if the browser should stay open and the
335 // downloads running.
336 void InProgressDownloadResponse(bool cancel_downloads);
338 // Indicates whether or not this browser window can be closed, or
339 // would be blocked by in-progress downloads.
340 // If executing downloads would be cancelled by this window close,
341 // then |*num_downloads_blocking| is updated with how many downloads
342 // would be canceled if the close continued.
343 DownloadClosePreventionType OkToCloseWithInProgressDownloads(
344 int* num_downloads_blocking) const;
346 // External state change handling ////////////////////////////////////////////
348 // Invoked when the fullscreen state of the window changes.
349 // BrowserWindow::EnterFullscreen invokes this after the window has become
351 void WindowFullscreenStateChanged();
353 // Invoked when visible SSL state (as defined by SSLStatus) changes.
354 void VisibleSSLStateChanged(content::WebContents* web_contents);
356 // Invoked when the |web_contents| no longer supports Instant. Refreshes the
357 // omnibox so it no longer shows search terms.
358 void OnWebContentsInstantSupportDisabled(
359 const content::WebContents* web_contents);
361 // Assorted browser commands ////////////////////////////////////////////////
363 // NOTE: Within each of the following sections, the IDs are ordered roughly by
364 // how they appear in the GUI/menus (left to right, top to bottom, etc.).
366 // See the description of
367 // FullscreenController::ToggleFullscreenModeWithExtension.
368 void ToggleFullscreenModeWithExtension(const GURL& extension_url);
370 // See the description of FullscreenController::ToggleMetroSnapMode.
371 void SetMetroSnapMode(bool enable);
374 // Returns true if the Browser supports the specified feature. The value of
375 // this varies during the lifetime of the browser. For example, if the window
376 // is fullscreen this may return a different value. If you only care about
377 // whether or not it's possible for the browser to support a particular
378 // feature use |CanSupportWindowFeature|.
379 bool SupportsWindowFeature(WindowFeature feature) const;
381 // Returns true if the Browser can support the specified feature. See comment
382 // in |SupportsWindowFeature| for details on this.
383 bool CanSupportWindowFeature(WindowFeature feature) const;
385 // TODO(port): port these, and re-merge the two function declaration lists.
386 // Page-related commands.
387 void ToggleEncodingAutoDetect();
388 void OverrideEncoding(int encoding_id);
390 // Show various bits of UI
393 void UpdateDownloadShelfVisibility(bool visible);
395 /////////////////////////////////////////////////////////////////////////////
397 // Helper function to run unload listeners on a WebContents.
398 static bool RunUnloadEventsHelper(content::WebContents* contents);
400 // Helper function to handle JS out of memory notifications
401 static void JSOutOfMemoryHelper(content::WebContents* web_contents);
403 // Helper function to register a protocol handler.
404 static void RegisterProtocolHandlerHelper(content::WebContents* web_contents,
405 const std::string& protocol,
407 const string16& title,
409 BrowserWindow* window);
411 // Helper function to handle find results.
412 static void FindReplyHelper(content::WebContents* web_contents,
414 int number_of_matches,
415 const gfx::Rect& selection_rect,
416 int active_match_ordinal,
419 // Called by chrome::Navigate() when a navigation has occurred in a tab in
420 // this Browser. Updates the UI for the start of this navigation.
421 void UpdateUIForNavigationInTab(content::WebContents* contents,
422 content::PageTransition transition,
423 bool user_initiated);
425 // Interface implementations ////////////////////////////////////////////////
427 // Overridden from content::PageNavigator:
428 virtual content::WebContents* OpenURL(
429 const content::OpenURLParams& params) OVERRIDE;
431 // Overridden from TabStripModelObserver:
432 virtual void TabInsertedAt(content::WebContents* contents,
434 bool foreground) OVERRIDE;
435 virtual void TabClosingAt(TabStripModel* tab_strip_model,
436 content::WebContents* contents,
438 virtual void TabDetachedAt(content::WebContents* contents,
440 virtual void TabDeactivated(content::WebContents* contents) OVERRIDE;
441 virtual void ActiveTabChanged(content::WebContents* old_contents,
442 content::WebContents* new_contents,
444 int reason) OVERRIDE;
445 virtual void TabMoved(content::WebContents* contents,
447 int to_index) OVERRIDE;
448 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
449 content::WebContents* old_contents,
450 content::WebContents* new_contents,
452 virtual void TabPinnedStateChanged(content::WebContents* contents,
454 virtual void TabStripEmpty() OVERRIDE;
456 // Overridden from content::WebContentsDelegate:
457 virtual bool CanOverscrollContent() const OVERRIDE;
458 virtual bool PreHandleKeyboardEvent(
459 content::WebContents* source,
460 const content::NativeWebKeyboardEvent& event,
461 bool* is_keyboard_shortcut) OVERRIDE;
462 virtual void HandleKeyboardEvent(
463 content::WebContents* source,
464 const content::NativeWebKeyboardEvent& event) OVERRIDE;
465 virtual void OverscrollUpdate(int delta_y) 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(FullscreenControllerTest,
506 TabEntersPresentationModeFromWindowed);
507 FRIEND_TEST_ALL_PREFIXES(FullscreenExitBubbleControllerTest,
508 DenyExitsFullscreen);
509 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref);
510 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
511 OpenAppShortcutWindowPref);
512 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref);
514 class InterstitialObserver;
516 // Used to describe why a tab is being detached. This is used by
517 // TabDetachedAtImpl.
519 // Result of TabDetachedAt.
522 // Result of TabReplacedAt.
525 // Result of the tab strip not having any significant tabs.
529 // Describes where the bookmark bar state change originated from.
530 enum BookmarkBarStateChangeReason {
531 // From the constructor.
532 BOOKMARK_BAR_STATE_CHANGE_INIT,
534 // Change is the result of the active tab changing.
535 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH,
537 // Change is the result of the bookmark bar pref changing.
538 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE,
540 // Change is the result of a state change in the active tab.
541 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE,
543 // Change is the result of window toggling in/out of fullscreen mode.
544 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN,
547 // Overridden from content::WebContentsDelegate:
548 virtual content::WebContents* OpenURLFromTab(
549 content::WebContents* source,
550 const content::OpenURLParams& params) OVERRIDE;
551 virtual void NavigationStateChanged(const content::WebContents* source,
552 unsigned changed_flags) OVERRIDE;
553 virtual void AddNewContents(content::WebContents* source,
554 content::WebContents* new_contents,
555 WindowOpenDisposition disposition,
556 const gfx::Rect& initial_pos,
558 bool* was_blocked) OVERRIDE;
559 virtual void ActivateContents(content::WebContents* contents) OVERRIDE;
560 virtual void DeactivateContents(content::WebContents* contents) OVERRIDE;
561 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE;
562 virtual void CloseContents(content::WebContents* source) OVERRIDE;
563 virtual void MoveContents(content::WebContents* source,
564 const gfx::Rect& pos) OVERRIDE;
565 virtual bool IsPopupOrPanel(
566 const content::WebContents* source) const OVERRIDE;
567 virtual void UpdateTargetURL(content::WebContents* source, int32 page_id,
568 const GURL& url) OVERRIDE;
569 virtual void ContentsMouseEvent(content::WebContents* source,
570 const gfx::Point& location,
571 bool motion) OVERRIDE;
572 virtual void ContentsZoomChange(bool zoom_in) OVERRIDE;
573 virtual void WebContentsFocused(content::WebContents* content) OVERRIDE;
574 virtual bool TakeFocus(content::WebContents* source, bool reverse) OVERRIDE;
575 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
576 virtual void BeforeUnloadFired(content::WebContents* source,
578 bool* proceed_to_fire_unload) OVERRIDE;
579 virtual bool ShouldFocusLocationBarByDefault(
580 content::WebContents* source) OVERRIDE;
581 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
582 virtual void RenderWidgetShowing() OVERRIDE;
583 virtual int GetExtraRenderViewHeight() const OVERRIDE;
584 virtual void ViewSourceForTab(content::WebContents* source,
585 const GURL& page_url) OVERRIDE;
586 virtual void ViewSourceForFrame(
587 content::WebContents* source,
588 const GURL& frame_url,
589 const content::PageState& frame_page_state) OVERRIDE;
590 virtual void ShowRepostFormWarningDialog(
591 content::WebContents* source) OVERRIDE;
592 virtual bool ShouldCreateWebContents(
593 content::WebContents* web_contents,
595 WindowContainerType window_container_type,
596 const string16& frame_name,
597 const GURL& target_url,
598 const std::string& partition_id,
599 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE;
600 virtual void WebContentsCreated(content::WebContents* source_contents,
601 int64 source_frame_id,
602 const string16& frame_name,
603 const GURL& target_url,
604 content::WebContents* new_contents) OVERRIDE;
605 virtual void RendererUnresponsive(content::WebContents* source) OVERRIDE;
606 virtual void RendererResponsive(content::WebContents* source) OVERRIDE;
607 virtual void WorkerCrashed(content::WebContents* source) OVERRIDE;
608 virtual void DidNavigateMainFramePostCommit(
609 content::WebContents* web_contents) OVERRIDE;
610 virtual void DidNavigateToPendingEntry(
611 content::WebContents* web_contents) OVERRIDE;
612 virtual content::JavaScriptDialogManager*
613 GetJavaScriptDialogManager() OVERRIDE;
614 virtual content::ColorChooser* OpenColorChooser(
615 content::WebContents* web_contents, SkColor color) OVERRIDE;
616 virtual void RunFileChooser(
617 content::WebContents* web_contents,
618 const content::FileChooserParams& params) OVERRIDE;
619 virtual void EnumerateDirectory(content::WebContents* web_contents,
621 const base::FilePath& path) OVERRIDE;
622 virtual bool EmbedsFullscreenWidget() const OVERRIDE;
623 virtual void ToggleFullscreenModeForTab(content::WebContents* web_contents,
624 bool enter_fullscreen) OVERRIDE;
625 virtual bool IsFullscreenForTabOrPending(
626 const content::WebContents* web_contents) const OVERRIDE;
627 virtual void JSOutOfMemory(content::WebContents* web_contents) OVERRIDE;
628 virtual void RegisterProtocolHandler(content::WebContents* web_contents,
629 const std::string& protocol,
631 const string16& title,
632 bool user_gesture) OVERRIDE;
633 virtual void UpdatePreferredSize(content::WebContents* source,
634 const gfx::Size& pref_size) OVERRIDE;
635 virtual void ResizeDueToAutoResize(content::WebContents* source,
636 const gfx::Size& new_size) OVERRIDE;
637 virtual void FindReply(content::WebContents* web_contents,
639 int number_of_matches,
640 const gfx::Rect& selection_rect,
641 int active_match_ordinal,
642 bool final_update) OVERRIDE;
643 virtual void RequestToLockMouse(content::WebContents* web_contents,
645 bool last_unlocked_by_target) OVERRIDE;
646 virtual void LostMouseLock() OVERRIDE;
647 virtual void RequestMediaAccessPermission(
648 content::WebContents* web_contents,
649 const content::MediaStreamRequest& request,
650 const content::MediaResponseCallback& callback) OVERRIDE;
651 virtual bool RequestPpapiBrokerPermission(
652 content::WebContents* web_contents,
654 const base::FilePath& plugin_path,
655 const base::Callback<void(bool)>& callback) OVERRIDE;
656 virtual gfx::Size GetSizeForNewRenderView(
657 const content::WebContents* web_contents) const OVERRIDE;
659 // Overridden from CoreTabHelperDelegate:
660 // Note that the caller is responsible for deleting |old_contents|.
661 virtual void SwapTabContents(content::WebContents* old_contents,
662 content::WebContents* new_contents) OVERRIDE;
663 virtual bool CanReloadContents(
664 content::WebContents* web_contents) const OVERRIDE;
665 virtual bool CanSaveContents(
666 content::WebContents* web_contents) const OVERRIDE;
668 // Overridden from SearchEngineTabHelperDelegate:
669 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
670 Profile* profile) OVERRIDE;
672 // Overridden from WebContentsModalDialogManagerDelegate:
673 virtual void SetWebContentsBlocked(content::WebContents* web_contents,
674 bool blocked) OVERRIDE;
675 virtual web_modal::WebContentsModalDialogHost*
676 GetWebContentsModalDialogHost() OVERRIDE;
678 // Overridden from BookmarkTabHelperDelegate:
679 virtual void URLStarredChanged(content::WebContents* web_contents,
680 bool starred) OVERRIDE;
682 // Overridden from ZoomObserver:
683 virtual void OnZoomChanged(content::WebContents* source,
684 bool can_show_bubble) OVERRIDE;
686 // Overridden from SelectFileDialog::Listener:
687 virtual void FileSelected(const base::FilePath& path,
689 void* params) OVERRIDE;
690 virtual void FileSelectedWithExtraInfo(
691 const ui::SelectedFileInfo& file_info,
693 void* params) OVERRIDE;
695 // Overridden from content::NotificationObserver:
696 virtual void Observe(int type,
697 const content::NotificationSource& source,
698 const content::NotificationDetails& details) OVERRIDE;
700 // Command and state updating ///////////////////////////////////////////////
702 // Handle changes to kDevTools preference.
703 void OnDevToolsDisabledChanged();
705 // UI update coalescing and handling ////////////////////////////////////////
707 // Asks the toolbar (and as such the location bar) to update its state to
708 // reflect the current tab's current URL, security state, etc.
709 // If |should_restore_state| is true, we're switching (back?) to this tab and
710 // should restore any previous location bar state (such as user editing) as
712 void UpdateToolbar(bool should_restore_state);
714 // Does one or both of the following for each bit in |changed_flags|:
715 // . If the update should be processed immediately, it is.
716 // . If the update should processed asynchronously (to avoid lots of ui
717 // updates), then scheduled_updates_ is updated for the |source| and update
718 // pair and a task is scheduled (assuming it isn't running already)
719 // that invokes ProcessPendingUIUpdates.
720 void ScheduleUIUpdate(const content::WebContents* source,
721 unsigned changed_flags);
723 // Processes all pending updates to the UI that have been scheduled by
724 // ScheduleUIUpdate in scheduled_updates_.
725 void ProcessPendingUIUpdates();
727 // Removes all entries from scheduled_updates_ whose source is contents.
728 void RemoveScheduledUpdatesFor(content::WebContents* contents);
730 // Getters for UI ///////////////////////////////////////////////////////////
732 // TODO(beng): remove, and provide AutomationProvider a better way to access
733 // the LocationBarView's edit.
734 friend class AutomationProvider;
735 friend class BrowserProxy;
736 friend class TestingAutomationProvider;
738 // Returns the StatusBubble from the current toolbar. It is possible for
739 // this to return NULL if called before the toolbar has initialized.
740 // TODO(beng): remove this.
741 StatusBubble* GetStatusBubble();
743 // Session restore functions ////////////////////////////////////////////////
745 // Notifies the history database of the index for all tabs whose index is
747 void SyncHistoryWithTabs(int index);
749 // In-progress download termination handling /////////////////////////////////
751 // Called when the window is closing to check if potential in-progress
752 // downloads should prevent it from closing.
753 // Returns true if the window can close, false otherwise.
754 bool CanCloseWithInProgressDownloads();
756 // Assorted utility functions ///////////////////////////////////////////////
758 // Sets the specified browser as the delegate of the WebContents and all the
759 // associated tab helpers that are needed.
760 void SetAsDelegate(content::WebContents* web_contents, Browser* delegate);
762 // Shows the Find Bar, optionally selecting the next entry that matches the
763 // existing search string for that Tab. |forward_direction| controls the
765 void FindInPage(bool find_next, bool forward_direction);
768 // TODO(beng): figure out if we need this now that the frame itself closes
769 // after a return to the message loop.
772 void TabDetachedAtImpl(content::WebContents* contents,
776 // Shared code between Reload() and ReloadIgnoringCache().
777 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache);
779 // Depending on the disposition, return the current tab or a clone of the
781 content::WebContents* GetOrCloneTabForDisposition(
782 WindowOpenDisposition disposition);
784 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
785 // |check_fullscreen| is true, the set of features reflect the actual state of
786 // the browser, otherwise the set of features reflect the possible state of
788 bool SupportsWindowFeatureImpl(WindowFeature feature,
789 bool check_fullscreen) const;
791 // Resets |bookmark_bar_state_| based on the active tab. Notifies the
792 // BrowserWindow if necessary.
793 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason);
795 bool ShouldHideUIForFullscreen() const;
797 // Creates a BackgroundContents if appropriate; return true if one was
799 bool MaybeCreateBackgroundContents(
801 content::WebContents* opener_web_contents,
802 const string16& frame_name,
803 const GURL& target_url,
804 const std::string& partition_id,
805 content::SessionStorageNamespace* session_storage_namespace);
807 // Data members /////////////////////////////////////////////////////////////
809 std::vector<InterstitialObserver*> interstitial_observers_;
811 content::NotificationRegistrar registrar_;
813 PrefChangeRegistrar profile_pref_registrar_;
815 // This Browser's type.
818 // This Browser's profile.
819 Profile* const profile_;
821 // This Browser's window.
822 BrowserWindow* window_;
824 scoped_ptr<TabStripModelDelegate> tab_strip_model_delegate_;
825 scoped_ptr<TabStripModel> tab_strip_model_;
827 // The application name that is also the name of the window to the shell.
828 // This name should be set when:
829 // 1) we launch an application via an application shortcut or extension API.
830 // 2) we launch an undocked devtool window.
831 std::string app_name_;
833 // Type of app (host or child). See description of AppType.
836 // Unique identifier of this browser for session restore. This id is only
837 // unique within the current session, and is not guaranteed to be unique
839 const SessionID session_id_;
841 // The model for the toolbar view.
842 scoped_ptr<ToolbarModel> toolbar_model_;
844 // The model for the "active" search state. There are per-tab search models
845 // as well. When a tab is active its model is kept in sync with this one.
846 // When a new tab is activated its model state is propagated to this active
847 // model. This way, observers only have to attach to this single model for
848 // updates, and don't have to worry about active tab changes directly.
849 scoped_ptr<SearchModel> search_model_;
851 // UI update coalescing and handling ////////////////////////////////////////
853 typedef std::map<const content::WebContents*, int> UpdateMap;
855 // Maps from WebContents to pending UI updates that need to be processed.
856 // We don't update things like the URL or tab title right away to avoid
857 // flickering and extra painting.
858 // See ScheduleUIUpdate and ProcessPendingUIUpdates.
859 UpdateMap scheduled_updates_;
861 // In-progress download termination handling /////////////////////////////////
863 enum CancelDownloadConfirmationState {
864 NOT_PROMPTED, // We have not asked the user.
865 WAITING_FOR_RESPONSE, // We have asked the user and have not received a
867 RESPONSE_RECEIVED // The user was prompted and made a decision already.
870 // State used to figure-out whether we should prompt the user for confirmation
871 // when the browser is closed with in-progress downloads.
872 CancelDownloadConfirmationState cancel_download_confirmation_state_;
874 /////////////////////////////////////////////////////////////////////////////
876 // Override values for the bounds of the window and its maximized or minimized
878 // These are supplied by callers that don't want to use the default values.
879 // The default values are typically loaded from local state (last session),
880 // obtained from the last window of the same type, or obtained from the
881 // shell shortcut's startup info.
882 gfx::Rect override_bounds_;
883 ui::WindowShowState initial_show_state_;
885 // Tracks when this browser is being created by session restore.
886 bool is_session_restore_;
888 const chrome::HostDesktopType host_desktop_type_;
890 scoped_ptr<chrome::UnloadController> unload_controller_;
891 scoped_ptr<chrome::FastUnloadController> fast_unload_controller_;
893 // The Find Bar. This may be NULL if there is no Find Bar, and if it is
894 // non-NULL, it may or may not be visible.
895 scoped_ptr<FindBarController> find_bar_controller_;
897 // Dialog box used for opening and saving files.
898 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
900 // Keep track of the encoding auto detect pref.
901 BooleanPrefMember encoding_auto_detect_;
903 // Helper which implements the ContentSettingBubbleModel interface.
904 scoped_ptr<BrowserContentSettingBubbleModelDelegate>
905 content_setting_bubble_model_delegate_;
907 // Helper which implements the ToolbarModelDelegate interface.
908 scoped_ptr<BrowserToolbarModelDelegate> toolbar_model_delegate_;
910 // A delegate that handles the details of updating the "active"
911 // |search_model_| state with the tab's state.
912 scoped_ptr<SearchDelegate> search_delegate_;
914 // Helper which implements the TabRestoreServiceDelegate interface.
915 scoped_ptr<BrowserTabRestoreServiceDelegate> tab_restore_service_delegate_;
917 // Helper which implements the SyncedWindowDelegate interface.
918 scoped_ptr<BrowserSyncedWindowDelegate> synced_window_delegate_;
920 scoped_ptr<BrowserInstantController> instant_controller_;
922 BookmarkBar::State bookmark_bar_state_;
924 scoped_ptr<FullscreenController> fullscreen_controller_;
926 scoped_ptr<extensions::WindowController> extension_window_controller_;
928 scoped_ptr<chrome::BrowserCommandController> command_controller_;
930 // True if the browser window has been shown at least once.
931 bool window_has_shown_;
933 // The following factory is used for chrome update coalescing.
934 base::WeakPtrFactory<Browser> chrome_updater_factory_;
936 // The following factory is used to close the frame at a later time.
937 base::WeakPtrFactory<Browser> weak_factory_;
939 scoped_ptr<BrowserLanguageStateObserver> language_state_observer_;
941 DISALLOW_COPY_AND_ASSIGN(Browser);
944 #endif // CHROME_BROWSER_UI_BROWSER_H_