| 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_INIT_H_ | 5 #ifndef CHROME_BROWSER_BROWSER_INIT_H_ |
| 6 #define CHROME_BROWSER_BROWSER_INIT_H_ | 6 #define CHROME_BROWSER_BROWSER_INIT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 | 12 |
| 13 class Browser; | 13 class Browser; |
| 14 class CommandLine; |
| 14 class GURL; | 15 class GURL; |
| 15 class PrefService; | 16 class PrefService; |
| 16 class Profile; | 17 class Profile; |
| 17 class TabContents; | 18 class TabContents; |
| 18 | 19 |
| 19 // Scoper class containing helpers for BrowserMain to spin up a new instance | 20 // Scoper class containing helpers for BrowserMain to spin up a new instance |
| 20 // and initialize the profile. | 21 // and initialize the profile. |
| 21 class BrowserInit { | 22 class BrowserInit { |
| 22 public: | 23 public: |
| 23 // Returns true if the browser is coming up. | 24 // Returns true if the browser is coming up. |
| 24 static bool InProcessStartup(); | 25 static bool InProcessStartup(); |
| 25 | 26 |
| 26 // LaunchWithProfile --------------------------------------------------------- | 27 // LaunchWithProfile --------------------------------------------------------- |
| 27 // | 28 // |
| 28 // Assists launching the application and appending the initial tabs for a | 29 // Assists launching the application and appending the initial tabs for a |
| 29 // browser window. | 30 // browser window. |
| 30 | 31 |
| 31 class LaunchWithProfile { | 32 class LaunchWithProfile { |
| 32 public: | 33 public: |
| 33 explicit LaunchWithProfile(const std::wstring& cur_dir); | 34 LaunchWithProfile(const std::wstring& cur_dir, |
| 35 const CommandLine& command_line); |
| 34 ~LaunchWithProfile() { } | 36 ~LaunchWithProfile() { } |
| 35 | 37 |
| 36 // Creates the necessary windows for startup. Returns true on success, | 38 // Creates the necessary windows for startup. Returns true on success, |
| 37 // false on failure. process_startup is true if Chrome is just | 39 // false on failure. process_startup is true if Chrome is just |
| 38 // starting up. If process_startup is false, it indicates Chrome was | 40 // starting up. If process_startup is false, it indicates Chrome was |
| 39 // already running and the user wants to launch another instance. | 41 // already running and the user wants to launch another instance. |
| 40 bool Launch(Profile* profile, bool process_startup); | 42 bool Launch(Profile* profile, bool process_startup); |
| 41 | 43 |
| 42 private: | 44 private: |
| 45 // If the process was launched with the web application command line flag, |
| 46 // e.g. --app=http://www.google.com/, opens a web application browser and |
| 47 // returns true. If there is no web application command line flag speciifed, |
| 48 // returns false to specify default processing. |
| 49 bool OpenApplicationURL(Profile* profile); |
| 50 |
| 43 // Does the following: | 51 // Does the following: |
| 44 // . If the user's startup pref is to restore the last session (or the | 52 // . If the user's startup pref is to restore the last session (or the |
| 45 // command line flag is present to force using last session), it is | 53 // command line flag is present to force using last session), it is |
| 46 // restored, and true is returned. | 54 // restored, and true is returned. |
| 47 // . If the user's startup pref is to launch a specific set of URLs, and | 55 // . If the user's startup pref is to launch a specific set of URLs, and |
| 48 // urls_to_open is empty, the user specified set of URLs is openned. | 56 // urls_to_open is empty, the user specified set of URLs is openned. |
| 49 // | 57 // |
| 50 // Otherwise false is returned. | 58 // Otherwise false is returned. |
| 51 bool OpenStartupURLs(bool is_process_startup, | 59 bool OpenStartupURLs(bool is_process_startup, |
| 52 const std::vector<GURL>& urls_to_open); | 60 const std::vector<GURL>& urls_to_open); |
| 53 | 61 |
| 54 // Opens the list of urls. If browser is non-null and a tabbed browser, the | 62 // Opens the list of urls. If browser is non-null and a tabbed browser, the |
| 55 // URLs are opened in it. Otherwise a new tabbed browser is created and the | 63 // URLs are opened in it. Otherwise a new tabbed browser is created and the |
| 56 // URLs are added to it. The browser the tabs are added to is returned, | 64 // URLs are added to it. The browser the tabs are added to is returned, |
| 57 // which is either |browser| or the newly created browser. | 65 // which is either |browser| or the newly created browser. |
| 58 Browser* OpenURLsInBrowser(Browser* browser, | 66 Browser* OpenURLsInBrowser(Browser* browser, |
| 59 bool process_startup, | 67 bool process_startup, |
| 60 const std::vector<GURL>& urls); | 68 const std::vector<GURL>& urls); |
| 61 | 69 |
| 62 // If the last session didn't exit cleanly and tab is a web contents tab, | 70 // If the last session didn't exit cleanly and tab is a web contents tab, |
| 63 // an infobar is added allowing the user to restore the last session. | 71 // an infobar is added allowing the user to restore the last session. |
| 64 void AddCrashedInfoBarIfNecessary(TabContents* tab); | 72 void AddCrashedInfoBarIfNecessary(TabContents* tab); |
| 65 | 73 |
| 66 // Returns the list of URLs to open from the command line. The returned | 74 // Returns the list of URLs to open from the command line. The returned |
| 67 // vector is empty if the user didn't specify any URLs on the command line. | 75 // vector is empty if the user didn't specify any URLs on the command line. |
| 68 std::vector<GURL> GetURLsFromCommandLine(Profile* profile); | 76 std::vector<GURL> GetURLsFromCommandLine(Profile* profile); |
| 69 | 77 |
| 78 // Adds additional startup URLs to the specified vector. |
| 79 void AddStartupURLs(std::vector<GURL>* startup_urls) const; |
| 80 |
| 70 std::wstring cur_dir_; | 81 std::wstring cur_dir_; |
| 82 const CommandLine& command_line_; |
| 71 Profile* profile_; | 83 Profile* profile_; |
| 72 | 84 |
| 73 DISALLOW_COPY_AND_ASSIGN(LaunchWithProfile); | 85 DISALLOW_COPY_AND_ASSIGN(LaunchWithProfile); |
| 74 }; | 86 }; |
| 75 | 87 |
| 76 // This function performs command-line handling and is invoked when | 88 // This function performs command-line handling and is invoked when |
| 77 // process starts as well as when we get a start request from another | 89 // process starts as well as when we get a start request from another |
| 78 // process (via the WM_COPYDATA message). The process_startup flag | 90 // process (via the WM_COPYDATA message). |command_line| holds the command |
| 79 // indicates if this is being called from the process startup code or | 91 // line we need to process - either from this process or from some other one |
| 80 // the WM_COPYDATA handler. | 92 // (if |process_startup| is true and we are being called from |
| 81 static bool ProcessCommandLine(const std::wstring& cur_dir, | 93 // MessageWindow::OnCopyData). |
| 94 static bool ProcessCommandLine(const CommandLine& command_line, |
| 95 const std::wstring& cur_dir, |
| 82 PrefService* prefs, bool process_startup, | 96 PrefService* prefs, bool process_startup, |
| 83 Profile* profile, int* return_code); | 97 Profile* profile, int* return_code); |
| 84 | 98 |
| 85 // Helper function to launch a new browser based on command-line arguments | 99 // Helper function to launch a new browser based on command-line arguments |
| 86 // This function takes in a specific profile to use. | 100 // This function takes in a specific profile to use. |
| 87 static bool LaunchBrowser(Profile* profile, const std::wstring& cur_dir, | 101 static bool LaunchBrowser(const CommandLine& command_line, |
| 102 Profile* profile, const std::wstring& cur_dir, |
| 88 bool process_startup, int* return_code); | 103 bool process_startup, int* return_code); |
| 89 | 104 |
| 90 #if defined(OS_WIN) | 105 #if defined(OS_WIN) |
| 91 template <class AutomationProviderClass> | 106 template <class AutomationProviderClass> |
| 92 static void CreateAutomationProvider(const std::wstring& channel_id, | 107 static void CreateAutomationProvider(const std::wstring& channel_id, |
| 93 Profile* profile, | 108 Profile* profile, |
| 94 size_t expected_tabs); | 109 size_t expected_tabs); |
| 95 #endif | 110 #endif |
| 96 | 111 |
| 97 private: | 112 private: |
| 98 // Does the work of LaunchBrowser returning the result. | 113 // Does the work of LaunchBrowser returning the result. |
| 99 static bool LaunchBrowserImpl(Profile* profile, const std::wstring& cur_dir, | 114 static bool LaunchBrowserImpl(const CommandLine& command_line, |
| 115 Profile* profile, const std::wstring& cur_dir, |
| 100 bool process_startup, int* return_code); | 116 bool process_startup, int* return_code); |
| 101 | 117 |
| 102 // This class is for scoping purposes. | 118 // This class is for scoping purposes. |
| 103 BrowserInit(); | 119 BrowserInit(); |
| 104 DISALLOW_COPY_AND_ASSIGN(BrowserInit); | 120 DISALLOW_COPY_AND_ASSIGN(BrowserInit); |
| 105 }; | 121 }; |
| 106 | 122 |
| 107 #endif // CHROME_BROWSER_BROWSER_INIT_H_ | 123 #endif // CHROME_BROWSER_BROWSER_INIT_H_ |
| 108 | 124 |
| OLD | NEW |