OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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. |
| 4 |
| 5 #include "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h" |
| 6 |
| 7 #include "base/i18n/rtl.h" |
| 8 #include "base/ios/weak_nsobject.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/mac/bundle_locations.h" |
| 11 #include "base/mac/foundation_util.h" |
| 12 #include "base/mac/objc_property_releaser.h" |
| 13 #include "base/mac/scoped_nsobject.h" |
| 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "components/metrics/metrics_pref_names.h" |
| 16 #include "components/metrics/metrics_reporting_default_state.h" |
| 17 #include "components/prefs/pref_service.h" |
| 18 #include "ios/chrome/browser/application_context.h" |
| 19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 20 #include "ios/chrome/browser/first_run/first_run_configuration.h" |
| 21 #include "ios/chrome/browser/tabs/tab_model.h" |
| 22 #include "ios/chrome/browser/ui/fancy_ui/primary_action_button.h" |
| 23 #include "ios/chrome/browser/ui/file_locations.h" |
| 24 #import "ios/chrome/browser/ui/first_run/first_run_chrome_signin_view_controller
.h" |
| 25 #include "ios/chrome/browser/ui/first_run/first_run_util.h" |
| 26 #include "ios/chrome/browser/ui/first_run/static_file_view_controller.h" |
| 27 #import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view.h" |
| 28 #include "ios/chrome/browser/ui/ui_util.h" |
| 29 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 30 #include "ios/chrome/common/string_util.h" |
| 31 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 32 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 33 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" |
| 34 #include "ui/base/l10n/l10n_util.h" |
| 35 |
| 36 NSString* const kUMAMetricsButtonAccessibilityIdentifier = |
| 37 @"UMAMetricsButtonAccessibilityIdentifier"; |
| 38 |
| 39 namespace { |
| 40 |
| 41 const CGFloat kFadeOutAnimationDuration = 0.16f; |
| 42 |
| 43 // Default value for metrics reporting state. "YES" corresponding to "opt-out" |
| 44 // state. |
| 45 const BOOL kDefaultStatsCheckboxValue = YES; |
| 46 } |
| 47 |
| 48 @interface WelcomeToChromeViewController ()<WelcomeToChromeViewDelegate> { |
| 49 ios::ChromeBrowserState* browserState_; // weak |
| 50 TabModel* tabModel_; // weak |
| 51 base::mac::ObjCPropertyReleaser |
| 52 propertyReleaser_WelcomeToChromeViewController_; |
| 53 } |
| 54 |
| 55 // The animation which occurs at launch has run. |
| 56 @property(nonatomic, assign) BOOL ranLaunchAnimation; |
| 57 |
| 58 @end |
| 59 |
| 60 @implementation WelcomeToChromeViewController |
| 61 |
| 62 @synthesize ranLaunchAnimation = _ranLaunchAnimation; |
| 63 |
| 64 + (BOOL)defaultStatsCheckboxValue { |
| 65 // Record metrics reporting as opt-in/opt-out only once. |
| 66 static dispatch_once_t once; |
| 67 dispatch_once(&once, ^{ |
| 68 metrics::RecordMetricsReportingDefaultState( |
| 69 GetApplicationContext()->GetLocalState(), |
| 70 kDefaultStatsCheckboxValue ? metrics::EnableMetricsDefault::OPT_OUT |
| 71 : metrics::EnableMetricsDefault::OPT_IN); |
| 72 }); |
| 73 return kDefaultStatsCheckboxValue; |
| 74 } |
| 75 |
| 76 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
| 77 tabModel:(TabModel*)tabModel { |
| 78 DCHECK(browserState); |
| 79 DCHECK(tabModel); |
| 80 self = [super initWithNibName:nil bundle:nil]; |
| 81 if (self) { |
| 82 browserState_ = browserState; |
| 83 tabModel_ = tabModel; |
| 84 propertyReleaser_WelcomeToChromeViewController_.Init( |
| 85 self, [WelcomeToChromeViewController class]); |
| 86 } |
| 87 return self; |
| 88 } |
| 89 |
| 90 - (instancetype)initWithNibName:(nullable NSString*)nibNameOrNil |
| 91 bundle:(nullable NSBundle*)nibBundleOrNil { |
| 92 NOTREACHED(); |
| 93 return nil; |
| 94 } |
| 95 |
| 96 - (instancetype)initWithCoder:(nonnull NSCoder*)aDecoder { |
| 97 NOTREACHED(); |
| 98 return nil; |
| 99 } |
| 100 |
| 101 - (void)loadView { |
| 102 base::scoped_nsobject<WelcomeToChromeView> welcomeToChromeView( |
| 103 [[WelcomeToChromeView alloc] initWithFrame:CGRectZero]); |
| 104 [welcomeToChromeView setDelegate:self]; |
| 105 [welcomeToChromeView |
| 106 setCheckBoxSelected:[[self class] defaultStatsCheckboxValue]]; |
| 107 self.view = welcomeToChromeView; |
| 108 } |
| 109 |
| 110 - (void)viewDidLoad { |
| 111 [super viewDidLoad]; |
| 112 [self.navigationController setNavigationBarHidden:YES]; |
| 113 } |
| 114 |
| 115 - (void)viewDidLayoutSubviews { |
| 116 [super viewDidLayoutSubviews]; |
| 117 if (self.ranLaunchAnimation) |
| 118 return; |
| 119 WelcomeToChromeView* view = |
| 120 base::mac::ObjCCastStrict<WelcomeToChromeView>(self.view); |
| 121 [view runLaunchAnimation]; |
| 122 self.ranLaunchAnimation = YES; |
| 123 } |
| 124 |
| 125 - (BOOL)prefersStatusBarHidden { |
| 126 return YES; |
| 127 } |
| 128 |
| 129 - (NSURL*)newTermsOfServiceUrl { |
| 130 std::string tos = GetTermsOfServicePath(); |
| 131 NSString* path = [[base::mac::FrameworkBundle() bundlePath] |
| 132 stringByAppendingPathComponent:base::SysUTF8ToNSString(tos)]; |
| 133 base::scoped_nsobject<NSURLComponents> components( |
| 134 [[NSURLComponents alloc] init]); |
| 135 [components setScheme:@"file"]; |
| 136 [components setHost:@""]; |
| 137 [components setPath:path]; |
| 138 return [[components URL] retain]; |
| 139 } |
| 140 |
| 141 // Displays the file at the given URL in a StaticFileViewController. |
| 142 - (void)openStaticFileWithURL:(NSURL*)url title:(NSString*)title { |
| 143 base::scoped_nsobject<StaticFileViewController> staticViewController( |
| 144 [[StaticFileViewController alloc] initWithBrowserState:browserState_ |
| 145 URL:url]); |
| 146 [staticViewController setTitle:title]; |
| 147 [self.navigationController pushViewController:staticViewController |
| 148 animated:YES]; |
| 149 } |
| 150 |
| 151 #pragma mark - WelcomeToChromeViewDelegate |
| 152 |
| 153 - (void)welcomeToChromeViewDidTapTOSLink:(WelcomeToChromeView*)view { |
| 154 NSString* title = l10n_util::GetNSString(IDS_IOS_FIRSTRUN_TERMS_TITLE); |
| 155 base::scoped_nsobject<NSURL> tosUrl([self newTermsOfServiceUrl]); |
| 156 [self openStaticFileWithURL:tosUrl title:title]; |
| 157 } |
| 158 |
| 159 - (void)welcomeToChromeViewDidTapOKButton:(WelcomeToChromeView*)view { |
| 160 GetApplicationContext()->GetLocalState()->SetBoolean( |
| 161 metrics::prefs::kMetricsReportingEnabled, view.checkBoxSelected); |
| 162 |
| 163 base::scoped_nsobject<FirstRunConfiguration> firstRunConfig( |
| 164 [[FirstRunConfiguration alloc] init]); |
| 165 bool hasSSOAccounts = ios::GetChromeBrowserProvider() |
| 166 ->GetChromeIdentityService() |
| 167 ->HasIdentities(); |
| 168 [firstRunConfig setHasSSOAccount:hasSSOAccounts]; |
| 169 base::scoped_nsobject<FirstRunChromeSigninViewController> signInController( |
| 170 [[FirstRunChromeSigninViewController alloc] |
| 171 initWithBrowserState:browserState_ |
| 172 tabModel:tabModel_ |
| 173 firstRunConfig:firstRunConfig |
| 174 signInIdentity:nil]); |
| 175 |
| 176 CATransition* transition = [CATransition animation]; |
| 177 transition.duration = kFadeOutAnimationDuration; |
| 178 transition.type = kCATransitionFade; |
| 179 [self.navigationController.view.layer addAnimation:transition |
| 180 forKey:kCATransition]; |
| 181 [self.navigationController pushViewController:signInController animated:NO]; |
| 182 } |
| 183 |
| 184 @end |
OLD | NEW |