| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_BROWSER_H_ | 5 #ifndef CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_BROWSER_H_ | 6 #define CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | |
| 10 #include <set> | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/basictypes.h" | |
| 15 #include "base/compiler_specific.h" | |
| 16 #include "base/gtest_prod_util.h" | |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/memory/weak_ptr.h" | |
| 19 #include "base/string16.h" | |
| 20 #include "chrome/browser/command_updater.h" | 9 #include "chrome/browser/command_updater.h" |
| 21 #include "chrome/browser/debugger/devtools_toggle_action.h" | |
| 22 #include "chrome/browser/event_disposition.h" | |
| 23 #include "chrome/browser/extensions/extension_tab_helper_delegate.h" | |
| 24 #include "chrome/browser/instant/instant_delegate.h" | |
| 25 #include "chrome/browser/prefs/pref_change_registrar.h" | 10 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 26 #include "chrome/browser/prefs/pref_member.h" | |
| 27 #include "chrome/browser/sessions/session_id.h" | |
| 28 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 11 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
| 29 #include "chrome/browser/sync/profile_sync_service_observer.h" | 12 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 30 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper_delegate.
h" | |
| 31 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" | |
| 32 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h" | |
| 33 #include "chrome/browser/ui/browser_navigator.h" | |
| 34 #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" | |
| 35 #include "chrome/browser/ui/fullscreen_exit_bubble_type.h" | |
| 36 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h" | |
| 37 #include "chrome/browser/ui/select_file_dialog.h" | |
| 38 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h" | |
| 39 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | |
| 40 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 41 #include "chrome/browser/ui/toolbar/toolbar_model.h" | |
| 42 #include "chrome/browser/ui/zoom/zoom_observer.h" | |
| 43 #include "chrome/common/content_settings.h" | |
| 44 #include "chrome/common/content_settings_types.h" | |
| 45 #include "chrome/common/extensions/extension_constants.h" | |
| 46 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
| 47 #include "content/public/browser/page_navigator.h" | 15 #include "content/public/browser/notification_observer.h" |
| 48 #include "content/public/browser/web_contents_delegate.h" | 16 #include "webkit/glue/window_open_disposition.h" |
| 49 #include "content/public/common/page_transition_types.h" | |
| 50 #include "content/public/common/page_zoom.h" | |
| 51 #include "ui/base/ui_base_types.h" | |
| 52 #include "ui/gfx/rect.h" | |
| 53 | 17 |
| 54 class BrowserContentSettingBubbleModelDelegate; | 18 class Browser; |
| 55 class BrowserSyncedWindowDelegate; | |
| 56 class BrowserToolbarModelDelegate; | |
| 57 class BrowserTabRestoreServiceDelegate; | |
| 58 class BrowserWindow; | 19 class BrowserWindow; |
| 59 class ExtensionWindowController; | |
| 60 class FindBarController; | |
| 61 class FullscreenController; | |
| 62 class InstantController; | |
| 63 class InstantUnloadHandler; | |
| 64 class PrefService; | |
| 65 class Profile; | 20 class Profile; |
| 66 class SkBitmap; | 21 class TabContents; |
| 67 class StatusBubble; | 22 |
| 68 class TabNavigation; | 23 namespace content { |
| 69 class TabStripModel; | 24 struct NativeWebKeyboardEvent; |
| 70 struct WebApplicationInfo; | 25 } |
| 71 | 26 |
| 72 namespace chrome { | 27 namespace chrome { |
| 73 namespace search { | |
| 74 class SearchDelegate; | |
| 75 class SearchModel; | |
| 76 } | |
| 77 } | |
| 78 | 28 |
| 79 namespace content { | 29 class BrowserCommandController : public CommandUpdater::CommandUpdaterDelegate, |
| 80 class NavigationController; | 30 public content::NotificationObserver, |
| 81 class SessionStorageNamespace; | 31 public TabStripModelObserver, |
| 82 } | 32 public TabRestoreServiceObserver, |
| 33 public ProfileSyncServiceObserver { |
| 34 public: |
| 35 explicit BrowserCommandController(Browser* browser); |
| 36 virtual ~BrowserCommandController(); |
| 83 | 37 |
| 84 namespace extensions { | |
| 85 class Extension; | |
| 86 } | |
| 87 | |
| 88 namespace gfx { | |
| 89 class Point; | |
| 90 } | |
| 91 | |
| 92 namespace ui { | |
| 93 class WebDialogDelegate; | |
| 94 } | |
| 95 | |
| 96 namespace webkit_glue { | |
| 97 struct WebIntentServiceData; | |
| 98 } | |
| 99 | |
| 100 class Browser : public TabStripModelDelegate, | |
| 101 public TabStripModelObserver, | |
| 102 public content::WebContentsDelegate, | |
| 103 public CoreTabHelperDelegate, | |
| 104 public SearchEngineTabHelperDelegate, | |
| 105 public ConstrainedWindowTabHelperDelegate, | |
| 106 public BlockedContentTabHelperDelegate, | |
| 107 public BookmarkTabHelperDelegate, | |
| 108 public ZoomObserver, | |
| 109 public ExtensionTabHelperDelegate, | |
| 110 public content::PageNavigator, | |
| 111 public CommandUpdater::CommandUpdaterDelegate, | |
| 112 public content::NotificationObserver, | |
| 113 public SelectFileDialog::Listener, | |
| 114 public TabRestoreServiceObserver, | |
| 115 public ProfileSyncServiceObserver, | |
| 116 public InstantDelegate { | |
| 117 public: | |
| 118 // SessionService::WindowType mirrors these values. If you add to this | |
| 119 // enum, look at SessionService::WindowType to see if it needs to be | |
| 120 // updated. | |
| 121 enum Type { | |
| 122 // If you add a new type, consider updating the test | |
| 123 // BrowserTest.StartMaximized. | |
| 124 TYPE_TABBED = 1, | |
| 125 TYPE_POPUP = 2, | |
| 126 TYPE_PANEL = 3 | |
| 127 }; | |
| 128 | |
| 129 // Distinguishes between browsers that host an app (opened from | |
| 130 // ApplicationLauncher::OpenApplication), and child browsers created by an app | |
| 131 // from Browser::CreateForApp (e.g. by windows.open or the extension API). | |
| 132 // TODO(stevenjb): This is currently only needed by the ash Launcher for | |
| 133 // identifying child panels. Remove this once panels are no longer | |
| 134 // implemented as Browsers, crbug.com/112198. | |
| 135 enum AppType { | |
| 136 APP_TYPE_HOST = 1, | |
| 137 APP_TYPE_CHILD = 2 | |
| 138 }; | |
| 139 | |
| 140 // Possible elements of the Browser window. | |
| 141 enum WindowFeature { | |
| 142 FEATURE_NONE = 0, | |
| 143 FEATURE_TITLEBAR = 1, | |
| 144 FEATURE_TABSTRIP = 2, | |
| 145 FEATURE_TOOLBAR = 4, | |
| 146 FEATURE_LOCATIONBAR = 8, | |
| 147 FEATURE_BOOKMARKBAR = 16, | |
| 148 FEATURE_INFOBAR = 32, | |
| 149 FEATURE_DOWNLOADSHELF = 64 | |
| 150 }; | |
| 151 | |
| 152 // The context for a download blocked notification from | |
| 153 // OkToCloseWithInProgressDownloads. | |
| 154 enum DownloadClosePreventionType { | |
| 155 // Browser close is not blocked by download state. | |
| 156 DOWNLOAD_CLOSE_OK, | |
| 157 | |
| 158 // The browser is shutting down and there are active downloads | |
| 159 // that would be cancelled. | |
| 160 DOWNLOAD_CLOSE_BROWSER_SHUTDOWN, | |
| 161 | |
| 162 // There are active downloads associated with this incognito profile | |
| 163 // that would be canceled. | |
| 164 DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE, | |
| 165 }; | |
| 166 | |
| 167 // Different types of action when web app info is available. | |
| 168 // OnDidGetApplicationInfo uses this to dispatch calls. | |
| 169 enum WebAppAction { | |
| 170 NONE, // No action at all. | |
| 171 CREATE_SHORTCUT, // Bring up create application shortcut dialog. | |
| 172 UPDATE_SHORTCUT // Update icon for app shortcut. | |
| 173 }; | |
| 174 | |
| 175 struct CreateParams { | |
| 176 CreateParams(); | |
| 177 CreateParams(Type type, Profile* profile); | |
| 178 | |
| 179 static CreateParams CreateForApp(Type type, | |
| 180 const std::string& app_name, | |
| 181 const gfx::Rect& window_bounds, | |
| 182 Profile* profile); | |
| 183 | |
| 184 static CreateParams CreateForDevTools(Profile* profile); | |
| 185 | |
| 186 // The browser type. | |
| 187 Type type; | |
| 188 | |
| 189 // The associated profile. | |
| 190 Profile* profile; | |
| 191 | |
| 192 // The application name that is also the name of the window to the shell. | |
| 193 // This name should be set when: | |
| 194 // 1) we launch an application via an application shortcut or extension API. | |
| 195 // 2) we launch an undocked devtool window. | |
| 196 std::string app_name; | |
| 197 | |
| 198 // Type of app (host or child). See description of AppType. | |
| 199 AppType app_type; | |
| 200 | |
| 201 // The bounds of the window to open. | |
| 202 gfx::Rect initial_bounds; | |
| 203 | |
| 204 ui::WindowShowState initial_show_state; | |
| 205 | |
| 206 bool is_session_restore; | |
| 207 }; | |
| 208 | |
| 209 // Constructors, Creation, Showing ////////////////////////////////////////// | |
| 210 | |
| 211 // Creates a new browser of the given |type| and for the given |profile|. The | |
| 212 // Browser has a NULL window after its construction, InitBrowserWindow must | |
| 213 // be called after configuration for window() to be valid. | |
| 214 // Avoid using this constructor directly if you can use one of the Create*() | |
| 215 // methods below. This applies to almost all non-testing code. | |
| 216 Browser(Type type, Profile* profile); | |
| 217 virtual ~Browser(); | |
| 218 | |
| 219 // Creates a normal tabbed browser with the specified profile. The Browser's | |
| 220 // window is created by this function call. | |
| 221 static Browser* Create(Profile* profile); | |
| 222 | |
| 223 // Like Create, but creates a browser of the specified parameters. | |
| 224 static Browser* CreateWithParams(const CreateParams& params); | |
| 225 | |
| 226 // Set overrides for the initial window bounds and maximized state. | |
| 227 void set_override_bounds(const gfx::Rect& bounds) { | |
| 228 override_bounds_ = bounds; | |
| 229 } | |
| 230 ui::WindowShowState initial_show_state() const { return initial_show_state_; } | |
| 231 void set_initial_show_state(ui::WindowShowState initial_show_state) { | |
| 232 initial_show_state_ = initial_show_state; | |
| 233 } | |
| 234 // Return true if the initial window bounds have been overridden. | |
| 235 bool bounds_overridden() const { | |
| 236 return !override_bounds_.IsEmpty(); | |
| 237 } | |
| 238 // Set indicator that this browser is being created via session restore. | |
| 239 // This is used on the Mac (only) to determine animation style when the | |
| 240 // browser window is shown. | |
| 241 void set_is_session_restore(bool is_session_restore) { | |
| 242 is_session_restore_ = is_session_restore; | |
| 243 } | |
| 244 bool is_session_restore() const { | |
| 245 return is_session_restore_; | |
| 246 } | |
| 247 | |
| 248 // Creates the Browser Window. Prefer to use the static helpers above where | |
| 249 // possible. This does not show the window. You need to call window()->Show() | |
| 250 // to show it. | |
| 251 void InitBrowserWindow(); | |
| 252 | |
| 253 // Sets the BrowserWindow. This is intended for tests only. | |
| 254 // Use CreateBrowserWindow outside of testing, or the static convenience | |
| 255 // methods that create a BrowserWindow for you. | |
| 256 void SetWindowForTesting(BrowserWindow* window); | |
| 257 | |
| 258 // Accessors //////////////////////////////////////////////////////////////// | |
| 259 | |
| 260 Type type() const { return type_; } | |
| 261 const std::string& app_name() const { return app_name_; } | |
| 262 AppType app_type() const { return app_type_; } | |
| 263 Profile* profile() const { return profile_; } | |
| 264 gfx::Rect override_bounds() const { return override_bounds_; } | |
| 265 | |
| 266 // Returns the InstantController or NULL if there is no InstantController for | |
| 267 // this Browser. | |
| 268 InstantController* instant() const { return instant_.get(); } | |
| 269 | |
| 270 // |window()| will return NULL if called before |CreateBrowserWindow()| | |
| 271 // is done. | |
| 272 BrowserWindow* window() const { return window_; } | |
| 273 ToolbarModel* toolbar_model() { return toolbar_model_.get(); } | |
| 274 chrome::search::SearchModel* search_model() { return search_model_.get(); } | |
| 275 const SessionID& session_id() const { return session_id_; } | |
| 276 CommandUpdater* command_updater() { return &command_updater_; } | 38 CommandUpdater* command_updater() { return &command_updater_; } |
| 277 bool block_command_execution() const { return block_command_execution_; } | 39 bool block_command_execution() const { return block_command_execution_; } |
| 278 BrowserContentSettingBubbleModelDelegate* | |
| 279 content_setting_bubble_model_delegate() { | |
| 280 return content_setting_bubble_model_delegate_.get(); | |
| 281 } | |
| 282 BrowserTabRestoreServiceDelegate* tab_restore_service_delegate() { | |
| 283 return tab_restore_service_delegate_.get(); | |
| 284 } | |
| 285 BrowserSyncedWindowDelegate* synced_window_delegate() { | |
| 286 return synced_window_delegate_.get(); | |
| 287 } | |
| 288 | |
| 289 // Get the FindBarController for this browser, creating it if it does not | |
| 290 // yet exist. | |
| 291 FindBarController* GetFindBarController(); | |
| 292 | |
| 293 // Returns true if a FindBarController exists for this browser. | |
| 294 bool HasFindBarController() const; | |
| 295 | |
| 296 // Returns the state of the bookmark bar. | |
| 297 BookmarkBar::State bookmark_bar_state() const { return bookmark_bar_state_; } | |
| 298 | |
| 299 // State Storage and Retrieval for UI /////////////////////////////////////// | |
| 300 | |
| 301 // Gets the Favicon of the page in the selected tab. | |
| 302 SkBitmap GetCurrentPageIcon() const; | |
| 303 | |
| 304 // Gets the title of the window based on the selected tab's title. | |
| 305 string16 GetWindowTitleForCurrentTab() const; | |
| 306 | |
| 307 // Prepares a title string for display (removes embedded newlines, etc). | |
| 308 static void FormatTitleForDisplay(string16* title); | |
| 309 | |
| 310 // OnBeforeUnload handling ////////////////////////////////////////////////// | |
| 311 | |
| 312 // Gives beforeunload handlers the chance to cancel the close. | |
| 313 bool ShouldCloseWindow(); | |
| 314 | |
| 315 bool IsAttemptingToCloseBrowser() const { | |
| 316 return is_attempting_to_close_browser_; | |
| 317 } | |
| 318 | |
| 319 // Invoked when the window containing us is closing. Performs the necessary | |
| 320 // cleanup. | |
| 321 void OnWindowClosing(); | |
| 322 | |
| 323 // OnWindowActivationChanged handling /////////////////////////////////////// | |
| 324 | |
| 325 // Invoked when the window containing us is activated. | |
| 326 void OnWindowActivated(); | |
| 327 | |
| 328 // In-progress download termination handling ///////////////////////////////// | |
| 329 | |
| 330 // Called when the user has decided whether to proceed or not with the browser | |
| 331 // closure. |cancel_downloads| is true if the downloads should be canceled | |
| 332 // and the browser closed, false if the browser should stay open and the | |
| 333 // downloads running. | |
| 334 void InProgressDownloadResponse(bool cancel_downloads); | |
| 335 | |
| 336 // Indicates whether or not this browser window can be closed, or | |
| 337 // would be blocked by in-progress downloads. | |
| 338 // If executing downloads would be cancelled by this window close, | |
| 339 // then |*num_downloads_blocking| is updated with how many downloads | |
| 340 // would be canceled if the close continued. | |
| 341 DownloadClosePreventionType OkToCloseWithInProgressDownloads( | |
| 342 int* num_downloads_blocking) const; | |
| 343 | |
| 344 // TabStripModel pass-thrus ///////////////////////////////////////////////// | |
| 345 | |
| 346 TabStripModel* tab_strip_model() const { return tab_strip_model_.get(); } | |
| 347 | |
| 348 int tab_count() const; | |
| 349 int active_index() const; | |
| 350 int GetIndexOfController( | |
| 351 const content::NavigationController* controller) const; | |
| 352 | |
| 353 TabContents* GetActiveTabContents() const; | |
| 354 // A convenient version of the above which returns the TabContents's | |
| 355 // WebContents. | |
| 356 content::WebContents* GetActiveWebContents() const; | |
| 357 TabContents* GetTabContentsAt(int index) const; | |
| 358 // A convenient version of the above which returns the TabContents's | |
| 359 // WebContents. | |
| 360 content::WebContents* GetWebContentsAt(int index) const; | |
| 361 void ActivateTabAt(int index, bool user_gesture); | |
| 362 bool IsTabPinned(int index) const; | |
| 363 bool IsTabDiscarded(int index) const; | |
| 364 void CloseAllTabs(); | |
| 365 | |
| 366 // Tab adding/showing functions ///////////////////////////////////////////// | |
| 367 | |
| 368 // Returns true if the tab strip is editable (for extensions). | |
| 369 bool IsTabStripEditable() const; | |
| 370 | |
| 371 // Returns the index to insert a tab at during session restore and startup. | |
| 372 // |relative_index| gives the index of the url into the number of tabs that | |
| 373 // are going to be opened. For example, if three urls are passed in on the | |
| 374 // command line this is invoked three times with the values 0, 1 and 2. | |
| 375 int GetIndexForInsertionDuringRestore(int relative_index); | |
| 376 | |
| 377 // Adds a selected tab with the specified URL and transition, returns the | |
| 378 // created TabContents. | |
| 379 TabContents* AddSelectedTabWithURL(const GURL& url, | |
| 380 content::PageTransition transition); | |
| 381 | |
| 382 // Add a new tab, given a TabContents. A WebContents appropriate to | |
| 383 // display the last committed entry is created and returned. | |
| 384 content::WebContents* AddTab(TabContents* tab_contents, | |
| 385 content::PageTransition type); | |
| 386 | |
| 387 // Add a tab with its session history restored from the SessionRestore | |
| 388 // system. If select is true, the tab is selected. |tab_index| gives the index | |
| 389 // to insert the tab at. |selected_navigation| is the index of the | |
| 390 // TabNavigation in |navigations| to select. If |extension_app_id| is | |
| 391 // non-empty the tab is an app tab and |extension_app_id| is the id of the | |
| 392 // extension. If |pin| is true and |tab_index|/ is the last pinned tab, then | |
| 393 // the newly created tab is pinned. If |from_last_session| is true, | |
| 394 // |navigations| are from the previous session. | |
| 395 content::WebContents* AddRestoredTab( | |
| 396 const std::vector<TabNavigation>& navigations, | |
| 397 int tab_index, | |
| 398 int selected_navigation, | |
| 399 const std::string& extension_app_id, | |
| 400 bool select, | |
| 401 bool pin, | |
| 402 bool from_last_session, | |
| 403 content::SessionStorageNamespace* storage_namespace); | |
| 404 | |
| 405 // Creates a new tab with the already-created WebContents 'new_contents'. | |
| 406 // The window for the added contents will be reparented correctly when this | |
| 407 // method returns. If |disposition| is NEW_POPUP, |pos| should hold the | |
| 408 // initial position. | |
| 409 void AddWebContents(content::WebContents* new_contents, | |
| 410 WindowOpenDisposition disposition, | |
| 411 const gfx::Rect& initial_pos, | |
| 412 bool user_gesture); | |
| 413 void CloseTabContents(content::WebContents* contents); | |
| 414 | |
| 415 // Replaces the state of the currently selected tab with the session | |
| 416 // history restored from the SessionRestore system. | |
| 417 void ReplaceRestoredTab( | |
| 418 const std::vector<TabNavigation>& navigations, | |
| 419 int selected_navigation, | |
| 420 bool from_last_session, | |
| 421 const std::string& extension_app_id, | |
| 422 content::SessionStorageNamespace* session_storage_namespace); | |
| 423 | |
| 424 // Invoked when the fullscreen state of the window changes. | |
| 425 // BrowserWindow::EnterFullscreen invokes this after the window has become | |
| 426 // fullscreen. | |
| 427 void WindowFullscreenStateChanged(); | |
| 428 | |
| 429 // Assorted browser commands //////////////////////////////////////////////// | |
| 430 | |
| 431 // NOTE: Within each of the following sections, the IDs are ordered roughly by | |
| 432 // how they appear in the GUI/menus (left to right, top to bottom, etc.). | |
| 433 | |
| 434 // In kiosk mode, the first toggle is valid, the rest is discarded. | |
| 435 void ToggleFullscreenMode(); | |
| 436 // See the description of | |
| 437 // FullscreenController::ToggleFullscreenModeWithExtension. | |
| 438 void ToggleFullscreenModeWithExtension(const GURL& extension_url); | |
| 439 #if defined(OS_WIN) | |
| 440 // See the description of FullscreenController::ToggleMetroSnapMode. | |
| 441 void SetMetroSnapMode(bool enable); | |
| 442 #endif | |
| 443 #if defined(OS_MACOSX) | |
| 444 void TogglePresentationMode(); | |
| 445 #endif | |
| 446 | |
| 447 // Returns true if the Browser supports the specified feature. The value of | |
| 448 // this varies during the lifetime of the browser. For example, if the window | |
| 449 // is fullscreen this may return a different value. If you only care about | |
| 450 // whether or not it's possible for the browser to support a particular | |
| 451 // feature use |CanSupportWindowFeature|. | |
| 452 bool SupportsWindowFeature(WindowFeature feature) const; | |
| 453 | |
| 454 // Returns true if the Browser can support the specified feature. See comment | |
| 455 // in |SupportsWindowFeature| for details on this. | |
| 456 bool CanSupportWindowFeature(WindowFeature feature) const; | |
| 457 | |
| 458 // TODO(port): port these, and re-merge the two function declaration lists. | |
| 459 // Page-related commands. | |
| 460 void ToggleEncodingAutoDetect(); | |
| 461 void OverrideEncoding(int encoding_id); | |
| 462 | |
| 463 // Show various bits of UI | |
| 464 void OpenFile(); | |
| 465 void OpenCreateShortcutsDialog(); | |
| 466 | |
| 467 void UpdateDownloadShelfVisibility(bool visible); | |
| 468 | |
| 469 // Commits the current instant, returning true on success. This is intended | |
| 470 // for use from OpenCurrentURL. | |
| 471 bool OpenInstant(WindowOpenDisposition disposition); | |
| 472 | |
| 473 ///////////////////////////////////////////////////////////////////////////// | |
| 474 | |
| 475 // Helper function to run unload listeners on a WebContents. | |
| 476 static bool RunUnloadEventsHelper(content::WebContents* contents); | |
| 477 | |
| 478 // Helper function to handle JS out of memory notifications | |
| 479 static void JSOutOfMemoryHelper(content::WebContents* web_contents); | |
| 480 | |
| 481 // Helper function to register a protocol handler. | |
| 482 static void RegisterProtocolHandlerHelper(content::WebContents* web_contents, | |
| 483 const std::string& protocol, | |
| 484 const GURL& url, | |
| 485 const string16& title, | |
| 486 bool user_gesture); | |
| 487 | |
| 488 // Helper function to register an intent handler. | |
| 489 // |data| is the registered handler data. |user_gesture| is true if the call | |
| 490 // was made in the context of a user gesture. | |
| 491 static void RegisterIntentHandlerHelper( | |
| 492 content::WebContents* web_contents, | |
| 493 const webkit_glue::WebIntentServiceData& data, | |
| 494 bool user_gesture); | |
| 495 | |
| 496 // Helper function to handle find results. | |
| 497 static void FindReplyHelper(content::WebContents* web_contents, | |
| 498 int request_id, | |
| 499 int number_of_matches, | |
| 500 const gfx::Rect& selection_rect, | |
| 501 int active_match_ordinal, | |
| 502 bool final_update); | |
| 503 | |
| 504 // Calls ExecuteCommandWithDisposition with CURRENT_TAB disposition. | |
| 505 void ExecuteCommand(int id); | |
| 506 | |
| 507 // Calls ExecuteCommandWithDisposition with the given event flags. | |
| 508 void ExecuteCommand(int id, int event_flags); | |
| 509 | |
| 510 // Executes a command if it's enabled. | |
| 511 // Returns true if the command is executed. | |
| 512 bool ExecuteCommandIfEnabled(int id); | |
| 513 | 40 |
| 514 // Returns true if |command_id| is a reserved command whose keyboard shortcuts | 41 // Returns true if |command_id| is a reserved command whose keyboard shortcuts |
| 515 // should not be sent to the renderer or |event| was triggered by a key that | 42 // should not be sent to the renderer or |event| was triggered by a key that |
| 516 // we never want to send to the renderer. | 43 // we never want to send to the renderer. |
| 517 bool IsReservedCommandOrKey(int command_id, | 44 bool IsReservedCommandOrKey(int command_id, |
| 518 const content::NativeWebKeyboardEvent& event); | 45 const content::NativeWebKeyboardEvent& event); |
| 519 | 46 |
| 520 // Sets if command execution shall be blocked. If |block| is true then | 47 // Sets if command execution shall be blocked. If |block| is true then |
| 521 // following calls to ExecuteCommand() or ExecuteCommandWithDisposition() | 48 // following calls to ExecuteCommand() or ExecuteCommandWithDisposition() |
| 522 // method will not execute the command, and the last blocked command will be | 49 // method will not execute the command, and the last blocked command will be |
| 523 // recorded for retrieval. | 50 // recorded for retrieval. |
| 524 void SetBlockCommandExecution(bool block); | 51 void SetBlockCommandExecution(bool block); |
| 525 | 52 |
| 526 // Gets the last blocked command after calling SetBlockCommandExecution(true). | 53 // Gets the last blocked command after calling SetBlockCommandExecution(true). |
| 527 // Returns the command id or -1 if there is no command blocked. The | 54 // Returns the command id or -1 if there is no command blocked. The |
| 528 // disposition type of the command will be stored in |*disposition| if it's | 55 // disposition type of the command will be stored in |*disposition| if it's |
| 529 // not null. | 56 // not NULL. |
| 530 int GetLastBlockedCommand(WindowOpenDisposition* disposition); | 57 int GetLastBlockedCommand(WindowOpenDisposition* disposition); |
| 531 | 58 |
| 532 // Called by browser::Navigate() when a navigation has occurred in a tab in | 59 // Notifies the controller that state has changed in one of the following |
| 533 // this Browser. Updates the UI for the start of this navigation. | 60 // areas and it should update command states. |
| 534 void UpdateUIForNavigationInTab(TabContents* contents, | 61 void TabStateChanged(); |
| 535 content::PageTransition transition, | 62 void ContentRestrictionsChanged(); |
| 536 bool user_initiated); | 63 void FullscreenStateChanged(); |
| 537 | 64 void PrintingStateChanged(); |
| 538 // Interface implementations //////////////////////////////////////////////// | 65 void LoadingStateChanged(bool is_loading, bool force); |
| 539 | 66 void SendToMobileStateChanged(bool send_to_mobile_available); |
| 540 // Overridden from content::PageNavigator: | |
| 541 virtual content::WebContents* OpenURL( | |
| 542 const content::OpenURLParams& params) OVERRIDE; | |
| 543 | |
| 544 // Overridden from CommandUpdater::CommandUpdaterDelegate: | |
| 545 virtual void ExecuteCommandWithDisposition( | |
| 546 int id, | |
| 547 WindowOpenDisposition disposition) OVERRIDE; | |
| 548 | |
| 549 // Overridden from TabRestoreServiceObserver: | |
| 550 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; | |
| 551 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; | |
| 552 | |
| 553 // Centralized method for creating a TabContents, configuring and | |
| 554 // installing all its supporting objects and observers. | |
| 555 static TabContents* TabContentsFactory( | |
| 556 Profile* profile, | |
| 557 content::SiteInstance* site_instance, | |
| 558 int routing_id, | |
| 559 const content::WebContents* base_web_contents, | |
| 560 content::SessionStorageNamespace* session_storage_namespace); | |
| 561 | |
| 562 // Overridden from TabStripModelDelegate: | |
| 563 virtual TabContents* AddBlankTab(bool foreground) OVERRIDE; | |
| 564 virtual TabContents* AddBlankTabAt(int index, | |
| 565 bool foreground) OVERRIDE; | |
| 566 virtual Browser* CreateNewStripWithContents( | |
| 567 TabContents* detached_contents, | |
| 568 const gfx::Rect& window_bounds, | |
| 569 const DockInfo& dock_info, | |
| 570 bool maximize) OVERRIDE; | |
| 571 virtual int GetDragActions() const OVERRIDE; | |
| 572 // Construct a TabContents for a given URL, profile and transition type. If | |
| 573 // instance is not null, its process will be used to render the tab. | |
| 574 virtual TabContents* CreateTabContentsForURL( | |
| 575 const GURL& url, | |
| 576 const content::Referrer& referrer, | |
| 577 Profile* profile, | |
| 578 content::PageTransition transition, | |
| 579 bool defer_load, | |
| 580 content::SiteInstance* instance) const OVERRIDE; | |
| 581 virtual bool CanDuplicateContentsAt(int index) OVERRIDE; | |
| 582 virtual void DuplicateContentsAt(int index) OVERRIDE; | |
| 583 virtual void CloseFrameAfterDragSession() OVERRIDE; | |
| 584 virtual void CreateHistoricalTab(TabContents* contents) OVERRIDE; | |
| 585 virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) OVERRIDE; | |
| 586 virtual bool CanBookmarkAllTabs() const OVERRIDE; | |
| 587 virtual void BookmarkAllTabs() OVERRIDE; | |
| 588 virtual bool CanRestoreTab() OVERRIDE; | |
| 589 virtual void RestoreTab() OVERRIDE; | |
| 590 | |
| 591 // Overridden from TabStripModelObserver: | |
| 592 virtual void TabInsertedAt(TabContents* contents, | |
| 593 int index, | |
| 594 bool foreground) OVERRIDE; | |
| 595 virtual void TabClosingAt(TabStripModel* tab_strip_model, | |
| 596 TabContents* contents, | |
| 597 int index) OVERRIDE; | |
| 598 virtual void TabDetachedAt(TabContents* contents, int index) OVERRIDE; | |
| 599 virtual void TabDeactivated(TabContents* contents) OVERRIDE; | |
| 600 virtual void ActiveTabChanged(TabContents* old_contents, | |
| 601 TabContents* new_contents, | |
| 602 int index, | |
| 603 bool user_gesture) OVERRIDE; | |
| 604 virtual void TabMoved(TabContents* contents, | |
| 605 int from_index, | |
| 606 int to_index) OVERRIDE; | |
| 607 virtual void TabReplacedAt(TabStripModel* tab_strip_model, | |
| 608 TabContents* old_contents, | |
| 609 TabContents* new_contents, | |
| 610 int index) OVERRIDE; | |
| 611 virtual void TabPinnedStateChanged(TabContents* contents, | |
| 612 int index) OVERRIDE; | |
| 613 virtual void TabStripEmpty() OVERRIDE; | |
| 614 | |
| 615 // Overridden from content::WebContentsDelegate: | |
| 616 virtual bool PreHandleKeyboardEvent( | |
| 617 const content::NativeWebKeyboardEvent& event, | |
| 618 bool* is_keyboard_shortcut) OVERRIDE; | |
| 619 virtual void HandleKeyboardEvent( | |
| 620 const content::NativeWebKeyboardEvent& event) OVERRIDE; | |
| 621 | |
| 622 // Fullscreen permission infobar callbacks. | |
| 623 // TODO(koz): Remove this and have callers call FullscreenController directly. | |
| 624 void OnAcceptFullscreenPermission(const GURL& url, | |
| 625 FullscreenExitBubbleType bubble_type); | |
| 626 void OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type); | |
| 627 | |
| 628 // Figure out if there are tabs that have beforeunload handlers. | |
| 629 bool TabsNeedBeforeUnloadFired(); | |
| 630 | |
| 631 bool is_type_tabbed() const { return type_ == TYPE_TABBED; } | |
| 632 bool is_type_popup() const { return type_ == TYPE_POPUP; } | |
| 633 bool is_type_panel() const { return type_ == TYPE_PANEL; } | |
| 634 | |
| 635 bool is_app() const; | |
| 636 bool is_devtools() const; | |
| 637 | |
| 638 // See FullscreenController::IsFullscreenForTabOrPending. | |
| 639 bool IsFullscreenForTabOrPending() const; | |
| 640 | |
| 641 // True when the mouse cursor is locked. | |
| 642 bool IsMouseLocked() const; | |
| 643 | |
| 644 // Called each time the browser window is shown. | |
| 645 void OnWindowDidShow(); | |
| 646 | |
| 647 // Show the first run search engine bubble on the location bar. | |
| 648 void ShowFirstRunBubble(); | |
| 649 | |
| 650 void set_pending_web_app_action(WebAppAction action) { | |
| 651 pending_web_app_action_ = action; | |
| 652 } | |
| 653 | |
| 654 ExtensionWindowController* extension_window_controller() const { | |
| 655 return extension_window_controller_.get(); | |
| 656 } | |
| 657 | |
| 658 protected: | |
| 659 // Funnel for the factory method in BrowserWindow. This allows subclasses to | |
| 660 // set their own window. | |
| 661 virtual BrowserWindow* CreateBrowserWindow(); | |
| 662 | 67 |
| 663 private: | 68 private: |
| 664 friend class BrowserTest; | |
| 665 friend class FullscreenControllerTest; | |
| 666 FRIEND_TEST_ALL_PREFIXES(AppModeTest, EnableAppModeTest); | |
| 667 FRIEND_TEST_ALL_PREFIXES(BrowserTest, NoTabsInPopups); | |
| 668 FRIEND_TEST_ALL_PREFIXES(BrowserTest, ConvertTabToAppShortcut); | |
| 669 FRIEND_TEST_ALL_PREFIXES(BrowserTest, OpenAppWindowLikeNtp); | |
| 670 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch); | |
| 671 FRIEND_TEST_ALL_PREFIXES(FullscreenControllerTest, | |
| 672 TabEntersPresentationModeFromWindowed); | |
| 673 FRIEND_TEST_ALL_PREFIXES(FullscreenExitBubbleControllerTest, | |
| 674 DenyExitsFullscreen); | |
| 675 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutNoPref); | |
| 676 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, | |
| 677 OpenAppShortcutWindowPref); | |
| 678 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutTabPref); | |
| 679 FRIEND_TEST_ALL_PREFIXES(StartupBrowserCreatorTest, OpenAppShortcutPanel); | |
| 680 | |
| 681 // Used to describe why a tab is being detached. This is used by | |
| 682 // TabDetachedAtImpl. | |
| 683 enum DetachType { | |
| 684 // Result of TabDetachedAt. | |
| 685 DETACH_TYPE_DETACH, | |
| 686 | |
| 687 // Result of TabReplacedAt. | |
| 688 DETACH_TYPE_REPLACE, | |
| 689 | |
| 690 // Result of the tab strip not having any significant tabs. | |
| 691 DETACH_TYPE_EMPTY | |
| 692 }; | |
| 693 | |
| 694 // Describes where the bookmark bar state change originated from. | |
| 695 enum BookmarkBarStateChangeReason { | |
| 696 // From the constructor. | |
| 697 BOOKMARK_BAR_STATE_CHANGE_INIT, | |
| 698 | |
| 699 // Change is the result of the active tab changing. | |
| 700 BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH, | |
| 701 | |
| 702 // Change is the result of the bookmark bar pref changing. | |
| 703 BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE, | |
| 704 | |
| 705 // Change is the result of a state change in the active tab. | |
| 706 BOOKMARK_BAR_STATE_CHANGE_TAB_STATE, | |
| 707 | |
| 708 // Change is the result of window toggling in/out of fullscreen mode. | |
| 709 BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN, | |
| 710 }; | |
| 711 | |
| 712 enum FullScreenMode { | 69 enum FullScreenMode { |
| 713 // Not in fullscreen mode. | 70 // Not in fullscreen mode. |
| 714 FULLSCREEN_DISABLED, | 71 FULLSCREEN_DISABLED, |
| 715 | 72 |
| 716 // Fullscreen mode, occupying the whole screen. | 73 // Fullscreen mode, occupying the whole screen. |
| 717 FULLSCREEN_NORMAL, | 74 FULLSCREEN_NORMAL, |
| 718 | 75 |
| 719 // Fullscreen mode for metro snap, occupying the full height and 20% of | 76 // Fullscreen mode for metro snap, occupying the full height and 20% of |
| 720 // the screen width. | 77 // the screen width. |
| 721 FULLSCREEN_METRO_SNAP, | 78 FULLSCREEN_METRO_SNAP, |
| 722 }; | 79 }; |
| 723 | 80 |
| 724 // Overridden from content::WebContentsDelegate: | 81 // Overridden from CommandUpdater::CommandUpdaterDelegate: |
| 725 virtual content::WebContents* OpenURLFromTab( | 82 virtual void ExecuteCommandWithDisposition( |
| 726 content::WebContents* source, | 83 int id, |
| 727 const content::OpenURLParams& params) OVERRIDE; | 84 WindowOpenDisposition disposition) OVERRIDE; |
| 728 virtual void NavigationStateChanged(const content::WebContents* source, | |
| 729 unsigned changed_flags) OVERRIDE; | |
| 730 virtual void AddNewContents(content::WebContents* source, | |
| 731 content::WebContents* new_contents, | |
| 732 WindowOpenDisposition disposition, | |
| 733 const gfx::Rect& initial_pos, | |
| 734 bool user_gesture) OVERRIDE; | |
| 735 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; | |
| 736 virtual void DeactivateContents(content::WebContents* contents) OVERRIDE; | |
| 737 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; | |
| 738 virtual void CloseContents(content::WebContents* source) OVERRIDE; | |
| 739 virtual void MoveContents(content::WebContents* source, | |
| 740 const gfx::Rect& pos) OVERRIDE; | |
| 741 virtual void DetachContents(content::WebContents* source) OVERRIDE; | |
| 742 virtual bool IsPopupOrPanel( | |
| 743 const content::WebContents* source) const OVERRIDE; | |
| 744 virtual void UpdateTargetURL(content::WebContents* source, int32 page_id, | |
| 745 const GURL& url) OVERRIDE; | |
| 746 virtual void ContentsMouseEvent(content::WebContents* source, | |
| 747 const gfx::Point& location, | |
| 748 bool motion) OVERRIDE; | |
| 749 virtual void ContentsZoomChange(bool zoom_in) OVERRIDE; | |
| 750 virtual void WebContentsFocused(content::WebContents* content) OVERRIDE; | |
| 751 virtual bool TakeFocus(bool reverse) OVERRIDE; | |
| 752 virtual bool IsApplication() const OVERRIDE; | |
| 753 virtual void ConvertContentsToApplication( | |
| 754 content::WebContents* source) OVERRIDE; | |
| 755 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; | |
| 756 virtual void BeforeUnloadFired(content::WebContents* source, | |
| 757 bool proceed, | |
| 758 bool* proceed_to_fire_unload) OVERRIDE; | |
| 759 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; | |
| 760 virtual void RenderWidgetShowing() OVERRIDE; | |
| 761 virtual int GetExtraRenderViewHeight() const OVERRIDE; | |
| 762 virtual void OnStartDownload(content::WebContents* source, | |
| 763 content::DownloadItem* download) OVERRIDE; | |
| 764 virtual void ViewSourceForTab(content::WebContents* source, | |
| 765 const GURL& page_url) OVERRIDE; | |
| 766 virtual void ViewSourceForFrame( | |
| 767 content::WebContents* source, | |
| 768 const GURL& frame_url, | |
| 769 const std::string& frame_content_state) OVERRIDE; | |
| 770 virtual void ShowRepostFormWarningDialog( | |
| 771 content::WebContents* source) OVERRIDE; | |
| 772 virtual bool ShouldAddNavigationToHistory( | |
| 773 const history::HistoryAddPageArgs& add_page_args, | |
| 774 content::NavigationType navigation_type) OVERRIDE; | |
| 775 virtual bool ShouldCreateWebContents( | |
| 776 content::WebContents* web_contents, | |
| 777 int route_id, | |
| 778 WindowContainerType window_container_type, | |
| 779 const string16& frame_name, | |
| 780 const GURL& target_url) OVERRIDE; | |
| 781 virtual void WebContentsCreated(content::WebContents* source_contents, | |
| 782 int64 source_frame_id, | |
| 783 const GURL& target_url, | |
| 784 content::WebContents* new_contents) OVERRIDE; | |
| 785 virtual void ContentRestrictionsChanged( | |
| 786 content::WebContents* source) OVERRIDE; | |
| 787 virtual void RendererUnresponsive(content::WebContents* source) OVERRIDE; | |
| 788 virtual void RendererResponsive(content::WebContents* source) OVERRIDE; | |
| 789 virtual void WorkerCrashed(content::WebContents* source) OVERRIDE; | |
| 790 virtual void DidNavigateMainFramePostCommit( | |
| 791 content::WebContents* web_contents) OVERRIDE; | |
| 792 virtual void DidNavigateToPendingEntry( | |
| 793 content::WebContents* web_contents) OVERRIDE; | |
| 794 virtual content::JavaScriptDialogCreator* | |
| 795 GetJavaScriptDialogCreator() OVERRIDE; | |
| 796 virtual content::ColorChooser* OpenColorChooser( | |
| 797 content::WebContents* web_contents, | |
| 798 int color_chooser_id, | |
| 799 SkColor color) OVERRIDE; | |
| 800 virtual void DidEndColorChooser() OVERRIDE; | |
| 801 virtual void RunFileChooser( | |
| 802 content::WebContents* web_contents, | |
| 803 const content::FileChooserParams& params) OVERRIDE; | |
| 804 virtual void EnumerateDirectory(content::WebContents* web_contents, | |
| 805 int request_id, | |
| 806 const FilePath& path) OVERRIDE; | |
| 807 virtual void ToggleFullscreenModeForTab(content::WebContents* web_contents, | |
| 808 bool enter_fullscreen) OVERRIDE; | |
| 809 virtual bool IsFullscreenForTabOrPending( | |
| 810 const content::WebContents* web_contents) const OVERRIDE; | |
| 811 virtual void JSOutOfMemory(content::WebContents* web_contents) OVERRIDE; | |
| 812 virtual void RegisterProtocolHandler(content::WebContents* web_contents, | |
| 813 const std::string& protocol, | |
| 814 const GURL& url, | |
| 815 const string16& title, | |
| 816 bool user_gesture) OVERRIDE; | |
| 817 virtual void RegisterIntentHandler( | |
| 818 content::WebContents* web_contents, | |
| 819 const webkit_glue::WebIntentServiceData& data, | |
| 820 bool user_gesture) OVERRIDE; | |
| 821 virtual void WebIntentDispatch( | |
| 822 content::WebContents* web_contents, | |
| 823 content::WebIntentsDispatcher* intents_dispatcher) OVERRIDE; | |
| 824 virtual void UpdatePreferredSize(content::WebContents* source, | |
| 825 const gfx::Size& pref_size) OVERRIDE; | |
| 826 virtual void ResizeDueToAutoResize(content::WebContents* source, | |
| 827 const gfx::Size& new_size) OVERRIDE; | |
| 828 virtual void FindReply(content::WebContents* web_contents, | |
| 829 int request_id, | |
| 830 int number_of_matches, | |
| 831 const gfx::Rect& selection_rect, | |
| 832 int active_match_ordinal, | |
| 833 bool final_update) OVERRIDE; | |
| 834 virtual void RequestToLockMouse(content::WebContents* web_contents, | |
| 835 bool user_gesture, | |
| 836 bool last_unlocked_by_target) OVERRIDE; | |
| 837 virtual void LostMouseLock() OVERRIDE; | |
| 838 virtual void RequestMediaAccessPermission( | |
| 839 content::WebContents* web_contents, | |
| 840 const content::MediaStreamRequest* request, | |
| 841 const content::MediaResponseCallback& callback) OVERRIDE; | |
| 842 | |
| 843 // Overridden from CoreTabHelperDelegate: | |
| 844 // Note that the caller is responsible for deleting |old_tab_contents|. | |
| 845 virtual void SwapTabContents(TabContents* old_tab_contents, | |
| 846 TabContents* new_tab_contents) OVERRIDE; | |
| 847 virtual bool CanReloadContents(TabContents* source) const OVERRIDE; | |
| 848 virtual bool CanSaveContents(TabContents* source) const OVERRIDE; | |
| 849 | |
| 850 // Overridden from SearchEngineTabHelperDelegate: | |
| 851 virtual void ConfirmAddSearchProvider(TemplateURL* template_url, | |
| 852 Profile* profile) OVERRIDE; | |
| 853 | |
| 854 // Overridden from ConstrainedWindowTabHelperDelegate: | |
| 855 virtual void SetTabContentBlocked(TabContents* contents, | |
| 856 bool blocked) OVERRIDE; | |
| 857 | |
| 858 // Overridden from BlockedContentTabHelperDelegate: | |
| 859 virtual TabContents* GetConstrainingTabContents(TabContents* source) OVERRIDE; | |
| 860 | |
| 861 // Overridden from BookmarkTabHelperDelegate: | |
| 862 virtual void URLStarredChanged(TabContents* source, | |
| 863 bool starred) OVERRIDE; | |
| 864 | |
| 865 // Overridden from ZoomObserver: | |
| 866 virtual void OnZoomIconChanged(TabContents* source, | |
| 867 ZoomController::ZoomIconState state) OVERRIDE; | |
| 868 virtual void OnZoomChanged(TabContents* source, | |
| 869 int zoom_percent, | |
| 870 bool can_show_bubble) OVERRIDE; | |
| 871 | |
| 872 // Overridden from ExtensionTabHelperDelegate: | |
| 873 virtual void OnDidGetApplicationInfo(TabContents* source, | |
| 874 int32 page_id) OVERRIDE; | |
| 875 virtual void OnInstallApplication( | |
| 876 TabContents* source, | |
| 877 const WebApplicationInfo& app_info) OVERRIDE; | |
| 878 | |
| 879 // Overridden from SelectFileDialog::Listener: | |
| 880 virtual void FileSelected(const FilePath& path, | |
| 881 int index, | |
| 882 void* params) OVERRIDE; | |
| 883 | 85 |
| 884 // Overridden from content::NotificationObserver: | 86 // Overridden from content::NotificationObserver: |
| 885 virtual void Observe(int type, | 87 virtual void Observe(int type, |
| 886 const content::NotificationSource& source, | 88 const content::NotificationSource& source, |
| 887 const content::NotificationDetails& details) OVERRIDE; | 89 const content::NotificationDetails& details) OVERRIDE; |
| 888 | 90 |
| 91 // Overridden from TabStripModelObserver: |
| 92 virtual void TabInsertedAt(TabContents* contents, |
| 93 int index, |
| 94 bool foreground) OVERRIDE; |
| 95 virtual void TabDetachedAt(TabContents* contents, int index) OVERRIDE; |
| 96 virtual void TabReplacedAt(TabStripModel* tab_strip_model, |
| 97 TabContents* old_contents, |
| 98 TabContents* new_contents, |
| 99 int index) OVERRIDE; |
| 100 |
| 101 // Overridden from TabRestoreServiceObserver: |
| 102 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; |
| 103 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; |
| 104 |
| 889 // Overridden from ProfileSyncServiceObserver: | 105 // Overridden from ProfileSyncServiceObserver: |
| 890 virtual void OnStateChanged() OVERRIDE; | 106 virtual void OnStateChanged() OVERRIDE; |
| 891 | 107 |
| 892 // Overriden from InstantDelegate: | |
| 893 virtual void ShowInstant(TabContents* preview_contents) OVERRIDE; | |
| 894 virtual void HideInstant() OVERRIDE; | |
| 895 virtual void CommitInstant(TabContents* preview_contents) OVERRIDE; | |
| 896 virtual void SetSuggestedText(const string16& text, | |
| 897 InstantCompleteBehavior behavior) OVERRIDE; | |
| 898 virtual gfx::Rect GetInstantBounds() OVERRIDE; | |
| 899 virtual void InstantPreviewFocused() OVERRIDE; | |
| 900 virtual TabContents* GetInstantHostTabContents() const OVERRIDE; | |
| 901 | |
| 902 // Command and state updating /////////////////////////////////////////////// | |
| 903 | |
| 904 // Returns true if the regular Chrome UI (not the fullscreen one and | 108 // Returns true if the regular Chrome UI (not the fullscreen one and |
| 905 // not the single-tab one) is shown. Used for updating window command states | 109 // not the single-tab one) is shown. Used for updating window command states |
| 906 // only. Consider using SupportsWindowFeature if you need the mentioned | 110 // only. Consider using SupportsWindowFeature if you need the mentioned |
| 907 // functionality anywhere else. | 111 // functionality anywhere else. |
| 908 bool IsShowingMainUI(bool is_fullscreen); | 112 bool IsShowingMainUI(bool is_fullscreen); |
| 909 | 113 |
| 910 // Initialize state for all browser commands. | 114 // Initialize state for all browser commands. |
| 911 void InitCommandState(); | 115 void InitCommandState(); |
| 912 | 116 |
| 913 // Update commands whose state depends on incognito mode availability. | 117 // Update commands whose state depends on incognito mode availability. |
| 914 void UpdateCommandsForIncognitoAvailability(); | 118 void UpdateCommandsForIncognitoAvailability(); |
| 915 | 119 |
| 916 // Update commands whose state depends on the tab's state. | 120 // Update commands whose state depends on the tab's state. |
| 917 void UpdateCommandsForTabState(); | 121 void UpdateCommandsForTabState(); |
| 918 | 122 |
| 919 // Updates commands when the content's restrictions change. | 123 // Updates commands when the content's restrictions change. |
| 920 void UpdateCommandsForContentRestrictionState(); | 124 void UpdateCommandsForContentRestrictionState(); |
| 921 | 125 |
| 922 // Updates commands for enabling developer tools. | 126 // Updates commands for enabling developer tools. |
| 923 void UpdateCommandsForDevTools(); | 127 void UpdateCommandsForDevTools(); |
| 924 | 128 |
| 925 // Updates commands for bookmark editing. | 129 // Updates commands for bookmark editing. |
| 926 void UpdateCommandsForBookmarkEditing(); | 130 void UpdateCommandsForBookmarkEditing(); |
| 927 | 131 |
| 928 // Updates commands that affect the bookmark bar. | 132 // Updates commands that affect the bookmark bar. |
| 929 void UpdateCommandsForBookmarkBar(); | 133 void UpdateCommandsForBookmarkBar(); |
| 930 | 134 |
| 931 // Set the preference that indicates that the home page has been changed. | |
| 932 void MarkHomePageAsChanged(PrefService* pref_service); | |
| 933 | |
| 934 // Update commands whose state depends on the type of fullscreen mode the | 135 // Update commands whose state depends on the type of fullscreen mode the |
| 935 // window is in. | 136 // window is in. |
| 936 void UpdateCommandsForFullscreenMode(FullScreenMode fullscreen_mode); | 137 void UpdateCommandsForFullscreenMode(FullScreenMode fullscreen_mode); |
| 937 | 138 |
| 938 // Update commands whose state depends on whether multiple profiles are | 139 // Update commands whose state depends on whether multiple profiles are |
| 939 // allowed. | 140 // allowed. |
| 940 void UpdateCommandsForMultipleProfiles(); | 141 void UpdateCommandsForMultipleProfiles(); |
| 941 | 142 |
| 942 // Updates the printing command state. | 143 // Updates the printing command state. |
| 943 void UpdatePrintingState(int content_restrictions); | 144 void UpdatePrintingState(); |
| 944 | 145 |
| 945 // Updates the save-page-as command state. | 146 // Updates the save-page-as command state. |
| 946 void UpdateSaveAsState(int content_restrictions); | 147 void UpdateSaveAsState(); |
| 947 | 148 |
| 948 // Updates the open-file state (Mac Only). | 149 // Updates the open-file state (Mac Only). |
| 949 void UpdateOpenFileState(); | 150 void UpdateOpenFileState(); |
| 950 | 151 |
| 951 // Ask the Reload/Stop button to change its icon, and update the Stop command | 152 // Ask the Reload/Stop button to change its icon, and update the Stop command |
| 952 // state. |is_loading| is true if the current WebContents is loading. | 153 // state. |is_loading| is true if the current WebContents is loading. |
| 953 // |force| is true if the button should change its icon immediately. | 154 // |force| is true if the button should change its icon immediately. |
| 954 void UpdateReloadStopState(bool is_loading, bool force); | 155 void UpdateReloadStopState(bool is_loading, bool force); |
| 955 | 156 |
| 956 // UI update coalescing and handling //////////////////////////////////////// | 157 // Add/remove observers for interstitial attachment/detachment from |
| 158 // |contents|. |
| 159 void AddInterstitialObservers(TabContents* contents); |
| 160 void RemoveInterstitialObservers(TabContents* contents); |
| 957 | 161 |
| 958 // Asks the toolbar (and as such the location bar) to update its state to | 162 inline BrowserWindow* window(); |
| 959 // reflect the current tab's current URL, security state, etc. | 163 inline Profile* profile(); |
| 960 // If |should_restore_state| is true, we're switching (back?) to this tab and | |
| 961 // should restore any previous location bar state (such as user editing) as | |
| 962 // well. | |
| 963 void UpdateToolbar(bool should_restore_state); | |
| 964 | 164 |
| 965 // Updates the browser's search model with the tab's search model. | 165 Browser* browser_; |
| 966 void UpdateSearchState(TabContents* contents); | |
| 967 | |
| 968 // Does one or both of the following for each bit in |changed_flags|: | |
| 969 // . If the update should be processed immediately, it is. | |
| 970 // . If the update should processed asynchronously (to avoid lots of ui | |
| 971 // updates), then scheduled_updates_ is updated for the |source| and update | |
| 972 // pair and a task is scheduled (assuming it isn't running already) | |
| 973 // that invokes ProcessPendingUIUpdates. | |
| 974 void ScheduleUIUpdate(const content::WebContents* source, | |
| 975 unsigned changed_flags); | |
| 976 | |
| 977 // Processes all pending updates to the UI that have been scheduled by | |
| 978 // ScheduleUIUpdate in scheduled_updates_. | |
| 979 void ProcessPendingUIUpdates(); | |
| 980 | |
| 981 // Removes all entries from scheduled_updates_ whose source is contents. | |
| 982 void RemoveScheduledUpdatesFor(content::WebContents* contents); | |
| 983 | |
| 984 // Getters for UI /////////////////////////////////////////////////////////// | |
| 985 | |
| 986 // TODO(beng): remove, and provide AutomationProvider a better way to access | |
| 987 // the LocationBarView's edit. | |
| 988 friend class AutomationProvider; | |
| 989 friend class BrowserProxy; | |
| 990 friend class TestingAutomationProvider; | |
| 991 | |
| 992 // Returns the StatusBubble from the current toolbar. It is possible for | |
| 993 // this to return NULL if called before the toolbar has initialized. | |
| 994 // TODO(beng): remove this. | |
| 995 StatusBubble* GetStatusBubble(); | |
| 996 | |
| 997 // Session restore functions //////////////////////////////////////////////// | |
| 998 | |
| 999 // Notifies the history database of the index for all tabs whose index is | |
| 1000 // >= index. | |
| 1001 void SyncHistoryWithTabs(int index); | |
| 1002 | |
| 1003 // OnBeforeUnload handling ////////////////////////////////////////////////// | |
| 1004 | |
| 1005 typedef std::set<content::WebContents*> UnloadListenerSet; | |
| 1006 | |
| 1007 // Processes the next tab that needs it's beforeunload/unload event fired. | |
| 1008 void ProcessPendingTabs(); | |
| 1009 | |
| 1010 // Whether we've completed firing all the tabs' beforeunload/unload events. | |
| 1011 bool HasCompletedUnloadProcessing() const; | |
| 1012 | |
| 1013 // Clears all the state associated with processing tabs' beforeunload/unload | |
| 1014 // events since the user cancelled closing the window. | |
| 1015 void CancelWindowClose(); | |
| 1016 | |
| 1017 // Removes |web_contents| from the passed |set|. | |
| 1018 // Returns whether the tab was in the set in the first place. | |
| 1019 // TODO(beng): this method needs a better name! | |
| 1020 bool RemoveFromSet(UnloadListenerSet* set, | |
| 1021 content::WebContents* web_contents); | |
| 1022 | |
| 1023 // Cleans up state appropriately when we are trying to close the browser and | |
| 1024 // the tab has finished firing its unload handler. We also use this in the | |
| 1025 // cases where a tab crashes or hangs even if the beforeunload/unload haven't | |
| 1026 // successfully fired. If |process_now| is true |ProcessPendingTabs| is | |
| 1027 // invoked immediately, otherwise it is invoked after a delay (PostTask). | |
| 1028 // | |
| 1029 // Typically you'll want to pass in true for |process_now|. Passing in true | |
| 1030 // may result in deleting |tab|. If you know that shouldn't happen (because of | |
| 1031 // the state of the stack), pass in false. | |
| 1032 void ClearUnloadState(content::WebContents* web_contents, bool process_now); | |
| 1033 | |
| 1034 // In-progress download termination handling ///////////////////////////////// | |
| 1035 | |
| 1036 // Called when the window is closing to check if potential in-progress | |
| 1037 // downloads should prevent it from closing. | |
| 1038 // Returns true if the window can close, false otherwise. | |
| 1039 bool CanCloseWithInProgressDownloads(); | |
| 1040 | |
| 1041 // Assorted utility functions /////////////////////////////////////////////// | |
| 1042 | |
| 1043 // Sets the delegate of all the parts of the TabContents that | |
| 1044 // are needed. | |
| 1045 void SetAsDelegate(TabContents* tab, Browser* delegate); | |
| 1046 | |
| 1047 // Shows the Find Bar, optionally selecting the next entry that matches the | |
| 1048 // existing search string for that Tab. |forward_direction| controls the | |
| 1049 // search direction. | |
| 1050 void FindInPage(bool find_next, bool forward_direction); | |
| 1051 | |
| 1052 // Closes the frame. | |
| 1053 // TODO(beng): figure out if we need this now that the frame itself closes | |
| 1054 // after a return to the message loop. | |
| 1055 void CloseFrame(); | |
| 1056 | |
| 1057 void TabDetachedAtImpl(TabContents* contents, int index, DetachType type); | |
| 1058 | |
| 1059 // Shared code between Reload() and ReloadIgnoringCache(). | |
| 1060 void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache); | |
| 1061 | |
| 1062 // Depending on the disposition, return the current tab or a clone of the | |
| 1063 // current tab. | |
| 1064 content::WebContents* GetOrCloneTabForDisposition( | |
| 1065 WindowOpenDisposition disposition); | |
| 1066 | |
| 1067 // Implementation of SupportsWindowFeature and CanSupportWindowFeature. If | |
| 1068 // |check_fullscreen| is true, the set of features reflect the actual state of | |
| 1069 // the browser, otherwise the set of features reflect the possible state of | |
| 1070 // the browser. | |
| 1071 bool SupportsWindowFeatureImpl(WindowFeature feature, | |
| 1072 bool check_fullscreen) const; | |
| 1073 | |
| 1074 // If this browser should have instant one is created, otherwise does nothing. | |
| 1075 void CreateInstantIfNecessary(); | |
| 1076 | |
| 1077 // Retrieves the content restrictions for the currently selected tab. | |
| 1078 // Returns 0 if no tab selected, which is equivalent to no content | |
| 1079 // restrictions active. | |
| 1080 int GetContentRestrictionsForSelectedTab(); | |
| 1081 | |
| 1082 // Resets |bookmark_bar_state_| based on the active tab. Notifies the | |
| 1083 // BrowserWindow if necessary. | |
| 1084 void UpdateBookmarkBarState(BookmarkBarStateChangeReason reason); | |
| 1085 | |
| 1086 // Creates a BackgroundContents if appropriate; return true if one was | |
| 1087 // created. | |
| 1088 bool MaybeCreateBackgroundContents(int route_id, | |
| 1089 content::WebContents* opener_web_contents, | |
| 1090 const string16& frame_name, | |
| 1091 const GURL& target_url); | |
| 1092 | |
| 1093 // Data members ///////////////////////////////////////////////////////////// | |
| 1094 | |
| 1095 content::NotificationRegistrar registrar_; | |
| 1096 | |
| 1097 PrefChangeRegistrar profile_pref_registrar_; | |
| 1098 | |
| 1099 PrefChangeRegistrar local_pref_registrar_; | |
| 1100 | |
| 1101 // This Browser's type. | |
| 1102 const Type type_; | |
| 1103 | |
| 1104 // This Browser's profile. | |
| 1105 Profile* const profile_; | |
| 1106 | |
| 1107 // This Browser's window. | |
| 1108 BrowserWindow* window_; | |
| 1109 | |
| 1110 scoped_ptr<TabStripModel> tab_strip_model_; | |
| 1111 | 166 |
| 1112 // The CommandUpdater that manages the browser window commands. | 167 // The CommandUpdater that manages the browser window commands. |
| 1113 CommandUpdater command_updater_; | 168 CommandUpdater command_updater_; |
| 1114 | 169 |
| 1115 // The application name that is also the name of the window to the shell. | |
| 1116 // This name should be set when: | |
| 1117 // 1) we launch an application via an application shortcut or extension API. | |
| 1118 // 2) we launch an undocked devtool window. | |
| 1119 std::string app_name_; | |
| 1120 | |
| 1121 // Type of app (host or child). See description of AppType. | |
| 1122 AppType app_type_; | |
| 1123 | |
| 1124 // Unique identifier of this browser for session restore. This id is only | |
| 1125 // unique within the current session, and is not guaranteed to be unique | |
| 1126 // across sessions. | |
| 1127 const SessionID session_id_; | |
| 1128 | |
| 1129 // The model for the toolbar view. | |
| 1130 scoped_ptr<ToolbarModel> toolbar_model_; | |
| 1131 | |
| 1132 // The model for the "active" search state. There are per-tab search models | |
| 1133 // as well. When a tab is active its model is kept in sync with this one. | |
| 1134 // When a new tab is activated its model state is propagated to this active | |
| 1135 // model. This way, observers only have to attach to this single model for | |
| 1136 // updates, and don't have to worry about active tab changes directly. | |
| 1137 scoped_ptr<chrome::search::SearchModel> search_model_; | |
| 1138 | |
| 1139 // UI update coalescing and handling //////////////////////////////////////// | |
| 1140 | |
| 1141 typedef std::map<const content::WebContents*, int> UpdateMap; | |
| 1142 | |
| 1143 // Maps from WebContents to pending UI updates that need to be processed. | |
| 1144 // We don't update things like the URL or tab title right away to avoid | |
| 1145 // flickering and extra painting. | |
| 1146 // See ScheduleUIUpdate and ProcessPendingUIUpdates. | |
| 1147 UpdateMap scheduled_updates_; | |
| 1148 | |
| 1149 // The following factory is used for chrome update coalescing. | |
| 1150 base::WeakPtrFactory<Browser> chrome_updater_factory_; | |
| 1151 | |
| 1152 // OnBeforeUnload handling ////////////////////////////////////////////////// | |
| 1153 | |
| 1154 // Tracks tabs that need there beforeunload event fired before we can | |
| 1155 // close the browser. Only gets populated when we try to close the browser. | |
| 1156 UnloadListenerSet tabs_needing_before_unload_fired_; | |
| 1157 | |
| 1158 // Tracks tabs that need there unload event fired before we can | |
| 1159 // close the browser. Only gets populated when we try to close the browser. | |
| 1160 UnloadListenerSet tabs_needing_unload_fired_; | |
| 1161 | |
| 1162 // Whether we are processing the beforeunload and unload events of each tab | |
| 1163 // in preparation for closing the browser. | |
| 1164 bool is_attempting_to_close_browser_; | |
| 1165 | |
| 1166 // In-progress download termination handling ///////////////////////////////// | |
| 1167 | |
| 1168 enum CancelDownloadConfirmationState { | |
| 1169 NOT_PROMPTED, // We have not asked the user. | |
| 1170 WAITING_FOR_RESPONSE, // We have asked the user and have not received a | |
| 1171 // reponse yet. | |
| 1172 RESPONSE_RECEIVED // The user was prompted and made a decision already. | |
| 1173 }; | |
| 1174 | |
| 1175 // State used to figure-out whether we should prompt the user for confirmation | |
| 1176 // when the browser is closed with in-progress downloads. | |
| 1177 CancelDownloadConfirmationState cancel_download_confirmation_state_; | |
| 1178 | |
| 1179 ///////////////////////////////////////////////////////////////////////////// | |
| 1180 | |
| 1181 // Override values for the bounds of the window and its maximized or minimized | |
| 1182 // state. | |
| 1183 // These are supplied by callers that don't want to use the default values. | |
| 1184 // The default values are typically loaded from local state (last session), | |
| 1185 // obtained from the last window of the same type, or obtained from the | |
| 1186 // shell shortcut's startup info. | |
| 1187 gfx::Rect override_bounds_; | |
| 1188 ui::WindowShowState initial_show_state_; | |
| 1189 | |
| 1190 // Tracks when this browser is being created by session restore. | |
| 1191 bool is_session_restore_; | |
| 1192 | |
| 1193 // The following factory is used to close the frame at a later time. | |
| 1194 base::WeakPtrFactory<Browser> weak_factory_; | |
| 1195 | |
| 1196 // The Find Bar. This may be NULL if there is no Find Bar, and if it is | |
| 1197 // non-NULL, it may or may not be visible. | |
| 1198 scoped_ptr<FindBarController> find_bar_controller_; | |
| 1199 | |
| 1200 // Dialog box used for opening and saving files. | |
| 1201 scoped_refptr<SelectFileDialog> select_file_dialog_; | |
| 1202 | |
| 1203 // Keep track of the encoding auto detect pref. | |
| 1204 BooleanPrefMember encoding_auto_detect_; | |
| 1205 | |
| 1206 // Indicates if command execution is blocked. | 170 // Indicates if command execution is blocked. |
| 1207 bool block_command_execution_; | 171 bool block_command_execution_; |
| 1208 | 172 |
| 1209 // Stores the last blocked command id when |block_command_execution_| is true. | 173 // Stores the last blocked command id when |block_command_execution_| is true. |
| 1210 int last_blocked_command_id_; | 174 int last_blocked_command_id_; |
| 1211 | 175 |
| 1212 // Stores the disposition type of the last blocked command. | 176 // Stores the disposition type of the last blocked command. |
| 1213 WindowOpenDisposition last_blocked_command_disposition_; | 177 WindowOpenDisposition last_blocked_command_disposition_; |
| 1214 | 178 |
| 1215 // Which deferred action to perform when OnDidGetApplicationInfo is notified | 179 content::NotificationRegistrar registrar_; |
| 1216 // from a WebContents. Currently, only one pending action is allowed. | 180 PrefChangeRegistrar profile_pref_registrar_; |
| 1217 WebAppAction pending_web_app_action_; | 181 PrefChangeRegistrar local_pref_registrar_; |
| 1218 | 182 |
| 1219 // The profile's tab restore service. The service is owned by the profile, | 183 DISALLOW_COPY_AND_ASSIGN(BrowserCommandController); |
| 1220 // and we install ourselves as an observer. | |
| 1221 TabRestoreService* tab_restore_service_; | |
| 1222 | |
| 1223 // Helper which implements the ContentSettingBubbleModel interface. | |
| 1224 scoped_ptr<BrowserContentSettingBubbleModelDelegate> | |
| 1225 content_setting_bubble_model_delegate_; | |
| 1226 | |
| 1227 // Helper which implements the ToolbarModelDelegate interface. | |
| 1228 scoped_ptr<BrowserToolbarModelDelegate> toolbar_model_delegate_; | |
| 1229 | |
| 1230 // A delegate that handles the details of updating the "active" | |
| 1231 // |search_model_| state with the tab's state. | |
| 1232 scoped_ptr<chrome::search::SearchDelegate> search_delegate_; | |
| 1233 | |
| 1234 // Helper which implements the TabRestoreServiceDelegate interface. | |
| 1235 scoped_ptr<BrowserTabRestoreServiceDelegate> tab_restore_service_delegate_; | |
| 1236 | |
| 1237 // Helper which implements the SyncedWindowDelegate interface. | |
| 1238 scoped_ptr<BrowserSyncedWindowDelegate> synced_window_delegate_; | |
| 1239 | |
| 1240 scoped_ptr<InstantController> instant_; | |
| 1241 scoped_ptr<InstantUnloadHandler> instant_unload_handler_; | |
| 1242 | |
| 1243 BookmarkBar::State bookmark_bar_state_; | |
| 1244 | |
| 1245 scoped_refptr<FullscreenController> fullscreen_controller_; | |
| 1246 | |
| 1247 scoped_ptr<ExtensionWindowController> extension_window_controller_; | |
| 1248 | |
| 1249 // True if the browser window has been shown at least once. | |
| 1250 bool window_has_shown_; | |
| 1251 | |
| 1252 // Currently open color chooser. Non-NULL after OpenColorChooser is called and | |
| 1253 // before DidEndColorChooser is called. | |
| 1254 scoped_ptr<content::ColorChooser> color_chooser_; | |
| 1255 | |
| 1256 DISALLOW_COPY_AND_ASSIGN(Browser); | |
| 1257 }; | 184 }; |
| 1258 | 185 |
| 1259 #endif // CHROME_BROWSER_UI_BROWSER_H_ | 186 } // namespace chrome |
| 187 |
| 188 #endif // CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_ |
| OLD | NEW |