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

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

Issue 1178063007: Updated error translation logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_web_controller.h" 5 #import "ios/web/web_state/ui/crw_web_controller.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/ios/block_types.h" 10 #include "base/ios/block_types.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "ios/web/public/referrer.h" 44 #include "ios/web/public/referrer.h"
45 #include "ios/web/public/referrer_util.h" 45 #include "ios/web/public/referrer_util.h"
46 #include "ios/web/public/ssl_status.h" 46 #include "ios/web/public/ssl_status.h"
47 #include "ios/web/public/url_scheme_util.h" 47 #include "ios/web/public/url_scheme_util.h"
48 #include "ios/web/public/url_util.h" 48 #include "ios/web/public/url_util.h"
49 #include "ios/web/public/user_metrics.h" 49 #include "ios/web/public/user_metrics.h"
50 #include "ios/web/public/web_client.h" 50 #include "ios/web/public/web_client.h"
51 #include "ios/web/public/web_state/credential.h" 51 #include "ios/web/public/web_state/credential.h"
52 #import "ios/web/public/web_state/crw_web_controller_observer.h" 52 #import "ios/web/public/web_state/crw_web_controller_observer.h"
53 #import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h" 53 #import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h"
54 #import "ios/web/public/web_state/error_translation_util.h"
54 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" 55 #import "ios/web/public/web_state/js/crw_js_injection_manager.h"
55 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" 56 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
56 #import "ios/web/public/web_state/ui/crw_native_content.h" 57 #import "ios/web/public/web_state/ui/crw_native_content.h"
57 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" 58 #import "ios/web/public/web_state/ui/crw_native_content_provider.h"
58 #include "ios/web/public/web_state/url_verification_constants.h" 59 #include "ios/web/public/web_state/url_verification_constants.h"
59 #include "ios/web/public/web_state/web_state.h" 60 #include "ios/web/public/web_state/web_state.h"
60 #include "ios/web/web_state/blocked_popup_info.h" 61 #include "ios/web/web_state/blocked_popup_info.h"
61 #import "ios/web/web_state/crw_web_view_proxy_impl.h" 62 #import "ios/web/web_state/crw_web_view_proxy_impl.h"
62 #import "ios/web/web_state/error_translation_util.h"
63 #include "ios/web/web_state/frame_info.h" 63 #include "ios/web/web_state/frame_info.h"
64 #import "ios/web/web_state/js/credential_util.h" 64 #import "ios/web/web_state/js/credential_util.h"
65 #import "ios/web/web_state/js/crw_js_early_script_manager.h" 65 #import "ios/web/web_state/js/crw_js_early_script_manager.h"
66 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h" 66 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h"
67 #import "ios/web/web_state/js/crw_js_window_id_manager.h" 67 #import "ios/web/web_state/js/crw_js_window_id_manager.h"
68 #import "ios/web/web_state/ui/crw_context_menu_provider.h" 68 #import "ios/web/web_state/ui/crw_context_menu_provider.h"
69 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" 69 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h"
70 #import "ios/web/web_state/ui/crw_ui_web_view_web_controller.h" 70 #import "ios/web/web_state/ui/crw_ui_web_view_web_controller.h"
71 #import "ios/web/web_state/ui/crw_web_controller+protected.h" 71 #import "ios/web/web_state/ui/crw_web_controller+protected.h"
72 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" 72 #import "ios/web/web_state/ui/crw_web_controller_container_view.h"
(...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 } 1416 }
1417 } 1417 }
1418 } 1418 }
1419 1419
1420 - (void)loadErrorInNativeView:(NSError*)error { 1420 - (void)loadErrorInNativeView:(NSError*)error {
1421 [self removeWebViewAllowingCachedReconstruction:NO]; 1421 [self removeWebViewAllowingCachedReconstruction:NO];
1422 1422
1423 const GURL currentUrl = [self currentNavigationURL]; 1423 const GURL currentUrl = [self currentNavigationURL];
1424 BOOL isPost = [self currentPOSTData] != nil; 1424 BOOL isPost = [self currentPOSTData] != nil;
1425 1425
1426 error = web::NetErrorFromError(error);
1426 [self setNativeController:[_nativeProvider controllerForURL:currentUrl 1427 [self setNativeController:[_nativeProvider controllerForURL:currentUrl
1427 withError:error 1428 withError:error
1428 isPost:isPost]]; 1429 isPost:isPost]];
1429 [self loadNativeViewWithSuccess:NO]; 1430 [self loadNativeViewWithSuccess:NO];
1430 } 1431 }
1431 1432
1432 // Load the current URL in a native controller, retrieved from the native 1433 // Load the current URL in a native controller, retrieved from the native
1433 // provider. Call |loadNativeViewWithSuccess:YES| to load the native controller. 1434 // provider. Call |loadNativeViewWithSuccess:YES| to load the native controller.
1434 - (void)loadCurrentURLInNativeView { 1435 - (void)loadCurrentURLInNativeView {
1435 // Free the web view. 1436 // Free the web view.
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after
2813 // Reset |_lastRegisteredRequestURL| so that it reflects the URL from before 2814 // Reset |_lastRegisteredRequestURL| so that it reflects the URL from before
2814 // the load was rejected. This value may be out of sync because 2815 // the load was rejected. This value may be out of sync because
2815 // |_lastRegisteredRequestURL| may have already been updated before the load 2816 // |_lastRegisteredRequestURL| may have already been updated before the load
2816 // was rejected. 2817 // was rejected.
2817 _lastRegisteredRequestURL = [self currentURL]; 2818 _lastRegisteredRequestURL = [self currentURL];
2818 _loadPhase = web::PAGE_LOADING; 2819 _loadPhase = web::PAGE_LOADING;
2819 [self didFinishNavigation]; 2820 [self didFinishNavigation];
2820 } 2821 }
2821 2822
2822 - (void)handleLoadError:(NSError*)error inMainFrame:(BOOL)inMainFrame { 2823 - (void)handleLoadError:(NSError*)error inMainFrame:(BOOL)inMainFrame {
2823 // Attempt to translate iOS errors into their corresponding net errors.
2824 error = web::NetErrorFromError(error);
2825
2826 if ([error code] == NSURLErrorUnsupportedURL) 2824 if ([error code] == NSURLErrorUnsupportedURL)
2827 return; 2825 return;
2828 // In cases where a Plug-in handles the load do not take any further action. 2826 // In cases where a Plug-in handles the load do not take any further action.
2829 if ([[error domain] isEqual:WebKitErrorDomain] && 2827 if ([[error domain] isEqual:WebKitErrorDomain] &&
2830 ([error code] == WebKitErrorPlugInLoadFailed || 2828 ([error code] == WebKitErrorPlugInLoadFailed ||
2831 [error code] == WebKitErrorCannotShowURL)) 2829 [error code] == WebKitErrorCannotShowURL))
2832 return; 2830 return;
2833 2831
2834 // Continue processing only if the error is on the main request or is the 2832 // Continue processing only if the error is on the main request or is the
2835 // result of a user interaction. 2833 // result of a user interaction.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2877 [_delegate controllerForUnhandledContentAtURL:errorGURL]; 2875 [_delegate controllerForUnhandledContentAtURL:errorGURL];
2878 if (controller) { 2876 if (controller) {
2879 [self loadCompleteWithSuccess:NO]; 2877 [self loadCompleteWithSuccess:NO];
2880 [self removeWebViewAllowingCachedReconstruction:NO]; 2878 [self removeWebViewAllowingCachedReconstruction:NO];
2881 [self setNativeController:controller]; 2879 [self setNativeController:controller];
2882 [self loadNativeViewWithSuccess:YES]; 2880 [self loadNativeViewWithSuccess:YES];
2883 return; 2881 return;
2884 } 2882 }
2885 } 2883 }
2886 2884
2887 // Otherwise, handle the error normally. 2885 // Ignore errors that originate from URLs that are opened in external apps.
2888 if ([_openedApplicationURL containsObject:errorURL]) 2886 if ([_openedApplicationURL containsObject:errorURL])
2889 return; 2887 return;
2890 // Certain frame errors don't have URL information for some reason; for 2888 // Certain frame errors don't have URL information for some reason; for
2891 // those cases (so far the only known case is plugin content loaded directly 2889 // those cases (so far the only known case is plugin content loaded directly
2892 // in a frame) just ignore the error. See crbug.com/414295 2890 // in a frame) just ignore the error. See crbug.com/414295
2893 if (!errorURL) { 2891 if (!errorURL) {
2894 DCHECK(!inMainFrame); 2892 DCHECK(!inMainFrame);
2895 return; 2893 return;
2896 } 2894 }
2897 // The wrapper error uses the URL of the error and not the requested URL 2895 // The wrapper error uses the URL of the error and not the requested URL
2898 // (which can be different in case of a redirect) to match desktop Chrome 2896 // (which can be different in case of a redirect) to match desktop Chrome
2899 // behavior. 2897 // behavior.
2900 NSError* wrapperError = [NSError 2898 NSError* wrapperError = [NSError
2901 errorWithDomain:[error domain] 2899 errorWithDomain:[error domain]
2902 code:[error code] 2900 code:[error code]
2903 userInfo:@{ 2901 userInfo:@{
2904 NSURLErrorFailingURLStringErrorKey : [errorURL absoluteString], 2902 NSURLErrorFailingURLStringErrorKey : [errorURL absoluteString],
2905 NSUnderlyingErrorKey : error 2903 NSUnderlyingErrorKey : error
2906 }]; 2904 }];
2907 [self loadCompleteWithSuccess:NO]; 2905 [self loadCompleteWithSuccess:NO];
2908 [self loadErrorInNativeView:wrapperError]; 2906 [self loadErrorInNativeView:wrapperError];
2909 return; 2907 return;
2910 } 2908 }
2911 2909
2912 // TODO(ios): Audit comments and behavior below regarding error origin. The
2913 // error has been translated and may appear to have originated in the Chrome
2914 // network stack when that is not true (crbug.com/496972)
2915 // Ignore cancelled errors.
2916 if ([error code] == NSURLErrorCancelled) { 2910 if ([error code] == NSURLErrorCancelled) {
2917 NSError* underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey]; 2911 NSError* underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey];
2918 if (underlyingError && [self shouldAbortLoadForCancelledURL:errorGURL]) { 2912 if (underlyingError && [self shouldAbortLoadForCancelledURL:errorGURL]) {
2919 DCHECK([underlyingError isKindOfClass:[NSError class]]); 2913 DCHECK([underlyingError isKindOfClass:[NSError class]]);
2920 2914
2921 // The Error contains an NSUnderlyingErrorKey so it's being generated 2915 // NSURLCancelled errors with underlying errors are generated from the
2922 // in the Chrome network stack. Aborting the load in this case. 2916 // chrome network stack. Aborting the load in this case.
2923 [self abortLoad]; 2917 [self abortLoad];
2924 2918
2925 switch ([underlyingError code]) { 2919 switch ([underlyingError code]) {
2926 case net::ERR_ABORTED: 2920 case net::ERR_ABORTED:
2927 // |NSURLErrorCancelled| errors with underlying net error code 2921 // |NSURLErrorCancelled| errors with underlying net error code
2928 // |net::ERR_ABORTED| are used by the Chrome network stack to 2922 // |net::ERR_ABORTED| are used by the Chrome network stack to
2929 // indicate that the current load should be aborted and the pending 2923 // indicate that the current load should be aborted and the pending
2930 // entry should be discarded. 2924 // entry should be discarded.
2931 [[self sessionController] discardNonCommittedEntries]; 2925 [[self sessionController] discardNonCommittedEntries];
2932 break; 2926 break;
2933 case net::ERR_BLOCKED_BY_CLIENT: 2927 case net::ERR_BLOCKED_BY_CLIENT:
2934 // |NSURLErrorCancelled| errors with underlying net error code 2928 // |NSURLErrorCancelled| errors with underlying net error code
2935 // |net::ERR_BLOCKED_BY_CLIENT| are used by the Chrome network stack 2929 // |net::ERR_BLOCKED_BY_CLIENT| are used by the Chrome network stack
2936 // to indicate that the current load should be aborted and the pending 2930 // to indicate that the current load should be aborted and the pending
2937 // entry should be kept. 2931 // entry should be kept.
2938 break; 2932 break;
2939 default: 2933 default:
2940 NOTREACHED(); 2934 NOTREACHED();
2941 } 2935 }
2942 } 2936 }
2937 // NSURLCancelled errors with no underlying error are generated by the web
2938 // view. Early return in this case, as the web view interally handles
2939 // reattempting this load.
Eugene But (OOO till 7-30) 2015/06/19 00:52:01 Please make sure that LoadState will still be PAGE
kkhorimoto 2015/06/23 20:33:58 Done, although the fix is somewhat speculative. T
2943 return; 2940 return;
2944 } 2941 }
2945 2942
2946 [self loadCompleteWithSuccess:NO]; 2943 [self loadCompleteWithSuccess:NO];
2947 [self loadErrorInNativeView:error]; 2944 [self loadErrorInNativeView:error];
2948 } 2945 }
2949 2946
2950 - (BOOL)shouldAbortLoadForCancelledURL:(const GURL &)cancelledURL { 2947 - (BOOL)shouldAbortLoadForCancelledURL:(const GURL &)cancelledURL {
2951 // Subclasses must implement this method. 2948 // Subclasses must implement this method.
2952 NOTREACHED(); 2949 NOTREACHED();
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
3836 if (!_externalRequest || !_externalRequest->window_name) 3833 if (!_externalRequest || !_externalRequest->window_name)
3837 return @""; 3834 return @"";
3838 return _externalRequest->window_name; 3835 return _externalRequest->window_name;
3839 } 3836 }
3840 3837
3841 - (void)resetExternalRequest { 3838 - (void)resetExternalRequest {
3842 _externalRequest.reset(); 3839 _externalRequest.reset();
3843 } 3840 }
3844 3841
3845 @end 3842 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698