OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/web/web_state/ui/crw_ui_web_view_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_ui_web_view_web_controller.h" |
6 | 6 |
7 #import "base/ios/ios_util.h" | |
7 #import "base/ios/ns_error_util.h" | 8 #import "base/ios/ns_error_util.h" |
8 #import "base/ios/weak_nsobject.h" | 9 #import "base/ios/weak_nsobject.h" |
9 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
10 #include "base/json/string_escape.h" | 11 #include "base/json/string_escape.h" |
11 #include "base/mac/bind_objc_block.h" | 12 #include "base/mac/bind_objc_block.h" |
12 #import "base/mac/scoped_nsobject.h" | 13 #import "base/mac/scoped_nsobject.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 // The core.js cannot pass messages back to obj-c if it is injected | 544 // The core.js cannot pass messages back to obj-c if it is injected |
544 // to |WEB_VIEW_DOCUMENT| because it does not support iframe creation used | 545 // to |WEB_VIEW_DOCUMENT| because it does not support iframe creation used |
545 // by core.js to communicate back. That functionality is only supported | 546 // by core.js to communicate back. That functionality is only supported |
546 // by |WEB_VIEW_HTML_DOCUMENT|. |WEB_VIEW_DOCUMENT| is used when displaying | 547 // by |WEB_VIEW_HTML_DOCUMENT|. |WEB_VIEW_DOCUMENT| is used when displaying |
547 // non-HTML contents (e.g. PDF documents). | 548 // non-HTML contents (e.g. PDF documents). |
548 - (web::WebViewDocumentType)webViewDocumentType { | 549 - (web::WebViewDocumentType)webViewDocumentType { |
549 // This happens during tests. | 550 // This happens during tests. |
550 if (!_uiWebView) { | 551 if (!_uiWebView) { |
551 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 552 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
552 } | 553 } |
553 NSString* documentType = | 554 |
554 [_uiWebView stringByEvaluatingJavaScriptFromString: | 555 if (base::ios::IsRunningOnIOS9OrLater()) { |
555 @"'' + document"]; | 556 // On iOS 9, evaluating '' + document always results in [object |
556 if ([documentType isEqualToString:@"[object HTMLDocument]"]) | 557 // HTMLDocument], even for PDFs. However, document.contentType is properly |
557 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; | 558 // defined. |
558 else if ([documentType isEqualToString:@"[object Document]"]) | 559 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.
| |
559 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 560 stringByEvaluatingJavaScriptFromString:@"document.contentType"]; |
561 return [self documentTypeFromMIMEType:documentType]; | |
562 } else { | |
563 // On iOS 8 and below, document.contentType is always undefined. Use this | |
564 // instead. | |
565 NSString* documentType = | |
566 [_uiWebView stringByEvaluatingJavaScriptFromString:@"'' + document"]; | |
567 if ([documentType isEqualToString:@"[object HTMLDocument]"]) | |
568 return web::WEB_VIEW_DOCUMENT_TYPE_HTML; | |
569 else if ([documentType isEqualToString:@"[object Document]"]) | |
570 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | |
571 } | |
572 | |
560 return web::WEB_VIEW_DOCUMENT_TYPE_UNKNOWN; | 573 return web::WEB_VIEW_DOCUMENT_TYPE_UNKNOWN; |
561 } | 574 } |
562 | 575 |
563 - (void)loadRequest:(NSMutableURLRequest*)request { | 576 - (void)loadRequest:(NSMutableURLRequest*)request { |
564 DCHECK(web::GetWebClient()); | 577 DCHECK(web::GetWebClient()); |
565 GURL requestURL = net::GURLWithNSURL(request.URL); | 578 GURL requestURL = net::GURLWithNSURL(request.URL); |
566 // If the request is for WebUI, add information to let the network stack | 579 // If the request is for WebUI, add information to let the network stack |
567 // access the requestGroupID. | 580 // access the requestGroupID. |
568 if (web::GetWebClient()->IsAppSpecificURL(requestURL)) { | 581 if (web::GetWebClient()->IsAppSpecificURL(requestURL)) { |
569 // Sub requests of a chrome:// page will not contain the user agent. | 582 // Sub requests of a chrome:// page will not contain the user agent. |
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1554 } | 1567 } |
1555 | 1568 |
1556 #pragma mark - | 1569 #pragma mark - |
1557 #pragma mark Testing methods | 1570 #pragma mark Testing methods |
1558 | 1571 |
1559 -(id<CRWRecurringTaskDelegate>)recurringTaskDelegate { | 1572 -(id<CRWRecurringTaskDelegate>)recurringTaskDelegate { |
1560 return _recurringTaskDelegate; | 1573 return _recurringTaskDelegate; |
1561 } | 1574 } |
1562 | 1575 |
1563 @end | 1576 @end |
OLD | NEW |