Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: headless/app/headless_shell.cc

Issue 2223563002: headless: expose window size through headless_shell switch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | headless/app/headless_shell_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include <iostream> 5 #include <iostream>
6 #include <memory> 6 #include <memory>
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 24 matching lines...) Expand all
35 using headless::HeadlessDevToolsClient; 35 using headless::HeadlessDevToolsClient;
36 using headless::HeadlessWebContents; 36 using headless::HeadlessWebContents;
37 namespace page = headless::page; 37 namespace page = headless::page;
38 namespace runtime = headless::runtime; 38 namespace runtime = headless::runtime;
39 39
40 namespace { 40 namespace {
41 // Address where to listen to incoming DevTools connections. 41 // Address where to listen to incoming DevTools connections.
42 const char kDevToolsHttpServerAddress[] = "127.0.0.1"; 42 const char kDevToolsHttpServerAddress[] = "127.0.0.1";
43 // Default file name for screenshot. Can be overriden by "--screenshot" switch. 43 // Default file name for screenshot. Can be overriden by "--screenshot" switch.
44 const char kDefaultScreenshotFileName[] = "screenshot.png"; 44 const char kDefaultScreenshotFileName[] = "screenshot.png";
45
46 gfx::Size WindowSizeFromString(std::string window_size) {
47 int width, height = 0;
48 if (sscanf(window_size.c_str(), "%dx%d", &width, &height) >= 2)
49 return gfx::Size(width, height);
50 return gfx::Size();
45 } 51 }
52 } // namespace
46 53
47 // A sample application which demonstrates the use of the headless API. 54 // A sample application which demonstrates the use of the headless API.
48 class HeadlessShell : public HeadlessWebContents::Observer, page::Observer { 55 class HeadlessShell : public HeadlessWebContents::Observer, page::Observer {
49 public: 56 public:
50 HeadlessShell() 57 HeadlessShell()
51 : browser_(nullptr), 58 : browser_(nullptr),
52 devtools_client_(HeadlessDevToolsClient::Create()), 59 devtools_client_(HeadlessDevToolsClient::Create()),
53 web_contents_(nullptr), 60 web_contents_(nullptr),
54 processed_page_ready_(false), 61 processed_page_ready_(false),
55 browser_context_(nullptr) {} 62 browser_context_(nullptr) {}
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 builder.SetGLImplementation( 352 builder.SetGLImplementation(
346 command_line.GetSwitchValueASCII(headless::switches::kUseGL)); 353 command_line.GetSwitchValueASCII(headless::switches::kUseGL));
347 } 354 }
348 355
349 if (command_line.HasSwitch(headless::switches::kUserDataDir)) { 356 if (command_line.HasSwitch(headless::switches::kUserDataDir)) {
350 builder.SetUserDataDir( 357 builder.SetUserDataDir(
351 command_line.GetSwitchValuePath(headless::switches::kUserDataDir)); 358 command_line.GetSwitchValuePath(headless::switches::kUserDataDir));
352 builder.SetIncognitoMode(false); 359 builder.SetIncognitoMode(false);
353 } 360 }
354 361
362 if (command_line.HasSwitch(headless::switches::kWindowSize)) {
363 std::string window_size =
364 command_line.GetSwitchValueASCII(headless::switches::kWindowSize);
365 gfx::Size parsed_window_size = WindowSizeFromString(window_size);
366 if (parsed_window_size.IsEmpty()) {
Sami 2016/08/05 18:18:25 0x0 might be useful in some cases -- could we allo
Eric Seckler 2016/08/05 18:40:02 Done.
367 LOG(ERROR) << "Malformed window size";
368 return EXIT_FAILURE;
369 }
370 builder.SetWindowSize(parsed_window_size);
371 }
372
355 return HeadlessBrowserMain( 373 return HeadlessBrowserMain(
356 builder.Build(), 374 builder.Build(),
357 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); 375 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell)));
358 } 376 }
OLDNEW
« no previous file with comments | « no previous file | headless/app/headless_shell_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698