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

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

Issue 2580333003: Upstream Chrome on iOS source code [10/11]. (Closed)
Patch Set: Created 4 years 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 2012 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_content.h"
6
7 #include <memory>
8
9 #import "base/ios/ns_error_util.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 "ios/web/public/referrer.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/page_transition_types.h"
19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/base/webui/jstemplate_builder.h"
21 #include "url/gurl.h"
22
23 @implementation ErrorPageContent
24
25 #pragma mark -
26 #pragma mark CRWNativeContent methods
27
28 // Override StaticHtmlNativeContent method to always force error pages to
29 // try loading the URL again, because the error might have been fixed.
30 - (void)reload {
31 // Because we don't have the original page transition at this point, just
32 // use PAGE_TRANSITION_TYPED. We can revisit if this causes problems.
33 [super loadURL:[self url]
34 referrer:web::Referrer()
35 transition:ui::PAGE_TRANSITION_TYPED
36 rendererInitiated:YES];
37 }
38
39 - (void)generateHtml:(HtmlCallback)callback {
40 callback(html_.get());
41 }
42
43 - (id)initWithLoader:(id<UrlLoader>)loader
44 browserState:(web::BrowserState*)browserState
45 url:(const GURL&)url
46 error:(NSError*)error
47 isPost:(BOOL)isPost
48 isIncognito:(BOOL)isIncognito {
49 NSString* badURLString =
50 [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey];
51 NSError* originalError = base::ios::GetFinalUnderlyingErrorFromError(error);
52 NSString* errorDomain = nil;
53 int errorCode = 0;
54
55 if (originalError) {
56 errorDomain = [originalError domain];
57 errorCode = [originalError code];
58 } else {
59 errorDomain = [error domain];
60 errorCode = [error code];
61 }
62 DCHECK(errorCode != 0);
63
64 base::DictionaryValue errorStrings;
65 error_page::LocalizedError::GetStrings(
66 errorCode, base::SysNSStringToUTF8(errorDomain),
67 GURL(base::SysNSStringToUTF16(badURLString)), isPost, false, false,
68 isIncognito, GetApplicationContext()->GetApplicationLocale(), nullptr,
69 &errorStrings);
70
71 ui::ScaleFactor scaleFactor =
72 ResourceBundle::GetSharedInstance().GetMaxScaleFactor();
73
74 const base::StringPiece templateHTML(
75 ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
76 IDR_NET_ERROR_HTML, scaleFactor));
77 if (templateHTML.empty())
78 NOTREACHED() << "unable to load template. ID: " << IDR_NET_ERROR_HTML;
79 std::string errorHTML = webui::GetTemplatesHtml(
80 templateHTML, &errorStrings, "t" /* IDR_NET_ERROR_HTML root id */);
81 html_.reset([base::SysUTF8ToNSString(errorHTML) retain]);
82
83 base::scoped_nsobject<StaticHtmlViewController> HTMLViewController(
84 [[StaticHtmlViewController alloc] initWithGenerator:self
85 browserState:browserState]);
86 return [super initWithLoader:loader
87 staticHTMLViewController:HTMLViewController
88 URL:url];
89 }
90
91 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/error_page_content.h ('k') | ios/chrome/browser/web/error_page_content_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698