Commit b53a987a authored by sdefresne's avatar sdefresne Committed by Commit bot

[iOS] Upstream switches and flags controlling which WebView is used

Which of UIWebView and WKWebView to use can be controller by command line
flags, finch and availability (iOS version).

BUG=429756

Review URL: https://codereview.chromium.org/1144803002

Cr-Commit-Position: refs/heads/master@{#330383}
parent 5a47aeab
...@@ -12,9 +12,15 @@ namespace switches { ...@@ -12,9 +12,15 @@ namespace switches {
// all work out. // all work out.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Disables the use of WKWebView instead of UIWebView.
const char kDisableIOSWKWebView[] = "disable-wkwebview";
// Enables Open from Clipboard. // Enables Open from Clipboard.
const char kEnableIOSOpenFromClipboard[] = "enable-ios-open-from-clipboard"; const char kEnableIOSOpenFromClipboard[] = "enable-ios-open-from-clipboard";
// Enables the use of WKWebView instead of UIWebView.
const char kEnableIOSWKWebView[] = "enable-wkwebview";
// Defines the value in MB of the memory wedge to insert at cold launch. // Defines the value in MB of the memory wedge to insert at cold launch.
const char kIOSMemoryWedgeSize[] = "ios-memory-wedge-size-mb"; const char kIOSMemoryWedgeSize[] = "ios-memory-wedge-size-mb";
......
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
namespace switches { namespace switches {
extern const char kDisableIOSWKWebView[];
extern const char kEnableIOSOpenFromClipboard[]; extern const char kEnableIOSOpenFromClipboard[];
extern const char kEnableIOSWKWebView[];
extern const char kIOSMemoryWedgeSize[]; extern const char kIOSMemoryWedgeSize[];
} // namespace switches } // namespace switches
......
...@@ -18,6 +18,9 @@ bool IsAlertOnBackgroundUploadEnabled(); ...@@ -18,6 +18,9 @@ bool IsAlertOnBackgroundUploadEnabled();
// Returns true if the contents of the clipboard can be used for autocomplete. // Returns true if the contents of the clipboard can be used for autocomplete.
bool IsOpenFromClipboardEnabled(); bool IsOpenFromClipboardEnabled();
// Whether the app uses WKWebView instead of UIWebView.
bool IsWKWebViewEnabled();
// Returns the size in MB of the memory wedge to insert during a cold start. // Returns the size in MB of the memory wedge to insert during a cold start.
// If 0, no memory wedge should be inserted. // If 0, no memory wedge should be inserted.
size_t MemoryWedgeSizeInMB(); size_t MemoryWedgeSizeInMB();
......
...@@ -12,8 +12,10 @@ ...@@ -12,8 +12,10 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "components/variations/variations_associated_data.h" #include "components/variations/variations_associated_data.h"
#include "ios/chrome/browser/chrome_switches.h" #include "ios/chrome/browser/chrome_switches.h"
#include "ios/web/public/web_view_util.h"
namespace { namespace {
NSString* const kEnableAlertOnBackgroundUpload = NSString* const kEnableAlertOnBackgroundUpload =
...@@ -32,6 +34,28 @@ bool IsOpenFromClipboardEnabled() { ...@@ -32,6 +34,28 @@ bool IsOpenFromClipboardEnabled() {
return command_line->HasSwitch(switches::kEnableIOSOpenFromClipboard); return command_line->HasSwitch(switches::kEnableIOSOpenFromClipboard);
} }
bool IsWKWebViewEnabled() {
// If WKWebView isn't supported, don't activate the experiment at all. This
// avoids someone being slotted into the WKWebView bucket (and thus reporting
// as WKWebView), but actually running UIWebView.
if (!web::IsWKWebViewSupported())
return false;
std::string group_name =
base::FieldTrialList::FindFullName("IOSUseWKWebView");
// First check if the experimental flag is turned on.
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kEnableIOSWKWebView)) {
return true;
} else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) {
return false;
}
// Check if the finch experiment is turned on.
return StartsWithASCII(group_name, "Enabled", false);
}
size_t MemoryWedgeSizeInMB() { size_t MemoryWedgeSizeInMB() {
std::string wedge_size_string; std::string wedge_size_string;
......
// Copyright 2015 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.
#ifndef IOS_CHROME_BROWSER_WEB_WEB_VIEW_TYPE_UTIL_H_
#define IOS_CHROME_BROWSER_WEB_WEB_VIEW_TYPE_UTIL_H_
#include "ios/web/public/web_view_type.h"
// Utilities for getting the web view type to use in the application, or to
// wrap web view creation APIs with versions that automatically select the
// right type.
namespace web_view_type_util {
// Returns the type to use for all web views in the application.
web::WebViewType GetWebViewType();
} // web_view_type_util
#endif // IOS_CHROME_BROWSER_WEB_WEB_VIEW_TYPE_UTIL_H_
// Copyright 2015 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.
#include "ios/chrome/browser/web/web_view_type_util.h"
#include "ios/chrome/browser/experimental_flags.h"
namespace web_view_type_util {
web::WebViewType GetWebViewType() {
return experimental_flags::IsWKWebViewEnabled() ? web::WK_WEB_VIEW_TYPE
: web::UI_WEB_VIEW_TYPE;
}
} // namespace web_view_type_util
...@@ -271,6 +271,8 @@ ...@@ -271,6 +271,8 @@
'browser/updatable_config/updatable_dictionary.mm', 'browser/updatable_config/updatable_dictionary.mm',
'browser/web/dom_altering_lock.h', 'browser/web/dom_altering_lock.h',
'browser/web/dom_altering_lock.mm', 'browser/web/dom_altering_lock.mm',
'browser/web/web_view_type_util.h',
'browser/web/web_view_type_util.mm',
'browser/web_resource/ios_web_resource_service.cc', 'browser/web_resource/ios_web_resource_service.cc',
'browser/web_resource/ios_web_resource_service.h', 'browser/web_resource/ios_web_resource_service.h',
'browser/xcallback_parameters.h', 'browser/xcallback_parameters.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment