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/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 "chrome/common/content_settings.h"
35 #include "components/content_settings/core/common/content_settings_types.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 BrowserContentTranslateDriverObserver;
49 class BrowserInstantController;
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;
69 class ValidationMessageBubble;
73 class NavigationController;
75 class SessionStorageNamespace;
78 namespace extensions {
80 class WindowController;
89 struct SelectedFileInfo;
90 class WebDialogDelegate;
94 class WebContentsModalDialogHost;
97 class Browser : public TabStripModelObserver,
98 public content::WebContentsDelegate,
99 public CoreTabHelperDelegate,
100 public SearchEngineTabHelperDelegate,
101 public SearchTabHelperDelegate,
102 public ChromeWebModalDialogManagerDelegate,
103 public BookmarkTabHelperDelegate,
105 public content::PageNavigator,
106 public content::NotificationObserver,
107 public ui::SelectFileDialog::Listener {
109 // SessionService::WindowType mirrors these values. If you add to this
110 // enum, look at SessionService::WindowType to see if it needs to be
113 // If you add a new type, consider updating the test
114 // BrowserTest.StartMaximized.
119 // Possible elements of the Browser window.
122 FEATURE_TITLEBAR = 1,
123 FEATURE_TABSTRIP = 2,
125 FEATURE_LOCATIONBAR = 8,
126 FEATURE_BOOKMARKBAR = 16,
127 FEATURE_INFOBAR = 32,
128 FEATURE_DOWNLOADSHELF = 64
131 // The context for a download blocked notification from
132 // OkToCloseWithInProgressDownloads.
133 enum DownloadClosePreventionType {
134 // Browser close is not blocked by download state.
137 // The browser is shutting down and there are active downloads
138 // that would be cancelled.
139 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN,
141 // There are active downloads associated with this incognito profile
142 // that would be canceled.
143 DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE,
146 struct CreateParams {
147 CreateParams(Profile* profile, chrome::HostDesktopType host_desktop_type);
148 CreateParams(Type type,
150 chrome::HostDesktopType host_desktop_type);
152 static CreateParams CreateForApp(const std::string& app_name,
154 const gfx::Rect& window_bounds,
156 chrome::HostDesktopType host_desktop_type);
158 static CreateParams CreateForDevTools(
160 chrome::HostDesktopType host_desktop_type);
165 // The associated profile.
168 // The host desktop the browser is created on.
169 chrome::HostDesktopType host_desktop_type;
171 // Specifies the browser is_trusted_source_ value.
174 // The bounds of the window to open.
175 gfx::Rect initial_bounds;
177 ui::WindowShowState initial_show_state;
179 bool is_session_restore;
181 // Supply a custom BrowserWindow implementation, to be used instead of the
182 // default. Intended for testing.
183 BrowserWindow* window;
186 friend class Browser;
188 // The application name that is also the name of the window to the shell.
189 // Do not set this value directly, use CreateForApp.
190 // This name will be set for:
191 // 1) v1 applications launched via an application shortcut or extension API.
192 // 2) undocked devtool windows.
193 // 3) popup windows spawned from v1 applications.
194 std::string app_name;
197 // Constructors, Creation, Showing //////////////////////////////////////////
199 explicit Browser(const CreateParams& params);
202 // Set overrides for the initial window bounds and maximized state.
203 void set_override_bounds(const gfx::Rect& bounds) {
204 override_bounds_ = bounds;
206 ui::WindowShowState initial_show_state() const { return initial_show_state_; }
207 void set_initial_show_state(ui::WindowShowState initial_show_state) {
208 initial_show_state_ = initial_show_state;
210 // Return true if the initial window bounds have been overridden.
211 bool bounds_overridden() const {
212 return !override_bounds_.IsEmpty();
214 // Set indicator that this browser is being created via session restore.
215 // This is used on the Mac (only) to determine animation style when the
216 // browser window is shown.
217 void set_is_session_restore(bool is_session_restore) {
218 is_session_restore_ = is_session_restore;
220 bool is_session_restore() const {
221 return is_session_restore_;
223 chrome::HostDesktopType host_desktop_type() const {
224 return host_desktop_type_;
227 // Accessors ////////////////////////////////////////////////////////////////
229 Type type() const { return type_; }
230 const std::string& app_name() const { return app_name_; }
231 bool is_trusted_source() const { return is_trusted_source_; }
232 Profile* profile() const { return profile_; }
233 gfx::Rect override_bounds() const { return override_bounds_; }
235 // |window()| will return NULL if called before |CreateBrowserWindow()|
237 BrowserWindow* window() const { return window_; }
238 ToolbarModel* toolbar_model() { return toolbar_model_.get(); }
239 const ToolbarModel* toolbar_model() const { return toolbar_model_.get(); }
240 #if defined(UNIT_TEST)
241 void swap_toolbar_models(scoped_ptr<ToolbarModel>* toolbar_model) {
242 toolbar_model->swap(toolbar_model_);
245 TabStripModel* tab_strip_model() const { return tab_strip_model_.get(); }
246 chrome::BrowserCommandController* command_controller() {
247 return command_controller_.get();
249 SearchModel* search_model() { return search_model_.get(); }
250 const SearchModel* search_model() const {
251 return search_model_.get();
253 SearchDelegate* search_delegate() {
254 return search_delegate_.get();
256 const SessionID& session_id() const { return session_id_; }
257 BrowserContentSettingBubbleModelDelegate*
258 content_setting_bubble_model_delegate() {
259 return content_setting_bubble_model_delegate_.get();
261 BrowserTabRestoreServiceDelegate* tab_restore_service_delegate() {
262 return tab_restore_service_delegate_.get();
264 BrowserSyncedWindowDelegate* synced_window_delegate() {
265 return synced_window_delegate_.get();
267 BrowserInstantController* instant_controller() {
268 return instant_controller_.get();
271 // Get the FindBarController for this browser, creating it if it does not
273 FindBarController* GetFindBarController();
275 // Returns true if a FindBarController exists for this browser.
276 bool HasFindBarController() const;
278 // Returns the state of the bookmark bar.
279 BookmarkBar::State bookmark_bar_state() const { return bookmark_bar_state_; }
281 // State Storage and Retrieval for UI ///////////////////////////////////////
283 // Gets the Favicon of the page in the selected tab.
284 gfx::Image GetCurrentPageIcon() const;
286 // Gets the title of the window based on the selected tab's title.
287 base::string16 GetWindowTitleForCurrentTab() const;
289 // Prepares a title string for display (removes embedded newlines, etc).
290 static void FormatTitleForDisplay(base::string16* title);
292 // OnBeforeUnload handling //////////////////////////////////////////////////
294 // Gives beforeunload handlers the chance to cancel the close. Returns whether
295 // to proceed with the close. If called while the process begun by
296 // CallBeforeUnloadHandlers is in progress, returns false without taking
298 bool ShouldCloseWindow();
300 // Begins the process of confirming whether the associated browser can be
301 // closed. If there are no tabs with beforeunload handlers it will immediately
302 // return false. Otherwise, it starts prompting the user, returns true and
303 // will call |on_close_confirmed| with the result of the user's decision.
304 // After calling this function, if the window will not be closed, call
305 // ResetBeforeUnloadHandlers() to reset all beforeunload handlers; calling
306 // this function multiple times without an intervening call to
307 // ResetBeforeUnloadHandlers() will run only the beforeunload handlers
308 // registered since the previous call.
309 bool CallBeforeUnloadHandlers(
310 const base::Callback<void(bool)>& on_close_confirmed);
312 // Clears the results of any beforeunload confirmation dialogs triggered by a
313 // CallBeforeUnloadHandlers call.
314 void ResetBeforeUnloadHandlers();
316 // Figure out if there are tabs that have beforeunload handlers.
317 // It starts beforeunload/unload processing as a side-effect.
318 bool TabsNeedBeforeUnloadFired();
320 // Returns true if all tabs' beforeunload/unload events have fired.
321 bool HasCompletedUnloadProcessing() const;
323 bool IsAttemptingToCloseBrowser() const;
325 // Invoked when the window containing us is closing. Performs the necessary
327 void OnWindowClosing();
329 // In-progress download termination handling /////////////////////////////////
331 // Called when the user has decided whether to proceed or not with the browser
332 // closure. |cancel_downloads| is true if the downloads should be canceled
333 // and the browser closed, false if the browser should stay open and the
334 // downloads running.
335 void InProgressDownloadResponse(bool cancel_downloads);
337 // Indicates whether or not this browser window can be closed, or
338 // would be blocked by in-progress downloads.
339 // If executing downloads would be cancelled by this window close,
340 // then |*num_downloads_blocking| is updated with how many downloads
341 // would be canceled if the close continued.
342 DownloadClosePreventionType OkToCloseWithInProgressDownloads(
343 int* num_downloads_blocking) const;
345 // External state change handling ////////////////////////////////////////////
347 // Invoked when the fullscreen state of the window changes.
348 // BrowserWindow::EnterFullscreen invokes this after the window has become
350 void WindowFullscreenStateChanged();
352 // Assorted browser commands ////////////////////////////////////////////////
354 // NOTE: Within each of the following sections, the IDs are ordered roughly by
355 // how they appear in the GUI/menus (left to right, top to bottom, etc.).
357 // See the description of
358 // FullscreenController::ToggleFullscreenModeWithExtension.
359 void ToggleFullscreenModeWithExtension(const GURL& extension_url);
362 // See the description of FullscreenController::ToggleMetroSnapMode.
363 void SetMetroSnapMode(bool enable);
366 // Returns true if the Browser supports the specified feature. The value of
367 // this varies during the lifetime of the browser. For example, if the window
368 // is fullscreen this may return a different value. If you only care about
369 // whether or not it's possible for the browser to support a particular
370 // feature use |CanSupportWindowFeature|.
371 bool SupportsWindowFeature(WindowFeature feature) const;
373 // Returns true if the Browser can support the specified feature. See comment
374 // in |SupportsWindowFeature| for details on this.
375 bool CanSupportWindowFeature(WindowFeature feature) const;
377 // TODO(port): port these, and re-merge the two function declaration lists.
378 // Page-related commands.
379 void ToggleEncodingAutoDetect();
380 void OverrideEncoding(int encoding_id);
382 // Show various bits of UI
385 void UpdateDownloadShelfVisibility(bool visible);
387 /////////////////////////////////////////////////////////////////////////////
389 // Called by chrome::Navigate() when a navigation has occurred in a tab in
390 // this Browser. Updates the UI for the start of this navigation.
391 void UpdateUIForNavigationInTab(content::WebContents* contents,
392 content::PageTransition transition,
393 bool user_initiated);
395 // Interface implementations ////////////////////////////////////////////////
397 // Overridden from content::PageNavigator:
398 virtual content::WebContents* OpenURL(
399 const content::OpenURLParams& params) OVERRIDE;
401 // Overridden from TabStripModelObserver:
402 virtual void TabInsertedAt(content::WebContents* contents,
404 bool foreground) OVERRIDE;
405 virtual void TabClosingAt(TabStripModel* tab_strip_model,
406 content::WebContents* contents,
408 virtual void TabDetachedAt(content::WebContents* contents,
410 virtual void TabDeactivated(content::WebContents* contents) OVERRIDE;
411 virtual void ActiveTabChanged(content::WebContents* old_contents,
412 content::WebContents* new_contents,
414 int reason) OVERRIDE;
415 virtual void TabMoved(content::WebContents* contents,
417 int to_index) OVERRIDE;
418 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
419 content::WebContents* old_contents,
420 content::WebContents* new_contents,
422 virtual void TabPinnedStateChanged(content::WebContents* contents,
424 virtual void TabStripEmpty() OVERRIDE;
426 // Overridden from content::WebContentsDelegate:
427 virtual bool CanOverscrollContent() const OVERRIDE;
428 virtual bool ShouldPreserveAbortedURLs(content::WebContents* source) OVERRIDE;
429 virtual bool PreHandleKeyboardEvent(
430 content::WebContents* source,
431 const content::NativeWebKeyboardEvent& event,
432 bool* is_keyboard_shortcut) OVERRIDE;
433 virtual void HandleKeyboardEvent(
434 content::WebContents* source,
435 const content::NativeWebKeyboardEvent& event) OVERRIDE;
436 virtual void OverscrollUpdate(int delta_y) OVERRIDE;
437 virtual void ShowValidationMessage(content::WebContents* web_contents,
438 const gfx::Rect& anchor_in_root_view,
439 const base::string16& main_text,
440 const base::string16& sub_text) OVERRIDE;
441 virtual void HideValidationMessage(
442 content::WebContents* web_contents) OVERRIDE;
443 virtual void MoveValidationMessage(
444 content::WebContents* web_contents,
445 const gfx::Rect& anchor_in_root_view) OVERRIDE;
446 virtual bool PreHandleGestureEvent(
447 content::WebContents* source,
448 const blink::WebGestureEvent& event) OVERRIDE;
449 virtual bool CanDragEnter(
450 content::WebContents* source,
451 const content::DropData& data,
452 blink::WebDragOperationsMask operations_allowed) OVERRIDE;
454 bool is_type_tabbed() const { return type_ == TYPE_TABBED; }
455 bool is_type_popup() const { return type_ == TYPE_POPUP; }
458 bool is_devtools() const;
460 // True when the mouse cursor is locked.
461 bool IsMouseLocked() const;
463 // Called each time the browser window is shown.
464 void OnWindowDidShow();
466 // Show the first run search engine bubble on the location bar.
467 void ShowFirstRunBubble();
469 // Show a download on the download shelf.
470 void ShowDownload(content::DownloadItem* download);
472 FullscreenController* fullscreen_controller() const {
473 return fullscreen_controller_.get();
476 extensions::WindowController* extension_window_controller() const {
477 return extension_window_controller_.get();
481 friend class BrowserTest;
482 friend class FullscreenControllerInteractiveTest;
483 friend class FullscreenControllerTest;
484 FRIEND_TEST_ALL_PREFIXES(AppModeTest, EnableAppModeTest);
485 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest,
486 IsReservedCommandOrKeyIsApp);
487 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest, AppFullScreen);
488 FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups);
489 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ConvertTabToAppShortcut);
490 FRIEND_TEST_ALL_PREFIXES(BrowserTest, OpenAppWindowLikeNtp);
491 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch);
492 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ShouldShowLocationBar);
493 FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest,
494 TabEntersPresentationModeFromWindowed);
495 FRIEND_TEST_ALL_PREFIXES(FullscreenExitBubbleControllerTest,
496 DenyExitsFullscreen);
497 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref);
498 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
499 OpenAppShortcutWindowPref);
500 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref);
502 class InterstitialObserver;
504 // Used to describe why a tab is being detached. This is used by
505 // TabDetachedAtImpl.
507 // Result of TabDetachedAt.
510 // Result of TabReplacedAt.
513 // Result of the tab strip not having any significant tabs.
517 // Describes where the bookmark bar state change originated from.
518 enum BookmarkBarStateChangeReason {
519 // From the constructor.
520 BOOKMARK_BAR_STATE_CHANGE_INIT,
522 // Change is the result of the active tab changing.
523 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH,
525 // Change is the result of the bookmark bar pref changing.
526 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE,
528 // Change is the result of a state change in the active tab.
529 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE,
531 // Change is the result of window toggling in/out of fullscreen mode.
532 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN,
535 // Overridden from content::WebContentsDelegate:
536 virtual content::WebContents* OpenURLFromTab(
537 content::WebContents* source,
538 const content::OpenURLParams& params) OVERRIDE;
539 virtual void NavigationStateChanged(
540 const content::WebContents* source,
541 content::InvalidateTypes changed_flags) OVERRIDE;
542 virtual void VisibleSSLStateChanged(
543 const content::WebContents* source) OVERRIDE;
544 virtual void AddNewContents(content::WebContents* source,
545 content::WebContents* new_contents,
546 WindowOpenDisposition disposition,
547 const gfx::Rect& initial_pos,
549 bool* was_blocked) OVERRIDE;
550 virtual void ActivateContents(content::WebContents* contents) OVERRIDE;
551 virtual void DeactivateContents(content::WebContents* contents) OVERRIDE;
552 virtual void LoadingStateChanged(content::WebContents* source,
553 bool to_different_document) OVERRIDE;
554 virtual void CloseContents(content::WebContents* source) OVERRIDE;
555 virtual void MoveContents(content::WebContents* source,
556 const gfx::Rect& pos) OVERRIDE;
557 virtual bool IsPopupOrPanel(
558 const content::WebContents* source) const OVERRIDE;
559 virtual void UpdateTargetURL(content::WebContents* source, int32 page_id,
560 const GURL& url) OVERRIDE;
561 virtual void ContentsMouseEvent(content::WebContents* source,
562 const gfx::Point& location,
563 bool motion) OVERRIDE;
564 virtual void ContentsZoomChange(bool zoom_in) OVERRIDE;
565 virtual void WebContentsFocused(content::WebContents* content) OVERRIDE;
566 virtual bool TakeFocus(content::WebContents* source, bool reverse) OVERRIDE;
567 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
568 virtual void BeforeUnloadFired(content::WebContents* source,
570 bool* proceed_to_fire_unload) OVERRIDE;
571 virtual bool ShouldFocusLocationBarByDefault(
572 content::WebContents* source) OVERRIDE;
573 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
574 virtual int GetExtraRenderViewHeight() const OVERRIDE;
575 virtual void ViewSourceForTab(content::WebContents* source,
576 const GURL& page_url) OVERRIDE;
577 virtual void ViewSourceForFrame(
578 content::WebContents* source,
579 const GURL& frame_url,
580 const content::PageState& frame_page_state) OVERRIDE;
581 virtual void ShowRepostFormWarningDialog(
582 content::WebContents* source) OVERRIDE;
583 virtual bool ShouldCreateWebContents(
584 content::WebContents* web_contents,
586 WindowContainerType window_container_type,
587 const base::string16& frame_name,
588 const GURL& target_url,
589 const std::string& partition_id,
590 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE;
591 virtual void WebContentsCreated(content::WebContents* source_contents,
592 int opener_render_frame_id,
593 const base::string16& frame_name,
594 const GURL& target_url,
595 content::WebContents* new_contents) OVERRIDE;
596 virtual void RendererUnresponsive(content::WebContents* source) OVERRIDE;
597 virtual void RendererResponsive(content::WebContents* source) OVERRIDE;
598 virtual void WorkerCrashed(content::WebContents* source) OVERRIDE;
599 virtual void DidNavigateMainFramePostCommit(
600 content::WebContents* web_contents) OVERRIDE;
601 virtual void DidNavigateToPendingEntry(
602 content::WebContents* web_contents) OVERRIDE;
603 virtual content::JavaScriptDialogManager*
604 GetJavaScriptDialogManager() OVERRIDE;
605 virtual content::ColorChooser* OpenColorChooser(
606 content::WebContents* web_contents,
608 const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE;
609 virtual void RunFileChooser(
610 content::WebContents* web_contents,
611 const content::FileChooserParams& params) OVERRIDE;
612 virtual void EnumerateDirectory(content::WebContents* web_contents,
614 const base::FilePath& path) OVERRIDE;
615 virtual bool EmbedsFullscreenWidget() const OVERRIDE;
616 virtual void ToggleFullscreenModeForTab(content::WebContents* web_contents,
617 bool enter_fullscreen) OVERRIDE;
618 virtual bool IsFullscreenForTabOrPending(
619 const content::WebContents* web_contents) const OVERRIDE;
620 virtual void RegisterProtocolHandler(content::WebContents* web_contents,
621 const std::string& protocol,
623 bool user_gesture) OVERRIDE;
624 virtual void UnregisterProtocolHandler(content::WebContents* web_contents,
625 const std::string& protocol,
627 bool user_gesture) OVERRIDE;
628 virtual void UpdatePreferredSize(content::WebContents* source,
629 const gfx::Size& pref_size) OVERRIDE;
630 virtual void ResizeDueToAutoResize(content::WebContents* source,
631 const gfx::Size& new_size) OVERRIDE;
632 virtual void FindReply(content::WebContents* web_contents,
634 int number_of_matches,
635 const gfx::Rect& selection_rect,
636 int active_match_ordinal,
637 bool final_update) OVERRIDE;
638 virtual void RequestToLockMouse(content::WebContents* web_contents,
640 bool last_unlocked_by_target) OVERRIDE;
641 virtual void LostMouseLock() OVERRIDE;
642 virtual void RequestMediaAccessPermission(
643 content::WebContents* web_contents,
644 const content::MediaStreamRequest& request,
645 const content::MediaResponseCallback& callback) OVERRIDE;
646 virtual bool RequestPpapiBrokerPermission(
647 content::WebContents* web_contents,
649 const base::FilePath& plugin_path,
650 const base::Callback<void(bool)>& callback) OVERRIDE;
651 virtual gfx::Size GetSizeForNewRenderView(
652 content::WebContents* web_contents) const OVERRIDE;
654 // Overridden from CoreTabHelperDelegate:
655 // Note that the caller is responsible for deleting |old_contents|.
656 virtual void SwapTabContents(content::WebContents* old_contents,
657 content::WebContents* new_contents,
659 bool did_finish_load) OVERRIDE;
660 virtual bool CanReloadContents(
661 content::WebContents* web_contents) const OVERRIDE;
662 virtual bool CanSaveContents(
663 content::WebContents* web_contents) const OVERRIDE;
665 // Overridden from SearchEngineTabHelperDelegate:
666 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
667 Profile* profile) OVERRIDE;
669 // Overridden from SearchTabHelperDelegate:
670 virtual void NavigateOnThumbnailClick(
672 WindowOpenDisposition disposition,
673 content::WebContents* source_contents) OVERRIDE;
674 virtual void OnWebContentsInstantSupportDisabled(
675 const content::WebContents* web_contents) OVERRIDE;
676 virtual OmniboxView* GetOmniboxView() OVERRIDE;
677 virtual std::set<std::string> GetOpenUrls() OVERRIDE;
679 // Overridden from WebContentsModalDialogManagerDelegate:
680 virtual void SetWebContentsBlocked(content::WebContents* web_contents,
681 bool blocked) OVERRIDE;
682 virtual web_modal::WebContentsModalDialogHost*
683 GetWebContentsModalDialogHost() OVERRIDE;
685 // Overridden from BookmarkTabHelperDelegate:
686 virtual void URLStarredChanged(content::WebContents* web_contents,
687 bool starred) OVERRIDE;
689 // Overridden from ZoomObserver:
690 virtual void OnZoomChanged(
691 const ZoomController::ZoomChangedEventData& data) OVERRIDE;
693 // Overridden from SelectFileDialog::Listener:
694 virtual void FileSelected(const base::FilePath& path,
696 void* params) OVERRIDE;
697 virtual void FileSelectedWithExtraInfo(
698 const ui::SelectedFileInfo& file_info,
700 void* params) OVERRIDE;
702 // Overridden from content::NotificationObserver:
703 virtual void Observe(int type,
704 const content::NotificationSource& source,
705 const content::NotificationDetails& details) OVERRIDE;
707 // Command and state updating ///////////////////////////////////////////////
709 // Handle changes to kDevTools preference.
710 void OnDevToolsDisabledChanged();
712 // UI update coalescing and handling ////////////////////////////////////////
714 // Asks the toolbar (and as such the location bar) to update its state to
715 // reflect the current tab's current URL, security state, etc.
716 // If |should_restore_state| is true, we're switching (back?) to this tab and
717 // should restore any previous location bar state (such as user editing) as
719 void UpdateToolbar(bool should_restore_state);
721 // Does one or both of the following for each bit in |changed_flags|:
722 // . If the update should be processed immediately, it is.
723 // . If the update should processed asynchronously (to avoid lots of ui
724 // updates), then scheduled_updates_ is updated for the |source| and update
725 // pair and a task is scheduled (assuming it isn't running already)
726 // that invokes ProcessPendingUIUpdates.
727 void ScheduleUIUpdate(const content::WebContents* source,
728 unsigned changed_flags);
730 // Processes all pending updates to the UI that have been scheduled by
731 // ScheduleUIUpdate in scheduled_updates_.
732 void ProcessPendingUIUpdates();
734 // Removes all entries from scheduled_updates_ whose source is contents.
735 void RemoveScheduledUpdatesFor(content::WebContents* contents);
737 // Getters for UI ///////////////////////////////////////////////////////////
739 // TODO(beng): remove, and provide AutomationProvider a better way to access
740 // the LocationBarView's edit.
741 friend class AutomationProvider;
742 friend class BrowserProxy;
743 friend class TestingAutomationProvider;
745 // Returns the StatusBubble from the current toolbar. It is possible for
746 // this to return NULL if called before the toolbar has initialized.
747 // TODO(beng): remove this.
748 StatusBubble* GetStatusBubble();
750 // Session restore functions ////////////////////////////////////////////////
752 // Notifies the history database of the index for all tabs whose index is
754 void SyncHistoryWithTabs(int index);
756 // In-progress download termination handling /////////////////////////////////
758 // Called when the window is closing to check if potential in-progress
759 // downloads should prevent it from closing.
760 // Returns true if the window can close, false otherwise.
761 bool CanCloseWithInProgressDownloads();
763 // Assorted utility functions ///////////////////////////////////////////////
765 // Sets the specified browser as the delegate of the WebContents and all the
766 // associated tab helpers that are needed. If |set_delegate| is true, this
767 // browser object is set as a delegate for |web_contents| components, else
768 // is is removed as a delegate.
769 void SetAsDelegate(content::WebContents* web_contents, bool set_delegate);
771 // Shows the Find Bar, optionally selecting the next entry that matches the
772 // existing search string for that Tab. |forward_direction| controls the
774 void FindInPage(bool find_next, bool forward_direction);
777 // TODO(beng): figure out if we need this now that the frame itself closes
778 // after a return to the message loop.
781 void TabDetachedAtImpl(content::WebContents* contents,
785 // Shared code between Reload() and ReloadIgnoringCache().
786 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache);
788 // Returns true if the Browser window should show the location bar.
789 bool ShouldShowLocationBar() const;
791 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
792 // |check_fullscreen| is true, the set of features reflect the actual state of
793 // the browser, otherwise the set of features reflect the possible state of
795 bool SupportsWindowFeatureImpl(WindowFeature feature,
796 bool check_fullscreen) const;
798 // Resets |bookmark_bar_state_| based on the active tab. Notifies the
799 // BrowserWindow if necessary.
800 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason);
802 bool ShouldHideUIForFullscreen() const;
804 // Creates a BackgroundContents if appropriate; return true if one was
806 bool MaybeCreateBackgroundContents(
808 content::WebContents* opener_web_contents,
809 const base::string16& frame_name,
810 const GURL& target_url,
811 const std::string& partition_id,
812 content::SessionStorageNamespace* session_storage_namespace);
814 // Data members /////////////////////////////////////////////////////////////
816 std::vector<InterstitialObserver*> interstitial_observers_;
818 content::NotificationRegistrar registrar_;
820 PrefChangeRegistrar profile_pref_registrar_;
822 // This Browser's type.
825 // This Browser's profile.
826 Profile* const profile_;
828 // This Browser's window.
829 BrowserWindow* window_;
831 scoped_ptr<TabStripModelDelegate> tab_strip_model_delegate_;
832 scoped_ptr<TabStripModel> tab_strip_model_;
834 // The application name that is also the name of the window to the shell.
835 // This name should be set when:
836 // 1) we launch an application via an application shortcut or extension API.
837 // 2) we launch an undocked devtool window.
838 std::string app_name_;
840 // True if the source is trusted (i.e. we do not need to show the URL in a
841 // a popup window). Also used to determine which app windows to save and
842 // restore on Chrome OS.
843 bool is_trusted_source_;
845 // Unique identifier of this browser for session restore. This id is only
846 // unique within the current session, and is not guaranteed to be unique
848 const SessionID session_id_;
850 // The model for the toolbar view.
851 scoped_ptr<ToolbarModel> toolbar_model_;
853 // The model for the "active" search state. There are per-tab search models
854 // as well. When a tab is active its model is kept in sync with this one.
855 // When a new tab is activated its model state is propagated to this active
856 // model. This way, observers only have to attach to this single model for
857 // updates, and don't have to worry about active tab changes directly.
858 scoped_ptr<SearchModel> search_model_;
860 // UI update coalescing and handling ////////////////////////////////////////
862 typedef std::map<const content::WebContents*, int> UpdateMap;
864 // Maps from WebContents to pending UI updates that need to be processed.
865 // We don't update things like the URL or tab title right away to avoid
866 // flickering and extra painting.
867 // See ScheduleUIUpdate and ProcessPendingUIUpdates.
868 UpdateMap scheduled_updates_;
870 // In-progress download termination handling /////////////////////////////////
872 enum CancelDownloadConfirmationState {
873 NOT_PROMPTED, // We have not asked the user.
874 WAITING_FOR_RESPONSE, // We have asked the user and have not received a
876 RESPONSE_RECEIVED // The user was prompted and made a decision already.
879 // State used to figure-out whether we should prompt the user for confirmation
880 // when the browser is closed with in-progress downloads.
881 CancelDownloadConfirmationState cancel_download_confirmation_state_;
883 /////////////////////////////////////////////////////////////////////////////
885 // Override values for the bounds of the window and its maximized or minimized
887 // These are supplied by callers that don't want to use the default values.
888 // The default values are typically loaded from local state (last session),
889 // obtained from the last window of the same type, or obtained from the
890 // shell shortcut's startup info.
891 gfx::Rect override_bounds_;
892 ui::WindowShowState initial_show_state_;
894 // Tracks when this browser is being created by session restore.
895 bool is_session_restore_;
897 const chrome::HostDesktopType host_desktop_type_;
899 scoped_ptr<chrome::UnloadController> unload_controller_;
900 scoped_ptr<chrome::FastUnloadController> fast_unload_controller_;
902 // The Find Bar. This may be NULL if there is no Find Bar, and if it is
903 // non-NULL, it may or may not be visible.
904 scoped_ptr<FindBarController> find_bar_controller_;
906 // Dialog box used for opening and saving files.
907 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
909 // Keep track of the encoding auto detect pref.
910 BooleanPrefMember encoding_auto_detect_;
912 // Helper which implements the ContentSettingBubbleModel interface.
913 scoped_ptr<BrowserContentSettingBubbleModelDelegate>
914 content_setting_bubble_model_delegate_;
916 // Helper which implements the ToolbarModelDelegate interface.
917 scoped_ptr<BrowserToolbarModelDelegate> toolbar_model_delegate_;
919 // A delegate that handles the details of updating the "active"
920 // |search_model_| state with the tab's state.
921 scoped_ptr<SearchDelegate> search_delegate_;
923 // Helper which implements the TabRestoreServiceDelegate interface.
924 scoped_ptr<BrowserTabRestoreServiceDelegate> tab_restore_service_delegate_;
926 // Helper which implements the SyncedWindowDelegate interface.
927 scoped_ptr<BrowserSyncedWindowDelegate> synced_window_delegate_;
929 scoped_ptr<BrowserInstantController> instant_controller_;
931 BookmarkBar::State bookmark_bar_state_;
933 scoped_ptr<FullscreenController> fullscreen_controller_;
935 scoped_ptr<extensions::WindowController> extension_window_controller_;
937 scoped_ptr<chrome::BrowserCommandController> command_controller_;
939 // True if the browser window has been shown at least once.
940 bool window_has_shown_;
942 // The following factory is used for chrome update coalescing.
943 base::WeakPtrFactory<Browser> chrome_updater_factory_;
945 // The following factory is used to close the frame at a later time.
946 base::WeakPtrFactory<Browser> weak_factory_;
948 scoped_ptr<BrowserContentTranslateDriverObserver> translate_driver_observer_;
950 scoped_ptr<chrome::ValidationMessageBubble> validation_message_bubble_;
952 DISALLOW_COPY_AND_ASSIGN(Browser);
955 #endif // CHROME_BROWSER_UI_BROWSER_H_