OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #import "ios/chrome/browser/ui/authentication/authentication_ui_util.h" |
| 6 |
| 7 #include "base/format_macros.h" |
| 8 #include "base/logging.h" |
| 9 #include "components/strings/grit/components_strings.h" |
| 10 #include "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h" |
| 11 #include "ios/chrome/grit/ios_strings.h" |
| 12 #include "ui/base/l10n/l10n_util.h" |
| 13 |
| 14 namespace ios_internal { |
| 15 |
| 16 AlertCoordinator* ErrorCoordinator(NSError* error, |
| 17 ProceduralBlock dismissAction, |
| 18 UIViewController* viewController) { |
| 19 DCHECK(error); |
| 20 |
| 21 AlertCoordinator* alertCoordinator = |
| 22 ErrorCoordinatorNoItem(error, viewController); |
| 23 |
| 24 NSString* okButtonLabel = l10n_util::GetNSString(IDS_OK); |
| 25 [alertCoordinator addItemWithTitle:okButtonLabel |
| 26 action:dismissAction |
| 27 style:UIAlertActionStyleDefault]; |
| 28 |
| 29 [alertCoordinator setCancelAction:dismissAction]; |
| 30 |
| 31 return alertCoordinator; |
| 32 } |
| 33 |
| 34 AlertCoordinator* ErrorCoordinatorNoItem(NSError* error, |
| 35 UIViewController* viewController) { |
| 36 DCHECK(error); |
| 37 |
| 38 NSString* title = l10n_util::GetNSString( |
| 39 IDS_IOS_SYNC_AUTHENTICATION_ERROR_ALERT_VIEW_TITLE); |
| 40 NSString* errorMessage; |
| 41 if ([NSURLErrorDomain isEqualToString:error.domain] && |
| 42 error.code == kCFURLErrorCannotConnectToHost) { |
| 43 errorMessage = |
| 44 l10n_util::GetNSString(IDS_IOS_SYNC_ERROR_INTERNET_DISCONNECTED); |
| 45 } else if ([error.userInfo objectForKey:NSLocalizedDescriptionKey]) { |
| 46 errorMessage = [NSString stringWithFormat:@"%@ (%@ %" PRIdNS ")", |
| 47 error.localizedDescription, |
| 48 error.domain, error.code]; |
| 49 } else { |
| 50 // If the error has no NSLocalizedDescriptionKey in its user info, then |
| 51 // |error.localizedDescription| contains the error domain and code. |
| 52 errorMessage = error.localizedDescription; |
| 53 } |
| 54 AlertCoordinator* alertCoordinator = [[[AlertCoordinator alloc] |
| 55 initWithBaseViewController:viewController |
| 56 title:title |
| 57 message:errorMessage] autorelease]; |
| 58 return alertCoordinator; |
| 59 } |
| 60 |
| 61 } // namespace ios_internal |
OLD | NEW |