Refactor views app list services to allow more code sharing
[chromium-blink-merge.git] / chrome / browser / ui / browser.h
blobefc35f175554ff360f9a9ccb5efb3e8371b10fe3
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 const base::string16& title,
620 bool user_gesture) OVERRIDE;
621 virtual void UpdatePreferredSize(content::WebContents* source,
622 const gfx::Size& pref_size) OVERRIDE;
623 virtual void ResizeDueToAutoResize(content::WebContents* source,
624 const gfx::Size& new_size) OVERRIDE;
625 virtual void FindReply(content::WebContents* web_contents,
626 int request_id,
627 int number_of_matches,
628 const gfx::Rect& selection_rect,
629 int active_match_ordinal,
630 bool final_update) OVERRIDE;
631 virtual void RequestToLockMouse(content::WebContents* web_contents,
632 bool user_gesture,
633 bool last_unlocked_by_target) OVERRIDE;
634 virtual void LostMouseLock() OVERRIDE;
635 virtual void RequestMediaAccessPermission(
636 content::WebContents* web_contents,
637 const content::MediaStreamRequest& request,
638 const content::MediaResponseCallback& callback) OVERRIDE;
639 virtual bool RequestPpapiBrokerPermission(
640 content::WebContents* web_contents,
641 const GURL& url,
642 const base::FilePath& plugin_path,
643 const base::Callback<void(bool)>& callback) OVERRIDE;
644 virtual gfx::Size GetSizeForNewRenderView(
645 const content::WebContents* web_contents) const OVERRIDE;
647 // Overridden from CoreTabHelperDelegate:
648 // Note that the caller is responsible for deleting |old_contents|.
649 virtual void SwapTabContents(content::WebContents* old_contents,
650 content::WebContents* new_contents,
651 bool did_start_load,
652 bool did_finish_load) OVERRIDE;
653 virtual bool CanReloadContents(
654 content::WebContents* web_contents) const OVERRIDE;
655 virtual bool CanSaveContents(
656 content::WebContents* web_contents) const OVERRIDE;
658 // Overridden from SearchEngineTabHelperDelegate:
659 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
660 Profile* profile) OVERRIDE;
662 // Overridden from SearchTabHelperDelegate:
663 virtual void NavigateOnThumbnailClick(
664 const GURL& url,
665 WindowOpenDisposition disposition,
666 content::WebContents* source_contents) OVERRIDE;
667 virtual void OnWebContentsInstantSupportDisabled(
668 const content::WebContents* web_contents) OVERRIDE;
669 virtual OmniboxView* GetOmniboxView() OVERRIDE;
670 virtual std::set<std::string> GetOpenUrls() 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,
688 int index,
689 void* params) OVERRIDE;
690 virtual void FileSelectedWithExtraInfo(
691 const ui::SelectedFileInfo& file_info,
692 int index,
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
711 // well.
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
746 // >= index.
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
764 // search direction.
765 void FindInPage(bool find_next, bool forward_direction);
767 // Closes the frame.
768 // TODO(beng): figure out if we need this now that the frame itself closes
769 // after a return to the message loop.
770 void CloseFrame();
772 void TabDetachedAtImpl(content::WebContents* contents,
773 int index,
774 DetachType type);
776 // Shared code between Reload() and ReloadIgnoringCache().
777 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache);
779 // Returns true if the Browser window should show the location bar.
780 bool ShouldShowLocationBar() const;
782 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
783 // |check_fullscreen| is true, the set of features reflect the actual state of
784 // the browser, otherwise the set of features reflect the possible state of
785 // the browser.
786 bool SupportsWindowFeatureImpl(WindowFeature feature,
787 bool check_fullscreen) const;
789 // Resets |bookmark_bar_state_| based on the active tab. Notifies the
790 // BrowserWindow if necessary.
791 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason);
793 bool ShouldHideUIForFullscreen() const;
795 // Creates a BackgroundContents if appropriate; return true if one was
796 // created.
797 bool MaybeCreateBackgroundContents(
798 int route_id,
799 content::WebContents* opener_web_contents,
800 const base::string16& frame_name,
801 const GURL& target_url,
802 const std::string& partition_id,
803 content::SessionStorageNamespace* session_storage_namespace);
805 // Data members /////////////////////////////////////////////////////////////
807 std::vector<InterstitialObserver*> interstitial_observers_;
809 content::NotificationRegistrar registrar_;
811 PrefChangeRegistrar profile_pref_registrar_;
813 // This Browser's type.
814 const Type type_;
816 // This Browser's profile.
817 Profile* const profile_;
819 // This Browser's window.
820 BrowserWindow* window_;
822 scoped_ptr<TabStripModelDelegate> tab_strip_model_delegate_;
823 scoped_ptr<TabStripModel> tab_strip_model_;
825 // The application name that is also the name of the window to the shell.
826 // This name should be set when:
827 // 1) we launch an application via an application shortcut or extension API.
828 // 2) we launch an undocked devtool window.
829 std::string app_name_;
831 // True if the source is trusted (i.e. we do not need to show the URL in a
832 // a popup window). Also used to determine which app windows to save and
833 // restore on Chrome OS.
834 bool is_trusted_source_;
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
838 // across sessions.
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
866 // reponse yet.
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
877 // state.
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<BrowserContentTranslateDriverObserver> translate_driver_observer_;
941 scoped_ptr<chrome::ValidationMessageBubble> validation_message_bubble_;
943 DISALLOW_COPY_AND_ASSIGN(Browser);
946 #endif // CHROME_BROWSER_UI_BROWSER_H_