OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "headless/public/headless_browser.h" | 5 #include "headless/public/headless_browser.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "content/public/common/user_agent.h" | 9 #include "content/public/common/user_agent.h" |
| 10 #include "headless/public/version.h" |
10 | 11 |
11 using Options = headless::HeadlessBrowser::Options; | 12 using Options = headless::HeadlessBrowser::Options; |
12 using Builder = headless::HeadlessBrowser::Options::Builder; | 13 using Builder = headless::HeadlessBrowser::Options::Builder; |
13 | 14 |
14 namespace headless { | 15 namespace headless { |
15 | 16 |
| 17 namespace { |
16 // Product name for building the default user agent string. | 18 // Product name for building the default user agent string. |
17 namespace { | |
18 const char kProductName[] = "HeadlessChrome"; | 19 const char kProductName[] = "HeadlessChrome"; |
19 constexpr gfx::Size kDefaultWindowSize(800, 600); | 20 constexpr gfx::Size kDefaultWindowSize(800, 600); |
| 21 |
| 22 std::string GetProductNameAndVersion() { |
| 23 return std::string(kProductName) + "/" + PRODUCT_VERSION; |
20 } | 24 } |
| 25 } // namespace |
21 | 26 |
22 Options::Options(int argc, const char** argv) | 27 Options::Options(int argc, const char** argv) |
23 : argc(argc), | 28 : argc(argc), |
24 argv(argv), | 29 argv(argv), |
25 message_pump(nullptr), | 30 message_pump(nullptr), |
26 single_process_mode(false), | 31 single_process_mode(false), |
27 disable_sandbox(false), | 32 disable_sandbox(false), |
28 gl_implementation("osmesa"), | 33 gl_implementation("osmesa"), |
29 user_agent(content::BuildUserAgentFromProduct(kProductName)), | 34 product_name_and_version(GetProductNameAndVersion()), |
| 35 user_agent(content::BuildUserAgentFromProduct(product_name_and_version)), |
30 window_size(kDefaultWindowSize), | 36 window_size(kDefaultWindowSize), |
31 incognito_mode(true), | 37 incognito_mode(true), |
32 enable_crash_reporter(false) {} | 38 enable_crash_reporter(false) {} |
33 | 39 |
34 Options::Options(Options&& options) = default; | 40 Options::Options(Options&& options) = default; |
35 | 41 |
36 Options::~Options() {} | 42 Options::~Options() {} |
37 | 43 |
38 Options& Options::operator=(Options&& options) = default; | 44 Options& Options::operator=(Options&& options) = default; |
39 | 45 |
40 Builder::Builder(int argc, const char** argv) : options_(argc, argv) {} | 46 Builder::Builder(int argc, const char** argv) : options_(argc, argv) {} |
41 | 47 |
42 Builder::Builder() : options_(0, nullptr) {} | 48 Builder::Builder() : options_(0, nullptr) {} |
43 | 49 |
44 Builder::~Builder() {} | 50 Builder::~Builder() {} |
45 | 51 |
| 52 Builder& Builder::SetProductNameAndVersion( |
| 53 const std::string& product_name_and_version) { |
| 54 options_.product_name_and_version = product_name_and_version; |
| 55 return *this; |
| 56 } |
| 57 |
46 Builder& Builder::SetUserAgent(const std::string& user_agent) { | 58 Builder& Builder::SetUserAgent(const std::string& user_agent) { |
47 options_.user_agent = user_agent; | 59 options_.user_agent = user_agent; |
48 return *this; | 60 return *this; |
49 } | 61 } |
50 | 62 |
51 Builder& Builder::EnableDevToolsServer(const net::IPEndPoint& endpoint) { | 63 Builder& Builder::EnableDevToolsServer(const net::IPEndPoint& endpoint) { |
52 options_.devtools_endpoint = endpoint; | 64 options_.devtools_endpoint = endpoint; |
53 return *this; | 65 return *this; |
54 } | 66 } |
55 | 67 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 Builder& Builder::SetCrashDumpsDir(const base::FilePath& dir) { | 129 Builder& Builder::SetCrashDumpsDir(const base::FilePath& dir) { |
118 options_.crash_dumps_dir = dir; | 130 options_.crash_dumps_dir = dir; |
119 return *this; | 131 return *this; |
120 } | 132 } |
121 | 133 |
122 Options Builder::Build() { | 134 Options Builder::Build() { |
123 return std::move(options_); | 135 return std::move(options_); |
124 } | 136 } |
125 | 137 |
126 } // namespace headless | 138 } // namespace headless |
OLD | NEW |