BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / browser.h
blobf44f3f02a98f3cc77ca89d2ea8f9813a00f9e5b0
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/scoped_observer.h"
21 #include "base/strings/string16.h"
22 #include "chrome/browser/devtools/devtools_toggle_action.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_bubble_manager.h"
27 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
28 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
29 #include "chrome/browser/ui/host_desktop.h"
30 #include "chrome/browser/ui/search/search_tab_helper_delegate.h"
31 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h"
32 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
33 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
34 #include "components/content_settings/core/common/content_settings.h"
35 #include "components/content_settings/core/common/content_settings_types.h"
36 #include "components/sessions/session_id.h"
37 #include "components/toolbar/toolbar_model.h"
38 #include "components/translate/content/browser/content_translate_driver.h"
39 #include "components/ui/zoom/zoom_observer.h"
40 #include "content/public/browser/notification_observer.h"
41 #include "content/public/browser/notification_registrar.h"
42 #include "content/public/browser/page_navigator.h"
43 #include "content/public/browser/web_contents_delegate.h"
44 #include "content/public/common/page_zoom.h"
45 #include "ui/base/page_transition_types.h"
46 #include "ui/base/ui_base_types.h"
47 #include "ui/base/window_open_disposition.h"
48 #include "ui/gfx/geometry/rect.h"
49 #include "ui/shell_dialogs/select_file_dialog.h"
51 #if defined(ENABLE_EXTENSIONS)
52 #include "extensions/browser/extension_registry_observer.h"
53 #endif
55 class BrowserContentSettingBubbleModelDelegate;
56 class BrowserInstantController;
57 class BrowserSyncedWindowDelegate;
58 class BrowserToolbarModelDelegate;
59 class BrowserTabRestoreServiceDelegate;
60 class BrowserWindow;
61 class FindBarController;
62 class PrefService;
63 class Profile;
64 class SearchDelegate;
65 class SearchModel;
66 class StatusBubble;
67 class TabStripModel;
68 class TabStripModelDelegate;
69 class ValidationMessageBubble;
70 struct WebApplicationInfo;
72 namespace chrome {
73 class BrowserCommandController;
74 class FastUnloadController;
75 class UnloadController;
78 namespace content {
79 class NavigationController;
80 class PageState;
81 class SessionStorageNamespace;
84 namespace extensions {
85 class HostedAppBrowserController;
86 class Extension;
87 class ExtensionRegistry;
88 class WindowController;
91 namespace gfx {
92 class Image;
93 class Point;
96 namespace ui {
97 struct SelectedFileInfo;
98 class WebDialogDelegate;
101 namespace web_modal {
102 class WebContentsModalDialogHost;
105 class Browser : public TabStripModelObserver,
106 public content::WebContentsDelegate,
107 public CoreTabHelperDelegate,
108 public SearchEngineTabHelperDelegate,
109 public SearchTabHelperDelegate,
110 public ChromeWebModalDialogManagerDelegate,
111 public BookmarkTabHelperDelegate,
112 public ui_zoom::ZoomObserver,
113 public content::PageNavigator,
114 public content::NotificationObserver,
115 #if defined(ENABLE_EXTENSIONS)
116 public extensions::ExtensionRegistryObserver,
117 #endif
118 public translate::ContentTranslateDriver::Observer,
119 public ui::SelectFileDialog::Listener {
120 public:
121 // SessionService::WindowType mirrors these values. If you add to this
122 // enum, look at SessionService::WindowType to see if it needs to be
123 // updated.
124 enum Type {
125 // If you add a new type, consider updating the test
126 // BrowserTest.StartMaximized.
127 TYPE_TABBED = 1,
128 TYPE_POPUP = 2
131 // Possible elements of the Browser window.
132 enum WindowFeature {
133 FEATURE_NONE = 0,
134 FEATURE_TITLEBAR = 1,
135 FEATURE_TABSTRIP = 2,
136 FEATURE_TOOLBAR = 4,
137 FEATURE_LOCATIONBAR = 8,
138 FEATURE_BOOKMARKBAR = 16,
139 FEATURE_INFOBAR = 32,
140 FEATURE_DOWNLOADSHELF = 64,
141 FEATURE_WEBAPPFRAME = 128
144 // The context for a download blocked notification from
145 // OkToCloseWithInProgressDownloads.
146 enum DownloadClosePreventionType {
147 // Browser close is not blocked by download state.
148 DOWNLOAD_CLOSE_OK,
150 // The browser is shutting down and there are active downloads
151 // that would be cancelled.
152 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN,
154 // There are active downloads associated with this incognito profile
155 // that would be canceled.
156 DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE,
159 struct CreateParams {
160 CreateParams(Profile* profile, chrome::HostDesktopType host_desktop_type);
161 CreateParams(Type type,
162 Profile* profile,
163 chrome::HostDesktopType host_desktop_type);
165 static CreateParams CreateForApp(const std::string& app_name,
166 bool trusted_source,
167 const gfx::Rect& window_bounds,
168 Profile* profile,
169 chrome::HostDesktopType host_desktop_type);
171 static CreateParams CreateForDevTools(
172 Profile* profile,
173 chrome::HostDesktopType host_desktop_type);
175 // The browser type.
176 Type type;
178 // The associated profile.
179 Profile* profile;
181 // The host desktop the browser is created on.
182 chrome::HostDesktopType host_desktop_type;
184 // Specifies the browser is_trusted_source_ value.
185 bool trusted_source;
187 // The bounds of the window to open.
188 gfx::Rect initial_bounds;
190 ui::WindowShowState initial_show_state;
192 bool is_session_restore;
194 // Supply a custom BrowserWindow implementation, to be used instead of the
195 // default. Intended for testing.
196 BrowserWindow* window;
198 private:
199 friend class Browser;
201 // The application name that is also the name of the window to the shell.
202 // Do not set this value directly, use CreateForApp.
203 // This name will be set for:
204 // 1) v1 applications launched via an application shortcut or extension API.
205 // 2) undocked devtool windows.
206 // 3) popup windows spawned from v1 applications.
207 std::string app_name;
210 // Constructors, Creation, Showing //////////////////////////////////////////
212 explicit Browser(const CreateParams& params);
213 ~Browser() override;
215 // Set overrides for the initial window bounds and maximized state.
216 void set_override_bounds(const gfx::Rect& bounds) {
217 override_bounds_ = bounds;
219 ui::WindowShowState initial_show_state() const { return initial_show_state_; }
220 void set_initial_show_state(ui::WindowShowState initial_show_state) {
221 initial_show_state_ = initial_show_state;
223 // Return true if the initial window bounds have been overridden.
224 bool bounds_overridden() const {
225 return !override_bounds_.IsEmpty();
227 // Set indicator that this browser is being created via session restore.
228 // This is used on the Mac (only) to determine animation style when the
229 // browser window is shown.
230 void set_is_session_restore(bool is_session_restore) {
231 is_session_restore_ = is_session_restore;
233 bool is_session_restore() const {
234 return is_session_restore_;
236 chrome::HostDesktopType host_desktop_type() const {
237 return host_desktop_type_;
240 // Accessors ////////////////////////////////////////////////////////////////
242 Type type() const { return type_; }
243 const std::string& app_name() const { return app_name_; }
244 bool is_trusted_source() const { return is_trusted_source_; }
245 Profile* profile() const { return profile_; }
246 gfx::Rect override_bounds() const { return override_bounds_; }
248 // |window()| will return NULL if called before |CreateBrowserWindow()|
249 // is done.
250 BrowserWindow* window() const { return window_; }
251 ToolbarModel* toolbar_model() { return toolbar_model_.get(); }
252 const ToolbarModel* toolbar_model() const { return toolbar_model_.get(); }
253 #if defined(UNIT_TEST)
254 void swap_toolbar_models(scoped_ptr<ToolbarModel>* toolbar_model) {
255 toolbar_model->swap(toolbar_model_);
257 #endif
258 TabStripModel* tab_strip_model() const { return tab_strip_model_.get(); }
259 chrome::BrowserCommandController* command_controller() {
260 return command_controller_.get();
262 SearchModel* search_model() { return search_model_.get(); }
263 const SearchModel* search_model() const {
264 return search_model_.get();
266 SearchDelegate* search_delegate() {
267 return search_delegate_.get();
269 const SessionID& session_id() const { return session_id_; }
270 BrowserContentSettingBubbleModelDelegate*
271 content_setting_bubble_model_delegate() {
272 return content_setting_bubble_model_delegate_.get();
274 BrowserTabRestoreServiceDelegate* tab_restore_service_delegate() {
275 return tab_restore_service_delegate_.get();
277 BrowserSyncedWindowDelegate* synced_window_delegate() {
278 return synced_window_delegate_.get();
280 BrowserInstantController* instant_controller() {
281 return instant_controller_.get();
283 extensions::HostedAppBrowserController* hosted_app_controller() {
284 return hosted_app_controller_.get();
287 // Will lazy create the bubble manager.
288 ChromeBubbleManager* GetBubbleManager();
290 // Get the FindBarController for this browser, creating it if it does not
291 // yet exist.
292 FindBarController* GetFindBarController();
294 // Returns true if a FindBarController exists for this browser.
295 bool HasFindBarController() const;
297 // Returns the state of the bookmark bar.
298 BookmarkBar::State bookmark_bar_state() const { return bookmark_bar_state_; }
300 // State Storage and Retrieval for UI ///////////////////////////////////////
302 // Gets the Favicon of the page in the selected tab.
303 gfx::Image GetCurrentPageIcon() const;
305 // Gets the title of the window based on the selected tab's title.
306 base::string16 GetWindowTitleForCurrentTab() const;
308 // Prepares a title string for display (removes embedded newlines, etc).
309 static void FormatTitleForDisplay(base::string16* title);
311 // OnBeforeUnload handling //////////////////////////////////////////////////
313 // Gives beforeunload handlers the chance to cancel the close. Returns whether
314 // to proceed with the close. If called while the process begun by
315 // CallBeforeUnloadHandlers is in progress, returns false without taking
316 // action.
317 bool ShouldCloseWindow();
319 // Begins the process of confirming whether the associated browser can be
320 // closed. If there are no tabs with beforeunload handlers it will immediately
321 // return false. Otherwise, it starts prompting the user, returns true and
322 // will call |on_close_confirmed| with the result of the user's decision.
323 // After calling this function, if the window will not be closed, call
324 // ResetBeforeUnloadHandlers() to reset all beforeunload handlers; calling
325 // this function multiple times without an intervening call to
326 // ResetBeforeUnloadHandlers() will run only the beforeunload handlers
327 // registered since the previous call.
328 bool CallBeforeUnloadHandlers(
329 const base::Callback<void(bool)>& on_close_confirmed);
331 // Clears the results of any beforeunload confirmation dialogs triggered by a
332 // CallBeforeUnloadHandlers call.
333 void ResetBeforeUnloadHandlers();
335 // Figure out if there are tabs that have beforeunload handlers.
336 // It starts beforeunload/unload processing as a side-effect.
337 bool TabsNeedBeforeUnloadFired();
339 // Returns true if all tabs' beforeunload/unload events have fired.
340 bool HasCompletedUnloadProcessing() const;
342 bool IsAttemptingToCloseBrowser() const;
344 // Invoked when the window containing us is closing. Performs the necessary
345 // cleanup.
346 void OnWindowClosing();
348 // In-progress download termination handling /////////////////////////////////
350 // Called when the user has decided whether to proceed or not with the browser
351 // closure. |cancel_downloads| is true if the downloads should be canceled
352 // and the browser closed, false if the browser should stay open and the
353 // downloads running.
354 void InProgressDownloadResponse(bool cancel_downloads);
356 // Indicates whether or not this browser window can be closed, or
357 // would be blocked by in-progress downloads.
358 // If executing downloads would be cancelled by this window close,
359 // then |*num_downloads_blocking| is updated with how many downloads
360 // would be canceled if the close continued.
361 DownloadClosePreventionType OkToCloseWithInProgressDownloads(
362 int* num_downloads_blocking) const;
364 // External state change handling ////////////////////////////////////////////
366 // Invoked when the fullscreen state of the window changes.
367 // BrowserWindow::EnterFullscreen invokes this after the window has become
368 // fullscreen.
369 void WindowFullscreenStateChanged();
371 // Assorted browser commands ////////////////////////////////////////////////
373 // NOTE: Within each of the following sections, the IDs are ordered roughly by
374 // how they appear in the GUI/menus (left to right, top to bottom, etc.).
376 // See the description of
377 // FullscreenController::ToggleFullscreenModeWithExtension.
378 void ToggleFullscreenModeWithExtension(const GURL& extension_url);
380 #if defined(OS_WIN)
381 // See the description of FullscreenController::ToggleMetroSnapMode.
382 void SetMetroSnapMode(bool enable);
383 #endif
385 // Returns true if the Browser supports the specified feature. The value of
386 // this varies during the lifetime of the browser. For example, if the window
387 // is fullscreen this may return a different value. If you only care about
388 // whether or not it's possible for the browser to support a particular
389 // feature use |CanSupportWindowFeature|.
390 bool SupportsWindowFeature(WindowFeature feature) const;
392 // Returns true if the Browser can support the specified feature. See comment
393 // in |SupportsWindowFeature| for details on this.
394 bool CanSupportWindowFeature(WindowFeature feature) const;
396 // TODO(port): port these, and re-merge the two function declaration lists.
397 // Page-related commands.
398 void ToggleEncodingAutoDetect();
399 void OverrideEncoding(int encoding_id);
401 // Show various bits of UI
402 void OpenFile();
404 void UpdateDownloadShelfVisibility(bool visible);
406 /////////////////////////////////////////////////////////////////////////////
408 // Called by chrome::Navigate() when a navigation has occurred in a tab in
409 // this Browser. Updates the UI for the start of this navigation.
410 void UpdateUIForNavigationInTab(content::WebContents* contents,
411 ui::PageTransition transition,
412 bool user_initiated);
414 // Interface implementations ////////////////////////////////////////////////
416 // Overridden from content::PageNavigator:
417 content::WebContents* OpenURL(const content::OpenURLParams& params) override;
419 // Overridden from TabStripModelObserver:
420 void TabInsertedAt(content::WebContents* contents,
421 int index,
422 bool foreground) override;
423 void TabClosingAt(TabStripModel* tab_strip_model,
424 content::WebContents* contents,
425 int index) override;
426 void TabDetachedAt(content::WebContents* contents, int index) override;
427 void TabDeactivated(content::WebContents* contents) override;
428 void ActiveTabChanged(content::WebContents* old_contents,
429 content::WebContents* new_contents,
430 int index,
431 int reason) override;
432 void TabMoved(content::WebContents* contents,
433 int from_index,
434 int to_index) override;
435 void TabReplacedAt(TabStripModel* tab_strip_model,
436 content::WebContents* old_contents,
437 content::WebContents* new_contents,
438 int index) override;
439 void TabPinnedStateChanged(content::WebContents* contents,
440 int index) override;
441 void TabStripEmpty() override;
443 // Overridden from content::WebContentsDelegate:
444 bool CanOverscrollContent() const override;
445 bool ShouldPreserveAbortedURLs(content::WebContents* source) override;
446 void SetFocusToLocationBar(bool select_all) override;
447 bool PreHandleKeyboardEvent(content::WebContents* source,
448 const content::NativeWebKeyboardEvent& event,
449 bool* is_keyboard_shortcut) override;
450 void HandleKeyboardEvent(
451 content::WebContents* source,
452 const content::NativeWebKeyboardEvent& event) override;
453 void ShowValidationMessage(content::WebContents* web_contents,
454 const gfx::Rect& anchor_in_root_view,
455 const base::string16& main_text,
456 const base::string16& sub_text) override;
457 void HideValidationMessage(content::WebContents* web_contents) override;
458 void MoveValidationMessage(content::WebContents* web_contents,
459 const gfx::Rect& anchor_in_root_view) override;
460 bool PreHandleGestureEvent(content::WebContents* source,
461 const blink::WebGestureEvent& event) override;
462 bool CanDragEnter(content::WebContents* source,
463 const content::DropData& data,
464 blink::WebDragOperationsMask operations_allowed) override;
465 content::SecurityStyle GetSecurityStyle(
466 content::WebContents* web_contents,
467 content::SecurityStyleExplanations* security_style_explanations) override;
468 void ShowCertificateViewerInDevTools(
469 content::WebContents* web_contents,
470 int cert_id) override;
472 bool is_type_tabbed() const { return type_ == TYPE_TABBED; }
473 bool is_type_popup() const { return type_ == TYPE_POPUP; }
475 bool is_app() const;
476 bool is_devtools() const;
478 // True when the mouse cursor is locked.
479 bool IsMouseLocked() const;
481 // Called each time the browser window is shown.
482 void OnWindowDidShow();
484 // Show the first run search engine bubble on the location bar.
485 void ShowFirstRunBubble();
487 ExclusiveAccessManager* exclusive_access_manager() {
488 return exclusive_access_manager_.get();
491 extensions::WindowController* extension_window_controller() const {
492 return extension_window_controller_.get();
495 private:
496 friend class BrowserTest;
497 friend class FullscreenControllerInteractiveTest;
498 friend class FullscreenControllerTest;
499 FRIEND_TEST_ALL_PREFIXES(AppModeTest, EnableAppModeTest);
500 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest,
501 IsReservedCommandOrKeyIsApp);
502 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest, AppFullScreen);
503 FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups);
504 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ConvertTabToAppShortcut);
505 FRIEND_TEST_ALL_PREFIXES(BrowserTest, OpenAppWindowLikeNtp);
506 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch);
507 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ShouldShowLocationBar);
508 FRIEND_TEST_ALL_PREFIXES(ExclusiveAccessBubbleWindowControllerTest,
509 DenyExitsFullscreen);
510 FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest,
511 TabEntersPresentationModeFromWindowed);
512 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref);
513 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
514 OpenAppShortcutWindowPref);
515 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref);
517 class InterstitialObserver;
519 // Used to describe why a tab is being detached. This is used by
520 // TabDetachedAtImpl.
521 enum DetachType {
522 // Result of TabDetachedAt.
523 DETACH_TYPE_DETACH,
525 // Result of TabReplacedAt.
526 DETACH_TYPE_REPLACE,
528 // Result of the tab strip not having any significant tabs.
529 DETACH_TYPE_EMPTY
532 // Describes where the bookmark bar state change originated from.
533 enum BookmarkBarStateChangeReason {
534 // From the constructor.
535 BOOKMARK_BAR_STATE_CHANGE_INIT,
537 // Change is the result of the active tab changing.
538 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH,
540 // Change is the result of the bookmark bar pref changing.
541 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE,
543 // Change is the result of a state change in the active tab.
544 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE,
546 // Change is the result of window toggling in/out of fullscreen mode.
547 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN,
550 // Overridden from content::WebContentsDelegate:
551 content::WebContents* OpenURLFromTab(
552 content::WebContents* source,
553 const content::OpenURLParams& params) override;
554 void NavigationStateChanged(content::WebContents* source,
555 content::InvalidateTypes changed_flags) override;
556 void VisibleSSLStateChanged(const content::WebContents* source) override;
557 void AddNewContents(content::WebContents* source,
558 content::WebContents* new_contents,
559 WindowOpenDisposition disposition,
560 const gfx::Rect& initial_rect,
561 bool user_gesture,
562 bool* was_blocked) override;
563 void ActivateContents(content::WebContents* contents) override;
564 void DeactivateContents(content::WebContents* contents) override;
565 void LoadingStateChanged(content::WebContents* source,
566 bool to_different_document) override;
567 void CloseContents(content::WebContents* source) override;
568 void MoveContents(content::WebContents* source,
569 const gfx::Rect& pos) override;
570 bool IsPopupOrPanel(const content::WebContents* source) const override;
571 void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
572 void ContentsMouseEvent(content::WebContents* source,
573 const gfx::Point& location,
574 bool motion) override;
575 void ContentsZoomChange(bool zoom_in) override;
576 bool TakeFocus(content::WebContents* source, bool reverse) override;
577 gfx::Rect GetRootWindowResizerRect() const override;
578 void BeforeUnloadFired(content::WebContents* source,
579 bool proceed,
580 bool* proceed_to_fire_unload) override;
581 bool ShouldFocusLocationBarByDefault(content::WebContents* source) override;
582 void ViewSourceForTab(content::WebContents* source,
583 const GURL& page_url) override;
584 void ViewSourceForFrame(content::WebContents* source,
585 const GURL& frame_url,
586 const content::PageState& frame_page_state) override;
587 void ShowRepostFormWarningDialog(content::WebContents* source) override;
588 bool ShouldCreateWebContents(
589 content::WebContents* web_contents,
590 int route_id,
591 int main_frame_route_id,
592 WindowContainerType window_container_type,
593 const std::string& frame_name,
594 const GURL& target_url,
595 const std::string& partition_id,
596 content::SessionStorageNamespace* session_storage_namespace) override;
597 void WebContentsCreated(content::WebContents* source_contents,
598 int opener_render_frame_id,
599 const std::string& frame_name,
600 const GURL& target_url,
601 content::WebContents* new_contents) override;
602 void RendererUnresponsive(content::WebContents* source) override;
603 void RendererResponsive(content::WebContents* source) override;
604 void DidNavigateMainFramePostCommit(
605 content::WebContents* web_contents) override;
606 content::JavaScriptDialogManager* GetJavaScriptDialogManager(
607 content::WebContents* source) override;
608 content::ColorChooser* OpenColorChooser(
609 content::WebContents* web_contents,
610 SkColor color,
611 const std::vector<content::ColorSuggestion>& suggestions) override;
612 void RunFileChooser(content::WebContents* web_contents,
613 const content::FileChooserParams& params) override;
614 void EnumerateDirectory(content::WebContents* web_contents,
615 int request_id,
616 const base::FilePath& path) override;
617 bool EmbedsFullscreenWidget() const override;
618 void EnterFullscreenModeForTab(content::WebContents* web_contents,
619 const GURL& origin) override;
620 void ExitFullscreenModeForTab(content::WebContents* web_contents) override;
621 bool IsFullscreenForTabOrPending(
622 const content::WebContents* web_contents) const override;
623 blink::WebDisplayMode GetDisplayMode(
624 const content::WebContents* web_contents) const override;
625 void RegisterProtocolHandler(content::WebContents* web_contents,
626 const std::string& protocol,
627 const GURL& url,
628 bool user_gesture) override;
629 void UnregisterProtocolHandler(content::WebContents* web_contents,
630 const std::string& protocol,
631 const GURL& url,
632 bool user_gesture) override;
633 void UpdatePreferredSize(content::WebContents* source,
634 const gfx::Size& pref_size) override;
635 void ResizeDueToAutoResize(content::WebContents* source,
636 const gfx::Size& new_size) override;
637 void FindReply(content::WebContents* web_contents,
638 int request_id,
639 int number_of_matches,
640 const gfx::Rect& selection_rect,
641 int active_match_ordinal,
642 bool final_update) override;
643 void RequestToLockMouse(content::WebContents* web_contents,
644 bool user_gesture,
645 bool last_unlocked_by_target) override;
646 void LostMouseLock() override;
647 void RequestMediaAccessPermission(
648 content::WebContents* web_contents,
649 const content::MediaStreamRequest& request,
650 const content::MediaResponseCallback& callback) override;
651 bool CheckMediaAccessPermission(content::WebContents* web_contents,
652 const GURL& security_origin,
653 content::MediaStreamType type) override;
654 bool RequestPpapiBrokerPermission(
655 content::WebContents* web_contents,
656 const GURL& url,
657 const base::FilePath& plugin_path,
658 const base::Callback<void(bool)>& callback) override;
659 gfx::Size GetSizeForNewRenderView(
660 content::WebContents* web_contents) const override;
662 // Overridden from CoreTabHelperDelegate:
663 // Note that the caller is responsible for deleting |old_contents|.
664 void SwapTabContents(content::WebContents* old_contents,
665 content::WebContents* new_contents,
666 bool did_start_load,
667 bool did_finish_load) override;
668 bool CanReloadContents(content::WebContents* web_contents) const override;
669 bool CanSaveContents(content::WebContents* web_contents) const override;
671 // Overridden from SearchEngineTabHelperDelegate:
672 void ConfirmAddSearchProvider(TemplateURL* template_url,
673 Profile* profile) override;
675 // Overridden from SearchTabHelperDelegate:
676 void NavigateOnThumbnailClick(const GURL& url,
677 WindowOpenDisposition disposition,
678 content::WebContents* source_contents) override;
679 void OnWebContentsInstantSupportDisabled(
680 const content::WebContents* web_contents) override;
681 OmniboxView* GetOmniboxView() override;
682 std::set<std::string> GetOpenUrls() override;
684 // Overridden from WebContentsModalDialogManagerDelegate:
685 void SetWebContentsBlocked(content::WebContents* web_contents,
686 bool blocked) override;
687 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()
688 override;
690 // Overridden from BookmarkTabHelperDelegate:
691 void URLStarredChanged(content::WebContents* web_contents,
692 bool starred) override;
694 // Overridden from ZoomObserver:
695 void OnZoomChanged(
696 const ui_zoom::ZoomController::ZoomChangedEventData& data) override;
698 // Overridden from SelectFileDialog::Listener:
699 void FileSelected(const base::FilePath& path,
700 int index,
701 void* params) override;
702 void FileSelectedWithExtraInfo(const ui::SelectedFileInfo& file_info,
703 int index,
704 void* params) override;
706 // Overridden from content::NotificationObserver:
707 void Observe(int type,
708 const content::NotificationSource& source,
709 const content::NotificationDetails& details) override;
711 #if defined(ENABLE_EXTENSIONS)
712 // Overridden from extensions::ExtensionRegistryObserver:
713 void OnExtensionUninstalled(content::BrowserContext* browser_context,
714 const extensions::Extension* extension,
715 extensions::UninstallReason reason) override;
716 void OnExtensionLoaded(content::BrowserContext* browser_context,
717 const extensions::Extension* extension) override;
718 void OnExtensionUnloaded(
719 content::BrowserContext* browser_context,
720 const extensions::Extension* extension,
721 extensions::UnloadedExtensionInfo::Reason reason) override;
722 #endif
724 // Overridden from translate::ContentTranslateDriver::Observer:
725 void OnIsPageTranslatedChanged(content::WebContents* source) override;
726 void OnTranslateEnabledChanged(content::WebContents* source) override;
728 // Command and state updating ///////////////////////////////////////////////
730 // Handle changes to kDevTools preference.
731 void OnDevToolsDisabledChanged();
733 // UI update coalescing and handling ////////////////////////////////////////
735 // Asks the toolbar (and as such the location bar) to update its state to
736 // reflect the current tab's current URL, security state, etc.
737 // If |should_restore_state| is true, we're switching (back?) to this tab and
738 // should restore any previous location bar state (such as user editing) as
739 // well.
740 void UpdateToolbar(bool should_restore_state);
742 // Does one or both of the following for each bit in |changed_flags|:
743 // . If the update should be processed immediately, it is.
744 // . If the update should processed asynchronously (to avoid lots of ui
745 // updates), then scheduled_updates_ is updated for the |source| and update
746 // pair and a task is scheduled (assuming it isn't running already)
747 // that invokes ProcessPendingUIUpdates.
748 void ScheduleUIUpdate(content::WebContents* source,
749 unsigned changed_flags);
751 // Processes all pending updates to the UI that have been scheduled by
752 // ScheduleUIUpdate in scheduled_updates_.
753 void ProcessPendingUIUpdates();
755 // Removes all entries from scheduled_updates_ whose source is contents.
756 void RemoveScheduledUpdatesFor(content::WebContents* contents);
758 // Getters for UI ///////////////////////////////////////////////////////////
760 // TODO(beng): remove, and provide AutomationProvider a better way to access
761 // the LocationBarView's edit.
762 friend class AutomationProvider;
763 friend class BrowserProxy;
765 // Returns the StatusBubble from the current toolbar. It is possible for
766 // this to return NULL if called before the toolbar has initialized.
767 // TODO(beng): remove this.
768 StatusBubble* GetStatusBubble();
770 // Session restore functions ////////////////////////////////////////////////
772 // Notifies the history database of the index for all tabs whose index is
773 // >= index.
774 void SyncHistoryWithTabs(int index);
776 // In-progress download termination handling /////////////////////////////////
778 // Called when the window is closing to check if potential in-progress
779 // downloads should prevent it from closing.
780 // Returns true if the window can close, false otherwise.
781 bool CanCloseWithInProgressDownloads();
783 // Assorted utility functions ///////////////////////////////////////////////
785 // Sets the specified browser as the delegate of the WebContents and all the
786 // associated tab helpers that are needed. If |set_delegate| is true, this
787 // browser object is set as a delegate for |web_contents| components, else
788 // is is removed as a delegate.
789 void SetAsDelegate(content::WebContents* web_contents, bool set_delegate);
791 // Shows the Find Bar, optionally selecting the next entry that matches the
792 // existing search string for that Tab. |forward_direction| controls the
793 // search direction.
794 void FindInPage(bool find_next, bool forward_direction);
796 // Closes the frame.
797 // TODO(beng): figure out if we need this now that the frame itself closes
798 // after a return to the message loop.
799 void CloseFrame();
801 void TabDetachedAtImpl(content::WebContents* contents,
802 int index,
803 DetachType type);
805 // Shared code between Reload() and ReloadIgnoringCache().
806 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache);
808 // Returns true if the Browser window supports a location bar. Having support
809 // for the location bar does not mean it will be visible.
810 bool SupportsLocationBar() const;
812 // Returns true if the Browser window should show the location bar.
813 bool ShouldShowLocationBar() const;
815 // Returns true if the Browser window should use a web app style frame.
816 bool ShouldUseWebAppFrame() const;
818 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
819 // |check_fullscreen| is true, the set of features reflect the actual state of
820 // the browser, otherwise the set of features reflect the possible state of
821 // the browser.
822 bool SupportsWindowFeatureImpl(WindowFeature feature,
823 bool check_fullscreen) const;
825 // Resets |bookmark_bar_state_| based on the active tab. Notifies the
826 // BrowserWindow if necessary.
827 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason);
829 bool ShouldHideUIForFullscreen() const;
831 // Creates a BackgroundContents if appropriate; return true if one was
832 // created.
833 bool MaybeCreateBackgroundContents(
834 int route_id,
835 int main_frame_route_id,
836 content::WebContents* opener_web_contents,
837 const std::string& frame_name,
838 const GURL& target_url,
839 const std::string& partition_id,
840 content::SessionStorageNamespace* session_storage_namespace);
842 // Data members /////////////////////////////////////////////////////////////
844 std::vector<InterstitialObserver*> interstitial_observers_;
846 content::NotificationRegistrar registrar_;
848 #if defined(ENABLE_EXTENSIONS)
849 ScopedObserver<extensions::ExtensionRegistry,
850 extensions::ExtensionRegistryObserver>
851 extension_registry_observer_;
852 #endif
854 PrefChangeRegistrar profile_pref_registrar_;
856 // This Browser's type.
857 const Type type_;
859 // This Browser's profile.
860 Profile* const profile_;
862 // This Browser's window.
863 BrowserWindow* window_;
865 scoped_ptr<TabStripModelDelegate> tab_strip_model_delegate_;
866 scoped_ptr<TabStripModel> tab_strip_model_;
868 // The application name that is also the name of the window to the shell.
869 // This name should be set when:
870 // 1) we launch an application via an application shortcut or extension API.
871 // 2) we launch an undocked devtool window.
872 std::string app_name_;
874 // True if the source is trusted (i.e. we do not need to show the URL in a
875 // a popup window). Also used to determine which app windows to save and
876 // restore on Chrome OS.
877 bool is_trusted_source_;
879 // Unique identifier of this browser for session restore. This id is only
880 // unique within the current session, and is not guaranteed to be unique
881 // across sessions.
882 const SessionID session_id_;
884 // The model for the toolbar view.
885 scoped_ptr<ToolbarModel> toolbar_model_;
887 // The model for the "active" search state. There are per-tab search models
888 // as well. When a tab is active its model is kept in sync with this one.
889 // When a new tab is activated its model state is propagated to this active
890 // model. This way, observers only have to attach to this single model for
891 // updates, and don't have to worry about active tab changes directly.
892 scoped_ptr<SearchModel> search_model_;
894 // UI update coalescing and handling ////////////////////////////////////////
896 typedef std::map<const content::WebContents*, int> UpdateMap;
898 // Maps from WebContents to pending UI updates that need to be processed.
899 // We don't update things like the URL or tab title right away to avoid
900 // flickering and extra painting.
901 // See ScheduleUIUpdate and ProcessPendingUIUpdates.
902 UpdateMap scheduled_updates_;
904 // In-progress download termination handling /////////////////////////////////
906 enum CancelDownloadConfirmationState {
907 NOT_PROMPTED, // We have not asked the user.
908 WAITING_FOR_RESPONSE, // We have asked the user and have not received a
909 // reponse yet.
910 RESPONSE_RECEIVED // The user was prompted and made a decision already.
913 // State used to figure-out whether we should prompt the user for confirmation
914 // when the browser is closed with in-progress downloads.
915 CancelDownloadConfirmationState cancel_download_confirmation_state_;
917 /////////////////////////////////////////////////////////////////////////////
919 // Override values for the bounds of the window and its maximized or minimized
920 // state.
921 // These are supplied by callers that don't want to use the default values.
922 // The default values are typically loaded from local state (last session),
923 // obtained from the last window of the same type, or obtained from the
924 // shell shortcut's startup info.
925 gfx::Rect override_bounds_;
926 ui::WindowShowState initial_show_state_;
928 // Tracks when this browser is being created by session restore.
929 bool is_session_restore_;
931 const chrome::HostDesktopType host_desktop_type_;
933 scoped_ptr<chrome::UnloadController> unload_controller_;
934 scoped_ptr<chrome::FastUnloadController> fast_unload_controller_;
936 scoped_ptr<ChromeBubbleManager> bubble_manager_;
938 // The Find Bar. This may be NULL if there is no Find Bar, and if it is
939 // non-NULL, it may or may not be visible.
940 scoped_ptr<FindBarController> find_bar_controller_;
942 // Dialog box used for opening and saving files.
943 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
945 // Keep track of the encoding auto detect pref.
946 BooleanPrefMember encoding_auto_detect_;
948 // Helper which implements the ContentSettingBubbleModel interface.
949 scoped_ptr<BrowserContentSettingBubbleModelDelegate>
950 content_setting_bubble_model_delegate_;
952 // Helper which implements the ToolbarModelDelegate interface.
953 scoped_ptr<BrowserToolbarModelDelegate> toolbar_model_delegate_;
955 // A delegate that handles the details of updating the "active"
956 // |search_model_| state with the tab's state.
957 scoped_ptr<SearchDelegate> search_delegate_;
959 // Helper which implements the TabRestoreServiceDelegate interface.
960 scoped_ptr<BrowserTabRestoreServiceDelegate> tab_restore_service_delegate_;
962 // Helper which implements the SyncedWindowDelegate interface.
963 scoped_ptr<BrowserSyncedWindowDelegate> synced_window_delegate_;
965 scoped_ptr<BrowserInstantController> instant_controller_;
967 // Helper which handles bookmark app specific browser configuration.
968 scoped_ptr<extensions::HostedAppBrowserController> hosted_app_controller_;
970 BookmarkBar::State bookmark_bar_state_;
972 scoped_ptr<ExclusiveAccessManager> exclusive_access_manager_;
974 scoped_ptr<extensions::WindowController> extension_window_controller_;
976 scoped_ptr<chrome::BrowserCommandController> command_controller_;
978 // True if the browser window has been shown at least once.
979 bool window_has_shown_;
981 scoped_ptr<ValidationMessageBubble> validation_message_bubble_;
983 // The following factory is used for chrome update coalescing.
984 base::WeakPtrFactory<Browser> chrome_updater_factory_;
986 // The following factory is used to close the frame at a later time.
987 base::WeakPtrFactory<Browser> weak_factory_;
989 DISALLOW_COPY_AND_ASSIGN(Browser);
992 #endif // CHROME_BROWSER_UI_BROWSER_H_