OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/glue/user_agent.h" | 5 #include "webkit/glue/user_agent.h" |
6 | 6 |
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 7 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
8 #include <sys/utsname.h> | 8 #include <sys/utsname.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "webkit_version.h" // NOLINT | 21 #include "webkit_version.h" // NOLINT |
22 | 22 |
23 #if defined(OS_ANDROID) | 23 #if defined(OS_ANDROID) |
24 namespace { | 24 namespace { |
25 | 25 |
26 base::LazyInstance<std::string>::Leaky g_os_info = LAZY_INSTANCE_INITIALIZER; | 26 base::LazyInstance<std::string>::Leaky g_os_info = LAZY_INSTANCE_INITIALIZER; |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 #endif | 29 #endif |
30 | 30 |
| 31 namespace { |
| 32 const char kUserAgentOverrideForTabletSite[] = |
| 33 "(Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B)"; |
| 34 } |
| 35 |
31 namespace webkit_glue { | 36 namespace webkit_glue { |
32 | 37 |
33 std::string GetWebKitVersion() { | 38 std::string GetWebKitVersion() { |
34 return base::StringPrintf("%d.%d (%s)", | 39 return base::StringPrintf("%d.%d (%s)", |
35 WEBKIT_VERSION_MAJOR, | 40 WEBKIT_VERSION_MAJOR, |
36 WEBKIT_VERSION_MINOR, | 41 WEBKIT_VERSION_MINOR, |
37 WEBKIT_SVN_REVISION); | 42 WEBKIT_SVN_REVISION); |
38 } | 43 } |
39 | 44 |
40 std::string GetWebKitRevision() { | 45 std::string GetWebKitRevision() { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 WEBKIT_VERSION_MINOR); | 160 WEBKIT_VERSION_MINOR); |
156 return user_agent; | 161 return user_agent; |
157 } | 162 } |
158 | 163 |
159 #if defined(OS_ANDROID) | 164 #if defined(OS_ANDROID) |
160 void SetUserAgentOSInfo(const std::string& os_info) { | 165 void SetUserAgentOSInfo(const std::string& os_info) { |
161 g_os_info.Get() = os_info; | 166 g_os_info.Get() = os_info; |
162 } | 167 } |
163 #endif | 168 #endif |
164 | 169 |
| 170 std::string BuildUserAgentOverrideForTabletSiteFromUserAgent( |
| 171 const std::string& user_agent) { |
| 172 // Example: original user agent text: |
| 173 // |
| 174 // Mozilla/5.0 (X11; CrOS x86_64 0.4.0) |
| 175 // AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1211.0 Safari/537.2 |
| 176 // |
| 177 // Copy & Edit to create user agent override text by replacing |
| 178 // the text within the first pair of "()". For example: |
| 179 // |
| 180 // Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) |
| 181 // AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1211.0 Safari/537.2 |
| 182 // |
| 183 size_t p1 = user_agent.find("("); |
| 184 if (p1 != std::string::npos) { |
| 185 size_t p2 = user_agent.find(")", p1); |
| 186 if (p2 != std::string::npos) { |
| 187 std::string ua_override(user_agent); |
| 188 ua_override.replace(p1, p2-p1+1, kUserAgentOverrideForTabletSite); |
| 189 return ua_override; |
| 190 } |
| 191 } |
| 192 return std::string(); |
| 193 } |
| 194 |
165 } // namespace webkit_glue | 195 } // namespace webkit_glue |
OLD | NEW |