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

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

Issue 2814043002: [headless] Add command line flag for default background color. (Closed)
Patch Set: Created 3 years, 8 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 <memory> 5 #include <memory>
6 #include <sstream> 6 #include <sstream>
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 web_contents_ = nullptr; 129 web_contents_ = nullptr;
130 browser_context_->Close(); 130 browser_context_->Close();
131 browser_->Shutdown(); 131 browser_->Shutdown();
132 } 132 }
133 133
134 void HeadlessShell::DevToolsTargetReady() { 134 void HeadlessShell::DevToolsTargetReady() {
135 web_contents_->GetDevToolsTarget()->AttachClient(devtools_client_.get()); 135 web_contents_->GetDevToolsTarget()->AttachClient(devtools_client_.get());
136 devtools_client_->GetInspector()->GetExperimental()->AddObserver(this); 136 devtools_client_->GetInspector()->GetExperimental()->AddObserver(this);
137 devtools_client_->GetPage()->GetExperimental()->AddObserver(this); 137 devtools_client_->GetPage()->GetExperimental()->AddObserver(this);
138 devtools_client_->GetPage()->Enable(); 138 devtools_client_->GetPage()->Enable();
139 // Check if the document had already finished loading by the time we
140 // attached.
141 139
142 devtools_client_->GetEmulation()->GetExperimental()->AddObserver(this); 140 devtools_client_->GetEmulation()->GetExperimental()->AddObserver(this);
143 141
144 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 142 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
145 switches::kDeterministicFetch)) { 143 switches::kDeterministicFetch)) {
146 devtools_client_->GetPage()->GetExperimental()->SetControlNavigations( 144 devtools_client_->GetPage()->GetExperimental()->SetControlNavigations(
147 headless::page::SetControlNavigationsParams::Builder() 145 headless::page::SetControlNavigationsParams::Builder()
148 .SetEnabled(true) 146 .SetEnabled(true)
149 .Build()); 147 .Build());
150 } 148 }
149 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
150 switches::kDefaultBackgroundColor)) {
151 std::string color_hex =
152 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
153 switches::kDefaultBackgroundColor);
154 uint32_t color;
155 CHECK(base::HexStringToUInt(color_hex, &color))
156 << "Expected a hex value for --default-background-color=";
157 auto rgba = headless::dom::RGBA::Builder()
158 .SetR((color & 0xff000000) >> 24)
159 .SetG((color & 0x00ff0000) >> 16)
160 .SetB((color & 0x0000ff00) >> 8)
161 .SetA(color & 0x000000ff)
162 .Build();
163 devtools_client_->GetEmulation()
164 ->GetExperimental()
165 ->SetDefaultBackgroundColorOverride(
166 headless::emulation::SetDefaultBackgroundColorOverrideParams::
167 Builder()
168 .SetColor(std::move(rgba))
169 .Build());
170 }
151 171
152 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 172 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
153 switches::kVirtualTimeBudget)) { 173 switches::kVirtualTimeBudget)) {
154 std::string budget_ms_ascii = 174 std::string budget_ms_ascii =
155 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 175 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
156 switches::kVirtualTimeBudget); 176 switches::kVirtualTimeBudget);
157 int budget_ms; 177 int budget_ms;
158 CHECK(base::StringToInt(budget_ms_ascii, &budget_ms)) 178 CHECK(base::StringToInt(budget_ms_ascii, &budget_ms))
159 << "Expected an integer value for --virtual-time-budget="; 179 << "Expected an integer value for --virtual-time-budget=";
160 devtools_client_->GetEmulation()->GetExperimental()->SetVirtualTimePolicy( 180 devtools_client_->GetEmulation()->GetExperimental()->SetVirtualTimePolicy(
161 emulation::SetVirtualTimePolicyParams::Builder() 181 emulation::SetVirtualTimePolicyParams::Builder()
162 .SetPolicy( 182 .SetPolicy(
163 emulation::VirtualTimePolicy::PAUSE_IF_NETWORK_FETCHES_PENDING) 183 emulation::VirtualTimePolicy::PAUSE_IF_NETWORK_FETCHES_PENDING)
164 .SetBudget(budget_ms) 184 .SetBudget(budget_ms)
165 .Build()); 185 .Build());
166 } else { 186 } else {
187 // Check if the document had already finished loading by the time we
188 // attached.
167 PollReadyState(); 189 PollReadyState();
168 } 190 }
169 191
170 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTimeout)) { 192 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTimeout)) {
171 std::string timeout_ms_ascii = 193 std::string timeout_ms_ascii =
172 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 194 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
173 switches::kTimeout); 195 switches::kTimeout);
174 int timeout_ms; 196 int timeout_ms;
175 CHECK(base::StringToInt(timeout_ms_ascii, &timeout_ms)) 197 CHECK(base::StringToInt(timeout_ms_ascii, &timeout_ms))
176 << "Expected an integer value for --timeout="; 198 << "Expected an integer value for --timeout=";
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 453 }
432 454
433 bool ValidateCommandLine(const base::CommandLine& command_line) { 455 bool ValidateCommandLine(const base::CommandLine& command_line) {
434 if (!command_line.HasSwitch(switches::kRemoteDebuggingPort)) { 456 if (!command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
435 if (command_line.GetArgs().size() <= 1) 457 if (command_line.GetArgs().size() <= 1)
436 return true; 458 return true;
437 LOG(ERROR) << "Open multiple tabs is only supported when the " 459 LOG(ERROR) << "Open multiple tabs is only supported when the "
438 << "remote debug port is set."; 460 << "remote debug port is set.";
439 return false; 461 return false;
440 } 462 }
463 if (command_line.HasSwitch(switches::kDefaultBackgroundColor)) {
464 LOG(ERROR) << "Setting default background color is disabled "
465 << "when remote debugging is enabled.";
466 return false;
467 }
441 if (command_line.HasSwitch(switches::kDumpDom)) { 468 if (command_line.HasSwitch(switches::kDumpDom)) {
442 LOG(ERROR) << "Dump DOM is disabled when remote debugging is enabled."; 469 LOG(ERROR) << "Dump DOM is disabled when remote debugging is enabled.";
443 return false; 470 return false;
444 } 471 }
472 if (command_line.HasSwitch(switches::kPrintToPDF)) {
473 LOG(ERROR) << "Print to PDF is disabled "
474 << "when remote debugging is enabled.";
475 return false;
476 }
445 if (command_line.HasSwitch(switches::kRepl)) { 477 if (command_line.HasSwitch(switches::kRepl)) {
446 LOG(ERROR) << "Evaluate Javascript is disabled " 478 LOG(ERROR) << "Evaluate Javascript is disabled "
447 << "when remote debugging is enabled."; 479 << "when remote debugging is enabled.";
448 return false; 480 return false;
449 } 481 }
450 if (command_line.HasSwitch(switches::kScreenshot)) { 482 if (command_line.HasSwitch(switches::kScreenshot)) {
451 LOG(ERROR) << "Capture screenshot is disabled " 483 LOG(ERROR) << "Capture screenshot is disabled "
452 << "when remote debugging is enabled."; 484 << "when remote debugging is enabled.";
453 return false; 485 return false;
454 } 486 }
455 if (command_line.HasSwitch(switches::kPrintToPDF)) {
456 LOG(ERROR) << "Print to PDF is disabled "
457 << "when remote debugging is enabled.";
458 return false;
459 }
460 if (command_line.HasSwitch(switches::kTimeout)) { 487 if (command_line.HasSwitch(switches::kTimeout)) {
461 LOG(ERROR) << "Navigation timeout is disabled " 488 LOG(ERROR) << "Navigation timeout is disabled "
462 << "when remote debugging is enabled."; 489 << "when remote debugging is enabled.";
463 return false; 490 return false;
464 } 491 }
465 if (command_line.HasSwitch(switches::kVirtualTimeBudget)) { 492 if (command_line.HasSwitch(switches::kVirtualTimeBudget)) {
466 LOG(ERROR) << "Virtual time budget is disabled " 493 LOG(ERROR) << "Virtual time budget is disabled "
467 << "when remote debugging is enabled."; 494 << "when remote debugging is enabled.";
468 return false; 495 return false;
469 } 496 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 if (net::HttpUtil::IsValidHeaderValue(ua)) 591 if (net::HttpUtil::IsValidHeaderValue(ua))
565 builder.SetUserAgent(ua); 592 builder.SetUserAgent(ua);
566 } 593 }
567 594
568 return HeadlessBrowserMain( 595 return HeadlessBrowserMain(
569 builder.Build(), 596 builder.Build(),
570 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); 597 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell)));
571 } 598 }
572 599
573 } // namespace headless 600 } // namespace headless
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