OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ |
6 #define CHROME_BROWSER_UI_BROWSER_H_ | 6 #define CHROME_BROWSER_UI_BROWSER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
17 #include "base/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
18 #include "base/string16.h" | 18 #include "base/string16.h" |
19 #include "base/task.h" | 19 #include "base/task.h" |
20 #include "chrome/browser/command_updater.h" | 20 #include "chrome/browser/command_updater.h" |
21 #include "chrome/browser/debugger/devtools_toggle_action.h" | 21 #include "chrome/browser/debugger/devtools_toggle_action.h" |
22 #include "chrome/browser/instant/instant_delegate.h" | 22 #include "chrome/browser/instant/instant_delegate.h" |
23 #include "chrome/browser/prefs/pref_member.h" | 23 #include "chrome/browser/prefs/pref_member.h" |
24 #include "chrome/browser/sessions/session_id.h" | 24 #include "chrome/browser/sessions/session_id.h" |
25 #include "chrome/browser/sessions/tab_restore_service_delegate.h" | |
25 #include "chrome/browser/sessions/tab_restore_service_observer.h" | 26 #include "chrome/browser/sessions/tab_restore_service_observer.h" |
26 #include "chrome/browser/sync/profile_sync_service_observer.h" | 27 #include "chrome/browser/sync/profile_sync_service_observer.h" |
27 #include "chrome/browser/tabs/tab_handler.h" | 28 #include "chrome/browser/tabs/tab_handler.h" |
28 #include "chrome/browser/tabs/tab_strip_model_delegate.h" // TODO(beng): remove | 29 #include "chrome/browser/tabs/tab_strip_model_delegate.h" // TODO(beng): remove |
29 #include "chrome/browser/tabs/tab_strip_model_observer.h" // TODO(beng): remove | 30 #include "chrome/browser/tabs/tab_strip_model_observer.h" // TODO(beng): remove |
30 #include "chrome/browser/ui/browser_navigator.h" | 31 #include "chrome/browser/ui/browser_navigator.h" |
31 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h" | 32 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h" |
32 #include "chrome/browser/ui/shell_dialogs.h" | 33 #include "chrome/browser/ui/shell_dialogs.h" |
33 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" | 34 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" |
34 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 35 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
58 } | 59 } |
59 | 60 |
60 class Browser : public TabHandlerDelegate, | 61 class Browser : public TabHandlerDelegate, |
61 public TabContentsDelegate, | 62 public TabContentsDelegate, |
62 public TabContentsWrapperDelegate, | 63 public TabContentsWrapperDelegate, |
63 public SearchEngineTabHelperDelegate, | 64 public SearchEngineTabHelperDelegate, |
64 public PageNavigator, | 65 public PageNavigator, |
65 public CommandUpdater::CommandUpdaterDelegate, | 66 public CommandUpdater::CommandUpdaterDelegate, |
66 public NotificationObserver, | 67 public NotificationObserver, |
67 public SelectFileDialog::Listener, | 68 public SelectFileDialog::Listener, |
69 public TabRestoreServiceDelegate, | |
68 public TabRestoreServiceObserver, | 70 public TabRestoreServiceObserver, |
69 public ProfileSyncServiceObserver, | 71 public ProfileSyncServiceObserver, |
70 public InstantDelegate { | 72 public InstantDelegate { |
71 public: | 73 public: |
72 // SessionService::WindowType mirrors these values. If you add to this | 74 // SessionService::WindowType mirrors these values. If you add to this |
73 // enum, look at SessionService::WindowType to see if it needs to be | 75 // enum, look at SessionService::WindowType to see if it needs to be |
74 // updated. | 76 // updated. |
75 enum Type { | 77 enum Type { |
76 TYPE_NORMAL = 1, | 78 TYPE_NORMAL = 1, |
77 TYPE_POPUP = 2, | 79 TYPE_POPUP = 2, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 } | 171 } |
170 | 172 |
171 // Creates the Browser Window. Prefer to use the static helpers above where | 173 // Creates the Browser Window. Prefer to use the static helpers above where |
172 // possible. This does not show the window. You need to call window()->Show() | 174 // possible. This does not show the window. You need to call window()->Show() |
173 // to show it. | 175 // to show it. |
174 void CreateBrowserWindow(); | 176 void CreateBrowserWindow(); |
175 | 177 |
176 // Accessors //////////////////////////////////////////////////////////////// | 178 // Accessors //////////////////////////////////////////////////////////////// |
177 | 179 |
178 Type type() const { return type_; } | 180 Type type() const { return type_; } |
181 virtual bool IsNormalBrowser() const { return type_ == TYPE_NORMAL; } | |
179 const std::string& app_name() const { return app_name_; } | 182 const std::string& app_name() const { return app_name_; } |
180 Profile* profile() const { return profile_; } | 183 virtual Profile* profile() const { return profile_; } |
181 const std::vector<std::wstring>& user_data_dir_profiles() const; | 184 const std::vector<std::wstring>& user_data_dir_profiles() const; |
182 | 185 |
183 // Returns the InstantController or NULL if there is no InstantController for | 186 // Returns the InstantController or NULL if there is no InstantController for |
184 // this Browser. | 187 // this Browser. |
185 InstantController* instant() const { return instant_.get(); } | 188 InstantController* instant() const { return instant_.get(); } |
186 | 189 |
187 #if defined(UNIT_TEST) | 190 #if defined(UNIT_TEST) |
188 // Sets the BrowserWindow. This is intended for testing and generally not | 191 // Sets the BrowserWindow. This is intended for testing and generally not |
189 // useful outside of testing. Use CreateBrowserWindow outside of testing, or | 192 // useful outside of testing. Use CreateBrowserWindow outside of testing, or |
190 // the static convenience methods that create a BrowserWindow for you. | 193 // the static convenience methods that create a BrowserWindow for you. |
191 void set_window(BrowserWindow* window) { | 194 void set_window(BrowserWindow* window) { |
192 DCHECK(!window_); | 195 DCHECK(!window_); |
193 window_ = window; | 196 window_ = window; |
194 } | 197 } |
195 #endif | 198 #endif |
196 | 199 |
197 // |window()| will return NULL if called before |CreateBrowserWindow()| | 200 // |window()| will return NULL if called before |CreateBrowserWindow()| |
198 // is done. | 201 // is done. |
199 BrowserWindow* window() const { return window_; } | 202 virtual BrowserWindow* window() const { return window_; } |
200 ToolbarModel* toolbar_model() { return &toolbar_model_; } | 203 ToolbarModel* toolbar_model() { return &toolbar_model_; } |
201 const SessionID& session_id() const { return session_id_; } | 204 virtual const SessionID& session_id() const { return session_id_; } |
202 CommandUpdater* command_updater() { return &command_updater_; } | 205 CommandUpdater* command_updater() { return &command_updater_; } |
203 bool block_command_execution() const { return block_command_execution_; } | 206 bool block_command_execution() const { return block_command_execution_; } |
204 | 207 |
205 // Get the FindBarController for this browser, creating it if it does not | 208 // Get the FindBarController for this browser, creating it if it does not |
206 // yet exist. | 209 // yet exist. |
207 FindBarController* GetFindBarController(); | 210 FindBarController* GetFindBarController(); |
208 | 211 |
209 // Returns true if a FindBarController exists for this browser. | 212 // Returns true if a FindBarController exists for this browser. |
210 bool HasFindBarController() const; | 213 bool HasFindBarController() const; |
211 | 214 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 // downloads running. | 330 // downloads running. |
328 void InProgressDownloadResponse(bool cancel_downloads); | 331 void InProgressDownloadResponse(bool cancel_downloads); |
329 | 332 |
330 // TabStripModel pass-thrus ///////////////////////////////////////////////// | 333 // TabStripModel pass-thrus ///////////////////////////////////////////////// |
331 | 334 |
332 TabStripModel* tabstrip_model() const { | 335 TabStripModel* tabstrip_model() const { |
333 // TODO(beng): remove this accessor. It violates google style. | 336 // TODO(beng): remove this accessor. It violates google style. |
334 return tab_handler_->GetTabStripModel(); | 337 return tab_handler_->GetTabStripModel(); |
335 } | 338 } |
336 | 339 |
337 int tab_count() const; | 340 virtual int tab_count() const; |
338 int selected_index() const; | 341 virtual int selected_index() const; |
339 int GetIndexOfController(const NavigationController* controller) const; | 342 virtual int GetIndexOfController( |
343 const NavigationController* controller) const; | |
340 TabContentsWrapper* GetSelectedTabContentsWrapper() const; | 344 TabContentsWrapper* GetSelectedTabContentsWrapper() const; |
341 TabContentsWrapper* GetTabContentsWrapperAt(int index) const; | 345 TabContentsWrapper* GetTabContentsWrapperAt(int index) const; |
342 // Same as above but correctly handles if GetSelectedTabContents() is NULL | 346 // Same as above but correctly handles if GetSelectedTabContents() is NULL |
343 // in the model before dereferencing to get the raw TabContents. | 347 // in the model before dereferencing to get the raw TabContents. |
344 // TODO(pinkerton): These should really be returning TabContentsWrapper | 348 // TODO(pinkerton): These should really be returning TabContentsWrapper |
345 // objects, but that would require changing about 50+ other files. In order | 349 // objects, but that would require changing about 50+ other files. In order |
346 // to keep changes localized, the default is to return a TabContents. Note | 350 // to keep changes localized, the default is to return a TabContents. Note |
347 // this differs from the TabStripModel because it has far fewer clients. | 351 // this differs from the TabStripModel because it has far fewer clients. |
348 TabContents* GetSelectedTabContents() const; | 352 virtual TabContents* GetSelectedTabContents() const; |
349 TabContents* GetTabContentsAt(int index) const; | 353 virtual TabContents* GetTabContentsAt(int index) const; |
350 void SelectTabContentsAt(int index, bool user_gesture); | 354 void SelectTabContentsAt(int index, bool user_gesture); |
355 virtual bool IsTabPinned(int index) const; | |
351 void CloseAllTabs(); | 356 void CloseAllTabs(); |
352 | 357 |
353 // Tab adding/showing functions ///////////////////////////////////////////// | 358 // Tab adding/showing functions ///////////////////////////////////////////// |
354 | 359 |
355 // Returns true if the tab strip is editable (for extensions). | 360 // Returns true if the tab strip is editable (for extensions). |
356 bool IsTabStripEditable() const; | 361 bool IsTabStripEditable() const; |
357 | 362 |
358 // Returns the index to insert a tab at during session restore and startup. | 363 // Returns the index to insert a tab at during session restore and startup. |
359 // |relative_index| gives the index of the url into the number of tabs that | 364 // |relative_index| gives the index of the url into the number of tabs that |
360 // are going to be opened. For example, if three urls are passed in on the | 365 // are going to be opened. For example, if three urls are passed in on the |
(...skipping 12 matching lines...) Expand all Loading... | |
373 PageTransition::Type type); | 378 PageTransition::Type type); |
374 | 379 |
375 // Add a tab with its session history restored from the SessionRestore | 380 // Add a tab with its session history restored from the SessionRestore |
376 // system. If select is true, the tab is selected. |tab_index| gives the index | 381 // system. If select is true, the tab is selected. |tab_index| gives the index |
377 // to insert the tab at. |selected_navigation| is the index of the | 382 // to insert the tab at. |selected_navigation| is the index of the |
378 // TabNavigation in |navigations| to select. If |extension_app_id| is | 383 // TabNavigation in |navigations| to select. If |extension_app_id| is |
379 // non-empty the tab is an app tab and |extension_app_id| is the id of the | 384 // non-empty the tab is an app tab and |extension_app_id| is the id of the |
380 // extension. If |pin| is true and |tab_index|/ is the last pinned tab, then | 385 // extension. If |pin| is true and |tab_index|/ is the last pinned tab, then |
381 // the newly created tab is pinned. If |from_last_session| is true, | 386 // the newly created tab is pinned. If |from_last_session| is true, |
382 // |navigations| are from the previous session. | 387 // |navigations| are from the previous session. |
383 TabContents* AddRestoredTab(const std::vector<TabNavigation>& navigations, | 388 virtual TabContents* AddRestoredTab( |
Ben Goodger (Google)
2011/03/10 18:28:35
In Chrome code we tend to put all the overrides fr
| |
384 int tab_index, | 389 const std::vector<TabNavigation>& navigations, |
385 int selected_navigation, | 390 int tab_index, |
386 const std::string& extension_app_id, | 391 int selected_navigation, |
387 bool select, | 392 const std::string& extension_app_id, |
388 bool pin, | 393 bool select, |
389 bool from_last_session, | 394 bool pin, |
390 SessionStorageNamespace* storage_namespace); | 395 bool from_last_session, |
396 SessionStorageNamespace* storage_namespace); | |
391 // Creates a new tab with the already-created TabContents 'new_contents'. | 397 // Creates a new tab with the already-created TabContents 'new_contents'. |
392 // The window for the added contents will be reparented correctly when this | 398 // The window for the added contents will be reparented correctly when this |
393 // method returns. If |disposition| is NEW_POPUP, |pos| should hold the | 399 // method returns. If |disposition| is NEW_POPUP, |pos| should hold the |
394 // initial position. | 400 // initial position. |
395 void AddTabContents(TabContents* new_contents, | 401 void AddTabContents(TabContents* new_contents, |
396 WindowOpenDisposition disposition, | 402 WindowOpenDisposition disposition, |
397 const gfx::Rect& initial_pos, | 403 const gfx::Rect& initial_pos, |
398 bool user_gesture); | 404 bool user_gesture); |
399 void CloseTabContents(TabContents* contents); | 405 void CloseTabContents(TabContents* contents); |
400 | 406 |
401 // Show a dialog with HTML content. |delegate| contains a pointer to the | 407 // Show a dialog with HTML content. |delegate| contains a pointer to the |
402 // delegate who knows how to display the dialog (which file URL and JSON | 408 // delegate who knows how to display the dialog (which file URL and JSON |
403 // string input to use during initialization). |parent_window| is the window | 409 // string input to use during initialization). |parent_window| is the window |
404 // that should be parent of the dialog, or NULL for the default. | 410 // that should be parent of the dialog, or NULL for the default. |
405 void BrowserShowHtmlDialog(HtmlDialogUIDelegate* delegate, | 411 void BrowserShowHtmlDialog(HtmlDialogUIDelegate* delegate, |
406 gfx::NativeWindow parent_window); | 412 gfx::NativeWindow parent_window); |
407 | 413 |
408 // Called when a popup select is about to be displayed. | 414 // Called when a popup select is about to be displayed. |
409 void BrowserRenderWidgetShowing(); | 415 void BrowserRenderWidgetShowing(); |
410 | 416 |
411 // Notification that some of our content has changed size as | 417 // Notification that some of our content has changed size as |
412 // part of an animation. | 418 // part of an animation. |
413 void ToolbarSizeChanged(bool is_animating); | 419 void ToolbarSizeChanged(bool is_animating); |
414 | 420 |
415 // Replaces the state of the currently selected tab with the session | 421 // Replaces the state of the currently selected tab with the session |
416 // history restored from the SessionRestore system. | 422 // history restored from the SessionRestore system. |
417 void ReplaceRestoredTab( | 423 virtual void ReplaceRestoredTab( |
418 const std::vector<TabNavigation>& navigations, | 424 const std::vector<TabNavigation>& navigations, |
419 int selected_navigation, | 425 int selected_navigation, |
420 bool from_last_session, | 426 bool from_last_session, |
421 const std::string& extension_app_id, | 427 const std::string& extension_app_id, |
422 SessionStorageNamespace* session_storage_namespace); | 428 SessionStorageNamespace* session_storage_namespace); |
423 | 429 |
424 // Navigate to an index in the tab history, opening a new tab depending on the | 430 // Navigate to an index in the tab history, opening a new tab depending on the |
425 // disposition. | 431 // disposition. |
426 bool NavigateToIndexWithDisposition(int index, WindowOpenDisposition disp); | 432 bool NavigateToIndexWithDisposition(int index, WindowOpenDisposition disp); |
427 | 433 |
(...skipping 19 matching lines...) Expand all Loading... | |
447 void Reload(WindowOpenDisposition disposition); | 453 void Reload(WindowOpenDisposition disposition); |
448 void ReloadIgnoringCache(WindowOpenDisposition disposition); // Shift-reload. | 454 void ReloadIgnoringCache(WindowOpenDisposition disposition); // Shift-reload. |
449 void Home(WindowOpenDisposition disposition); | 455 void Home(WindowOpenDisposition disposition); |
450 void OpenCurrentURL(); | 456 void OpenCurrentURL(); |
451 void Stop(); | 457 void Stop(); |
452 // Window management commands | 458 // Window management commands |
453 void NewWindow(); | 459 void NewWindow(); |
454 void NewIncognitoWindow(); | 460 void NewIncognitoWindow(); |
455 void CloseWindow(); | 461 void CloseWindow(); |
456 void NewTab(); | 462 void NewTab(); |
457 void CloseTab(); | 463 virtual void CloseTab(); |
458 void SelectNextTab(); | 464 void SelectNextTab(); |
459 void SelectPreviousTab(); | 465 void SelectPreviousTab(); |
460 void OpenTabpose(); | 466 void OpenTabpose(); |
461 void MoveTabNext(); | 467 void MoveTabNext(); |
462 void MoveTabPrevious(); | 468 void MoveTabPrevious(); |
463 void SelectNumberedTab(int index); | 469 void SelectNumberedTab(int index); |
464 void SelectLastTab(); | 470 void SelectLastTab(); |
465 void DuplicateTab(); | 471 void DuplicateTab(); |
466 void WriteCurrentURLToClipboard(); | 472 void WriteCurrentURLToClipboard(); |
467 void ConvertPopupToTabbedBrowser(); | 473 void ConvertPopupToTabbedBrowser(); |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1151 // and we install ourselves as an observer. | 1157 // and we install ourselves as an observer. |
1152 TabRestoreService* tab_restore_service_; | 1158 TabRestoreService* tab_restore_service_; |
1153 | 1159 |
1154 scoped_ptr<InstantController> instant_; | 1160 scoped_ptr<InstantController> instant_; |
1155 scoped_ptr<InstantUnloadHandler> instant_unload_handler_; | 1161 scoped_ptr<InstantUnloadHandler> instant_unload_handler_; |
1156 | 1162 |
1157 DISALLOW_COPY_AND_ASSIGN(Browser); | 1163 DISALLOW_COPY_AND_ASSIGN(Browser); |
1158 }; | 1164 }; |
1159 | 1165 |
1160 #endif // CHROME_BROWSER_UI_BROWSER_H_ | 1166 #endif // CHROME_BROWSER_UI_BROWSER_H_ |
OLD | NEW |