OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_BROWSER_H_ | 5 #ifndef CHROME_BROWSER_BROWSER_H_ |
6 #define CHROME_BROWSER_BROWSER_H_ | 6 #define CHROME_BROWSER_BROWSER_H_ |
7 | 7 |
8 #include "chrome/browser/controller.h" | 8 #include "chrome/browser/controller.h" |
9 #include "chrome/browser/shell_dialogs.h" | 9 #include "chrome/browser/shell_dialogs.h" |
10 #include "chrome/browser/browser_type.h" | 10 #include "chrome/browser/browser_type.h" |
| 11 #include "chrome/browser/browser_window.h" |
11 #include "chrome/browser/session_id.h" | 12 #include "chrome/browser/session_id.h" |
12 #include "chrome/browser/tab_contents_delegate.h" | 13 #include "chrome/browser/tab_contents_delegate.h" |
13 #include "chrome/browser/tabs/tab_strip_model.h" | 14 #include "chrome/browser/tabs/tab_strip_model.h" |
14 #include "chrome/browser/toolbar_model.h" | 15 #include "chrome/browser/toolbar_model.h" |
15 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
16 #include "chrome/common/pref_member.h" | 17 #include "chrome/common/pref_member.h" |
17 | 18 |
18 class BrowserIdleTimer; | 19 class BrowserIdleTimer; |
19 class BrowserWindow; | 20 class BrowserWindow; |
20 class DebuggerWindow; | 21 class DebuggerWindow; |
21 class GoButton; | 22 class GoButton; |
22 class LocationBarView; | 23 class LocationBarView; |
23 class PrefService; | 24 class PrefService; |
24 class Profile; | 25 class Profile; |
25 class StatusBubble; | 26 class StatusBubble; |
26 struct TabNavigation; | 27 struct TabNavigation; |
27 class WebContents; | |
28 class WebApp; | 28 class WebApp; |
29 | 29 |
30 class Browser : public TabStripModelDelegate, | 30 class Browser : public TabStripModelDelegate, |
31 public TabStripModelObserver, | 31 public TabStripModelObserver, |
32 public TabContentsDelegate, | 32 public TabContentsDelegate, |
33 public CommandHandler, | 33 public CommandHandler, |
34 public NotificationObserver, | 34 public NotificationObserver, |
35 public SelectFileDialog::Listener { | 35 public SelectFileDialog::Listener { |
36 public: | 36 public: |
37 // Constructors, Creation, Showing ////////////////////////////////////////// | 37 // Constructors, Creation, Showing ////////////////////////////////////////// |
38 | 38 |
39 // Creates a new browser with the given bounds. If the bounds are empty, the | 39 // Creates a new browser of the given |type| and for the given |profile|. The |
40 // system will try to find a saved size from a previous session, if none | 40 // Browser has a NULL window after its construction, CreateBrowserWindow must |
41 // exists, the operating system will be allowed to size the window. | 41 // be called after configuration for window() to be valid. |
42 // |type| defines the kind of browser to create. | 42 Browser(BrowserType::Type type, Profile* profile); |
43 // | |
44 // Creating a browser does NOT show the window. You must manually call Show() | |
45 // to display the window. | |
46 Browser(const gfx::Rect& initial_bounds, | |
47 int show_command, | |
48 Profile* profile, | |
49 BrowserType::Type browser_type, | |
50 const std::wstring& app_name); | |
51 ~Browser(); | 43 ~Browser(); |
52 | 44 |
53 // Shows the browser window. It is initially created hidden. It will be shown | 45 // Creates a normal tabbed browser with the specified profile. The Browser's |
54 // with the show command passed to the constructor, or possibly another state | 46 // window is created by this function call. |
55 // if it was overridden in the preferences. | 47 static Browser* Create(Profile* profile); |
56 // | 48 |
57 // Ideally, this function is called after everything in the window is | 49 // Like Create, but creates a tabstrip-less popup window. |
58 // initialized so that we do not have to repaint again. | 50 static Browser* CreateForPopup(Profile* profile); |
59 void Show(); | 51 |
| 52 // Like Create, but creates a tabstrip-less and toolbar-less "app" window for |
| 53 // the specified app. |
| 54 static Browser* CreateForApp(const std::wstring& app_name, Profile* profile); |
| 55 |
| 56 // Set overrides for the initial window bounds and maximized state. |
| 57 void set_override_bounds(const gfx::Rect& bounds) { |
| 58 override_bounds_ = bounds; |
| 59 } |
| 60 void set_override_maximized(bool maximized) { |
| 61 override_maximized_ = maximized; |
| 62 } |
| 63 |
| 64 // Creates the Browser Window. Prefer to use the static helpers above where |
| 65 // possible. This does not show the window. You need to call window()->Show() |
| 66 // to show it. |
| 67 void CreateBrowserWindow(); |
60 | 68 |
61 // Accessors //////////////////////////////////////////////////////////////// | 69 // Accessors //////////////////////////////////////////////////////////////// |
62 | 70 |
63 BrowserType::Type type() const { return type_; } | 71 BrowserType::Type type() const { return type_; } |
64 Profile* profile() const { return profile_; } | 72 Profile* profile() const { return profile_; } |
65 BrowserWindow* window() const { return window_; } | 73 BrowserWindow* window() const { return window_; } |
66 ToolbarModel* toolbar_model() { return &toolbar_model_; } | 74 ToolbarModel* toolbar_model() { return &toolbar_model_; } |
67 const SessionID& session_id() const { return session_id_; } | 75 const SessionID& session_id() const { return session_id_; } |
68 CommandController* controller() { return &controller_; } | 76 CommandController* controller() { return &controller_; } |
69 | 77 |
70 // Browser Creation Helpers ///////////////////////////////////////////////// | 78 // Browser Creation Helpers ///////////////////////////////////////////////// |
71 | 79 |
72 // Opens a new browser window for the specified |profile|, shown according to | 80 // Opens a new window with the default blank tab. |
73 // |show_command| | 81 static void OpenEmptyWindow(Profile* profile); |
74 static void OpenNewBrowserWindow(Profile* profile, int show_command); | |
75 | 82 |
76 // Opens the specified URL in a new browser window in an incognito session. | 83 // Opens the specified URL in a new browser window in an incognito session. |
77 // If there is already an existing active incognito session for the specified | 84 // If there is already an existing active incognito session for the specified |
78 // |profile|, that session is re-used. | 85 // |profile|, that session is re-used. |
79 static void OpenURLOffTheRecord(Profile* profile, const GURL& url); | 86 static void OpenURLOffTheRecord(Profile* profile, const GURL& url); |
80 | 87 |
81 // Opens the a new application window for the specified WebApp. | 88 // Opens the a new application window for the specified WebApp. |
82 static void OpenWebApplication(Profile* profile, | 89 static void OpenWebApplication(Profile* profile, WebApp* app); |
83 WebApp* app, | |
84 int show_command); | |
85 | 90 |
86 // Command API ////////////////////////////////////////////////////////////// | 91 // Command API ////////////////////////////////////////////////////////////// |
87 | 92 |
88 // Please fix the incestuous nest that is */controller.h and eliminate the | 93 // Please fix the incestuous nest that is */controller.h and eliminate the |
89 // need for this retarded hack. | 94 // need for this retarded hack. |
90 bool SupportsCommand(int id) const; | 95 bool SupportsCommand(int id) const; |
91 bool IsCommandEnabled(int id) const; | 96 bool IsCommandEnabled(int id) const; |
92 | 97 |
93 // DEPRECATED DEPRECATED DEPRECATED ///////////////////////////////////////// | 98 // DEPRECATED DEPRECATED DEPRECATED ///////////////////////////////////////// |
94 | 99 |
95 // Returns the HWND of the top-level system window for this Browser. | 100 // Returns the HWND of the top-level system window for this Browser. |
96 HWND GetTopLevelHWND() const; | 101 HWND GetTopLevelHWND() const; |
97 | 102 |
98 // State Storage and Retrieval for UI /////////////////////////////////////// | 103 // State Storage and Retrieval for UI /////////////////////////////////////// |
99 | 104 |
100 // Save and restore the window position. | 105 // Save and restore the window position. |
101 void SaveWindowPosition(const gfx::Rect& bounds, bool maximized); | 106 void SaveWindowPlacement(const gfx::Rect& bounds, bool maximized); |
102 void RestoreWindowPosition(gfx::Rect* bounds, bool* maximized); | 107 gfx::Rect GetSavedWindowBounds() const; |
| 108 bool GetSavedMaximizedState() const; |
103 | 109 |
104 // Gets the FavIcon of the page in the selected tab. | 110 // Gets the FavIcon of the page in the selected tab. |
105 SkBitmap GetCurrentPageIcon() const; | 111 SkBitmap GetCurrentPageIcon() const; |
106 | 112 |
107 // Gets the title of the page in the selected tab. | 113 // Gets the title of the page in the selected tab. |
108 std::wstring GetCurrentPageTitle() const; | 114 std::wstring GetCurrentPageTitle() const; |
109 | 115 |
110 // Prepares a title string for display (removes embedded newlines, etc). | 116 // Prepares a title string for display (removes embedded newlines, etc). |
111 static void FormatTitleForDisplay(std::wstring* title); | 117 static void FormatTitleForDisplay(std::wstring* title); |
112 | 118 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 287 |
282 // Interface implementations //////////////////////////////////////////////// | 288 // Interface implementations //////////////////////////////////////////////// |
283 | 289 |
284 // Overridden from CommandHandler: | 290 // Overridden from CommandHandler: |
285 virtual bool GetContextualLabel(int id, std::wstring* out) const { | 291 virtual bool GetContextualLabel(int id, std::wstring* out) const { |
286 return false; | 292 return false; |
287 } | 293 } |
288 virtual void ExecuteCommand(int id); | 294 virtual void ExecuteCommand(int id); |
289 | 295 |
290 // Overridden from TabStripModelDelegate: | 296 // Overridden from TabStripModelDelegate: |
| 297 virtual GURL GetBlankTabURL() const; |
291 virtual void CreateNewStripWithContents(TabContents* detached_contents, | 298 virtual void CreateNewStripWithContents(TabContents* detached_contents, |
292 const gfx::Point& drop_point); | 299 const gfx::Point& drop_point); |
293 virtual int GetDragActions() const; | 300 virtual int GetDragActions() const; |
294 // Construct a TabContents for a given URL, profile and transition type. | 301 // Construct a TabContents for a given URL, profile and transition type. |
295 // If instance is not null, its process will be used to render the tab. | 302 // If instance is not null, its process will be used to render the tab. |
296 // TODO(beng): remove this from TabStripDelegate, it's only used by | |
297 // TabStripModel::AddBlankTab*, which should really live here | |
298 // on Browser. | |
299 virtual TabContents* CreateTabContentsForURL( | 303 virtual TabContents* CreateTabContentsForURL( |
300 const GURL& url, | 304 const GURL& url, |
301 const GURL& referrer, | 305 const GURL& referrer, |
302 Profile* profile, | 306 Profile* profile, |
303 PageTransition::Type transition, | 307 PageTransition::Type transition, |
304 bool defer_load, | 308 bool defer_load, |
305 SiteInstance* instance) const; | 309 SiteInstance* instance) const; |
306 virtual bool CanDuplicateContentsAt(int index); | 310 virtual bool CanDuplicateContentsAt(int index); |
307 virtual void DuplicateContentsAt(int index); | 311 virtual void DuplicateContentsAt(int index); |
308 virtual void ValidateLoadingAnimations(); | 312 virtual void ValidateLoadingAnimations(); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 496 |
493 // This Browser's type. | 497 // This Browser's type. |
494 BrowserType::Type type_; | 498 BrowserType::Type type_; |
495 | 499 |
496 // This Browser's profile. | 500 // This Browser's profile. |
497 Profile* profile_; | 501 Profile* profile_; |
498 | 502 |
499 // This Browser's window. | 503 // This Browser's window. |
500 BrowserWindow* window_; | 504 BrowserWindow* window_; |
501 | 505 |
502 // Controls how the window will appear when Show() is called. This is one | |
503 // of the SW_* constants passed to ShowWindow, and will be initialized in the | |
504 // constructor. | |
505 // | |
506 // After the first call to Show() succeeds, this is set to -1, indicating that | |
507 // subsequent calls to Show() should be ignored. | |
508 // TODO(beng): This should be removed (http://crbug.com/3557) and put into | |
509 // BrowserView, or some more likely place. | |
510 int initial_show_command_; | |
511 | |
512 // This Browser's TabStripModel. | 506 // This Browser's TabStripModel. |
513 TabStripModel tabstrip_model_; | 507 TabStripModel tabstrip_model_; |
514 | 508 |
515 // The Controller that updates all browser commands. | 509 // The Controller that updates all browser commands. |
516 CommandController controller_; | 510 CommandController controller_; |
517 | 511 |
518 // An optional application name which is used to retrieve and save window | 512 // An optional application name which is used to retrieve and save window |
519 // positions. | 513 // positions. |
520 std::wstring app_name_; | 514 std::wstring app_name_; |
521 | 515 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 // Tracks tabs that need there unload event fired before we can | 562 // Tracks tabs that need there unload event fired before we can |
569 // close the browser. Only gets populated when we try to close the browser. | 563 // close the browser. Only gets populated when we try to close the browser. |
570 UnloadListenerVector tabs_needing_unload_fired_; | 564 UnloadListenerVector tabs_needing_unload_fired_; |
571 | 565 |
572 // Whether we are processing the beforeunload and unload events of each tab | 566 // Whether we are processing the beforeunload and unload events of each tab |
573 // in preparation for closing the browser. | 567 // in preparation for closing the browser. |
574 bool is_attempting_to_close_browser_; | 568 bool is_attempting_to_close_browser_; |
575 | 569 |
576 ///////////////////////////////////////////////////////////////////////////// | 570 ///////////////////////////////////////////////////////////////////////////// |
577 | 571 |
| 572 // Override values for the bounds of the window and its maximized state. |
| 573 // These are supplied by callers that don't want to use the default values. |
| 574 // The default values are typically loaded from local state (last session), |
| 575 // obtained from the last window of the same type, or obtained from the |
| 576 // shell shortcut's startup info. |
| 577 gfx::Rect override_bounds_; |
| 578 bool override_maximized_; |
| 579 |
578 // The following factory is used to close the frame at a later time. | 580 // The following factory is used to close the frame at a later time. |
579 ScopedRunnableMethodFactory<Browser> method_factory_; | 581 ScopedRunnableMethodFactory<Browser> method_factory_; |
580 | 582 |
581 // Debugger Window, created lazily | 583 // Debugger Window, created lazily |
582 scoped_refptr<DebuggerWindow> debugger_window_; | 584 scoped_refptr<DebuggerWindow> debugger_window_; |
583 | 585 |
584 // Dialog box used for opening and saving files. | 586 // Dialog box used for opening and saving files. |
585 scoped_refptr<SelectFileDialog> select_file_dialog_; | 587 scoped_refptr<SelectFileDialog> select_file_dialog_; |
586 | 588 |
587 // The browser idle task helps cleanup unused memory resources when idle. | 589 // The browser idle task helps cleanup unused memory resources when idle. |
588 scoped_ptr<BrowserIdleTimer> idle_task_; | 590 scoped_ptr<BrowserIdleTimer> idle_task_; |
589 | 591 |
590 // Keep track of the encoding auto detect pref. | 592 // Keep track of the encoding auto detect pref. |
591 BooleanPrefMember encoding_auto_detect_; | 593 BooleanPrefMember encoding_auto_detect_; |
592 | 594 |
593 DISALLOW_COPY_AND_ASSIGN(Browser); | 595 DISALLOW_COPY_AND_ASSIGN(Browser); |
594 }; | 596 }; |
595 | 597 |
596 #endif // CHROME_BROWSER_BROWSER_H_ | 598 #endif // CHROME_BROWSER_BROWSER_H_ |
OLD | NEW |