OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/chrome/browser/web/error_page_generator.h" | 5 #import "ios/chrome/browser/web/error_page_generator.h" |
6 | 6 |
7 #import "base/ios/ns_error_util.h" | 7 #import "base/ios/ns_error_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #import "base/mac/scoped_nsobject.h" | |
10 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
11 #include "base/values.h" | 10 #include "base/values.h" |
12 #include "components/error_page/common/error_page_params.h" | 11 #include "components/error_page/common/error_page_params.h" |
13 #include "components/error_page/common/localized_error.h" | 12 #include "components/error_page/common/localized_error.h" |
14 #include "components/grit/components_resources.h" | 13 #include "components/grit/components_resources.h" |
15 #include "ios/chrome/browser/application_context.h" | 14 #include "ios/chrome/browser/application_context.h" |
16 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/base/resource/scale_factor.h" | 17 #include "ui/base/resource/scale_factor.h" |
19 #include "ui/base/webui/jstemplate_builder.h" | 18 #include "ui/base/webui/jstemplate_builder.h" |
20 #include "url/gurl.h" | 19 #include "url/gurl.h" |
21 | 20 |
| 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 22 #error "This file requires ARC support." |
| 23 #endif |
| 24 |
22 @implementation ErrorPageGenerator { | 25 @implementation ErrorPageGenerator { |
23 // Stores the HTML generated from the NSError in the initializer. | 26 // Stores the HTML generated from the NSError in the initializer. |
24 base::scoped_nsobject<NSString> html_; | 27 NSString* _HTML; |
25 } | 28 } |
26 | 29 |
27 - (instancetype)initWithError:(NSError*)error | 30 - (instancetype)initWithError:(NSError*)error |
28 isPost:(BOOL)isPost | 31 isPost:(BOOL)isPost |
29 isIncognito:(BOOL)isIncognito { | 32 isIncognito:(BOOL)isIncognito { |
30 self = [super init]; | 33 self = [super init]; |
31 if (self) { | 34 if (self) { |
32 NSString* badURLSpec = error.userInfo[NSURLErrorFailingURLStringErrorKey]; | 35 NSString* badURLSpec = error.userInfo[NSURLErrorFailingURLStringErrorKey]; |
33 NSError* originalError = base::ios::GetFinalUnderlyingErrorFromError(error); | 36 NSError* originalError = base::ios::GetFinalUnderlyingErrorFromError(error); |
34 NSString* errorDomain = nil; | 37 NSString* errorDomain = nil; |
(...skipping 18 matching lines...) Expand all Loading... |
53 ui::ScaleFactor scaleFactor = | 56 ui::ScaleFactor scaleFactor = |
54 ResourceBundle::GetSharedInstance().GetMaxScaleFactor(); | 57 ResourceBundle::GetSharedInstance().GetMaxScaleFactor(); |
55 | 58 |
56 const base::StringPiece templateHTML( | 59 const base::StringPiece templateHTML( |
57 ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( | 60 ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( |
58 IDR_NET_ERROR_HTML, scaleFactor)); | 61 IDR_NET_ERROR_HTML, scaleFactor)); |
59 if (templateHTML.empty()) | 62 if (templateHTML.empty()) |
60 NOTREACHED() << "unable to load template. ID: " << IDR_NET_ERROR_HTML; | 63 NOTREACHED() << "unable to load template. ID: " << IDR_NET_ERROR_HTML; |
61 std::string errorHTML = webui::GetTemplatesHtml( | 64 std::string errorHTML = webui::GetTemplatesHtml( |
62 templateHTML, &errorStrings, "t" /* IDR_NET_ERROR_HTML root id */); | 65 templateHTML, &errorStrings, "t" /* IDR_NET_ERROR_HTML root id */); |
63 html_.reset([base::SysUTF8ToNSString(errorHTML) retain]); | 66 _HTML = base::SysUTF8ToNSString(errorHTML); |
64 } | 67 } |
65 return self; | 68 return self; |
66 } | 69 } |
67 | 70 |
68 #pragma mark - HtmlGenerator | 71 #pragma mark - HtmlGenerator |
69 | 72 |
70 - (void)generateHtml:(HtmlCallback)callback { | 73 - (void)generateHtml:(HtmlCallback)callback { |
71 callback(html_.get()); | 74 callback(_HTML); |
72 } | 75 } |
73 | 76 |
74 @end | 77 @end |
OLD | NEW |