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

Unified Diff: headless/lib/browser/headless_browser_impl.cc

Issue 2805793003: Add user-agent flag to headless (Closed)
Patch Set: Add shell switches to build file 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « headless/app/headless_shell_switches.cc ('k') | headless/lib/browser/headless_content_browser_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: headless/lib/browser/headless_browser_impl.cc
diff --git a/headless/lib/browser/headless_browser_impl.cc b/headless/lib/browser/headless_browser_impl.cc
index 37a9c928ba25d33869d18a89cb9203c3e123cbd3..747639ca3f68c116562f531cef63a57c8e19a0b6 100644
--- a/headless/lib/browser/headless_browser_impl.cc
+++ b/headless/lib/browser/headless_browser_impl.cc
@@ -15,10 +15,12 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
+#include "headless/app/headless_shell_switches.h"
#include "headless/lib/browser/headless_browser_context_impl.h"
#include "headless/lib/browser/headless_browser_main_parts.h"
#include "headless/lib/browser/headless_web_contents_impl.h"
#include "headless/lib/headless_content_main_delegate.h"
+#include "net/http/http_util.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
@@ -200,11 +202,19 @@ HeadlessBrowserContext* HeadlessBrowserImpl::GetBrowserContextForId(
void RunChildProcessIfNeeded(int argc, const char** argv) {
base::CommandLine::Init(argc, argv);
- if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kProcessType))
+ const base::CommandLine& command_line(
+ *base::CommandLine::ForCurrentProcess());
+
+ if (!command_line.HasSwitch(::switches::kProcessType))
return;
HeadlessBrowser::Options::Builder builder(argc, argv);
+ if (command_line.HasSwitch(switches::kUserAgent)) {
+ std::string ua = command_line.GetSwitchValueASCII(switches::kUserAgent);
+ if (net::HttpUtil::IsValidHeaderValue(ua))
+ builder.SetUserAgent(ua);
+ }
+
exit(RunContentMain(builder.Build(),
base::Callback<void(HeadlessBrowser*)>()));
}
@@ -221,7 +231,7 @@ int HeadlessBrowserMain(
// Child processes should not end up here.
DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kProcessType));
+ ::switches::kProcessType));
#endif
return RunContentMain(std::move(options),
std::move(on_browser_start_callback));
« no previous file with comments | « headless/app/headless_shell_switches.cc ('k') | headless/lib/browser/headless_content_browser_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698