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; |
} |