No longer register app window placement preference keys on
[chromium-blink-merge.git] / chrome / browser / ui / browser.h
blob9a1cbed1819fd41f510c09b7a2395b2e12c0637e
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/ui/bookmarks/bookmark_bar.h"
23 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h"
24 #include "chrome/browser/ui/browser_navigator.h"
25 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
26 #include "chrome/browser/ui/host_desktop.h"
27 #include "chrome/browser/ui/search/search_tab_helper_delegate.h"
28 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h"
29 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
31 #include "chrome/browser/ui/toolbar/toolbar_model.h"
32 #include "chrome/browser/ui/zoom/zoom_observer.h"
33 #include "components/content_settings/core/common/content_settings.h"
34 #include "components/content_settings/core/common/content_settings_types.h"
35 #include "components/sessions/session_id.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 PopupManager;
95 class WebContentsModalDialogHost;
98 class Browser : public TabStripModelObserver,
99 public content::WebContentsDelegate,
100 public CoreTabHelperDelegate,
101 public SearchEngineTabHelperDelegate,
102 public SearchTabHelperDelegate,
103 public ChromeWebModalDialogManagerDelegate,
104 public BookmarkTabHelperDelegate,
105 public ZoomObserver,
106 public content::PageNavigator,
107 public content::NotificationObserver,
108 public ui::SelectFileDialog::Listener {
109 public:
110 // SessionService::WindowType mirrors these values. If you add to this
111 // enum, look at SessionService::WindowType to see if it needs to be
112 // updated.
113 enum Type {
114 // If you add a new type, consider updating the test
115 // BrowserTest.StartMaximized.
116 TYPE_TABBED = 1,
117 TYPE_POPUP = 2
120 // Possible elements of the Browser window.
121 enum WindowFeature {
122 FEATURE_NONE = 0,
123 FEATURE_TITLEBAR = 1,
124 FEATURE_TABSTRIP = 2,
125 FEATURE_TOOLBAR = 4,
126 FEATURE_LOCATIONBAR = 8,
127 FEATURE_BOOKMARKBAR = 16,
128 FEATURE_INFOBAR = 32,
129 FEATURE_DOWNLOADSHELF = 64
132 // The context for a download blocked notification from
133 // OkToCloseWithInProgressDownloads.
134 enum DownloadClosePreventionType {
135 // Browser close is not blocked by download state.
136 DOWNLOAD_CLOSE_OK,
138 // The browser is shutting down and there are active downloads
139 // that would be cancelled.
140 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN,
142 // There are active downloads associated with this incognito profile
143 // that would be canceled.
144 DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE,
147 struct CreateParams {
148 CreateParams(Profile* profile, chrome::HostDesktopType host_desktop_type);
149 CreateParams(Type type,
150 Profile* profile,
151 chrome::HostDesktopType host_desktop_type);
153 static CreateParams CreateForApp(const std::string& app_name,
154 bool trusted_source,
155 const gfx::Rect& window_bounds,
156 Profile* profile,
157 chrome::HostDesktopType host_desktop_type);
159 static CreateParams CreateForDevTools(
160 Profile* profile,
161 chrome::HostDesktopType host_desktop_type);
163 // The browser type.
164 Type type;
166 // The associated profile.
167 Profile* profile;
169 // The host desktop the browser is created on.
170 chrome::HostDesktopType host_desktop_type;
172 // Specifies the browser is_trusted_source_ value.
173 bool trusted_source;
175 // The bounds of the window to open.
176 gfx::Rect initial_bounds;
178 ui::WindowShowState initial_show_state;
180 bool is_session_restore;
182 // Supply a custom BrowserWindow implementation, to be used instead of the
183 // default. Intended for testing.
184 BrowserWindow* window;
186 private:
187 friend class Browser;
189 // The application name that is also the name of the window to the shell.
190 // Do not set this value directly, use CreateForApp.
191 // This name will be set for:
192 // 1) v1 applications launched via an application shortcut or extension API.
193 // 2) undocked devtool windows.
194 // 3) popup windows spawned from v1 applications.
195 std::string app_name;
198 // Constructors, Creation, Showing //////////////////////////////////////////
200 explicit Browser(const CreateParams& params);
201 virtual ~Browser();
203 // Set overrides for the initial window bounds and maximized state.
204 void set_override_bounds(const gfx::Rect& bounds) {
205 override_bounds_ = bounds;
207 ui::WindowShowState initial_show_state() const { return initial_show_state_; }
208 void set_initial_show_state(ui::WindowShowState initial_show_state) {
209 initial_show_state_ = initial_show_state;
211 // Return true if the initial window bounds have been overridden.
212 bool bounds_overridden() const {
213 return !override_bounds_.IsEmpty();
215 // Set indicator that this browser is being created via session restore.
216 // This is used on the Mac (only) to determine animation style when the
217 // browser window is shown.
218 void set_is_session_restore(bool is_session_restore) {
219 is_session_restore_ = is_session_restore;
221 bool is_session_restore() const {
222 return is_session_restore_;
224 chrome::HostDesktopType host_desktop_type() const {
225 return host_desktop_type_;
228 // Accessors ////////////////////////////////////////////////////////////////
230 Type type() const { return type_; }
231 const std::string& app_name() const { return app_name_; }
232 bool is_trusted_source() const { return is_trusted_source_; }
233 Profile* profile() const { return profile_; }
234 gfx::Rect override_bounds() const { return override_bounds_; }
236 // |window()| will return NULL if called before |CreateBrowserWindow()|
237 // is done.
238 BrowserWindow* window() const { return window_; }
239 ToolbarModel* toolbar_model() { return toolbar_model_.get(); }
240 const ToolbarModel* toolbar_model() const { return toolbar_model_.get(); }
241 #if defined(UNIT_TEST)
242 void swap_toolbar_models(scoped_ptr<ToolbarModel>* toolbar_model) {
243 toolbar_model->swap(toolbar_model_);
245 #endif
246 web_modal::PopupManager* popup_manager() {
247 return popup_manager_.get();
249 TabStripModel* tab_strip_model() const { return tab_strip_model_.get(); }
250 chrome::BrowserCommandController* command_controller() {
251 return command_controller_.get();
253 SearchModel* search_model() { return search_model_.get(); }
254 const SearchModel* search_model() const {
255 return search_model_.get();
257 SearchDelegate* search_delegate() {
258 return search_delegate_.get();
260 const SessionID& session_id() const { return session_id_; }
261 BrowserContentSettingBubbleModelDelegate*
262 content_setting_bubble_model_delegate() {
263 return content_setting_bubble_model_delegate_.get();
265 BrowserTabRestoreServiceDelegate* tab_restore_service_delegate() {
266 return tab_restore_service_delegate_.get();
268 BrowserSyncedWindowDelegate* synced_window_delegate() {
269 return synced_window_delegate_.get();
271 BrowserInstantController* instant_controller() {
272 return instant_controller_.get();
275 // Get the FindBarController for this browser, creating it if it does not
276 // yet exist.
277 FindBarController* GetFindBarController();
279 // Returns true if a FindBarController exists for this browser.
280 bool HasFindBarController() const;
282 // Returns the state of the bookmark bar.
283 BookmarkBar::State bookmark_bar_state() const { return bookmark_bar_state_; }
285 // State Storage and Retrieval for UI ///////////////////////////////////////
287 // Gets the Favicon of the page in the selected tab.
288 gfx::Image GetCurrentPageIcon() const;
290 // Gets the title of the window based on the selected tab's title.
291 base::string16 GetWindowTitleForCurrentTab() const;
293 // Prepares a title string for display (removes embedded newlines, etc).
294 static void FormatTitleForDisplay(base::string16* title);
296 // OnBeforeUnload handling //////////////////////////////////////////////////
298 // Gives beforeunload handlers the chance to cancel the close. Returns whether
299 // to proceed with the close. If called while the process begun by
300 // CallBeforeUnloadHandlers is in progress, returns false without taking
301 // action.
302 bool ShouldCloseWindow();
304 // Begins the process of confirming whether the associated browser can be
305 // closed. If there are no tabs with beforeunload handlers it will immediately
306 // return false. Otherwise, it starts prompting the user, returns true and
307 // will call |on_close_confirmed| with the result of the user's decision.
308 // After calling this function, if the window will not be closed, call
309 // ResetBeforeUnloadHandlers() to reset all beforeunload handlers; calling
310 // this function multiple times without an intervening call to
311 // ResetBeforeUnloadHandlers() will run only the beforeunload handlers
312 // registered since the previous call.
313 bool CallBeforeUnloadHandlers(
314 const base::Callback<void(bool)>& on_close_confirmed);
316 // Clears the results of any beforeunload confirmation dialogs triggered by a
317 // CallBeforeUnloadHandlers call.
318 void ResetBeforeUnloadHandlers();
320 // Figure out if there are tabs that have beforeunload handlers.
321 // It starts beforeunload/unload processing as a side-effect.
322 bool TabsNeedBeforeUnloadFired();
324 // Returns true if all tabs' beforeunload/unload events have fired.
325 bool HasCompletedUnloadProcessing() const;
327 bool IsAttemptingToCloseBrowser() const;
329 // Invoked when the window containing us is closing. Performs the necessary
330 // cleanup.
331 void OnWindowClosing();
333 // In-progress download termination handling /////////////////////////////////
335 // Called when the user has decided whether to proceed or not with the browser
336 // closure. |cancel_downloads| is true if the downloads should be canceled
337 // and the browser closed, false if the browser should stay open and the
338 // downloads running.
339 void InProgressDownloadResponse(bool cancel_downloads);
341 // Indicates whether or not this browser window can be closed, or
342 // would be blocked by in-progress downloads.
343 // If executing downloads would be cancelled by this window close,
344 // then |*num_downloads_blocking| is updated with how many downloads
345 // would be canceled if the close continued.
346 DownloadClosePreventionType OkToCloseWithInProgressDownloads(
347 int* num_downloads_blocking) const;
349 // External state change handling ////////////////////////////////////////////
351 // Invoked when the fullscreen state of the window changes.
352 // BrowserWindow::EnterFullscreen invokes this after the window has become
353 // fullscreen.
354 void WindowFullscreenStateChanged();
356 // Assorted browser commands ////////////////////////////////////////////////
358 // NOTE: Within each of the following sections, the IDs are ordered roughly by
359 // how they appear in the GUI/menus (left to right, top to bottom, etc.).
361 // See the description of
362 // FullscreenController::ToggleFullscreenModeWithExtension.
363 void ToggleFullscreenModeWithExtension(const GURL& extension_url);
365 #if defined(OS_WIN)
366 // See the description of FullscreenController::ToggleMetroSnapMode.
367 void SetMetroSnapMode(bool enable);
368 #endif
370 // Returns true if the Browser supports the specified feature. The value of
371 // this varies during the lifetime of the browser. For example, if the window
372 // is fullscreen this may return a different value. If you only care about
373 // whether or not it's possible for the browser to support a particular
374 // feature use |CanSupportWindowFeature|.
375 bool SupportsWindowFeature(WindowFeature feature) const;
377 // Returns true if the Browser can support the specified feature. See comment
378 // in |SupportsWindowFeature| for details on this.
379 bool CanSupportWindowFeature(WindowFeature feature) const;
381 // TODO(port): port these, and re-merge the two function declaration lists.
382 // Page-related commands.
383 void ToggleEncodingAutoDetect();
384 void OverrideEncoding(int encoding_id);
386 // Show various bits of UI
387 void OpenFile();
389 void UpdateDownloadShelfVisibility(bool visible);
391 /////////////////////////////////////////////////////////////////////////////
393 // Called by chrome::Navigate() when a navigation has occurred in a tab in
394 // this Browser. Updates the UI for the start of this navigation.
395 void UpdateUIForNavigationInTab(content::WebContents* contents,
396 content::PageTransition transition,
397 bool user_initiated);
399 // Interface implementations ////////////////////////////////////////////////
401 // Overridden from content::PageNavigator:
402 virtual content::WebContents* OpenURL(
403 const content::OpenURLParams& params) OVERRIDE;
405 // Overridden from TabStripModelObserver:
406 virtual void TabInsertedAt(content::WebContents* contents,
407 int index,
408 bool foreground) OVERRIDE;
409 virtual void TabClosingAt(TabStripModel* tab_strip_model,
410 content::WebContents* contents,
411 int index) OVERRIDE;
412 virtual void TabDetachedAt(content::WebContents* contents,
413 int index) OVERRIDE;
414 virtual void TabDeactivated(content::WebContents* contents) OVERRIDE;
415 virtual void ActiveTabChanged(content::WebContents* old_contents,
416 content::WebContents* new_contents,
417 int index,
418 int reason) OVERRIDE;
419 virtual void TabMoved(content::WebContents* contents,
420 int from_index,
421 int to_index) OVERRIDE;
422 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
423 content::WebContents* old_contents,
424 content::WebContents* new_contents,
425 int index) OVERRIDE;
426 virtual void TabPinnedStateChanged(content::WebContents* contents,
427 int index) OVERRIDE;
428 virtual void TabStripEmpty() OVERRIDE;
430 // Overridden from content::WebContentsDelegate:
431 virtual bool CanOverscrollContent() const OVERRIDE;
432 virtual bool ShouldPreserveAbortedURLs(content::WebContents* source) OVERRIDE;
433 virtual bool PreHandleKeyboardEvent(
434 content::WebContents* source,
435 const content::NativeWebKeyboardEvent& event,
436 bool* is_keyboard_shortcut) OVERRIDE;
437 virtual void HandleKeyboardEvent(
438 content::WebContents* source,
439 const content::NativeWebKeyboardEvent& event) OVERRIDE;
440 virtual void OverscrollUpdate(int delta_y) OVERRIDE;
441 virtual void ShowValidationMessage(content::WebContents* web_contents,
442 const gfx::Rect& anchor_in_root_view,
443 const base::string16& main_text,
444 const base::string16& sub_text) OVERRIDE;
445 virtual void HideValidationMessage(
446 content::WebContents* web_contents) OVERRIDE;
447 virtual void MoveValidationMessage(
448 content::WebContents* web_contents,
449 const gfx::Rect& anchor_in_root_view) OVERRIDE;
450 virtual bool PreHandleGestureEvent(
451 content::WebContents* source,
452 const blink::WebGestureEvent& event) OVERRIDE;
453 virtual bool CanDragEnter(
454 content::WebContents* source,
455 const content::DropData& data,
456 blink::WebDragOperationsMask operations_allowed) OVERRIDE;
458 bool is_type_tabbed() const { return type_ == TYPE_TABBED; }
459 bool is_type_popup() const { return type_ == TYPE_POPUP; }
461 bool is_app() const;
462 bool is_devtools() const;
464 // True when the mouse cursor is locked.
465 bool IsMouseLocked() const;
467 // Called each time the browser window is shown.
468 void OnWindowDidShow();
470 // Show the first run search engine bubble on the location bar.
471 void ShowFirstRunBubble();
473 // Show a download on the download shelf.
474 void ShowDownload(content::DownloadItem* download);
476 FullscreenController* fullscreen_controller() const {
477 return fullscreen_controller_.get();
480 extensions::WindowController* extension_window_controller() const {
481 return extension_window_controller_.get();
484 private:
485 friend class BrowserTest;
486 friend class FullscreenControllerInteractiveTest;
487 friend class FullscreenControllerTest;
488 FRIEND_TEST_ALL_PREFIXES(AppModeTest, EnableAppModeTest);
489 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest,
490 IsReservedCommandOrKeyIsApp);
491 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest, AppFullScreen);
492 FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups);
493 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ConvertTabToAppShortcut);
494 FRIEND_TEST_ALL_PREFIXES(BrowserTest, OpenAppWindowLikeNtp);
495 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch);
496 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ShouldShowLocationBar);
497 FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest,
498 TabEntersPresentationModeFromWindowed);
499 FRIEND_TEST_ALL_PREFIXES(FullscreenExitBubbleControllerTest,
500 DenyExitsFullscreen);
501 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref);
502 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
503 OpenAppShortcutWindowPref);
504 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref);
506 class InterstitialObserver;
508 // Used to describe why a tab is being detached. This is used by
509 // TabDetachedAtImpl.
510 enum DetachType {
511 // Result of TabDetachedAt.
512 DETACH_TYPE_DETACH,
514 // Result of TabReplacedAt.
515 DETACH_TYPE_REPLACE,
517 // Result of the tab strip not having any significant tabs.
518 DETACH_TYPE_EMPTY
521 // Describes where the bookmark bar state change originated from.
522 enum BookmarkBarStateChangeReason {
523 // From the constructor.
524 BOOKMARK_BAR_STATE_CHANGE_INIT,
526 // Change is the result of the active tab changing.
527 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH,
529 // Change is the result of the bookmark bar pref changing.
530 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE,
532 // Change is the result of a state change in the active tab.
533 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE,
535 // Change is the result of window toggling in/out of fullscreen mode.
536 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN,
539 // Overridden from content::WebContentsDelegate:
540 virtual content::WebContents* OpenURLFromTab(
541 content::WebContents* source,
542 const content::OpenURLParams& params) OVERRIDE;
543 virtual void NavigationStateChanged(
544 const content::WebContents* source,
545 content::InvalidateTypes changed_flags) OVERRIDE;
546 virtual void VisibleSSLStateChanged(
547 const content::WebContents* source) OVERRIDE;
548 virtual void AddNewContents(content::WebContents* source,
549 content::WebContents* new_contents,
550 WindowOpenDisposition disposition,
551 const gfx::Rect& initial_pos,
552 bool user_gesture,
553 bool* was_blocked) OVERRIDE;
554 virtual void ActivateContents(content::WebContents* contents) OVERRIDE;
555 virtual void DeactivateContents(content::WebContents* contents) OVERRIDE;
556 virtual void LoadingStateChanged(content::WebContents* source,
557 bool to_different_document) OVERRIDE;
558 virtual void CloseContents(content::WebContents* source) OVERRIDE;
559 virtual void MoveContents(content::WebContents* source,
560 const gfx::Rect& pos) OVERRIDE;
561 virtual bool IsPopupOrPanel(
562 const content::WebContents* source) const OVERRIDE;
563 virtual void UpdateTargetURL(content::WebContents* source, int32 page_id,
564 const GURL& url) OVERRIDE;
565 virtual void ContentsMouseEvent(content::WebContents* source,
566 const gfx::Point& location,
567 bool motion) OVERRIDE;
568 virtual void ContentsZoomChange(bool zoom_in) OVERRIDE;
569 virtual void WebContentsFocused(content::WebContents* content) OVERRIDE;
570 virtual bool TakeFocus(content::WebContents* source, bool reverse) OVERRIDE;
571 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
572 virtual void BeforeUnloadFired(content::WebContents* source,
573 bool proceed,
574 bool* proceed_to_fire_unload) OVERRIDE;
575 virtual bool ShouldFocusLocationBarByDefault(
576 content::WebContents* source) OVERRIDE;
577 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
578 virtual int GetExtraRenderViewHeight() const OVERRIDE;
579 virtual void ViewSourceForTab(content::WebContents* source,
580 const GURL& page_url) OVERRIDE;
581 virtual void ViewSourceForFrame(
582 content::WebContents* source,
583 const GURL& frame_url,
584 const content::PageState& frame_page_state) OVERRIDE;
585 virtual void ShowRepostFormWarningDialog(
586 content::WebContents* source) OVERRIDE;
587 virtual bool ShouldCreateWebContents(
588 content::WebContents* web_contents,
589 int route_id,
590 WindowContainerType window_container_type,
591 const base::string16& frame_name,
592 const GURL& target_url,
593 const std::string& partition_id,
594 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE;
595 virtual void WebContentsCreated(content::WebContents* source_contents,
596 int opener_render_frame_id,
597 const base::string16& frame_name,
598 const GURL& target_url,
599 content::WebContents* new_contents) OVERRIDE;
600 virtual void RendererUnresponsive(content::WebContents* source) OVERRIDE;
601 virtual void RendererResponsive(content::WebContents* source) OVERRIDE;
602 virtual void WorkerCrashed(content::WebContents* source) OVERRIDE;
603 virtual void DidNavigateMainFramePostCommit(
604 content::WebContents* web_contents) OVERRIDE;
605 virtual void DidNavigateToPendingEntry(
606 content::WebContents* web_contents) OVERRIDE;
607 virtual content::JavaScriptDialogManager*
608 GetJavaScriptDialogManager() OVERRIDE;
609 virtual content::ColorChooser* OpenColorChooser(
610 content::WebContents* web_contents,
611 SkColor color,
612 const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE;
613 virtual void RunFileChooser(
614 content::WebContents* web_contents,
615 const content::FileChooserParams& params) OVERRIDE;
616 virtual void EnumerateDirectory(content::WebContents* web_contents,
617 int request_id,
618 const base::FilePath& path) OVERRIDE;
619 virtual bool EmbedsFullscreenWidget() const OVERRIDE;
620 virtual void ToggleFullscreenModeForTab(content::WebContents* web_contents,
621 bool enter_fullscreen) OVERRIDE;
622 virtual bool IsFullscreenForTabOrPending(
623 const content::WebContents* web_contents) const OVERRIDE;
624 virtual void RegisterProtocolHandler(content::WebContents* web_contents,
625 const std::string& protocol,
626 const GURL& url,
627 bool user_gesture) OVERRIDE;
628 virtual void UnregisterProtocolHandler(content::WebContents* web_contents,
629 const std::string& protocol,
630 const GURL& url,
631 bool user_gesture) OVERRIDE;
632 virtual void UpdatePreferredSize(content::WebContents* source,
633 const gfx::Size& pref_size) OVERRIDE;
634 virtual void ResizeDueToAutoResize(content::WebContents* source,
635 const gfx::Size& new_size) OVERRIDE;
636 virtual void FindReply(content::WebContents* web_contents,
637 int request_id,
638 int number_of_matches,
639 const gfx::Rect& selection_rect,
640 int active_match_ordinal,
641 bool final_update) OVERRIDE;
642 virtual void RequestToLockMouse(content::WebContents* web_contents,
643 bool user_gesture,
644 bool last_unlocked_by_target) OVERRIDE;
645 virtual void LostMouseLock() OVERRIDE;
646 virtual void RequestMediaAccessPermission(
647 content::WebContents* web_contents,
648 const content::MediaStreamRequest& request,
649 const content::MediaResponseCallback& callback) OVERRIDE;
650 virtual bool RequestPpapiBrokerPermission(
651 content::WebContents* web_contents,
652 const GURL& url,
653 const base::FilePath& plugin_path,
654 const base::Callback<void(bool)>& callback) OVERRIDE;
655 virtual gfx::Size GetSizeForNewRenderView(
656 content::WebContents* web_contents) const OVERRIDE;
658 // Overridden from CoreTabHelperDelegate:
659 // Note that the caller is responsible for deleting |old_contents|.
660 virtual void SwapTabContents(content::WebContents* old_contents,
661 content::WebContents* new_contents,
662 bool did_start_load,
663 bool did_finish_load) OVERRIDE;
664 virtual bool CanReloadContents(
665 content::WebContents* web_contents) const OVERRIDE;
666 virtual bool CanSaveContents(
667 content::WebContents* web_contents) const OVERRIDE;
669 // Overridden from SearchEngineTabHelperDelegate:
670 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
671 Profile* profile) OVERRIDE;
673 // Overridden from SearchTabHelperDelegate:
674 virtual void NavigateOnThumbnailClick(
675 const GURL& url,
676 WindowOpenDisposition disposition,
677 content::WebContents* source_contents) OVERRIDE;
678 virtual void OnWebContentsInstantSupportDisabled(
679 const content::WebContents* web_contents) OVERRIDE;
680 virtual OmniboxView* GetOmniboxView() OVERRIDE;
681 virtual std::set<std::string> GetOpenUrls() OVERRIDE;
683 // Overridden from WebContentsModalDialogManagerDelegate:
684 virtual void SetWebContentsBlocked(content::WebContents* web_contents,
685 bool blocked) OVERRIDE;
686 virtual web_modal::WebContentsModalDialogHost*
687 GetWebContentsModalDialogHost() OVERRIDE;
689 // Overridden from BookmarkTabHelperDelegate:
690 virtual void URLStarredChanged(content::WebContents* web_contents,
691 bool starred) OVERRIDE;
693 // Overridden from ZoomObserver:
694 virtual void OnZoomChanged(
695 const ZoomController::ZoomChangedEventData& data) OVERRIDE;
697 // Overridden from SelectFileDialog::Listener:
698 virtual void FileSelected(const base::FilePath& path,
699 int index,
700 void* params) OVERRIDE;
701 virtual void FileSelectedWithExtraInfo(
702 const ui::SelectedFileInfo& file_info,
703 int index,
704 void* params) OVERRIDE;
706 // Overridden from content::NotificationObserver:
707 virtual void Observe(int type,
708 const content::NotificationSource& source,
709 const content::NotificationDetails& details) OVERRIDE;
711 // Command and state updating ///////////////////////////////////////////////
713 // Handle changes to kDevTools preference.
714 void OnDevToolsDisabledChanged();
716 // UI update coalescing and handling ////////////////////////////////////////
718 // Asks the toolbar (and as such the location bar) to update its state to
719 // reflect the current tab's current URL, security state, etc.
720 // If |should_restore_state| is true, we're switching (back?) to this tab and
721 // should restore any previous location bar state (such as user editing) as
722 // well.
723 void UpdateToolbar(bool should_restore_state);
725 // Does one or both of the following for each bit in |changed_flags|:
726 // . If the update should be processed immediately, it is.
727 // . If the update should processed asynchronously (to avoid lots of ui
728 // updates), then scheduled_updates_ is updated for the |source| and update
729 // pair and a task is scheduled (assuming it isn't running already)
730 // that invokes ProcessPendingUIUpdates.
731 void ScheduleUIUpdate(const content::WebContents* source,
732 unsigned changed_flags);
734 // Processes all pending updates to the UI that have been scheduled by
735 // ScheduleUIUpdate in scheduled_updates_.
736 void ProcessPendingUIUpdates();
738 // Removes all entries from scheduled_updates_ whose source is contents.
739 void RemoveScheduledUpdatesFor(content::WebContents* contents);
741 // Getters for UI ///////////////////////////////////////////////////////////
743 // TODO(beng): remove, and provide AutomationProvider a better way to access
744 // the LocationBarView's edit.
745 friend class AutomationProvider;
746 friend class BrowserProxy;
747 friend class TestingAutomationProvider;
749 // Returns the StatusBubble from the current toolbar. It is possible for
750 // this to return NULL if called before the toolbar has initialized.
751 // TODO(beng): remove this.
752 StatusBubble* GetStatusBubble();
754 // Session restore functions ////////////////////////////////////////////////
756 // Notifies the history database of the index for all tabs whose index is
757 // >= index.
758 void SyncHistoryWithTabs(int index);
760 // In-progress download termination handling /////////////////////////////////
762 // Called when the window is closing to check if potential in-progress
763 // downloads should prevent it from closing.
764 // Returns true if the window can close, false otherwise.
765 bool CanCloseWithInProgressDownloads();
767 // Assorted utility functions ///////////////////////////////////////////////
769 // Sets the specified browser as the delegate of the WebContents and all the
770 // associated tab helpers that are needed. If |set_delegate| is true, this
771 // browser object is set as a delegate for |web_contents| components, else
772 // is is removed as a delegate.
773 void SetAsDelegate(content::WebContents* web_contents, bool set_delegate);
775 // Shows the Find Bar, optionally selecting the next entry that matches the
776 // existing search string for that Tab. |forward_direction| controls the
777 // search direction.
778 void FindInPage(bool find_next, bool forward_direction);
780 // Closes the frame.
781 // TODO(beng): figure out if we need this now that the frame itself closes
782 // after a return to the message loop.
783 void CloseFrame();
785 void TabDetachedAtImpl(content::WebContents* contents,
786 int index,
787 DetachType type);
789 // Shared code between Reload() and ReloadIgnoringCache().
790 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache);
792 // Returns true if the Browser window should show the location bar.
793 bool ShouldShowLocationBar() const;
795 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
796 // |check_fullscreen| is true, the set of features reflect the actual state of
797 // the browser, otherwise the set of features reflect the possible state of
798 // the browser.
799 bool SupportsWindowFeatureImpl(WindowFeature feature,
800 bool check_fullscreen) const;
802 // Resets |bookmark_bar_state_| based on the active tab. Notifies the
803 // BrowserWindow if necessary.
804 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason);
806 bool ShouldHideUIForFullscreen() const;
808 // Creates a BackgroundContents if appropriate; return true if one was
809 // created.
810 bool MaybeCreateBackgroundContents(
811 int route_id,
812 content::WebContents* opener_web_contents,
813 const base::string16& frame_name,
814 const GURL& target_url,
815 const std::string& partition_id,
816 content::SessionStorageNamespace* session_storage_namespace);
818 // Data members /////////////////////////////////////////////////////////////
820 std::vector<InterstitialObserver*> interstitial_observers_;
822 content::NotificationRegistrar registrar_;
824 PrefChangeRegistrar profile_pref_registrar_;
826 // This Browser's type.
827 const Type type_;
829 // This Browser's profile.
830 Profile* const profile_;
832 // This Browser's window.
833 BrowserWindow* window_;
835 // Manages popup windows (bubbles, tab-modals) visible overlapping this
836 // window. JS alerts are not handled by this manager.
837 scoped_ptr<web_modal::PopupManager> popup_manager_;
839 scoped_ptr<TabStripModelDelegate> tab_strip_model_delegate_;
840 scoped_ptr<TabStripModel> tab_strip_model_;
842 // The application name that is also the name of the window to the shell.
843 // This name should be set when:
844 // 1) we launch an application via an application shortcut or extension API.
845 // 2) we launch an undocked devtool window.
846 std::string app_name_;
848 // True if the source is trusted (i.e. we do not need to show the URL in a
849 // a popup window). Also used to determine which app windows to save and
850 // restore on Chrome OS.
851 bool is_trusted_source_;
853 // Unique identifier of this browser for session restore. This id is only
854 // unique within the current session, and is not guaranteed to be unique
855 // across sessions.
856 const SessionID session_id_;
858 // The model for the toolbar view.
859 scoped_ptr<ToolbarModel> toolbar_model_;
861 // The model for the "active" search state. There are per-tab search models
862 // as well. When a tab is active its model is kept in sync with this one.
863 // When a new tab is activated its model state is propagated to this active
864 // model. This way, observers only have to attach to this single model for
865 // updates, and don't have to worry about active tab changes directly.
866 scoped_ptr<SearchModel> search_model_;
868 // UI update coalescing and handling ////////////////////////////////////////
870 typedef std::map<const content::WebContents*, int> UpdateMap;
872 // Maps from WebContents to pending UI updates that need to be processed.
873 // We don't update things like the URL or tab title right away to avoid
874 // flickering and extra painting.
875 // See ScheduleUIUpdate and ProcessPendingUIUpdates.
876 UpdateMap scheduled_updates_;
878 // In-progress download termination handling /////////////////////////////////
880 enum CancelDownloadConfirmationState {
881 NOT_PROMPTED, // We have not asked the user.
882 WAITING_FOR_RESPONSE, // We have asked the user and have not received a
883 // reponse yet.
884 RESPONSE_RECEIVED // The user was prompted and made a decision already.
887 // State used to figure-out whether we should prompt the user for confirmation
888 // when the browser is closed with in-progress downloads.
889 CancelDownloadConfirmationState cancel_download_confirmation_state_;
891 /////////////////////////////////////////////////////////////////////////////
893 // Override values for the bounds of the window and its maximized or minimized
894 // state.
895 // These are supplied by callers that don't want to use the default values.
896 // The default values are typically loaded from local state (last session),
897 // obtained from the last window of the same type, or obtained from the
898 // shell shortcut's startup info.
899 gfx::Rect override_bounds_;
900 ui::WindowShowState initial_show_state_;
902 // Tracks when this browser is being created by session restore.
903 bool is_session_restore_;
905 const chrome::HostDesktopType host_desktop_type_;
907 scoped_ptr<chrome::UnloadController> unload_controller_;
908 scoped_ptr<chrome::FastUnloadController> fast_unload_controller_;
910 // The Find Bar. This may be NULL if there is no Find Bar, and if it is
911 // non-NULL, it may or may not be visible.
912 scoped_ptr<FindBarController> find_bar_controller_;
914 // Dialog box used for opening and saving files.
915 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
917 // Keep track of the encoding auto detect pref.
918 BooleanPrefMember encoding_auto_detect_;
920 // Helper which implements the ContentSettingBubbleModel interface.
921 scoped_ptr<BrowserContentSettingBubbleModelDelegate>
922 content_setting_bubble_model_delegate_;
924 // Helper which implements the ToolbarModelDelegate interface.
925 scoped_ptr<BrowserToolbarModelDelegate> toolbar_model_delegate_;
927 // A delegate that handles the details of updating the "active"
928 // |search_model_| state with the tab's state.
929 scoped_ptr<SearchDelegate> search_delegate_;
931 // Helper which implements the TabRestoreServiceDelegate interface.
932 scoped_ptr<BrowserTabRestoreServiceDelegate> tab_restore_service_delegate_;
934 // Helper which implements the SyncedWindowDelegate interface.
935 scoped_ptr<BrowserSyncedWindowDelegate> synced_window_delegate_;
937 scoped_ptr<BrowserInstantController> instant_controller_;
939 BookmarkBar::State bookmark_bar_state_;
941 scoped_ptr<FullscreenController> fullscreen_controller_;
943 scoped_ptr<extensions::WindowController> extension_window_controller_;
945 scoped_ptr<chrome::BrowserCommandController> command_controller_;
947 // True if the browser window has been shown at least once.
948 bool window_has_shown_;
950 // The following factory is used for chrome update coalescing.
951 base::WeakPtrFactory<Browser> chrome_updater_factory_;
953 // The following factory is used to close the frame at a later time.
954 base::WeakPtrFactory<Browser> weak_factory_;
956 scoped_ptr<BrowserContentTranslateDriverObserver> translate_driver_observer_;
958 scoped_ptr<chrome::ValidationMessageBubble> validation_message_bubble_;
960 DISALLOW_COPY_AND_ASSIGN(Browser);
963 #endif // CHROME_BROWSER_UI_BROWSER_H_