Commit 178c1926 authored by Yi Su's avatar Yi Su Committed by Commit Bot

Move safeBrowsingWarningDetectionTimer into CRWWKNavigationHandler.

CRWWebController.safeBrowsingWarningDetectionTimer is used for updating
navigation status when SafeBrowsingWarning is displayed. This CL moves
it into CRWWKNavigationHandler to support next step refactor.

Bug: 956511
Change-Id: I662605492d461f4f8a5f3ed171705539f9a8eaa9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1598803Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658987}
parent 310ca88e
......@@ -11,6 +11,10 @@
@class CRWPendingNavigationInfo;
@class CRWWKNavigationStates;
namespace base {
class RepeatingTimer;
}
// CRWWKNavigationHandler uses this protocol to interact with its owner.
@protocol CRWWKNavigationHandlerDelegate <NSObject>
......@@ -30,6 +34,14 @@
// flight.
@property(nonatomic, readonly, strong) CRWWKNavigationStates* navigationStates;
// The SafeBrowsingDetection timer.
// TODO(crbug.com/956511): Remove this once refactor is done.
@property(nonatomic, readonly, assign)
base::RepeatingTimer* safeBrowsingWarningDetectionTimer;
// Instructs this handler to stop loading.
- (void)stopLoading;
@end
#endif // IOS_WEB_NAVIGATION_CRW_WK_NAVIGATION_HANDLER_H_
......@@ -3,13 +3,22 @@
// found in the LICENSE file.
#import "ios/web/navigation/crw_wk_navigation_handler.h"
#include "base/timer/timer.h"
#import "ios/web/navigation/crw_pending_navigation_info.h"
#import "ios/web/navigation/crw_wk_navigation_states.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation CRWWKNavigationHandler
@implementation CRWWKNavigationHandler {
// Used to poll for a SafeBrowsing warning being displayed. This is created in
// |decidePolicyForNavigationAction| and destroyed once any of the following
// happens: 1) a SafeBrowsing warning is detected; 2) any WKNavigationDelegate
// method is called; 3) |stopLoading| is called.
base::RepeatingTimer _safeBrowsingWarningDetectionTimer;
}
- (instancetype)init {
if (self = [super init]) {
......@@ -18,4 +27,15 @@
return self;
}
#pragma mark - Public methods
- (void)stopLoading {
self.pendingNavigationInfo.cancelled = YES;
_safeBrowsingWarningDetectionTimer.Stop();
}
- (base::RepeatingTimer*)safeBrowsingWarningDetectionTimer {
return &_safeBrowsingWarningDetectionTimer;
}
@end
......@@ -312,12 +312,6 @@ bool RequiresContentFilterBlockingWorkaround() {
// helps with diagnosing a navigation related crash (crbug.com/565457).
__weak WKNavigation* _stoppedWKNavigation;
// Used to poll for a SafeBrowsing warning being displayed. This is created in
// |decidePolicyForNavigationAction| and destroyed once any of the following
// happens: 1) a SafeBrowsing warning is detected; 2) any WKNavigationDelegate
// method is called; 3) |abortLoad| is called.
base::RepeatingTimer _safeBrowsingWarningDetectionTimer;
// Updates SSLStatus for current navigation item.
CRWSSLStatusUpdater* _SSLStatusUpdater;
......@@ -2187,10 +2181,9 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
- (void)abortLoad {
[self.webView stopLoading];
self.navigationHandler.pendingNavigationInfo.cancelled = YES;
[self.navigationHandler stopLoading];
_certVerificationErrors->Clear();
[self loadCancelled];
_safeBrowsingWarningDetectionTimer.Stop();
}
- (void)loadCancelled {
......@@ -4294,7 +4287,7 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
__weak CRWWebController* weakSelf = self;
const base::TimeDelta kDelayUntilSafeBrowsingWarningCheck =
base::TimeDelta::FromMilliseconds(20);
_safeBrowsingWarningDetectionTimer.Start(
self.navigationHandler.safeBrowsingWarningDetectionTimer->Start(
FROM_HERE, kDelayUntilSafeBrowsingWarningCheck, base::BindRepeating(^{
__strong __typeof(weakSelf) strongSelf = weakSelf;
if ([strongSelf isSafeBrowsingWarningDisplayedInWebView]) {
......@@ -4317,7 +4310,8 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
strongSelf.navigationManagerImpl->AddTransientItem(requestURL);
strongSelf.webStateImpl->OnNavigationStarted(context.get());
strongSelf.webStateImpl->OnNavigationFinished(context.get());
strongSelf->_safeBrowsingWarningDetectionTimer.Stop();
strongSelf.navigationHandler.safeBrowsingWarningDetectionTimer
->Stop();
if (!existingContext) {
// If there's an existing context, observers will already be aware
// of a load in progress. Otherwise, observers need to be notified
......@@ -5386,7 +5380,7 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
if (_isBeingDestroyed) {
UMA_HISTOGRAM_BOOLEAN("Renderer.WKWebViewCallbackAfterDestroy", true);
}
_safeBrowsingWarningDetectionTimer.Stop();
self.navigationHandler.safeBrowsingWarningDetectionTimer->Stop();
}
// Returns YES if response should be rendered in WKWebView.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment