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