- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / browser.h
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.
4
5 #ifndef CHROME_BROWSER_UI_BROWSER_H_
6 #define CHROME_BROWSER_UI_BROWSER_H_
7
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/prefs/pref_change_registrar.h"
19 #include "base/prefs/pref_member.h"
20 #include "base/strings/string16.h"
21 #include "chrome/browser/devtools/devtools_toggle_action.h"
22 #include "chrome/browser/sessions/session_id.h"
23 #include "chrome/browser/ui/bookmarks/bookmark_bar.h"
24 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h"
25 #include "chrome/browser/ui/browser_navigator.h"
26 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
27 #include "chrome/browser/ui/host_desktop.h"
28 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h"
29 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
31 #include "chrome/browser/ui/toolbar/toolbar_model.h"
32 #include "chrome/browser/ui/zoom/zoom_observer.h"
33 #include "chrome/common/content_settings.h"
34 #include "chrome/common/content_settings_types.h"
35 #include "chrome/common/extensions/extension_constants.h"
36 #include "content/public/browser/notification_observer.h"
37 #include "content/public/browser/notification_registrar.h"
38 #include "content/public/browser/page_navigator.h"
39 #include "content/public/browser/web_contents_delegate.h"
40 #include "content/public/common/page_transition_types.h"
41 #include "content/public/common/page_zoom.h"
42 #include "ui/base/ui_base_types.h"
43 #include "ui/base/window_open_disposition.h"
44 #include "ui/gfx/rect.h"
45 #include "ui/shell_dialogs/select_file_dialog.h"
46
47 class BrowserContentSettingBubbleModelDelegate;
48 class BrowserInstantController;
49 class BrowserLanguageStateObserver;
50 class BrowserSyncedWindowDelegate;
51 class BrowserToolbarModelDelegate;
52 class BrowserTabRestoreServiceDelegate;
53 class BrowserWindow;
54 class FindBarController;
55 class FullscreenController;
56 class PrefService;
57 class Profile;
58 class SearchDelegate;
59 class SearchModel;
60 class StatusBubble;
61 class TabStripModel;
62 class TabStripModelDelegate;
63 struct WebApplicationInfo;
64
65 namespace chrome {
66 class BrowserCommandController;
67 class FastUnloadController;
68 class UnloadController;
69 }
70
71 namespace content {
72 class NavigationController;
73 class PageState;
74 class SessionStorageNamespace;
75 }
76
77 namespace extensions {
78 class Extension;
79 class WindowController;
80 }
81
82 namespace gfx {
83 class Image;
84 class Point;
85 }
86
87 namespace ui {
88 struct SelectedFileInfo;
89 class WebDialogDelegate;
90 }
91
92 namespace web_modal {
93 class WebContentsModalDialogHost;
94 }
95
96 class Browser : public TabStripModelObserver,
97                 public content::WebContentsDelegate,
98                 public CoreTabHelperDelegate,
99                 public SearchEngineTabHelperDelegate,
100                 public ChromeWebModalDialogManagerDelegate,
101                 public BookmarkTabHelperDelegate,
102                 public ZoomObserver,
103                 public content::PageNavigator,
104                 public content::NotificationObserver,
105                 public ui::SelectFileDialog::Listener {
106  public:
107   // SessionService::WindowType mirrors these values.  If you add to this
108   // enum, look at SessionService::WindowType to see if it needs to be
109   // updated.
110   enum Type {
111     // If you add a new type, consider updating the test
112     // BrowserTest.StartMaximized.
113     TYPE_TABBED = 1,
114     TYPE_POPUP = 2
115   };
116
117   // Distinguishes between browsers that host an app (opened from
118   // ApplicationLauncher::OpenApplication), and child browsers created by an app
119   // from Browser::CreateForApp (e.g. by windows.open or the extension API).
120   enum AppType {
121     APP_TYPE_HOST = 1,
122     APP_TYPE_CHILD = 2
123   };
124
125   // Possible elements of the Browser window.
126   enum WindowFeature {
127     FEATURE_NONE = 0,
128     FEATURE_TITLEBAR = 1,
129     FEATURE_TABSTRIP = 2,
130     FEATURE_TOOLBAR = 4,
131     FEATURE_LOCATIONBAR = 8,
132     FEATURE_BOOKMARKBAR = 16,
133     FEATURE_INFOBAR = 32,
134     FEATURE_DOWNLOADSHELF = 64
135   };
136
137   // The context for a download blocked notification from
138   // OkToCloseWithInProgressDownloads.
139   enum DownloadClosePreventionType {
140     // Browser close is not blocked by download state.
141     DOWNLOAD_CLOSE_OK,
142
143     // The browser is shutting down and there are active downloads
144     // that would be cancelled.
145     DOWNLOAD_CLOSE_BROWSER_SHUTDOWN,
146
147     // There are active downloads associated with this incognito profile
148     // that would be canceled.
149     DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE,
150   };
151
152   struct CreateParams {
153     CreateParams(Profile* profile, chrome::HostDesktopType host_desktop_type);
154     CreateParams(Type type,
155                  Profile* profile,
156                  chrome::HostDesktopType host_desktop_type);
157
158     static CreateParams CreateForApp(Type type,
159                                      const std::string& app_name,
160                                      const gfx::Rect& window_bounds,
161                                      Profile* profile,
162                                      chrome::HostDesktopType host_desktop_type);
163
164     static CreateParams CreateForDevTools(
165         Profile* profile,
166         chrome::HostDesktopType host_desktop_type);
167
168     // The browser type.
169     Type type;
170
171     // The associated profile.
172     Profile* profile;
173
174     // The host desktop the browser is created on.
175     chrome::HostDesktopType host_desktop_type;
176
177     // The application name that is also the name of the window to the shell.
178     // This name should be set when:
179     // 1) we launch an application via an application shortcut or extension API.
180     // 2) we launch an undocked devtool window.
181     std::string app_name;
182
183     // Type of app (host or child). See description of AppType.
184     AppType app_type;
185
186     // The bounds of the window to open.
187     gfx::Rect initial_bounds;
188
189     ui::WindowShowState initial_show_state;
190
191     bool is_session_restore;
192
193     // Supply a custom BrowserWindow implementation, to be used instead of the
194     // default. Intended for testing.
195     BrowserWindow* window;
196   };
197
198   // Constructors, Creation, Showing //////////////////////////////////////////
199
200   explicit Browser(const CreateParams& params);
201   virtual ~Browser();
202
203   // Set overrides for the initial window bounds and maximized state.
204   void set_override_bounds(const gfx::Rect& bounds) {
205     override_bounds_ = bounds;
206   }
207   ui::WindowShowState initial_show_state() const { return initial_show_state_; }
208   void set_initial_show_state(ui::WindowShowState initial_show_state) {
209     initial_show_state_ = initial_show_state;
210   }
211   // Return true if the initial window bounds have been overridden.
212   bool bounds_overridden() const {
213     return !override_bounds_.IsEmpty();
214   }
215   // Set indicator that this browser is being created via session restore.
216   // This is used on the Mac (only) to determine animation style when the
217   // browser window is shown.
218   void set_is_session_restore(bool is_session_restore) {
219     is_session_restore_ = is_session_restore;
220   }
221   bool is_session_restore() const {
222     return is_session_restore_;
223   }
224   chrome::HostDesktopType host_desktop_type() const {
225     return host_desktop_type_;
226   }
227
228   // Accessors ////////////////////////////////////////////////////////////////
229
230   Type type() const { return type_; }
231   const std::string& app_name() const { return app_name_; }
232   AppType app_type() const { return app_type_; }
233   Profile* profile() const { return profile_; }
234   gfx::Rect override_bounds() const { return override_bounds_; }
235
236   // |window()| will return NULL if called before |CreateBrowserWindow()|
237   // is done.
238   BrowserWindow* window() const { return window_; }
239   ToolbarModel* toolbar_model() { return toolbar_model_.get(); }
240   const ToolbarModel* toolbar_model() const { return toolbar_model_.get(); }
241 #if defined(UNIT_TEST)
242   void swap_toolbar_models(scoped_ptr<ToolbarModel>* toolbar_model) {
243     toolbar_model->swap(toolbar_model_);
244   }
245 #endif
246   TabStripModel* tab_strip_model() const { return tab_strip_model_.get(); }
247   chrome::BrowserCommandController* command_controller() {
248     return command_controller_.get();
249   }
250   SearchModel* search_model() { return search_model_.get(); }
251   const SearchModel* search_model() const {
252       return search_model_.get();
253   }
254   SearchDelegate* search_delegate() {
255     return search_delegate_.get();
256   }
257   const SessionID& session_id() const { return session_id_; }
258   BrowserContentSettingBubbleModelDelegate*
259       content_setting_bubble_model_delegate() {
260     return content_setting_bubble_model_delegate_.get();
261   }
262   BrowserTabRestoreServiceDelegate* tab_restore_service_delegate() {
263     return tab_restore_service_delegate_.get();
264   }
265   BrowserSyncedWindowDelegate* synced_window_delegate() {
266     return synced_window_delegate_.get();
267   }
268   BrowserInstantController* instant_controller() {
269     return instant_controller_.get();
270   }
271
272   // Get the FindBarController for this browser, creating it if it does not
273   // yet exist.
274   FindBarController* GetFindBarController();
275
276   // Returns true if a FindBarController exists for this browser.
277   bool HasFindBarController() const;
278
279   // Returns the state of the bookmark bar.
280   BookmarkBar::State bookmark_bar_state() const { return bookmark_bar_state_; }
281
282   // State Storage and Retrieval for UI ///////////////////////////////////////
283
284   // Gets the Favicon of the page in the selected tab.
285   gfx::Image GetCurrentPageIcon() const;
286
287   // Gets the title of the window based on the selected tab's title.
288   string16 GetWindowTitleForCurrentTab() const;
289
290   // Prepares a title string for display (removes embedded newlines, etc).
291   static void FormatTitleForDisplay(string16* title);
292
293   // OnBeforeUnload handling //////////////////////////////////////////////////
294
295   // Gives beforeunload handlers the chance to cancel the close. Returns whether
296   // to proceed with the close. If called while the process begun by
297   // CallBeforeUnloadHandlers is in progress, returns false without taking
298   // action.
299   bool ShouldCloseWindow();
300
301   // Begins the process of confirming whether the associated browser can be
302   // closed. If there are no tabs with beforeunload handlers it will immediately
303   // return false. Otherwise, it starts prompting the user, returns true and
304   // will call |on_close_confirmed| with the result of the user's decision.
305   // After calling this function, if the window will not be closed, call
306   // ResetBeforeUnloadHandlers() to reset all beforeunload handlers; calling
307   // this function multiple times without an intervening call to
308   // ResetBeforeUnloadHandlers() will run only the beforeunload handlers
309   // registered since the previous call.
310   bool CallBeforeUnloadHandlers(
311       const base::Callback<void(bool)>& on_close_confirmed);
312
313   // Clears the results of any beforeunload confirmation dialogs triggered by a
314   // CallBeforeUnloadHandlers call.
315   void ResetBeforeUnloadHandlers();
316
317   // Figure out if there are tabs that have beforeunload handlers.
318   // It starts beforeunload/unload processing as a side-effect.
319   bool TabsNeedBeforeUnloadFired();
320
321   // Returns true if all tabs' beforeunload/unload events have fired.
322   bool HasCompletedUnloadProcessing() const;
323
324   bool IsAttemptingToCloseBrowser() const;
325
326   // Invoked when the window containing us is closing. Performs the necessary
327   // cleanup.
328   void OnWindowClosing();
329
330   // In-progress download termination handling /////////////////////////////////
331
332   // Called when the user has decided whether to proceed or not with the browser
333   // closure.  |cancel_downloads| is true if the downloads should be canceled
334   // and the browser closed, false if the browser should stay open and the
335   // downloads running.
336   void InProgressDownloadResponse(bool cancel_downloads);
337
338   // Indicates whether or not this browser window can be closed, or
339   // would be blocked by in-progress downloads.
340   // If executing downloads would be cancelled by this window close,
341   // then |*num_downloads_blocking| is updated with how many downloads
342   // would be canceled if the close continued.
343   DownloadClosePreventionType OkToCloseWithInProgressDownloads(
344       int* num_downloads_blocking) const;
345
346   // External state change handling ////////////////////////////////////////////
347
348   // Invoked when the fullscreen state of the window changes.
349   // BrowserWindow::EnterFullscreen invokes this after the window has become
350   // fullscreen.
351   void WindowFullscreenStateChanged();
352
353   // Invoked when visible SSL state (as defined by SSLStatus) changes.
354   void VisibleSSLStateChanged(content::WebContents* web_contents);
355
356   // Invoked when the |web_contents| no longer supports Instant. Refreshes the
357   // omnibox so it no longer shows search terms.
358   void OnWebContentsInstantSupportDisabled(
359       const content::WebContents* web_contents);
360
361   // Assorted browser commands ////////////////////////////////////////////////
362
363   // NOTE: Within each of the following sections, the IDs are ordered roughly by
364   // how they appear in the GUI/menus (left to right, top to bottom, etc.).
365
366   // See the description of
367   // FullscreenController::ToggleFullscreenModeWithExtension.
368   void ToggleFullscreenModeWithExtension(const GURL& extension_url);
369 #if defined(OS_WIN)
370   // See the description of FullscreenController::ToggleMetroSnapMode.
371   void SetMetroSnapMode(bool enable);
372 #endif
373
374   // Returns true if the Browser supports the specified feature. The value of
375   // this varies during the lifetime of the browser. For example, if the window
376   // is fullscreen this may return a different value. If you only care about
377   // whether or not it's possible for the browser to support a particular
378   // feature use |CanSupportWindowFeature|.
379   bool SupportsWindowFeature(WindowFeature feature) const;
380
381   // Returns true if the Browser can support the specified feature. See comment
382   // in |SupportsWindowFeature| for details on this.
383   bool CanSupportWindowFeature(WindowFeature feature) const;
384
385   // TODO(port): port these, and re-merge the two function declaration lists.
386   // Page-related commands.
387   void ToggleEncodingAutoDetect();
388   void OverrideEncoding(int encoding_id);
389
390   // Show various bits of UI
391   void OpenFile();
392
393   void UpdateDownloadShelfVisibility(bool visible);
394
395   /////////////////////////////////////////////////////////////////////////////
396
397   // Helper function to run unload listeners on a WebContents.
398   static bool RunUnloadEventsHelper(content::WebContents* contents);
399
400   // Helper function to handle JS out of memory notifications
401   static void JSOutOfMemoryHelper(content::WebContents* web_contents);
402
403   // Helper function to register a protocol handler.
404   static void RegisterProtocolHandlerHelper(content::WebContents* web_contents,
405                                             const std::string& protocol,
406                                             const GURL& url,
407                                             const string16& title,
408                                             bool user_gesture,
409                                             BrowserWindow* window);
410
411   // Helper function to handle find results.
412   static void FindReplyHelper(content::WebContents* web_contents,
413                               int request_id,
414                               int number_of_matches,
415                               const gfx::Rect& selection_rect,
416                               int active_match_ordinal,
417                               bool final_update);
418
419   // Called by chrome::Navigate() when a navigation has occurred in a tab in
420   // this Browser. Updates the UI for the start of this navigation.
421   void UpdateUIForNavigationInTab(content::WebContents* contents,
422                                   content::PageTransition transition,
423                                   bool user_initiated);
424
425   // Interface implementations ////////////////////////////////////////////////
426
427   // Overridden from content::PageNavigator:
428   virtual content::WebContents* OpenURL(
429       const content::OpenURLParams& params) OVERRIDE;
430
431   // Overridden from TabStripModelObserver:
432   virtual void TabInsertedAt(content::WebContents* contents,
433                              int index,
434                              bool foreground) OVERRIDE;
435   virtual void TabClosingAt(TabStripModel* tab_strip_model,
436                             content::WebContents* contents,
437                             int index) OVERRIDE;
438   virtual void TabDetachedAt(content::WebContents* contents,
439                              int index) OVERRIDE;
440   virtual void TabDeactivated(content::WebContents* contents) OVERRIDE;
441   virtual void ActiveTabChanged(content::WebContents* old_contents,
442                                 content::WebContents* new_contents,
443                                 int index,
444                                 int reason) OVERRIDE;
445   virtual void TabMoved(content::WebContents* contents,
446                         int from_index,
447                         int to_index) OVERRIDE;
448   virtual void TabReplacedAt(TabStripModel* tab_strip_model,
449                              content::WebContents* old_contents,
450                              content::WebContents* new_contents,
451                              int index) OVERRIDE;
452   virtual void TabPinnedStateChanged(content::WebContents* contents,
453                                      int index) OVERRIDE;
454   virtual void TabStripEmpty() OVERRIDE;
455
456   // Overridden from content::WebContentsDelegate:
457   virtual bool CanOverscrollContent() const OVERRIDE;
458   virtual bool PreHandleKeyboardEvent(
459       content::WebContents* source,
460       const content::NativeWebKeyboardEvent& event,
461       bool* is_keyboard_shortcut) OVERRIDE;
462   virtual void HandleKeyboardEvent(
463       content::WebContents* source,
464       const content::NativeWebKeyboardEvent& event) OVERRIDE;
465   virtual void OverscrollUpdate(int delta_y) OVERRIDE;
466
467   bool is_type_tabbed() const { return type_ == TYPE_TABBED; }
468   bool is_type_popup() const { return type_ == TYPE_POPUP; }
469
470   bool is_app() const;
471   bool is_devtools() const;
472
473   // True when the mouse cursor is locked.
474   bool IsMouseLocked() const;
475
476   // Called each time the browser window is shown.
477   void OnWindowDidShow();
478
479   // Show the first run search engine bubble on the location bar.
480   void ShowFirstRunBubble();
481
482   // Show a download on the download shelf.
483   void ShowDownload(content::DownloadItem* download);
484
485   FullscreenController* fullscreen_controller() const {
486     return fullscreen_controller_.get();
487   }
488
489   extensions::WindowController* extension_window_controller() const {
490     return extension_window_controller_.get();
491   }
492
493  private:
494   friend class BrowserTest;
495   friend class FullscreenControllerInteractiveTest;
496   friend class FullscreenControllerTest;
497   FRIEND_TEST_ALL_PREFIXES(AppModeTest, EnableAppModeTest);
498   FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest,
499                            IsReservedCommandOrKeyIsApp);
500   FRIEND_TEST_ALL_PREFIXES(BrowserCommandControllerTest, AppFullScreen);
501   FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups);
502   FRIEND_TEST_ALL_PREFIXES(BrowserTest, ConvertTabToAppShortcut);
503   FRIEND_TEST_ALL_PREFIXES(BrowserTest, OpenAppWindowLikeNtp);
504   FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch);
505   FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest,
506                            TabEntersPresentationModeFromWindowed);
507   FRIEND_TEST_ALL_PREFIXES(FullscreenExitBubbleControllerTest,
508                            DenyExitsFullscreen);
509   FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref);
510   FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest,
511                            OpenAppShortcutWindowPref);
512   FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref);
513
514   class InterstitialObserver;
515
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,
521
522     // Result of TabReplacedAt.
523     DETACH_TYPE_REPLACE,
524
525     // Result of the tab strip not having any significant tabs.
526     DETACH_TYPE_EMPTY
527   };
528
529   // Describes where the bookmark bar state change originated from.
530   enum BookmarkBarStateChangeReason {
531     // From the constructor.
532     BOOKMARK_BAR_STATE_CHANGE_INIT,
533
534     // Change is the result of the active tab changing.
535     BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH,
536
537     // Change is the result of the bookmark bar pref changing.
538     BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE,
539
540     // Change is the result of a state change in the active tab.
541     BOOKMARK_BAR_STATE_CHANGE_TAB_STATE,
542
543     // Change is the result of window toggling in/out of fullscreen mode.
544     BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN,
545   };
546
547   // Overridden from content::WebContentsDelegate:
548   virtual content::WebContents* OpenURLFromTab(
549       content::WebContents* source,
550       const content::OpenURLParams& params) OVERRIDE;
551   virtual void NavigationStateChanged(const content::WebContents* source,
552                                       unsigned changed_flags) OVERRIDE;
553   virtual void AddNewContents(content::WebContents* source,
554                               content::WebContents* new_contents,
555                               WindowOpenDisposition disposition,
556                               const gfx::Rect& initial_pos,
557                               bool user_gesture,
558                               bool* was_blocked) OVERRIDE;
559   virtual void ActivateContents(content::WebContents* contents) OVERRIDE;
560   virtual void DeactivateContents(content::WebContents* contents) OVERRIDE;
561   virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE;
562   virtual void CloseContents(content::WebContents* source) OVERRIDE;
563   virtual void MoveContents(content::WebContents* source,
564                             const gfx::Rect& pos) OVERRIDE;
565   virtual bool IsPopupOrPanel(
566       const content::WebContents* source) const OVERRIDE;
567   virtual void UpdateTargetURL(content::WebContents* source, int32 page_id,
568                                const GURL& url) OVERRIDE;
569   virtual void ContentsMouseEvent(content::WebContents* source,
570                                   const gfx::Point& location,
571                                   bool motion) OVERRIDE;
572   virtual void ContentsZoomChange(bool zoom_in) OVERRIDE;
573   virtual void WebContentsFocused(content::WebContents* content) OVERRIDE;
574   virtual bool TakeFocus(content::WebContents* source, bool reverse) OVERRIDE;
575   virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
576   virtual void BeforeUnloadFired(content::WebContents* source,
577                                  bool proceed,
578                                  bool* proceed_to_fire_unload) OVERRIDE;
579   virtual bool ShouldFocusLocationBarByDefault(
580       content::WebContents* source) OVERRIDE;
581   virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
582   virtual void RenderWidgetShowing() OVERRIDE;
583   virtual int GetExtraRenderViewHeight() const OVERRIDE;
584   virtual void ViewSourceForTab(content::WebContents* source,
585                                 const GURL& page_url) OVERRIDE;
586   virtual void ViewSourceForFrame(
587       content::WebContents* source,
588       const GURL& frame_url,
589       const content::PageState& frame_page_state) OVERRIDE;
590   virtual void ShowRepostFormWarningDialog(
591       content::WebContents* source) OVERRIDE;
592   virtual bool ShouldCreateWebContents(
593       content::WebContents* web_contents,
594       int route_id,
595       WindowContainerType window_container_type,
596       const string16& frame_name,
597       const GURL& target_url,
598       const std::string& partition_id,
599       content::SessionStorageNamespace* session_storage_namespace) OVERRIDE;
600   virtual void WebContentsCreated(content::WebContents* source_contents,
601                                   int64 source_frame_id,
602                                   const string16& frame_name,
603                                   const GURL& target_url,
604                                   content::WebContents* new_contents) OVERRIDE;
605   virtual void RendererUnresponsive(content::WebContents* source) OVERRIDE;
606   virtual void RendererResponsive(content::WebContents* source) OVERRIDE;
607   virtual void WorkerCrashed(content::WebContents* source) OVERRIDE;
608   virtual void DidNavigateMainFramePostCommit(
609       content::WebContents* web_contents) OVERRIDE;
610   virtual void DidNavigateToPendingEntry(
611       content::WebContents* web_contents) OVERRIDE;
612   virtual content::JavaScriptDialogManager*
613       GetJavaScriptDialogManager() OVERRIDE;
614   virtual content::ColorChooser* OpenColorChooser(
615       content::WebContents* web_contents, SkColor color) OVERRIDE;
616   virtual void RunFileChooser(
617       content::WebContents* web_contents,
618       const content::FileChooserParams& params) OVERRIDE;
619   virtual void EnumerateDirectory(content::WebContents* web_contents,
620                                   int request_id,
621                                   const base::FilePath& path) OVERRIDE;
622   virtual bool EmbedsFullscreenWidget() const OVERRIDE;
623   virtual void ToggleFullscreenModeForTab(content::WebContents* web_contents,
624       bool enter_fullscreen) OVERRIDE;
625   virtual bool IsFullscreenForTabOrPending(
626       const content::WebContents* web_contents) const OVERRIDE;
627   virtual void JSOutOfMemory(content::WebContents* web_contents) OVERRIDE;
628   virtual void RegisterProtocolHandler(content::WebContents* web_contents,
629                                        const std::string& protocol,
630                                        const GURL& url,
631                                        const string16& title,
632                                        bool user_gesture) OVERRIDE;
633   virtual void UpdatePreferredSize(content::WebContents* source,
634                                    const gfx::Size& pref_size) OVERRIDE;
635   virtual void ResizeDueToAutoResize(content::WebContents* source,
636                                      const gfx::Size& new_size) OVERRIDE;
637   virtual 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   virtual void RequestToLockMouse(content::WebContents* web_contents,
644                                   bool user_gesture,
645                                   bool last_unlocked_by_target) OVERRIDE;
646   virtual void LostMouseLock() OVERRIDE;
647   virtual void RequestMediaAccessPermission(
648       content::WebContents* web_contents,
649       const content::MediaStreamRequest& request,
650       const content::MediaResponseCallback& callback) OVERRIDE;
651   virtual bool RequestPpapiBrokerPermission(
652       content::WebContents* web_contents,
653       const GURL& url,
654       const base::FilePath& plugin_path,
655       const base::Callback<void(bool)>& callback) OVERRIDE;
656   virtual gfx::Size GetSizeForNewRenderView(
657       const content::WebContents* web_contents) const OVERRIDE;
658
659   // Overridden from CoreTabHelperDelegate:
660   // Note that the caller is responsible for deleting |old_contents|.
661   virtual void SwapTabContents(content::WebContents* old_contents,
662                                content::WebContents* new_contents) OVERRIDE;
663   virtual bool CanReloadContents(
664       content::WebContents* web_contents) const OVERRIDE;
665   virtual bool CanSaveContents(
666       content::WebContents* web_contents) const OVERRIDE;
667
668   // Overridden from SearchEngineTabHelperDelegate:
669   virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
670                                         Profile* profile) OVERRIDE;
671
672   // Overridden from WebContentsModalDialogManagerDelegate:
673   virtual void SetWebContentsBlocked(content::WebContents* web_contents,
674                                      bool blocked) OVERRIDE;
675   virtual web_modal::WebContentsModalDialogHost*
676       GetWebContentsModalDialogHost() OVERRIDE;
677
678   // Overridden from BookmarkTabHelperDelegate:
679   virtual void URLStarredChanged(content::WebContents* web_contents,
680                                  bool starred) OVERRIDE;
681
682   // Overridden from ZoomObserver:
683   virtual void OnZoomChanged(content::WebContents* source,
684                              bool can_show_bubble) OVERRIDE;
685
686   // Overridden from SelectFileDialog::Listener:
687   virtual void FileSelected(const base::FilePath& path,
688                             int index,
689                             void* params) OVERRIDE;
690   virtual void FileSelectedWithExtraInfo(
691       const ui::SelectedFileInfo& file_info,
692       int index,
693       void* params) OVERRIDE;
694
695   // Overridden from content::NotificationObserver:
696   virtual void Observe(int type,
697                        const content::NotificationSource& source,
698                        const content::NotificationDetails& details) OVERRIDE;
699
700   // Command and state updating ///////////////////////////////////////////////
701
702   // Handle changes to kDevTools preference.
703   void OnDevToolsDisabledChanged();
704
705   // UI update coalescing and handling ////////////////////////////////////////
706
707   // Asks the toolbar (and as such the location bar) to update its state to
708   // reflect the current tab's current URL, security state, etc.
709   // If |should_restore_state| is true, we're switching (back?) to this tab and
710   // should restore any previous location bar state (such as user editing) as
711   // well.
712   void UpdateToolbar(bool should_restore_state);
713
714   // Does one or both of the following for each bit in |changed_flags|:
715   // . If the update should be processed immediately, it is.
716   // . If the update should processed asynchronously (to avoid lots of ui
717   //   updates), then scheduled_updates_ is updated for the |source| and update
718   //   pair and a task is scheduled (assuming it isn't running already)
719   //   that invokes ProcessPendingUIUpdates.
720   void ScheduleUIUpdate(const content::WebContents* source,
721                         unsigned changed_flags);
722
723   // Processes all pending updates to the UI that have been scheduled by
724   // ScheduleUIUpdate in scheduled_updates_.
725   void ProcessPendingUIUpdates();
726
727   // Removes all entries from scheduled_updates_ whose source is contents.
728   void RemoveScheduledUpdatesFor(content::WebContents* contents);
729
730   // Getters for UI ///////////////////////////////////////////////////////////
731
732   // TODO(beng): remove, and provide AutomationProvider a better way to access
733   //             the LocationBarView's edit.
734   friend class AutomationProvider;
735   friend class BrowserProxy;
736   friend class TestingAutomationProvider;
737
738   // Returns the StatusBubble from the current toolbar. It is possible for
739   // this to return NULL if called before the toolbar has initialized.
740   // TODO(beng): remove this.
741   StatusBubble* GetStatusBubble();
742
743   // Session restore functions ////////////////////////////////////////////////
744
745   // Notifies the history database of the index for all tabs whose index is
746   // >= index.
747   void SyncHistoryWithTabs(int index);
748
749   // In-progress download termination handling /////////////////////////////////
750
751   // Called when the window is closing to check if potential in-progress
752   // downloads should prevent it from closing.
753   // Returns true if the window can close, false otherwise.
754   bool CanCloseWithInProgressDownloads();
755
756   // Assorted utility functions ///////////////////////////////////////////////
757
758   // Sets the specified browser as the delegate of the WebContents and all the
759   // associated tab helpers that are needed.
760   void SetAsDelegate(content::WebContents* web_contents, Browser* delegate);
761
762   // Shows the Find Bar, optionally selecting the next entry that matches the
763   // existing search string for that Tab. |forward_direction| controls the
764   // search direction.
765   void FindInPage(bool find_next, bool forward_direction);
766
767   // Closes the frame.
768   // TODO(beng): figure out if we need this now that the frame itself closes
769   //             after a return to the message loop.
770   void CloseFrame();
771
772   void TabDetachedAtImpl(content::WebContents* contents,
773                          int index,
774                          DetachType type);
775
776   // Shared code between Reload() and ReloadIgnoringCache().
777   void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache);
778
779   // Depending on the disposition, return the current tab or a clone of the
780   // current tab.
781   content::WebContents* GetOrCloneTabForDisposition(
782       WindowOpenDisposition disposition);
783
784   // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
785   // |check_fullscreen| is true, the set of features reflect the actual state of
786   // the browser, otherwise the set of features reflect the possible state of
787   // the browser.
788   bool SupportsWindowFeatureImpl(WindowFeature feature,
789                                  bool check_fullscreen) const;
790
791   // Resets |bookmark_bar_state_| based on the active tab. Notifies the
792   // BrowserWindow if necessary.
793   void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason);
794
795   bool ShouldHideUIForFullscreen() const;
796
797   // Creates a BackgroundContents if appropriate; return true if one was
798   // created.
799   bool MaybeCreateBackgroundContents(
800       int route_id,
801       content::WebContents* opener_web_contents,
802       const string16& frame_name,
803       const GURL& target_url,
804       const std::string& partition_id,
805       content::SessionStorageNamespace* session_storage_namespace);
806
807   // Data members /////////////////////////////////////////////////////////////
808
809   std::vector<InterstitialObserver*> interstitial_observers_;
810
811   content::NotificationRegistrar registrar_;
812
813   PrefChangeRegistrar profile_pref_registrar_;
814
815   // This Browser's type.
816   const Type type_;
817
818   // This Browser's profile.
819   Profile* const profile_;
820
821   // This Browser's window.
822   BrowserWindow* window_;
823
824   scoped_ptr<TabStripModelDelegate> tab_strip_model_delegate_;
825   scoped_ptr<TabStripModel> tab_strip_model_;
826
827   // The application name that is also the name of the window to the shell.
828   // This name should be set when:
829   // 1) we launch an application via an application shortcut or extension API.
830   // 2) we launch an undocked devtool window.
831   std::string app_name_;
832
833   // Type of app (host or child). See description of AppType.
834   AppType app_type_;
835
836   // Unique identifier of this browser for session restore. This id is only
837   // unique within the current session, and is not guaranteed to be unique
838   // across sessions.
839   const SessionID session_id_;
840
841   // The model for the toolbar view.
842   scoped_ptr<ToolbarModel> toolbar_model_;
843
844   // The model for the "active" search state.  There are per-tab search models
845   // as well.  When a tab is active its model is kept in sync with this one.
846   // When a new tab is activated its model state is propagated to this active
847   // model.  This way, observers only have to attach to this single model for
848   // updates, and don't have to worry about active tab changes directly.
849   scoped_ptr<SearchModel> search_model_;
850
851   // UI update coalescing and handling ////////////////////////////////////////
852
853   typedef std::map<const content::WebContents*, int> UpdateMap;
854
855   // Maps from WebContents to pending UI updates that need to be processed.
856   // We don't update things like the URL or tab title right away to avoid
857   // flickering and extra painting.
858   // See ScheduleUIUpdate and ProcessPendingUIUpdates.
859   UpdateMap scheduled_updates_;
860
861   // In-progress download termination handling /////////////////////////////////
862
863   enum CancelDownloadConfirmationState {
864     NOT_PROMPTED,          // We have not asked the user.
865     WAITING_FOR_RESPONSE,  // We have asked the user and have not received a
866                            // reponse yet.
867     RESPONSE_RECEIVED      // The user was prompted and made a decision already.
868   };
869
870   // State used to figure-out whether we should prompt the user for confirmation
871   // when the browser is closed with in-progress downloads.
872   CancelDownloadConfirmationState cancel_download_confirmation_state_;
873
874   /////////////////////////////////////////////////////////////////////////////
875
876   // Override values for the bounds of the window and its maximized or minimized
877   // state.
878   // These are supplied by callers that don't want to use the default values.
879   // The default values are typically loaded from local state (last session),
880   // obtained from the last window of the same type, or obtained from the
881   // shell shortcut's startup info.
882   gfx::Rect override_bounds_;
883   ui::WindowShowState initial_show_state_;
884
885   // Tracks when this browser is being created by session restore.
886   bool is_session_restore_;
887
888   const chrome::HostDesktopType host_desktop_type_;
889
890   scoped_ptr<chrome::UnloadController> unload_controller_;
891   scoped_ptr<chrome::FastUnloadController> fast_unload_controller_;
892
893   // The Find Bar. This may be NULL if there is no Find Bar, and if it is
894   // non-NULL, it may or may not be visible.
895   scoped_ptr<FindBarController> find_bar_controller_;
896
897   // Dialog box used for opening and saving files.
898   scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
899
900   // Keep track of the encoding auto detect pref.
901   BooleanPrefMember encoding_auto_detect_;
902
903   // Helper which implements the ContentSettingBubbleModel interface.
904   scoped_ptr<BrowserContentSettingBubbleModelDelegate>
905       content_setting_bubble_model_delegate_;
906
907   // Helper which implements the ToolbarModelDelegate interface.
908   scoped_ptr<BrowserToolbarModelDelegate> toolbar_model_delegate_;
909
910   // A delegate that handles the details of updating the "active"
911   // |search_model_| state with the tab's state.
912   scoped_ptr<SearchDelegate> search_delegate_;
913
914   // Helper which implements the TabRestoreServiceDelegate interface.
915   scoped_ptr<BrowserTabRestoreServiceDelegate> tab_restore_service_delegate_;
916
917   // Helper which implements the SyncedWindowDelegate interface.
918   scoped_ptr<BrowserSyncedWindowDelegate> synced_window_delegate_;
919
920   scoped_ptr<BrowserInstantController> instant_controller_;
921
922   BookmarkBar::State bookmark_bar_state_;
923
924   scoped_ptr<FullscreenController> fullscreen_controller_;
925
926   scoped_ptr<extensions::WindowController> extension_window_controller_;
927
928   scoped_ptr<chrome::BrowserCommandController> command_controller_;
929
930   // True if the browser window has been shown at least once.
931   bool window_has_shown_;
932
933   // The following factory is used for chrome update coalescing.
934   base::WeakPtrFactory<Browser> chrome_updater_factory_;
935
936   // The following factory is used to close the frame at a later time.
937   base::WeakPtrFactory<Browser> weak_factory_;
938
939   scoped_ptr<BrowserLanguageStateObserver> language_state_observer_;
940
941   DISALLOW_COPY_AND_ASSIGN(Browser);
942 };
943
944 #endif  // CHROME_BROWSER_UI_BROWSER_H_