Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ios / chrome / browser / experimental_flags.mm
blob401c9287b29fd51fe3943dabebe075f2fd1b8de0
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>
12 #include <string>
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"
21 namespace {
22 NSString* const kEnableAlertOnBackgroundUpload =
23     @"EnableAlertsOnBackgroundUpload";
24 NSString* const kEnableBookmarkRefreshImageOnEachVisit =
25     @"EnableBookmarkRefreshImageOnEachVisit";
26 NSString* const kEnableViewCopyPasswords = @"EnableViewCopyPasswords";
27 }  // namespace
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)) {
44     return true;
45   } else if (command_line->HasSwitch(
46                  switches::kDisableIOSBlockUnpromptedExternalURLs)) {
47     return false;
48   }
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())
61     return false;
63   NSUserDefaults* user_defaults = [NSUserDefaults standardUserDefaults];
64   if ([user_defaults boolForKey:kEnableBookmarkRefreshImageOnEachVisit])
65     return true;
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())
78     return false;
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)) {
86     return true;
87   } else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) {
88     return false;
89   }
91   // Check if the finch experiment is turned on.
92   return base::StartsWith(group_name, "Enabled",
93                           base::CompareCase::INSENSITIVE_ASCII);
96 bool IsViewCopyPasswordsEnabled() {
97   NSString* viewCopyPasswordFlag = [[NSUserDefaults standardUserDefaults]
98       objectForKey:kEnableViewCopyPasswords];
99   if ([viewCopyPasswordFlag isEqualToString:@"Enabled"])
100     return true;
101   return false;
104 }  // namespace experimental_flags