[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / browser.h
blobbeb3dddd95fead3fb82cef1c065537b2e9e8b2f6
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_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
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 "chrome/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;
53 class BrowserWindow;
54 class FindBarController;
55 class FullscreenController;
56 class PrefService;
57 class Profile;
58 class SearchDelegate;
59 class SearchModel;
60 class StatusBubble;
61 class TabStripModel;
62 class TabStripModelDelegate;
63 struct WebApplicationInfo;
65 namespace chrome {
66 class BrowserCommandController;
67 class FastUnloadController;
68 class UnloadController;
69 class ValidationMessageBubble;
72 namespace content {
73 class NavigationController;
74 class PageState;
75 class SessionStorageNamespace;
78 namespace extensions {
79 class Extension;
80 class WindowController;
83 namespace gfx {
84 class Image;
85 class Point;
88 namespace ui {
89 struct SelectedFileInfo;
90 class WebDialogDelegate;
93 namespace web_modal {
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,
104 public ZoomObserver,
105 public content::PageNavigator,
106 public content::NotificationObserver,
107 public ui::SelectFileDialog::Listener {
108 public:
109 // SessionService::WindowType mirrors these values. If you add to this
110 // enum, look at SessionService::WindowType to see if it needs to be
111 // updated.
112 enum Type {
113 // If you add a new type, consider updating the test
114 // BrowserTest.StartMaximized.
115 TYPE_TABBED = 1,
116 TYPE_POPUP = 2
119 // Possible elements of the Browser window.
120 enum WindowFeature {
121 FEATURE_NONE = 0,
122 FEATURE_TITLEBAR = 1,
123 FEATURE_TABSTRIP = 2,
124 FEATURE_TOOLBAR = 4,
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.
135 DOWNLOAD_CLOSE_OK,
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,
149 Profile* profile,
150 chrome::HostDesktopType host_desktop_type);
152 static CreateParams CreateForApp(const std::string& app_name,
153 bool trusted_source,
154 const gfx::Rect& window_bounds,
155 Profile* profile,
156 chrome::HostDesktopType host_desktop_type);
158 static CreateParams CreateForDevTools(
159 Profile* profile,
160 chrome::HostDesktopType host_desktop_type);
162 // The browser type.
163 Type type;
165 // The associated profile.
166 Profile* profile;
168 // The host desktop the browser is created on.
169 chrome::HostDesktopType host_desktop_type;
171 // Specifies the browser is_trusted_source_ value.
172 bool trusted_source;
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;
185 private:
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);
200 virtual ~Browser();
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()|
236 // is done.
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_);
244 #endif
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
272 // yet exist.
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
297 // action.
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
326 // cleanup.
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
349 // fullscreen.
350 void WindowFullscreenStateChanged();
352 // Invoked when visible SSL state (as defined by SSLStatus) changes.
353 void VisibleSSLStateChanged(content::WebContents* web_contents);
355 // Assorted browser commands ////////////////////////////////////////////////
357 // NOTE: Within each of the following sections, the IDs are ordered roughly by
358 // how they appear in the GUI/menus (left to right, top to bottom, etc.).
360 // See the description of
361 // FullscreenController::ToggleFullscreenModeWithExtension.
362 void ToggleFullscreenModeWithExtension(const GURL& extension_url);
364 #if defined(OS_WIN)
365 // See the description of FullscreenController::ToggleMetroSnapMode.
366 void SetMetroSnapMode(bool enable);
367 #endif
369 // Returns true if the Browser supports the specified feature. The value of
370 // this varies during the lifetime of the browser. For example, if the window
371 // is fullscreen this may return a different value. If you only care about
372 // whether or not it's possible for the browser to support a particular
373 // feature use |CanSupportWindowFeature|.
374 bool SupportsWindowFeature(WindowFeature feature) const;
376 // Returns true if the Browser can support the specified feature. See comment
377 // in |SupportsWindowFeature| for details on this.
378 bool CanSupportWindowFeature(WindowFeature feature) const;
380 // TODO(port): port these, and re-merge the two function declaration lists.
381 // Page-related commands.
382 void ToggleEncodingAutoDetect();
383 void OverrideEncoding(int encoding_id);
385 // Show various bits of UI
386 void OpenFile();
388 void UpdateDownloadShelfVisibility(bool visible);
390 /////////////////////////////////////////////////////////////////////////////
392 // Called by chrome::Navigate() when a navigation has occurred in a tab in
393 // this Browser. Updates the UI for the start of this navigation.
394 void UpdateUIForNavigationInTab(content::WebContents* contents,
395 content::PageTransition transition,
396 bool user_initiated);
398 // Interface implementations ////////////////////////////////////////////////
400 // Overridden from content::PageNavigator:
401 virtual content::WebContents* OpenURL(
402 const content::OpenURLParams& params) OVERRIDE;
404 // Overridden from TabStripModelObserver:
405 virtual void TabInsertedAt(content::WebContents* contents,
406 int index,
407 bool foreground) OVERRIDE;
408 virtual void TabClosingAt(TabStripModel* tab_strip_model,
409 content::WebContents* contents,
410 int index) OVERRIDE;
411 virtual void TabDetachedAt(content::WebContents* contents,
412 int index) OVERRIDE;
413 virtual void TabDeactivated(content::WebContents* contents) OVERRIDE;
414 virtual void ActiveTabChanged(content::WebContents* old_contents,
415 content::WebContents* new_contents,
416 int index,
417 int reason) OVERRIDE;
418 virtual void TabMoved(content::WebContents* contents,
419 int from_index,
420 int to_index) OVERRIDE;
421 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
422 content::WebContents* old_contents,
423 content::WebContents* new_contents,
424 int index) OVERRIDE;
425 virtual void TabPinnedStateChanged(content::WebContents* contents,
426 int index) OVERRIDE;
427 virtual void TabStripEmpty() OVERRIDE;
429 // Overridden from content::WebContentsDelegate:
430 virtual bool CanOverscrollContent() const OVERRIDE;
431 virtual bool ShouldPreserveAbortedURLs(content::WebContents* source) OVERRIDE;
432 virtual bool PreHandleKeyboardEvent(
433 content::WebContents* source,
434 const content::NativeWebKeyboardEvent& event,
435 bool* is_keyboard_shortcut) OVERRIDE;
436 virtual void HandleKeyboardEvent(
437 content::WebContents* source,
438 const content::NativeWebKeyboardEvent& event) OVERRIDE;
439 virtual void OverscrollUpdate(int delta_y) OVERRIDE;
440 virtual void ShowValidationMessage(content::WebContents* web_contents,
441 const gfx::Rect& anchor_in_root_view,
442 const base::string16& main_text,
443 const base::string16& sub_text) OVERRIDE;
444 virtual void HideValidationMessage(
445 content::WebContents* web_contents) OVERRIDE;
446 virtual void MoveValidationMessage(
447 content::WebContents* web_contents,
448 const gfx::Rect& anchor_in_root_view) OVERRIDE;
449 virtual bool PreHandleGestureEvent(
450 content::WebContents* source,
451 const blink::WebGestureEvent& event) OVERRIDE;
453 bool is_type_tabbed() const { return type_ == TYPE_TABBED; }
454 bool is_type_popup() const { return type_ == TYPE_POPUP; }
456 bool is_app() const;
457 bool is_devtools() const;
459 // True when the mouse cursor is locked.
460 bool IsMouseLocked() const;
462 // Called each time the browser window is shown.
463 void OnWindowDidShow();
465 // Show the first run search engine bubble on the location bar.
466 void ShowFirstRunBubble();
468 // Show a download on the download shelf.
469 void ShowDownload(content::DownloadItem* download);
471 FullscreenController* fullscreen_controller() const {
472 return fullscreen_controller_.get();
475 extensions::WindowController* extension_window_controller() const {
476 return extension_window_controller_.get();
479 private:
480 friend class BrowserTest;
481 friend class FullscreenControllerInteractiveTest;
482 friend class FullscreenControllerTest;
483 FRIEND_TEST_ALL_PREFIXES(AppModeTest, EnableAppModeTest);
484 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest,
485 IsReservedCommandOrKeyIsApp);
486 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest, AppFullScreen);
487 FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups);
488 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ConvertTabToAppShortcut);
489 FRIEND_TEST_ALL_PREFIXES(BrowserTest, OpenAppWindowLikeNtp);
490 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch);
491 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ShouldShowLocationBar);
492 FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest,
493 TabEntersPresentationModeFromWindowed);
494 FRIEND_TEST_ALL_PREFIXES(FullscreenExitBubbleControllerTest,
495 DenyExitsFullscreen);
496 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref);
497 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
498 OpenAppShortcutWindowPref);
499 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref);
501 class InterstitialObserver;
503 // Used to describe why a tab is being detached. This is used by
504 // TabDetachedAtImpl.
505 enum DetachType {
506 // Result of TabDetachedAt.
507 DETACH_TYPE_DETACH,
509 // Result of TabReplacedAt.
510 DETACH_TYPE_REPLACE,
512 // Result of the tab strip not having any significant tabs.
513 DETACH_TYPE_EMPTY
516 // Describes where the bookmark bar state change originated from.
517 enum BookmarkBarStateChangeReason {
518 // From the constructor.
519 BOOKMARK_BAR_STATE_CHANGE_INIT,
521 // Change is the result of the active tab changing.
522 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH,
524 // Change is the result of the bookmark bar pref changing.
525 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE,
527 // Change is the result of a state change in the active tab.
528 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE,
530 // Change is the result of window toggling in/out of fullscreen mode.
531 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN,
534 // Overridden from content::WebContentsDelegate:
535 virtual content::WebContents* OpenURLFromTab(
536 content::WebContents* source,
537 const content::OpenURLParams& params) OVERRIDE;
538 virtual void NavigationStateChanged(const content::WebContents* source,
539 unsigned changed_flags) OVERRIDE;
540 virtual void AddNewContents(content::WebContents* source,
541 content::WebContents* new_contents,
542 WindowOpenDisposition disposition,
543 const gfx::Rect& initial_pos,
544 bool user_gesture,
545 bool* was_blocked) OVERRIDE;
546 virtual void ActivateContents(content::WebContents* contents) OVERRIDE;
547 virtual void DeactivateContents(content::WebContents* contents) OVERRIDE;
548 virtual void LoadingStateChanged(content::WebContents* source,
549 bool to_different_document) OVERRIDE;
550 virtual void CloseContents(content::WebContents* source) OVERRIDE;
551 virtual void MoveContents(content::WebContents* source,
552 const gfx::Rect& pos) OVERRIDE;
553 virtual bool IsPopupOrPanel(
554 const content::WebContents* source) const OVERRIDE;
555 virtual void UpdateTargetURL(content::WebContents* source, int32 page_id,
556 const GURL& url) OVERRIDE;
557 virtual void ContentsMouseEvent(content::WebContents* source,
558 const gfx::Point& location,
559 bool motion) OVERRIDE;
560 virtual void ContentsZoomChange(bool zoom_in) OVERRIDE;
561 virtual void WebContentsFocused(content::WebContents* content) OVERRIDE;
562 virtual bool TakeFocus(content::WebContents* source, bool reverse) OVERRIDE;
563 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
564 virtual void BeforeUnloadFired(content::WebContents* source,
565 bool proceed,
566 bool* proceed_to_fire_unload) OVERRIDE;
567 virtual bool ShouldFocusLocationBarByDefault(
568 content::WebContents* source) OVERRIDE;
569 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
570 virtual int GetExtraRenderViewHeight() const OVERRIDE;
571 virtual void ViewSourceForTab(content::WebContents* source,
572 const GURL& page_url) OVERRIDE;
573 virtual void ViewSourceForFrame(
574 content::WebContents* source,
575 const GURL& frame_url,
576 const content::PageState& frame_page_state) OVERRIDE;
577 virtual void ShowRepostFormWarningDialog(
578 content::WebContents* source) OVERRIDE;
579 virtual bool ShouldCreateWebContents(
580 content::WebContents* web_contents,
581 int route_id,
582 WindowContainerType window_container_type,
583 const base::string16& frame_name,
584 const GURL& target_url,
585 const std::string& partition_id,
586 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE;
587 virtual void WebContentsCreated(content::WebContents* source_contents,
588 int opener_render_frame_id,
589 const base::string16& frame_name,
590 const GURL& target_url,
591 content::WebContents* new_contents) OVERRIDE;
592 virtual void RendererUnresponsive(content::WebContents* source) OVERRIDE;
593 virtual void RendererResponsive(content::WebContents* source) OVERRIDE;
594 virtual void WorkerCrashed(content::WebContents* source) OVERRIDE;
595 virtual void DidNavigateMainFramePostCommit(
596 content::WebContents* web_contents) OVERRIDE;
597 virtual void DidNavigateToPendingEntry(
598 content::WebContents* web_contents) OVERRIDE;
599 virtual content::JavaScriptDialogManager*
600 GetJavaScriptDialogManager() OVERRIDE;
601 virtual content::ColorChooser* OpenColorChooser(
602 content::WebContents* web_contents,
603 SkColor color,
604 const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE;
605 virtual void RunFileChooser(
606 content::WebContents* web_contents,
607 const content::FileChooserParams& params) OVERRIDE;
608 virtual void EnumerateDirectory(content::WebContents* web_contents,
609 int request_id,
610 const base::FilePath& path) OVERRIDE;
611 virtual bool EmbedsFullscreenWidget() const OVERRIDE;
612 virtual void ToggleFullscreenModeForTab(content::WebContents* web_contents,
613 bool enter_fullscreen) OVERRIDE;
614 virtual bool IsFullscreenForTabOrPending(
615 const content::WebContents* web_contents) const OVERRIDE;
616 virtual void RegisterProtocolHandler(content::WebContents* web_contents,
617 const std::string& protocol,
618 const GURL& url,
619 bool user_gesture) OVERRIDE;
620 virtual void UpdatePreferredSize(content::WebContents* source,
621 const gfx::Size& pref_size) OVERRIDE;
622 virtual void ResizeDueToAutoResize(content::WebContents* source,
623 const gfx::Size& new_size) OVERRIDE;
624 virtual void FindReply(content::WebContents* web_contents,
625 int request_id,
626 int number_of_matches,
627 const gfx::Rect& selection_rect,
628 int active_match_ordinal,
629 bool final_update) OVERRIDE;
630 virtual void RequestToLockMouse(content::WebContents* web_contents,
631 bool user_gesture,
632 bool last_unlocked_by_target) OVERRIDE;
633 virtual void LostMouseLock() OVERRIDE;
634 virtual void RequestMediaAccessPermission(
635 content::WebContents* web_contents,
636 const content::MediaStreamRequest& request,
637 const content::MediaResponseCallback& callback) OVERRIDE;
638 virtual bool RequestPpapiBrokerPermission(
639 content::WebContents* web_contents,
640 const GURL& url,
641 const base::FilePath& plugin_path,
642 const base::Callback<void(bool)>& callback) OVERRIDE;
643 virtual gfx::Size GetSizeForNewRenderView(
644 content::WebContents* web_contents) const OVERRIDE;
646 // Overridden from CoreTabHelperDelegate:
647 // Note that the caller is responsible for deleting |old_contents|.
648 virtual void SwapTabContents(content::WebContents* old_contents,
649 content::WebContents* new_contents,
650 bool did_start_load,
651 bool did_finish_load) OVERRIDE;
652 virtual bool CanReloadContents(
653 content::WebContents* web_contents) const OVERRIDE;
654 virtual bool CanSaveContents(
655 content::WebContents* web_contents) const OVERRIDE;
657 // Overridden from SearchEngineTabHelperDelegate:
658 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
659 Profile* profile) OVERRIDE;
661 // Overridden from SearchTabHelperDelegate:
662 virtual void NavigateOnThumbnailClick(
663 const GURL& url,
664 WindowOpenDisposition disposition,
665 content::WebContents* source_contents) OVERRIDE;
666 virtual void OnWebContentsInstantSupportDisabled(
667 const content::WebContents* web_contents) OVERRIDE;
668 virtual OmniboxView* GetOmniboxView() OVERRIDE;
669 virtual std::set<std::string> GetOpenUrls() OVERRIDE;
671 // Overridden from WebContentsModalDialogManagerDelegate:
672 virtual void SetWebContentsBlocked(content::WebContents* web_contents,
673 bool blocked) OVERRIDE;
674 virtual web_modal::WebContentsModalDialogHost*
675 GetWebContentsModalDialogHost() OVERRIDE;
677 // Overridden from BookmarkTabHelperDelegate:
678 virtual void URLStarredChanged(content::WebContents* web_contents,
679 bool starred) OVERRIDE;
681 // Overridden from ZoomObserver:
682 virtual void OnZoomChanged(content::WebContents* source,
683 bool can_show_bubble) OVERRIDE;
685 // Overridden from SelectFileDialog::Listener:
686 virtual void FileSelected(const base::FilePath& path,
687 int index,
688 void* params) OVERRIDE;
689 virtual void FileSelectedWithExtraInfo(
690 const ui::SelectedFileInfo& file_info,
691 int index,
692 void* params) OVERRIDE;
694 // Overridden from content::NotificationObserver:
695 virtual void Observe(int type,
696 const content::NotificationSource& source,
697 const content::NotificationDetails& details) OVERRIDE;
699 // Command and state updating ///////////////////////////////////////////////
701 // Handle changes to kDevTools preference.
702 void OnDevToolsDisabledChanged();
704 // UI update coalescing and handling ////////////////////////////////////////
706 // Asks the toolbar (and as such the location bar) to update its state to
707 // reflect the current tab's current URL, security state, etc.
708 // If |should_restore_state| is true, we're switching (back?) to this tab and
709 // should restore any previous location bar state (such as user editing) as
710 // well.
711 void UpdateToolbar(bool should_restore_state);
713 // Does one or both of the following for each bit in |changed_flags|:
714 // . If the update should be processed immediately, it is.
715 // . If the update should processed asynchronously (to avoid lots of ui
716 // updates), then scheduled_updates_ is updated for the |source| and update
717 // pair and a task is scheduled (assuming it isn't running already)
718 // that invokes ProcessPendingUIUpdates.
719 void ScheduleUIUpdate(const content::WebContents* source,
720 unsigned changed_flags);
722 // Processes all pending updates to the UI that have been scheduled by
723 // ScheduleUIUpdate in scheduled_updates_.
724 void ProcessPendingUIUpdates();
726 // Removes all entries from scheduled_updates_ whose source is contents.
727 void RemoveScheduledUpdatesFor(content::WebContents* contents);
729 // Getters for UI ///////////////////////////////////////////////////////////
731 // TODO(beng): remove, and provide AutomationProvider a better way to access
732 // the LocationBarView's edit.
733 friend class AutomationProvider;
734 friend class BrowserProxy;
735 friend class TestingAutomationProvider;
737 // Returns the StatusBubble from the current toolbar. It is possible for
738 // this to return NULL if called before the toolbar has initialized.
739 // TODO(beng): remove this.
740 StatusBubble* GetStatusBubble();
742 // Session restore functions ////////////////////////////////////////////////
744 // Notifies the history database of the index for all tabs whose index is
745 // >= index.
746 void SyncHistoryWithTabs(int index);
748 // In-progress download termination handling /////////////////////////////////
750 // Called when the window is closing to check if potential in-progress
751 // downloads should prevent it from closing.
752 // Returns true if the window can close, false otherwise.
753 bool CanCloseWithInProgressDownloads();
755 // Assorted utility functions ///////////////////////////////////////////////
757 // Sets the specified browser as the delegate of the WebContents and all the
758 // associated tab helpers that are needed.
759 void SetAsDelegate(content::WebContents* web_contents, Browser* delegate);
761 // Shows the Find Bar, optionally selecting the next entry that matches the
762 // existing search string for that Tab. |forward_direction| controls the
763 // search direction.
764 void FindInPage(bool find_next, bool forward_direction);
766 // Closes the frame.
767 // TODO(beng): figure out if we need this now that the frame itself closes
768 // after a return to the message loop.
769 void CloseFrame();
771 void TabDetachedAtImpl(content::WebContents* contents,
772 int index,
773 DetachType type);
775 // Shared code between Reload() and ReloadIgnoringCache().
776 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache);
778 // Returns true if the Browser window should show the location bar.
779 bool ShouldShowLocationBar() const;
781 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
782 // |check_fullscreen| is true, the set of features reflect the actual state of
783 // the browser, otherwise the set of features reflect the possible state of
784 // the browser.
785 bool SupportsWindowFeatureImpl(WindowFeature feature,
786 bool check_fullscreen) const;
788 // Resets |bookmark_bar_state_| based on the active tab. Notifies the
789 // BrowserWindow if necessary.
790 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason);
792 bool ShouldHideUIForFullscreen() const;
794 // Creates a BackgroundContents if appropriate; return true if one was
795 // created.
796 bool MaybeCreateBackgroundContents(
797 int route_id,
798 content::WebContents* opener_web_contents,
799 const base::string16& frame_name,
800 const GURL& target_url,
801 const std::string& partition_id,
802 content::SessionStorageNamespace* session_storage_namespace);
804 // Data members /////////////////////////////////////////////////////////////
806 std::vector<InterstitialObserver*> interstitial_observers_;
808 content::NotificationRegistrar registrar_;
810 PrefChangeRegistrar profile_pref_registrar_;
812 // This Browser's type.
813 const Type type_;
815 // This Browser's profile.
816 Profile* const profile_;
818 // This Browser's window.
819 BrowserWindow* window_;
821 scoped_ptr<TabStripModelDelegate> tab_strip_model_delegate_;
822 scoped_ptr<TabStripModel> tab_strip_model_;
824 // The application name that is also the name of the window to the shell.
825 // This name should be set when:
826 // 1) we launch an application via an application shortcut or extension API.
827 // 2) we launch an undocked devtool window.
828 std::string app_name_;
830 // True if the source is trusted (i.e. we do not need to show the URL in a
831 // a popup window). Also used to determine which app windows to save and
832 // restore on Chrome OS.
833 bool is_trusted_source_;
835 // Unique identifier of this browser for session restore. This id is only
836 // unique within the current session, and is not guaranteed to be unique
837 // across sessions.
838 const SessionID session_id_;
840 // The model for the toolbar view.
841 scoped_ptr<ToolbarModel> toolbar_model_;
843 // The model for the "active" search state. There are per-tab search models
844 // as well. When a tab is active its model is kept in sync with this one.
845 // When a new tab is activated its model state is propagated to this active
846 // model. This way, observers only have to attach to this single model for
847 // updates, and don't have to worry about active tab changes directly.
848 scoped_ptr<SearchModel> search_model_;
850 // UI update coalescing and handling ////////////////////////////////////////
852 typedef std::map<const content::WebContents*, int> UpdateMap;
854 // Maps from WebContents to pending UI updates that need to be processed.
855 // We don't update things like the URL or tab title right away to avoid
856 // flickering and extra painting.
857 // See ScheduleUIUpdate and ProcessPendingUIUpdates.
858 UpdateMap scheduled_updates_;
860 // In-progress download termination handling /////////////////////////////////
862 enum CancelDownloadConfirmationState {
863 NOT_PROMPTED, // We have not asked the user.
864 WAITING_FOR_RESPONSE, // We have asked the user and have not received a
865 // reponse yet.
866 RESPONSE_RECEIVED // The user was prompted and made a decision already.
869 // State used to figure-out whether we should prompt the user for confirmation
870 // when the browser is closed with in-progress downloads.
871 CancelDownloadConfirmationState cancel_download_confirmation_state_;
873 /////////////////////////////////////////////////////////////////////////////
875 // Override values for the bounds of the window and its maximized or minimized
876 // state.
877 // These are supplied by callers that don't want to use the default values.
878 // The default values are typically loaded from local state (last session),
879 // obtained from the last window of the same type, or obtained from the
880 // shell shortcut's startup info.
881 gfx::Rect override_bounds_;
882 ui::WindowShowState initial_show_state_;
884 // Tracks when this browser is being created by session restore.
885 bool is_session_restore_;
887 const chrome::HostDesktopType host_desktop_type_;
889 scoped_ptr<chrome::UnloadController> unload_controller_;
890 scoped_ptr<chrome::FastUnloadController> fast_unload_controller_;
892 // The Find Bar. This may be NULL if there is no Find Bar, and if it is
893 // non-NULL, it may or may not be visible.
894 scoped_ptr<FindBarController> find_bar_controller_;
896 // Dialog box used for opening and saving files.
897 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
899 // Keep track of the encoding auto detect pref.
900 BooleanPrefMember encoding_auto_detect_;
902 // Helper which implements the ContentSettingBubbleModel interface.
903 scoped_ptr<BrowserContentSettingBubbleModelDelegate>
904 content_setting_bubble_model_delegate_;
906 // Helper which implements the ToolbarModelDelegate interface.
907 scoped_ptr<BrowserToolbarModelDelegate> toolbar_model_delegate_;
909 // A delegate that handles the details of updating the "active"
910 // |search_model_| state with the tab's state.
911 scoped_ptr<SearchDelegate> search_delegate_;
913 // Helper which implements the TabRestoreServiceDelegate interface.
914 scoped_ptr<BrowserTabRestoreServiceDelegate> tab_restore_service_delegate_;
916 // Helper which implements the SyncedWindowDelegate interface.
917 scoped_ptr<BrowserSyncedWindowDelegate> synced_window_delegate_;
919 scoped_ptr<BrowserInstantController> instant_controller_;
921 BookmarkBar::State bookmark_bar_state_;
923 scoped_ptr<FullscreenController> fullscreen_controller_;
925 scoped_ptr<extensions::WindowController> extension_window_controller_;
927 scoped_ptr<chrome::BrowserCommandController> command_controller_;
929 // True if the browser window has been shown at least once.
930 bool window_has_shown_;
932 // The following factory is used for chrome update coalescing.
933 base::WeakPtrFactory<Browser> chrome_updater_factory_;
935 // The following factory is used to close the frame at a later time.
936 base::WeakPtrFactory<Browser> weak_factory_;
938 scoped_ptr<BrowserContentTranslateDriverObserver> translate_driver_observer_;
940 scoped_ptr<chrome::ValidationMessageBubble> validation_message_bubble_;
942 DISALLOW_COPY_AND_ASSIGN(Browser);
945 #endif // CHROME_BROWSER_UI_BROWSER_H_