Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: ios/chrome/browser/web/error_page_generator.mm

Issue 2704383003: Error pages: Break retain cycle NativeContent/StaticHTMLViewController (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/web/error_page_generator.h"
6
7 #import "base/ios/ns_error_util.h"
8 #include "base/logging.h"
9 #import "base/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h"
11 #include "base/values.h"
12 #include "components/error_page/common/error_page_params.h"
13 #include "components/error_page/common/localized_error.h"
14 #include "components/grit/components_resources.h"
15 #include "ios/chrome/browser/application_context.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/base/resource/scale_factor.h"
19 #include "ui/base/webui/jstemplate_builder.h"
20 #include "url/gurl.h"
21
22 @implementation ErrorPageGenerator {
23 // Stores the HTML generated from the NSError in the initializer.
24 base::scoped_nsobject<NSString> html_;
25 }
26
27 - (instancetype)initWithError:(NSError*)error
28 isPost:(BOOL)isPost
29 isIncognito:(BOOL)isIncognito {
30 self = [super init];
31 if (self) {
32 NSString* badURLSpec = error.userInfo[NSURLErrorFailingURLStringErrorKey];
33 NSError* originalError = base::ios::GetFinalUnderlyingErrorFromError(error);
34 NSString* errorDomain = nil;
35 int errorCode = 0;
36
37 if (originalError) {
38 errorDomain = [originalError domain];
39 errorCode = [originalError code];
40 } else {
41 errorDomain = [error domain];
42 errorCode = [error code];
43 }
44 DCHECK(errorCode != 0);
45
46 base::DictionaryValue errorStrings;
47 error_page::LocalizedError::GetStrings(
48 errorCode, base::SysNSStringToUTF8(errorDomain),
49 GURL(base::SysNSStringToUTF16(badURLSpec)), isPost, false, false,
50 isIncognito, GetApplicationContext()->GetApplicationLocale(), nullptr,
51 &errorStrings);
52
53 ui::ScaleFactor scaleFactor =
54 ResourceBundle::GetSharedInstance().GetMaxScaleFactor();
55
56 const base::StringPiece templateHTML(
57 ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
58 IDR_NET_ERROR_HTML, scaleFactor));
59 if (templateHTML.empty())
60 NOTREACHED() << "unable to load template. ID: " << IDR_NET_ERROR_HTML;
61 std::string errorHTML = webui::GetTemplatesHtml(
62 templateHTML, &errorStrings, "t" /* IDR_NET_ERROR_HTML root id */);
63 html_.reset([base::SysUTF8ToNSString(errorHTML) retain]);
64 }
65 return self;
66 }
67
68 #pragma mark - HtmlGenerator
69
70 - (void)generateHtml:(HtmlCallback)callback {
71 callback(html_.get());
72 }
73
74 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/error_page_generator.h ('k') | ios/chrome/browser/web/error_page_generator_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698