| 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 8888ca50ed4dc63499cac7b99af2524868fb9742..9bc07e431b9b49e2378c5904ca0f659c30040ff4 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* MIMEType = [_uiWebView
|
| + stringByEvaluatingJavaScriptFromString:@"document.contentType"];
|
| + return [self documentTypeFromMIMEType:MIMEType];
|
| + } 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;
|
| }
|
|
|
|
|