summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_init.cc
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-14 00:29:05 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-14 00:29:05 +0000
commit15952e462a8d6ef6d555219d0af62ceae093a173 (patch)
tree530c1a3e238e3ca7488b5589c49480df51f7378d /chrome/browser/browser_init.cc
parentd6dfe0d2402e2dbf997833f2deaf5b4a55b9b40a (diff)
downloadchromium_src-15952e462a8d6ef6d555219d0af62ceae093a173.zip
chromium_src-15952e462a8d6ef6d555219d0af62ceae093a173.tar.gz
chromium_src-15952e462a8d6ef6d555219d0af62ceae093a173.tar.bz2
Re-do the way browser windows are shown:
- Remove the path from WinMain to the Browser object passing the show_command. For the Browser object, this is a problem since this value isn't portable. For the code in general it involves a lot of ugly wiring. It's completely unnecessary since the value is obtainable via GetStartupInfo. - Remove show_command plumbing from all over the place (session restore, web app launcher, etc) Change the way browser windows are constructed: - The browser constructor now takes just a type and a profile, and simply initializes the object. - Some configuration that used to be part of the constructor that was only used in one or two use cases (initial bounds, maximized state, web app name) are split into separate setters. - Window creation is split out into a separate step to be called post configuration. - Assorted static helper functions added to Browser to make construction of common types easy. - Remove Browser::Show in favor of BrowserWindow::Show - Adjust all callers to use the new helpers. Change the way ChromeViews restores window placement: - Split restored size determination from restored maximized determination. They are needed by the code at different times. Size restoration happens when the window is constructed and Window::SetInitialBounds is called. Maximized state restoration happens when the window is shown for the first time and SW_SHOWMAXIMIZED or SW_SHOWNORMAL is needed. Thus, replace WindowDelegate::RestoreWindowPosition with WindowDelegate::RestoreWindowBounds and WindowDelegate::RestoreMaximizedState. - Window::SetInitialBounds calls WindowDelegate::RestoreWindowBounds - Window::Show calls WindowDelegate::RestoreMaximizedState - Adjusts all WindowDelegate implementations that override RestoreWindowPosition to implement these new methods instead. - Move "playback/record" mode window size setting from browser_init to Browser::RestoreWindowBounds. - Provide a virtual function on Window called GetShowState that determines the default show state to be used when Window::Show is called. For most windows and dialogs this is SW_SHOWNORMAL. AeroGlassFrame/OpaqueFrame (the browser window frames) override this since they're the app's main windows to return the value provided by GetStartupInfo which gives the value from the app shortcut. http://crbug.com/3557 Review URL: http://codereview.chromium.org/10896 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5417 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_init.cc')
-rw-r--r--chrome/browser/browser_init.cc90
1 files changed, 22 insertions, 68 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc
index 1a2941d..ff9cb3f 100644
--- a/chrome/browser/browser_init.cc
+++ b/chrome/browser/browser_init.cc
@@ -104,12 +104,12 @@ BrowserInit::MessageWindow::~MessageWindow() {
DestroyWindow(window_);
}
-bool BrowserInit::MessageWindow::NotifyOtherProcess(int show_cmd) {
+bool BrowserInit::MessageWindow::NotifyOtherProcess() {
if (!remote_window_)
return false;
// Found another window, send our command line to it
- // format is "START\0<<<current directory>>>\0<<<commandline>>>\0show_cmd".
+ // format is "START\0<<<current directory>>>\0<<<commandline>>>".
std::wstring to_send(L"START\0", 6); // want the NULL in the string.
std::wstring cur_dir;
if (!PathService::Get(base::DIR_CURRENT, &cur_dir))
@@ -119,22 +119,6 @@ bool BrowserInit::MessageWindow::NotifyOtherProcess(int show_cmd) {
to_send.append(GetCommandLineW());
to_send.append(L"\0", 1); // Null separator.
- // Append the windows show_command flags.
- if (show_cmd == SW_SHOWDEFAULT) {
- // SW_SHOWDEFAULT makes no sense to the other process. We need to
- // use the SW_ flag from OUR STARTUPUNFO;
- STARTUPINFO startup_info = {0};
- startup_info.cb = sizeof(startup_info);
- GetStartupInfo(&startup_info);
- show_cmd = startup_info.wShowWindow;
- // In certain situations the window status above is returned as SW_HIDE.
- // In such cases we need to fall back to a default case of SW_SHOWNORMAL
- // so that user actually get to see the window.
- if (show_cmd != SW_SHOWNORMAL && show_cmd != SW_SHOWMAXIMIZED)
- show_cmd = SW_SHOWNORMAL;
- }
- StringAppendF(&to_send, L"%d", static_cast<uint8>(show_cmd));
-
// Allow the current running browser window making itself the foreground
// window (otherwise it will just flash in the taskbar).
DWORD process_id = 0;
@@ -266,15 +250,6 @@ LRESULT BrowserInit::MessageWindow::OnCopyData(HWND hwnd,
const std::wstring cmd_line =
msg.substr(second_null + 1, third_null - second_null);
- // The last component is probably null terminated but we don't require it
- // because everything here is based on counts.
- std::wstring show_cmd_str = msg.substr(third_null + 1);
- if (!show_cmd_str.empty() &&
- show_cmd_str[show_cmd_str.length() - 1] == L'\0')
- show_cmd_str.resize(cmd_line.length() - 1);
-
- int show_cmd = _wtoi(show_cmd_str.c_str());
-
CommandLine parsed_command_line(cmd_line);
PrefService* prefs = g_browser_process->local_state();
DCHECK(prefs);
@@ -289,8 +264,8 @@ LRESULT BrowserInit::MessageWindow::OnCopyData(HWND hwnd,
NOTREACHED();
return TRUE;
}
- ProcessCommandLine(parsed_command_line, cur_dir, prefs, show_cmd, false,
- profile, NULL);
+ ProcessCommandLine(parsed_command_line, cur_dir, prefs, false, profile,
+ NULL);
return TRUE;
}
return TRUE;
@@ -371,10 +346,8 @@ void BrowserInit::MessageWindow::HuntForZombieChromeProcesses() {
// LaunchWithProfile ----------------------------------------------------------
BrowserInit::LaunchWithProfile::LaunchWithProfile(const std::wstring& cur_dir,
- const std::wstring& cmd_line,
- int show_command)
+ const std::wstring& cmd_line)
: command_line_(cmd_line),
- show_command_(show_command),
cur_dir_(cur_dir) {
}
@@ -384,22 +357,6 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
profile_ = profile;
CommandLine parsed_command_line(command_line_);
- gfx::Rect start_position;
-
- bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode);
- bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode);
- if (record_mode || playback_mode) {
- // In playback/record mode we always fix the size of the browser and
- // move it to (0,0). The reason for this is two reasons: First we want
- // resize/moves in the playback to still work, and Second we want
- // playbacks to work (as much as possible) on machines w/ different
- // screen sizes.
- start_position_.set_height(800);
- start_position_.set_width(600);
- start_position_.set_x(0);
- start_position_.set_y(0);
- }
-
if (parsed_command_line.HasSwitch(switches::kDnsLogDetails))
chrome_browser_net::EnableDnsDetailedLog(true);
if (parsed_command_line.HasSwitch(switches::kDnsPrefetchDisable))
@@ -475,6 +432,11 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
if (!parsed_command_line.HasSwitch(switches::kNoEvents)) {
std::wstring script_path;
PathService::Get(chrome::FILE_RECORDED_SCRIPT, &script_path);
+
+ bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode);
+ bool playback_mode =
+ parsed_command_line.HasSwitch(switches::kPlaybackMode);
+
if (record_mode && chrome::kRecordModeEnabled)
base::EventRecorder::current()->StartRecording(script_path);
if (playback_mode)
@@ -484,11 +446,6 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
return true;
}
-Browser* BrowserInit::LaunchWithProfile::CreateTabbedBrowser() {
- return new Browser(start_position_, show_command_, profile_,
- BrowserType::TABBED_BROWSER, std::wstring());
-}
-
bool BrowserInit::LaunchWithProfile::OpenStartupURLs(
bool is_process_startup,
const CommandLine& command_line,
@@ -507,8 +464,8 @@ bool BrowserInit::LaunchWithProfile::OpenStartupURLs(
// infobar.
return false;
}
- SessionRestore::RestoreSessionSynchronously(
- profile_, false, show_command_, urls_to_open);
+ SessionRestore::RestoreSessionSynchronously(profile_, false,
+ urls_to_open);
return true;
case SessionStartupPref::URLS:
@@ -533,7 +490,7 @@ Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser(
const std::vector<GURL>& urls) {
DCHECK(!urls.empty());
if (!browser || browser->type() != BrowserType::TABBED_BROWSER)
- browser = CreateTabbedBrowser();
+ browser = Browser::Create(profile_);
for (size_t i = 0; i < urls.size(); ++i) {
TabContents* tab = browser->AddTabWithURL(
@@ -541,7 +498,7 @@ Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser(
if (i == 0 && process_startup)
AddCrashedInfoBarIfNecessary(tab);
}
- browser->Show();
+ browser->window()->Show();
return browser;
}
@@ -592,8 +549,8 @@ std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine(
}
bool BrowserInit::ProcessCommandLine(const CommandLine& parsed_command_line,
- const std::wstring& cur_dir, PrefService* prefs, int show_command,
- bool process_startup, Profile* profile, int* return_code) {
+ const std::wstring& cur_dir, PrefService* prefs, bool process_startup,
+ Profile* profile, int* return_code) {
DCHECK(profile);
if (process_startup) {
const std::wstring popup_count_string =
@@ -655,19 +612,18 @@ bool BrowserInit::ProcessCommandLine(const CommandLine& parsed_command_line,
// If we don't want to launch a new browser window or tab (in the case
// of an automation request), we are done here.
if (!silent_launch) {
- return LaunchBrowser(parsed_command_line, profile, show_command, cur_dir,
+ return LaunchBrowser(parsed_command_line, profile, cur_dir,
process_startup, return_code);
}
return true;
}
bool BrowserInit::LaunchBrowser(const CommandLine& parsed_command_line,
- Profile* profile,
- int show_command, const std::wstring& cur_dir,
+ Profile* profile, const std::wstring& cur_dir,
bool process_startup, int* return_code) {
in_startup = process_startup;
- bool result = LaunchBrowserImpl(parsed_command_line, profile, show_command,
- cur_dir, process_startup, return_code);
+ bool result = LaunchBrowserImpl(parsed_command_line, profile, cur_dir,
+ process_startup, return_code);
in_startup = false;
return result;
}
@@ -689,7 +645,6 @@ void BrowserInit::CreateAutomationProvider(const std::wstring& channel_id,
bool BrowserInit::LaunchBrowserImpl(const CommandLine& parsed_command_line,
Profile* profile,
- int show_command,
const std::wstring& cur_dir,
bool process_startup,
int* return_code) {
@@ -710,12 +665,11 @@ bool BrowserInit::LaunchBrowserImpl(const CommandLine& parsed_command_line,
if (url.SchemeIs("mailto"))
url = GURL("about:blank");
- WebAppLauncher::Launch(profile, url, show_command);
+ WebAppLauncher::Launch(profile, url);
return true;
}
- LaunchWithProfile lwp(cur_dir, parsed_command_line.command_line_string(),
- show_command);
+ LaunchWithProfile lwp(cur_dir, parsed_command_line.command_line_string());
bool launched = lwp.Launch(profile, process_startup);
if (!launched) {
LOG(ERROR) << "launch error";