1 // Copyright 2015 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 // This file can be empty. Its purpose is to contain the relatively short lived
6 // definitions required for experimental flags.
8 #include "ios/chrome/browser/experimental_flags.h"
10 #import <Foundation/Foundation.h>
14 #include "base/command_line.h"
15 #include "base/strings/string_util.h"
16 #include "components/enhanced_bookmarks/enhanced_bookmark_features.h"
17 #include "components/variations/variations_associated_data.h"
18 #include "ios/chrome/browser/chrome_switches.h"
19 #include "ios/web/public/web_view_creation_util.h"
22 NSString* const kEnableAlertOnBackgroundUpload =
23 @"EnableAlertsOnBackgroundUpload";
24 NSString* const kEnableBookmarkRefreshImageOnEachVisit =
25 @"EnableBookmarkRefreshImageOnEachVisit";
26 NSString* const kEnableViewCopyPasswords = @"EnableViewCopyPasswords";
29 namespace experimental_flags {
31 bool IsAlertOnBackgroundUploadEnabled() {
32 return [[NSUserDefaults standardUserDefaults]
33 boolForKey:kEnableAlertOnBackgroundUpload];
36 bool IsExternalURLBlockingEnabled() {
37 std::string group_name =
38 base::FieldTrialList::FindFullName("IOSBlockUnpromptedExternalURLs");
40 // Check if the experimental flag is turned on.
41 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
42 if (command_line->HasSwitch(
43 switches::kEnableIOSBlockUnpromptedExternalURLs)) {
45 } else if (command_line->HasSwitch(
46 switches::kDisableIOSBlockUnpromptedExternalURLs)) {
50 // Check if the finch experiment is turned on.
51 return !base::StartsWith(group_name, "Disabled",
52 base::CompareCase::INSENSITIVE_ASCII);
55 bool IsBookmarkCollectionEnabled() {
56 return enhanced_bookmarks::IsEnhancedBookmarksEnabled();
59 bool IsBookmarkImageFetchingOnVisitEnabled() {
60 if (!IsBookmarkCollectionEnabled())
63 NSUserDefaults* user_defaults = [NSUserDefaults standardUserDefaults];
64 if ([user_defaults boolForKey:kEnableBookmarkRefreshImageOnEachVisit])
67 const char kFieldTrialName[] = "EnhancedBookmarks";
68 std::string enable_fetching = variations::GetVariationParamValue(
69 kFieldTrialName, "EnableImagesFetchingOnVisit");
70 return !enable_fetching.empty();
73 bool IsWKWebViewEnabled() {
74 // If WKWebView isn't supported, don't activate the experiment at all. This
75 // avoids someone being slotted into the WKWebView bucket (and thus reporting
76 // as WKWebView), but actually running UIWebView.
77 if (!web::IsWKWebViewSupported())
80 std::string group_name =
81 base::FieldTrialList::FindFullName("IOSUseWKWebView");
83 // First check if the experimental flag is turned on.
84 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
85 if (command_line->HasSwitch(switches::kEnableIOSWKWebView)) {
87 } else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) {
91 // Check if the finch experiment is turned on.
92 return base::StartsWith(group_name, "Enabled",
93 base::CompareCase::INSENSITIVE_ASCII);
96 bool AreKeyboardCommandsEnabled() {
97 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
98 switches::kDisableKeyboardCommands);
101 bool IsViewCopyPasswordsEnabled() {
102 NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults]
103 objectForKey:kEnableViewCopyPasswords];
104 if ([viewCopyPasswordFlag isEqualToString:@"Enabled"])
109 } // namespace experimental_flags