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

Side by Side Diff: ios/web/web_state/ui/crw_ui_web_view_web_controller.mm

Issue 1491263002: Revert of Fixes document type detection on iOS 9. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2564
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #import "base/ios/ns_error_util.h" 7 #import "base/ios/ns_error_util.h"
9 #import "base/ios/weak_nsobject.h" 8 #import "base/ios/weak_nsobject.h"
10 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
11 #include "base/json/string_escape.h" 10 #include "base/json/string_escape.h"
12 #include "base/mac/bind_objc_block.h" 11 #include "base/mac/bind_objc_block.h"
13 #import "base/mac/scoped_nsobject.h" 12 #import "base/mac/scoped_nsobject.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
16 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
17 #include "base/strings/sys_string_conversions.h" 16 #include "base/strings/sys_string_conversions.h"
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 // The core.js cannot pass messages back to obj-c if it is injected 543 // The core.js cannot pass messages back to obj-c if it is injected
545 // to |WEB_VIEW_DOCUMENT| because it does not support iframe creation used 544 // to |WEB_VIEW_DOCUMENT| because it does not support iframe creation used
546 // by core.js to communicate back. That functionality is only supported 545 // by core.js to communicate back. That functionality is only supported
547 // by |WEB_VIEW_HTML_DOCUMENT|. |WEB_VIEW_DOCUMENT| is used when displaying 546 // by |WEB_VIEW_HTML_DOCUMENT|. |WEB_VIEW_DOCUMENT| is used when displaying
548 // non-HTML contents (e.g. PDF documents). 547 // non-HTML contents (e.g. PDF documents).
549 - (web::WebViewDocumentType)webViewDocumentType { 548 - (web::WebViewDocumentType)webViewDocumentType {
550 // This happens during tests. 549 // This happens during tests.
551 if (!_uiWebView) { 550 if (!_uiWebView) {
552 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 551 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
553 } 552 }
554 553 NSString* documentType =
555 if (base::ios::IsRunningOnIOS9OrLater()) { 554 [_uiWebView stringByEvaluatingJavaScriptFromString:
556 // On iOS 9, evaluating '' + document always results in [object 555 @"'' + document"];
557 // HTMLDocument], even for PDFs. However, document.contentType is properly 556 if ([documentType isEqualToString:@"[object HTMLDocument]"])
558 // defined. 557 return web::WEB_VIEW_DOCUMENT_TYPE_HTML;
559 NSString* MIMEType = [_uiWebView 558 else if ([documentType isEqualToString:@"[object Document]"])
560 stringByEvaluatingJavaScriptFromString:@"document.contentType"]; 559 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
561 return [self documentTypeFromMIMEType:MIMEType];
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
573 return web::WEB_VIEW_DOCUMENT_TYPE_UNKNOWN; 560 return web::WEB_VIEW_DOCUMENT_TYPE_UNKNOWN;
574 } 561 }
575 562
576 - (void)loadRequest:(NSMutableURLRequest*)request { 563 - (void)loadRequest:(NSMutableURLRequest*)request {
577 DCHECK(web::GetWebClient()); 564 DCHECK(web::GetWebClient());
578 GURL requestURL = net::GURLWithNSURL(request.URL); 565 GURL requestURL = net::GURLWithNSURL(request.URL);
579 // If the request is for WebUI, add information to let the network stack 566 // If the request is for WebUI, add information to let the network stack
580 // access the requestGroupID. 567 // access the requestGroupID.
581 if (web::GetWebClient()->IsAppSpecificURL(requestURL)) { 568 if (web::GetWebClient()->IsAppSpecificURL(requestURL)) {
582 // Sub requests of a chrome:// page will not contain the user agent. 569 // Sub requests of a chrome:// page will not contain the user agent.
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 } 1562 }
1576 1563
1577 #pragma mark - 1564 #pragma mark -
1578 #pragma mark Testing methods 1565 #pragma mark Testing methods
1579 1566
1580 -(id<CRWRecurringTaskDelegate>)recurringTaskDelegate { 1567 -(id<CRWRecurringTaskDelegate>)recurringTaskDelegate {
1581 return _recurringTaskDelegate; 1568 return _recurringTaskDelegate;
1582 } 1569 }
1583 1570
1584 @end 1571 @end
OLDNEW
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698