summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-14 02:21:06 +0000
committerjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-14 02:21:06 +0000
commit113baf98fdf2b0992ee668cd414fa34ce3c53b12 (patch)
tree99145004eae546bf4bd8f730b15d463921d6936a
parent3942a25369d4e15de6c47b0c1df59827eec49a5e (diff)
downloadchromium_src-113baf98fdf2b0992ee668cd414fa34ce3c53b12.zip
chromium_src-113baf98fdf2b0992ee668cd414fa34ce3c53b12.tar.gz
chromium_src-113baf98fdf2b0992ee668cd414fa34ce3c53b12.tar.bz2
Add --window-size and --window-position commandline options.
BUG=35153 TEST=run chrome with --window-size=w,h and/or --window-position=x,y and verify correct window placement and size. Review URL: http://codereview.chromium.org/9379026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121821 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/browser.cc45
-rw-r--r--chrome/common/chrome_switches.cc6
-rw-r--r--chrome/common/chrome_switches.h2
3 files changed, 49 insertions, 4 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index ec25231..889169b 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -292,6 +292,26 @@ GURL UrlForExtension(const Extension* extension, const GURL& override_url) {
return url;
}
+// Parse two comma-separated integers from str. Return true on success.
+bool ParseCommaSeparatedIntegers(const std::string& str,
+ int* ret_num1,
+ int* ret_num2) {
+ size_t num1_size = str.find_first_of(',');
+ if (num1_size == std::string::npos)
+ return false;
+
+ size_t num2_pos = num1_size + 1;
+ size_t num2_size = str.size() - num2_pos;
+ int num1, num2;
+ if (!base::StringToInt(str.substr(0, num1_size), &num1) ||
+ !base::StringToInt(str.substr(num2_pos, num2_size), &num2))
+ return false;
+
+ *ret_num1 = num1;
+ *ret_num2 = num2;
+ return true;
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -951,6 +971,10 @@ void Browser::SaveWindowPlacement(const gfx::Rect& bounds,
}
gfx::Rect Browser::GetSavedWindowBounds() const {
+ gfx::Rect restored_bounds = override_bounds_;
+ WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this,
+ &restored_bounds);
+
const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode);
bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode);
@@ -960,12 +984,25 @@ gfx::Rect Browser::GetSavedWindowBounds() const {
// 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.
- return gfx::Rect(0, 0, 800, 600);
+ restored_bounds = gfx::Rect(0, 0, 800, 600);
+ }
+
+ // The following options override playback/record.
+ if (parsed_command_line.HasSwitch(switches::kWindowSize)) {
+ std::string str =
+ parsed_command_line.GetSwitchValueASCII(switches::kWindowSize);
+ int width, height;
+ if (ParseCommaSeparatedIntegers(str, &width, &height))
+ restored_bounds.set_size(gfx::Size(width, height));
+ }
+ if (parsed_command_line.HasSwitch(switches::kWindowPosition)) {
+ std::string str =
+ parsed_command_line.GetSwitchValueASCII(switches::kWindowPosition);
+ int x, y;
+ if (ParseCommaSeparatedIntegers(str, &x, &y))
+ restored_bounds.set_origin(gfx::Point(x, y));
}
- gfx::Rect restored_bounds = override_bounds_;
- WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this,
- &restored_bounds);
return restored_bounds;
}
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 81833b3..98a3308 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -1109,6 +1109,12 @@ const char kVersion[] = "version";
// Adds the given extension ID to all the permission whitelists.
const char kWhitelistedExtensionID[] = "whitelisted-extension-id";
+// Specify the initial window position: --window-position=x,y
+const char kWindowPosition[] = "window-position";
+
+// Specify the initial window size: --window-size=w,h
+const char kWindowSize[] = "window-size";
+
// Uses WinHTTP to fetch and evaluate PAC scripts. Otherwise the default is to
// use Chromium's network stack to fetch, and V8 to evaluate.
const char kWinHttpProxyResolver[] = "winhttp-proxy-resolver";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index fcbdec5..20a296a 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -302,6 +302,8 @@ extern const char kMaxSpdyConcurrentStreams[];
extern const char kUserDataDir[];
extern const char kVersion[];
extern const char kWhitelistedExtensionID[];
+extern const char kWindowPosition[];
+extern const char kWindowSize[];
extern const char kWinHttpProxyResolver[];
extern const char kMemoryWidget[];