1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/web/public/web_view_creation_util.h"
7 #include <Foundation/Foundation.h>
8 #include <sys/sysctl.h>
10 #include "base/ios/ios_util.h"
11 #include "base/logging.h"
12 #import "ios/web/public/browsing_data_partition.h"
13 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h"
14 #import "ios/web/web_state/web_view_internal_creation_util.h"
18 bool IsWKWebViewSupported() {
19 // WKWebView is available starting from iOS8.
20 if (!base::ios::IsRunningOnIOS8OrLater())
23 // WKWebView does not work with 32-bit binaries running on 64-bit hardware.
25 #if !defined(__LP64__)
26 NSString* simulator_model_id =
27 [[NSProcessInfo processInfo] environment][@"SIMULATOR_MODEL_IDENTIFIER"];
28 // For simulator it's not possible to query hw.cpu64bit_capable value as the
29 // function will return information for mac hardware rather than simulator.
30 if (simulator_model_id) {
31 // A set of known 32-bit simulators that are also iOS 8 compatible.
32 // (taken from iOS 8.1 SDK simulators list).
33 NSSet* known_32_bit_devices = [NSSet
34 setWithArray:@[ @"iPad2,1", @"iPad3,1", @"iPhone4,1", @"iPhone5,1" ]];
35 return [known_32_bit_devices containsObject:simulator_model_id];
37 uint32_t cpu64bit_capable = 0;
38 size_t sizes = sizeof(cpu64bit_capable);
39 sysctlbyname("hw.cpu64bit_capable", &cpu64bit_capable, &sizes, NULL, 0);
40 return !cpu64bit_capable;
46 WKWebView* CreateWKWebView(CGRect frame, BrowserState* browser_state) {
47 DCHECK(browser_state);
49 WKWebViewConfigurationProvider& config_provider =
50 WKWebViewConfigurationProvider::FromBrowserState(browser_state);
51 return CreateWKWebView(frame, config_provider.GetWebViewConfiguration(),