Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/test/chromedriver/chrome/browser_info.h" | 5 #include "chrome/test/chromedriver/chrome/browser_info.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kVersionPrefix[] = "Chrome/"; | 19 const char kVersionPrefix[] = "Chrome/"; |
| 20 const size_t kVersionPrefixLen = sizeof(kVersionPrefix) - 1; | 20 const size_t kVersionPrefixLen = sizeof(kVersionPrefix) - 1; |
| 21 | 21 |
| 22 const char kHeadlessVersionPrefix[] = "HeadlessChrome/"; | |
| 23 const size_t kHeadlessVersionPrefixLen = sizeof(kHeadlessVersionPrefix) - 1; | |
| 24 | |
| 22 } // namespace | 25 } // namespace |
| 23 | 26 |
| 24 BrowserInfo::BrowserInfo() | 27 BrowserInfo::BrowserInfo() |
| 25 : major_version(0), | 28 : major_version(0), |
| 26 build_no(kToTBuildNo), | 29 build_no(kToTBuildNo), |
| 27 blink_revision(kToTBlinkRevision), | 30 blink_revision(kToTBlinkRevision), |
| 28 is_android(false) { | 31 is_android(false) { |
| 29 } | 32 } |
| 30 | 33 |
| 31 BrowserInfo::BrowserInfo(std::string android_package, | 34 BrowserInfo::BrowserInfo(std::string android_package, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 BrowserInfo* browser_info) { | 83 BrowserInfo* browser_info) { |
| 81 if (has_android_package) | 84 if (has_android_package) |
| 82 browser_info->is_android = true; | 85 browser_info->is_android = true; |
| 83 | 86 |
| 84 if (browser_string.empty()) { | 87 if (browser_string.empty()) { |
| 85 browser_info->browser_name = "content shell"; | 88 browser_info->browser_name = "content shell"; |
| 86 return Status(kOk); | 89 return Status(kOk); |
| 87 } | 90 } |
| 88 | 91 |
| 89 int build_no = 0; | 92 int build_no = 0; |
| 90 if (base::StartsWith(browser_string, kVersionPrefix, | 93 if (base::StartsWith(browser_string, kVersionPrefix, |
|
samuong
2017/03/08 21:24:15
Can we merge these two if blocks somehow? I'm thin
irisu
2017/03/08 23:49:34
Done.
| |
| 91 base::CompareCase::SENSITIVE)) { | 94 base::CompareCase::SENSITIVE)) { |
| 92 std::string version = browser_string.substr(kVersionPrefixLen); | 95 std::string version = browser_string.substr(kVersionPrefixLen); |
| 93 | 96 |
| 94 Status status = ParseBrowserVersionString( | 97 Status status = ParseBrowserVersionString( |
| 95 version, &browser_info->major_version, &build_no); | 98 version, &browser_info->major_version, &build_no); |
| 96 if (status.IsError()) | 99 if (status.IsError()) |
| 97 return status; | 100 return status; |
| 98 | 101 |
| 99 if (build_no != 0) { | 102 if (build_no != 0) { |
| 100 browser_info->browser_name = "chrome"; | 103 browser_info->browser_name = "chrome"; |
| 101 browser_info->browser_version = version; | 104 browser_info->browser_version = version; |
| 102 browser_info->build_no = build_no; | 105 browser_info->build_no = build_no; |
| 103 return Status(kOk); | 106 return Status(kOk); |
| 104 } | 107 } |
| 105 } | 108 } |
| 106 | 109 |
| 110 if (base::StartsWith(browser_string, kHeadlessVersionPrefix, | |
| 111 base::CompareCase::SENSITIVE)) { | |
| 112 std::string version = browser_string.substr(kHeadlessVersionPrefixLen); | |
| 113 | |
| 114 Status status = ParseBrowserVersionString( | |
| 115 version, &browser_info->major_version, &build_no); | |
| 116 if (status.IsError()) | |
| 117 return status; | |
| 118 | |
| 119 if (build_no != 0) { | |
| 120 browser_info->browser_name = "headless chrome"; | |
| 121 browser_info->browser_version = version; | |
| 122 browser_info->build_no = build_no; | |
| 123 return Status(kOk); | |
| 124 } | |
| 125 } | |
| 126 | |
| 107 if (browser_string.find("Version/") == 0u || // KitKat | 127 if (browser_string.find("Version/") == 0u || // KitKat |
| 108 (has_android_package && build_no == 0)) { // Lollipop | 128 (has_android_package && build_no == 0)) { // Lollipop |
| 109 size_t pos = browser_string.find(kVersionPrefix); | 129 size_t pos = browser_string.find(kVersionPrefix); |
| 110 if (pos != std::string::npos) { | 130 if (pos != std::string::npos) { |
| 111 browser_info->browser_name = "webview"; | 131 browser_info->browser_name = "webview"; |
| 112 browser_info->browser_version = | 132 browser_info->browser_version = |
| 113 browser_string.substr(pos + kVersionPrefixLen); | 133 browser_string.substr(pos + kVersionPrefixLen); |
| 114 browser_info->is_android = true; | 134 browser_info->is_android = true; |
| 115 return ParseBrowserVersionString(browser_info->browser_version, | 135 return ParseBrowserVersionString(browser_info->browser_version, |
| 116 &browser_info->major_version, &build_no); | 136 &browser_info->major_version, &build_no); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 return Status(kOk); | 176 return Status(kOk); |
| 157 } | 177 } |
| 158 | 178 |
| 159 bool IsGitHash(const std::string& revision) { | 179 bool IsGitHash(const std::string& revision) { |
| 160 const int kShortGitHashLength = 7; | 180 const int kShortGitHashLength = 7; |
| 161 const int kFullGitHashLength = 40; | 181 const int kFullGitHashLength = 40; |
| 162 return kShortGitHashLength <= revision.size() | 182 return kShortGitHashLength <= revision.size() |
| 163 && revision.size() <= kFullGitHashLength | 183 && revision.size() <= kFullGitHashLength |
| 164 && base::ContainsOnlyChars(revision, "0123456789abcdefABCDEF"); | 184 && base::ContainsOnlyChars(revision, "0123456789abcdefABCDEF"); |
| 165 } | 185 } |
| OLD | NEW |