blob: 35c634798b7279c0a5779c8ed7f24b230929c74b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
|