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

Unified Diff: ios/web/ui_web_view_util.mm

Issue 1043243003: Upstream most of ios/web/net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove accidentally-added clients Created 5 years, 9 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 | « ios/web/ui_web_view_util.h ('k') | ios/web/ui_web_view_util_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/ui_web_view_util.mm
diff --git a/ios/web/ui_web_view_util.mm b/ios/web/ui_web_view_util.mm
new file mode 100644
index 0000000000000000000000000000000000000000..35c634798b7279c0a5779c8ed7f24b230929c74b
--- /dev/null
+++ b/ios/web/ui_web_view_util.mm
@@ -0,0 +1,40 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/web/ui_web_view_util.h"
+
+#include "base/logging.h"
+#include "base/mac/scoped_nsobject.h"
+#include "base/strings/sys_string_conversions.h"
+#include "ios/web/net/request_group_util.h"
+#include "ios/web/public/web_client.h"
+
+namespace {
+// Returns true if given Request Group ID string contains only decimal digits.
+BOOL IsValidRequestGroupID(NSString* request_group_id) {
+ return [[NSCharacterSet decimalDigitCharacterSet] isSupersetOfSet:
+ [NSCharacterSet characterSetWithCharactersInString:request_group_id]];
+}
+} // namespace
+
+namespace web {
+
+void BuildAndRegisterUserAgentForUIWebView(NSString* request_group_id,
+ BOOL use_desktop_user_agent) {
+ DCHECK(!request_group_id || IsValidRequestGroupID(request_group_id));
+ DCHECK(web::GetWebClient());
+ std::string baseUserAgent = web::GetWebClient()->GetUserAgent(
+ use_desktop_user_agent);
+ web::RegisterUserAgentForUIWebView(
+ web::AddRequestGroupIDToUserAgent(base::SysUTF8ToNSString(baseUserAgent),
+ request_group_id));
+}
+
+void RegisterUserAgentForUIWebView(NSString* user_agent) {
+ [[NSUserDefaults standardUserDefaults] registerDefaults:@{
+ @"UserAgent" : user_agent
+ }];
+}
+
+} // namespace web
« no previous file with comments | « ios/web/ui_web_view_util.h ('k') | ios/web/ui_web_view_util_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698