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

Unified Diff: ios/web/web_state/ui/crw_ui_web_view_web_controller.mm

Issue 1458703004: Fixes document type detection on iOS 9. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments 1 Created 5 years, 1 month 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
Index: ios/web/web_state/ui/crw_ui_web_view_web_controller.mm
diff --git a/ios/web/web_state/ui/crw_ui_web_view_web_controller.mm b/ios/web/web_state/ui/crw_ui_web_view_web_controller.mm
index 5efb858d0e6f8282bb24ef10662775e5e9ee5150..48b6431003f9c07301cc7d192ae315040fa5f3c8 100644
--- a/ios/web/web_state/ui/crw_ui_web_view_web_controller.mm
+++ b/ios/web/web_state/ui/crw_ui_web_view_web_controller.mm
@@ -4,6 +4,7 @@
#import "ios/web/web_state/ui/crw_ui_web_view_web_controller.h"
+#import "base/ios/ios_util.h"
#import "base/ios/ns_error_util.h"
#import "base/ios/weak_nsobject.h"
#include "base/json/json_reader.h"
@@ -550,13 +551,25 @@ const size_t kMaxMessageQueueSize = 262144;
if (!_uiWebView) {
return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
}
- NSString* documentType =
- [_uiWebView stringByEvaluatingJavaScriptFromString:
- @"'' + document"];
- if ([documentType isEqualToString:@"[object HTMLDocument]"])
- return web::WEB_VIEW_DOCUMENT_TYPE_HTML;
- else if ([documentType isEqualToString:@"[object Document]"])
- return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
+
+ if (base::ios::IsRunningOnIOS9OrLater()) {
+ // On iOS 9, evaluating '' + document always results in [object
+ // HTMLDocument], even for PDFs. However, document.contentType is properly
+ // defined.
+ NSString* documentType = [_uiWebView
Eugene But (OOO till 7-30) 2015/11/19 16:29:01 s/documentType/MIMEType
stkhapugin 2015/11/20 10:50:43 Done.
+ stringByEvaluatingJavaScriptFromString:@"document.contentType"];
+ return [self documentTypeFromMIMEType:documentType];
+ } else {
+ // On iOS 8 and below, document.contentType is always undefined. Use this
+ // instead.
+ NSString* documentType =
+ [_uiWebView stringByEvaluatingJavaScriptFromString:@"'' + document"];
+ if ([documentType isEqualToString:@"[object HTMLDocument]"])
+ return web::WEB_VIEW_DOCUMENT_TYPE_HTML;
+ else if ([documentType isEqualToString:@"[object Document]"])
+ return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
+ }
+
return web::WEB_VIEW_DOCUMENT_TYPE_UNKNOWN;
}
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_web_controller.mm » ('j') | ios/web/web_state/ui/crw_web_controller.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698