Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / browser.h
blob56add135c3899cd979499b860705aa8b8b8e745a
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;
469 bool is_type_tabbed() const { return type_ == TYPE_TABBED; }
470 bool is_type_popup() const { return type_ == TYPE_POPUP; }
472 bool is_app() const;
473 bool is_devtools() const;
475 // True when the mouse cursor is locked.
476 bool IsMouseLocked() const;
478 // Called each time the browser window is shown.
479 void OnWindowDidShow();
481 // Show the first run search engine bubble on the location bar.
482 void ShowFirstRunBubble();
484 ExclusiveAccessManager* exclusive_access_manager() {
485 return exclusive_access_manager_.get();
488 extensions::WindowController* extension_window_controller() const {
489 return extension_window_controller_.get();
492 private:
493 friend class BrowserTest;
494 friend class FullscreenControllerInteractiveTest;
495 friend class FullscreenControllerTest;
496 FRIEND_TEST_ALL_PREFIXES(AppModeTest, EnableAppModeTest);
497 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest,
498 IsReservedCommandOrKeyIsApp);
499 FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest, AppFullScreen);
500 FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups);
501 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ConvertTabToAppShortcut);
502 FRIEND_TEST_ALL_PREFIXES(BrowserTest, OpenAppWindowLikeNtp);
503 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch);
504 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ShouldShowLocationBar);
505 FRIEND_TEST_ALL_PREFIXES(ExclusiveAccessBubbleWindowControllerTest,
506 DenyExitsFullscreen);
507 FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest,
508 TabEntersPresentationModeFromWindowed);
509 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref);
510 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
511 OpenAppShortcutWindowPref);
512 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref);
514 class InterstitialObserver;
516 // Used to describe why a tab is being detached. This is used by
517 // TabDetachedAtImpl.
518 enum DetachType {
519 // Result of TabDetachedAt.
520 DETACH_TYPE_DETACH,
522 // Result of TabReplacedAt.
523 DETACH_TYPE_REPLACE,
525 // Result of the tab strip not having any significant tabs.
526 DETACH_TYPE_EMPTY
529 // Describes where the bookmark bar state change originated from.
530 enum BookmarkBarStateChangeReason {
531 // From the constructor.
532 BOOKMARK_BAR_STATE_CHANGE_INIT,
534 // Change is the result of the active tab changing.
535 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH,
537 // Change is the result of the bookmark bar pref changing.
538 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE,
540 // Change is the result of a state change in the active tab.
541 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE,
543 // Change is the result of window toggling in/out of fullscreen mode.
544 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN,
547 // Overridden from content::WebContentsDelegate:
548 content::WebContents* OpenURLFromTab(
549 content::WebContents* source,
550 const content::OpenURLParams& params) override;
551 void NavigationStateChanged(content::WebContents* source,
552 content::InvalidateTypes changed_flags) override;
553 void VisibleSSLStateChanged(const content::WebContents* source) override;
554 void AddNewContents(content::WebContents* source,
555 content::WebContents* new_contents,
556 WindowOpenDisposition disposition,
557 const gfx::Rect& initial_rect,
558 bool user_gesture,
559 bool* was_blocked) override;
560 void ActivateContents(content::WebContents* contents) override;
561 void DeactivateContents(content::WebContents* contents) override;
562 void LoadingStateChanged(content::WebContents* source,
563 bool to_different_document) override;
564 void CloseContents(content::WebContents* source) override;
565 void MoveContents(content::WebContents* source,
566 const gfx::Rect& pos) override;
567 bool IsPopupOrPanel(const content::WebContents* source) const override;
568 void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
569 void ContentsMouseEvent(content::WebContents* source,
570 const gfx::Point& location,
571 bool motion) override;
572 void ContentsZoomChange(bool zoom_in) override;
573 bool TakeFocus(content::WebContents* source, bool reverse) override;
574 gfx::Rect GetRootWindowResizerRect() const override;
575 void BeforeUnloadFired(content::WebContents* source,
576 bool proceed,
577 bool* proceed_to_fire_unload) override;
578 bool ShouldFocusLocationBarByDefault(content::WebContents* source) override;
579 void ViewSourceForTab(content::WebContents* source,
580 const GURL& page_url) override;
581 void ViewSourceForFrame(content::WebContents* source,
582 const GURL& frame_url,
583 const content::PageState& frame_page_state) override;
584 void ShowRepostFormWarningDialog(content::WebContents* source) override;
585 bool ShouldCreateWebContents(
586 content::WebContents* web_contents,
587 int route_id,
588 int main_frame_route_id,
589 WindowContainerType window_container_type,
590 const std::string& frame_name,
591 const GURL& target_url,
592 const std::string& partition_id,
593 content::SessionStorageNamespace* session_storage_namespace) override;
594 void WebContentsCreated(content::WebContents* source_contents,
595 int opener_render_frame_id,
596 const std::string& frame_name,
597 const GURL& target_url,
598 content::WebContents* new_contents) override;
599 void RendererUnresponsive(content::WebContents* source) override;
600 void RendererResponsive(content::WebContents* source) override;
601 void DidNavigateMainFramePostCommit(
602 content::WebContents* web_contents) override;
603 content::JavaScriptDialogManager* GetJavaScriptDialogManager(
604 content::WebContents* source) override;
605 content::ColorChooser* OpenColorChooser(
606 content::WebContents* web_contents,
607 SkColor color,
608 const std::vector<content::ColorSuggestion>& suggestions) override;
609 void RunFileChooser(content::WebContents* web_contents,
610 const content::FileChooserParams& params) override;
611 void EnumerateDirectory(content::WebContents* web_contents,
612 int request_id,
613 const base::FilePath& path) override;
614 bool EmbedsFullscreenWidget() const override;
615 void EnterFullscreenModeForTab(content::WebContents* web_contents,
616 const GURL& origin) override;
617 void ExitFullscreenModeForTab(content::WebContents* web_contents) override;
618 bool IsFullscreenForTabOrPending(
619 const content::WebContents* web_contents) const override;
620 void RegisterProtocolHandler(content::WebContents* web_contents,
621 const std::string& protocol,
622 const GURL& url,
623 bool user_gesture) override;
624 void UnregisterProtocolHandler(content::WebContents* web_contents,
625 const std::string& protocol,
626 const GURL& url,
627 bool user_gesture) override;
628 void UpdatePreferredSize(content::WebContents* source,
629 const gfx::Size& pref_size) override;
630 void ResizeDueToAutoResize(content::WebContents* source,
631 const gfx::Size& new_size) override;
632 void FindReply(content::WebContents* web_contents,
633 int request_id,
634 int number_of_matches,
635 const gfx::Rect& selection_rect,
636 int active_match_ordinal,
637 bool final_update) override;
638 void RequestToLockMouse(content::WebContents* web_contents,
639 bool user_gesture,
640 bool last_unlocked_by_target) override;
641 void LostMouseLock() override;
642 void RequestMediaAccessPermission(
643 content::WebContents* web_contents,
644 const content::MediaStreamRequest& request,
645 const content::MediaResponseCallback& callback) override;
646 bool CheckMediaAccessPermission(content::WebContents* web_contents,
647 const GURL& security_origin,
648 content::MediaStreamType type) override;
649 bool RequestPpapiBrokerPermission(
650 content::WebContents* web_contents,
651 const GURL& url,
652 const base::FilePath& plugin_path,
653 const base::Callback<void(bool)>& callback) override;
654 gfx::Size GetSizeForNewRenderView(
655 content::WebContents* web_contents) const override;
657 // Overridden from CoreTabHelperDelegate:
658 // Note that the caller is responsible for deleting |old_contents|.
659 void SwapTabContents(content::WebContents* old_contents,
660 content::WebContents* new_contents,
661 bool did_start_load,
662 bool did_finish_load) override;
663 bool CanReloadContents(content::WebContents* web_contents) const override;
664 bool CanSaveContents(content::WebContents* web_contents) const override;
666 // Overridden from SearchEngineTabHelperDelegate:
667 void ConfirmAddSearchProvider(TemplateURL* template_url,
668 Profile* profile) override;
670 // Overridden from SearchTabHelperDelegate:
671 void NavigateOnThumbnailClick(const GURL& url,
672 WindowOpenDisposition disposition,
673 content::WebContents* source_contents) override;
674 void OnWebContentsInstantSupportDisabled(
675 const content::WebContents* web_contents) override;
676 OmniboxView* GetOmniboxView() override;
677 std::set<std::string> GetOpenUrls() override;
679 // Overridden from WebContentsModalDialogManagerDelegate:
680 void SetWebContentsBlocked(content::WebContents* web_contents,
681 bool blocked) override;
682 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()
683 override;
685 // Overridden from BookmarkTabHelperDelegate:
686 void URLStarredChanged(content::WebContents* web_contents,
687 bool starred) override;
689 // Overridden from ZoomObserver:
690 void OnZoomChanged(
691 const ui_zoom::ZoomController::ZoomChangedEventData& data) override;
693 // Overridden from SelectFileDialog::Listener:
694 void FileSelected(const base::FilePath& path,
695 int index,
696 void* params) override;
697 void FileSelectedWithExtraInfo(const ui::SelectedFileInfo& file_info,
698 int index,
699 void* params) override;
701 // Overridden from content::NotificationObserver:
702 void Observe(int type,
703 const content::NotificationSource& source,
704 const content::NotificationDetails& details) override;
706 #if defined(ENABLE_EXTENSIONS)
707 // Overridden from extensions::ExtensionRegistryObserver:
708 void OnExtensionUninstalled(content::BrowserContext* browser_context,
709 const extensions::Extension* extension,
710 extensions::UninstallReason reason) override;
711 void OnExtensionLoaded(content::BrowserContext* browser_context,
712 const extensions::Extension* extension) override;
713 void OnExtensionUnloaded(
714 content::BrowserContext* browser_context,
715 const extensions::Extension* extension,
716 extensions::UnloadedExtensionInfo::Reason reason) override;
717 #endif
719 // Overridden from translate::ContentTranslateDriver::Observer:
720 void OnIsPageTranslatedChanged(content::WebContents* source) override;
721 void OnTranslateEnabledChanged(content::WebContents* source) override;
723 // Command and state updating ///////////////////////////////////////////////
725 // Handle changes to kDevTools preference.
726 void OnDevToolsDisabledChanged();
728 // UI update coalescing and handling ////////////////////////////////////////
730 // Asks the toolbar (and as such the location bar) to update its state to
731 // reflect the current tab's current URL, security state, etc.
732 // If |should_restore_state| is true, we're switching (back?) to this tab and
733 // should restore any previous location bar state (such as user editing) as
734 // well.
735 void UpdateToolbar(bool should_restore_state);
737 // Does one or both of the following for each bit in |changed_flags|:
738 // . If the update should be processed immediately, it is.
739 // . If the update should processed asynchronously (to avoid lots of ui
740 // updates), then scheduled_updates_ is updated for the |source| and update
741 // pair and a task is scheduled (assuming it isn't running already)
742 // that invokes ProcessPendingUIUpdates.
743 void ScheduleUIUpdate(content::WebContents* source,
744 unsigned changed_flags);
746 // Processes all pending updates to the UI that have been scheduled by
747 // ScheduleUIUpdate in scheduled_updates_.
748 void ProcessPendingUIUpdates();
750 // Removes all entries from scheduled_updates_ whose source is contents.
751 void RemoveScheduledUpdatesFor(content::WebContents* contents);
753 // Getters for UI ///////////////////////////////////////////////////////////
755 // TODO(beng): remove, and provide AutomationProvider a better way to access
756 // the LocationBarView's edit.
757 friend class AutomationProvider;
758 friend class BrowserProxy;
760 // Returns the StatusBubble from the current toolbar. It is possible for
761 // this to return NULL if called before the toolbar has initialized.
762 // TODO(beng): remove this.
763 StatusBubble* GetStatusBubble();
765 // Session restore functions ////////////////////////////////////////////////
767 // Notifies the history database of the index for all tabs whose index is
768 // >= index.
769 void SyncHistoryWithTabs(int index);
771 // In-progress download termination handling /////////////////////////////////
773 // Called when the window is closing to check if potential in-progress
774 // downloads should prevent it from closing.
775 // Returns true if the window can close, false otherwise.
776 bool CanCloseWithInProgressDownloads();
778 // Assorted utility functions ///////////////////////////////////////////////
780 // Sets the specified browser as the delegate of the WebContents and all the
781 // associated tab helpers that are needed. If |set_delegate| is true, this
782 // browser object is set as a delegate for |web_contents| components, else
783 // is is removed as a delegate.
784 void SetAsDelegate(content::WebContents* web_contents, bool set_delegate);
786 // Shows the Find Bar, optionally selecting the next entry that matches the
787 // existing search string for that Tab. |forward_direction| controls the
788 // search direction.
789 void FindInPage(bool find_next, bool forward_direction);
791 // Closes the frame.
792 // TODO(beng): figure out if we need this now that the frame itself closes
793 // after a return to the message loop.
794 void CloseFrame();
796 void TabDetachedAtImpl(content::WebContents* contents,
797 int index,
798 DetachType type);
800 // Shared code between Reload() and ReloadIgnoringCache().
801 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache);
803 // Returns true if the Browser window supports a location bar. Having support
804 // for the location bar does not mean it will be visible.
805 bool SupportsLocationBar() const;
807 // Returns true if the Browser window should show the location bar.
808 bool ShouldShowLocationBar() const;
810 // Returns true if the Browser window should use a web app style frame.
811 bool ShouldUseWebAppFrame() const;
813 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
814 // |check_fullscreen| is true, the set of features reflect the actual state of
815 // the browser, otherwise the set of features reflect the possible state of
816 // the browser.
817 bool SupportsWindowFeatureImpl(WindowFeature feature,
818 bool check_fullscreen) const;
820 // Resets |bookmark_bar_state_| based on the active tab. Notifies the
821 // BrowserWindow if necessary.
822 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason);
824 bool ShouldHideUIForFullscreen() const;
826 // Creates a BackgroundContents if appropriate; return true if one was
827 // created.
828 bool MaybeCreateBackgroundContents(
829 int route_id,
830 int main_frame_route_id,
831 content::WebContents* opener_web_contents,
832 const std::string& frame_name,
833 const GURL& target_url,
834 const std::string& partition_id,
835 content::SessionStorageNamespace* session_storage_namespace);
837 // Data members /////////////////////////////////////////////////////////////
839 std::vector<InterstitialObserver*> interstitial_observers_;
841 content::NotificationRegistrar registrar_;
843 #if defined(ENABLE_EXTENSIONS)
844 ScopedObserver<extensions::ExtensionRegistry,
845 extensions::ExtensionRegistryObserver>
846 extension_registry_observer_;
847 #endif
849 PrefChangeRegistrar profile_pref_registrar_;
851 // This Browser's type.
852 const Type type_;
854 // This Browser's profile.
855 Profile* const profile_;
857 // This Browser's window.
858 BrowserWindow* window_;
860 scoped_ptr<TabStripModelDelegate> tab_strip_model_delegate_;
861 scoped_ptr<TabStripModel> tab_strip_model_;
863 // The application name that is also the name of the window to the shell.
864 // This name should be set when:
865 // 1) we launch an application via an application shortcut or extension API.
866 // 2) we launch an undocked devtool window.
867 std::string app_name_;
869 // True if the source is trusted (i.e. we do not need to show the URL in a
870 // a popup window). Also used to determine which app windows to save and
871 // restore on Chrome OS.
872 bool is_trusted_source_;
874 // Unique identifier of this browser for session restore. This id is only
875 // unique within the current session, and is not guaranteed to be unique
876 // across sessions.
877 const SessionID session_id_;
879 // The model for the toolbar view.
880 scoped_ptr<ToolbarModel> toolbar_model_;
882 // The model for the "active" search state. There are per-tab search models
883 // as well. When a tab is active its model is kept in sync with this one.
884 // When a new tab is activated its model state is propagated to this active
885 // model. This way, observers only have to attach to this single model for
886 // updates, and don't have to worry about active tab changes directly.
887 scoped_ptr<SearchModel> search_model_;
889 // UI update coalescing and handling ////////////////////////////////////////
891 typedef std::map<const content::WebContents*, int> UpdateMap;
893 // Maps from WebContents to pending UI updates that need to be processed.
894 // We don't update things like the URL or tab title right away to avoid
895 // flickering and extra painting.
896 // See ScheduleUIUpdate and ProcessPendingUIUpdates.
897 UpdateMap scheduled_updates_;
899 // In-progress download termination handling /////////////////////////////////
901 enum CancelDownloadConfirmationState {
902 NOT_PROMPTED, // We have not asked the user.
903 WAITING_FOR_RESPONSE, // We have asked the user and have not received a
904 // reponse yet.
905 RESPONSE_RECEIVED // The user was prompted and made a decision already.
908 // State used to figure-out whether we should prompt the user for confirmation
909 // when the browser is closed with in-progress downloads.
910 CancelDownloadConfirmationState cancel_download_confirmation_state_;
912 /////////////////////////////////////////////////////////////////////////////
914 // Override values for the bounds of the window and its maximized or minimized
915 // state.
916 // These are supplied by callers that don't want to use the default values.
917 // The default values are typically loaded from local state (last session),
918 // obtained from the last window of the same type, or obtained from the
919 // shell shortcut's startup info.
920 gfx::Rect override_bounds_;
921 ui::WindowShowState initial_show_state_;
923 // Tracks when this browser is being created by session restore.
924 bool is_session_restore_;
926 const chrome::HostDesktopType host_desktop_type_;
928 scoped_ptr<chrome::UnloadController> unload_controller_;
929 scoped_ptr<chrome::FastUnloadController> fast_unload_controller_;
931 scoped_ptr<ChromeBubbleManager> bubble_manager_;
933 // The Find Bar. This may be NULL if there is no Find Bar, and if it is
934 // non-NULL, it may or may not be visible.
935 scoped_ptr<FindBarController> find_bar_controller_;
937 // Dialog box used for opening and saving files.
938 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
940 // Keep track of the encoding auto detect pref.
941 BooleanPrefMember encoding_auto_detect_;
943 // Helper which implements the ContentSettingBubbleModel interface.
944 scoped_ptr<BrowserContentSettingBubbleModelDelegate>
945 content_setting_bubble_model_delegate_;
947 // Helper which implements the ToolbarModelDelegate interface.
948 scoped_ptr<BrowserToolbarModelDelegate> toolbar_model_delegate_;
950 // A delegate that handles the details of updating the "active"
951 // |search_model_| state with the tab's state.
952 scoped_ptr<SearchDelegate> search_delegate_;
954 // Helper which implements the TabRestoreServiceDelegate interface.
955 scoped_ptr<BrowserTabRestoreServiceDelegate> tab_restore_service_delegate_;
957 // Helper which implements the SyncedWindowDelegate interface.
958 scoped_ptr<BrowserSyncedWindowDelegate> synced_window_delegate_;
960 scoped_ptr<BrowserInstantController> instant_controller_;
962 // Helper which handles bookmark app specific browser configuration.
963 scoped_ptr<extensions::HostedAppBrowserController> hosted_app_controller_;
965 BookmarkBar::State bookmark_bar_state_;
967 scoped_ptr<ExclusiveAccessManager> exclusive_access_manager_;
969 scoped_ptr<extensions::WindowController> extension_window_controller_;
971 scoped_ptr<chrome::BrowserCommandController> command_controller_;
973 // True if the browser window has been shown at least once.
974 bool window_has_shown_;
976 scoped_ptr<ValidationMessageBubble> validation_message_bubble_;
978 // The following factory is used for chrome update coalescing.
979 base::WeakPtrFactory<Browser> chrome_updater_factory_;
981 // The following factory is used to close the frame at a later time.
982 base::WeakPtrFactory<Browser> weak_factory_;
984 DISALLOW_COPY_AND_ASSIGN(Browser);
987 #endif // CHROME_BROWSER_UI_BROWSER_H_