Skip to content

Commit

Permalink
Expose window size through a headless_shell switch.
Browse files Browse the repository at this point in the history
BUG=546953

Review-Url: https://codereview.chromium.org/2223563002
Cr-Commit-Position: refs/heads/master@{#410140}
  • Loading branch information
betasheet authored and Commit bot committed Aug 5, 2016
1 parent b4b7c8e commit 2c13b37
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions headless/app/headless_shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ namespace {
const char kDevToolsHttpServerAddress[] = "127.0.0.1";
// Default file name for screenshot. Can be overriden by "--screenshot" switch.
const char kDefaultScreenshotFileName[] = "screenshot.png";

bool ParseWindowSize(std::string window_size, gfx::Size* parsed_window_size) {
int width, height = 0;
if (sscanf(window_size.c_str(), "%dx%d", &width, &height) >= 2 &&
width >= 0 && height >= 0) {
parsed_window_size->set_width(width);
parsed_window_size->set_height(height);
return true;
}
return false;
}
} // namespace

// A sample application which demonstrates the use of the headless API.
class HeadlessShell : public HeadlessWebContents::Observer, page::Observer {
Expand Down Expand Up @@ -352,6 +363,17 @@ int main(int argc, const char** argv) {
builder.SetIncognitoMode(false);
}

if (command_line.HasSwitch(headless::switches::kWindowSize)) {
std::string window_size =
command_line.GetSwitchValueASCII(headless::switches::kWindowSize);
gfx::Size parsed_window_size;
if (!ParseWindowSize(window_size, &parsed_window_size)) {
LOG(ERROR) << "Malformed window size";
return EXIT_FAILURE;
}
builder.SetWindowSize(parsed_window_size);
}

return HeadlessBrowserMain(
builder.Build(),
base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell)));
Expand Down
3 changes: 3 additions & 0 deletions headless/app/headless_shell_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ const char kUseGL[] = "use-gl";
// Directory where the browser stores the user profile.
const char kUserDataDir[] = "user-data-dir";

// Sets the initial window size. Provided as string in the format "800x600".
const char kWindowSize[] = "window-size";

} // namespace switches
} // namespace headless
1 change: 1 addition & 0 deletions headless/app/headless_shell_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern const char kRepl[];
extern const char kScreenshot[];
extern const char kUseGL[];
extern const char kUserDataDir[];
extern const char kWindowSize[];
} // namespace switches
} // namespace headless

Expand Down

0 comments on commit 2c13b37

Please sign in to comment.