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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/web/error_page_content.mm
diff --git a/ios/chrome/browser/web/error_page_content.mm b/ios/chrome/browser/web/error_page_content.mm
new file mode 100644
index 0000000000000000000000000000000000000000..fbd846d316c1c82a740d820beddd0463048d2cf7
--- /dev/null
+++ b/ios/chrome/browser/web/error_page_content.mm
@@ -0,0 +1,91 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/web/error_page_content.h"
+
+#include <memory>
+
+#import "base/ios/ns_error_util.h"
+#include "base/strings/sys_string_conversions.h"
+#include "base/values.h"
+#include "components/error_page/common/error_page_params.h"
+#include "components/error_page/common/localized_error.h"
+#include "components/grit/components_resources.h"
+#include "ios/chrome/browser/application_context.h"
+#include "ios/web/public/referrer.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/page_transition_types.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/webui/jstemplate_builder.h"
+#include "url/gurl.h"
+
+@implementation ErrorPageContent
+
+#pragma mark -
+#pragma mark CRWNativeContent methods
+
+// Override StaticHtmlNativeContent method to always force error pages to
+// try loading the URL again, because the error might have been fixed.
+- (void)reload {
+ // Because we don't have the original page transition at this point, just
+ // use PAGE_TRANSITION_TYPED. We can revisit if this causes problems.
+ [super loadURL:[self url]
+ referrer:web::Referrer()
+ transition:ui::PAGE_TRANSITION_TYPED
+ rendererInitiated:YES];
+}
+
+- (void)generateHtml:(HtmlCallback)callback {
+ callback(html_.get());
+}
+
+- (id)initWithLoader:(id<UrlLoader>)loader
+ browserState:(web::BrowserState*)browserState
+ url:(const GURL&)url
+ error:(NSError*)error
+ isPost:(BOOL)isPost
+ isIncognito:(BOOL)isIncognito {
+ NSString* badURLString =
+ [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey];
+ NSError* originalError = base::ios::GetFinalUnderlyingErrorFromError(error);
+ NSString* errorDomain = nil;
+ int errorCode = 0;
+
+ if (originalError) {
+ errorDomain = [originalError domain];
+ errorCode = [originalError code];
+ } else {
+ errorDomain = [error domain];
+ errorCode = [error code];
+ }
+ DCHECK(errorCode != 0);
+
+ base::DictionaryValue errorStrings;
+ error_page::LocalizedError::GetStrings(
+ errorCode, base::SysNSStringToUTF8(errorDomain),
+ GURL(base::SysNSStringToUTF16(badURLString)), isPost, false, false,
+ isIncognito, GetApplicationContext()->GetApplicationLocale(), nullptr,
+ &errorStrings);
+
+ ui::ScaleFactor scaleFactor =
+ ResourceBundle::GetSharedInstance().GetMaxScaleFactor();
+
+ const base::StringPiece templateHTML(
+ ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
+ IDR_NET_ERROR_HTML, scaleFactor));
+ if (templateHTML.empty())
+ NOTREACHED() << "unable to load template. ID: " << IDR_NET_ERROR_HTML;
+ std::string errorHTML = webui::GetTemplatesHtml(
+ templateHTML, &errorStrings, "t" /* IDR_NET_ERROR_HTML root id */);
+ html_.reset([base::SysUTF8ToNSString(errorHTML) retain]);
+
+ base::scoped_nsobject<StaticHtmlViewController> HTMLViewController(
+ [[StaticHtmlViewController alloc] initWithGenerator:self
+ browserState:browserState]);
+ return [super initWithLoader:loader
+ staticHTMLViewController:HTMLViewController
+ URL:url];
+}
+
+@end
« 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