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