blob: 510af60e362a9882f68930ce7ec5a87881bb0bd5 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/public/navigation/web_state_policy_decider_bridge.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web {
WebStatePolicyDeciderBridge::WebStatePolicyDeciderBridge(
web::WebState* web_state,
id<CRWWebStatePolicyDecider> decider)
: WebStatePolicyDecider(web_state), decider_(decider) {}
WebStatePolicyDeciderBridge::~WebStatePolicyDeciderBridge() = default;
WebStatePolicyDecider::PolicyDecision
WebStatePolicyDeciderBridge::ShouldAllowRequest(
NSURLRequest* request,
const WebStatePolicyDecider::RequestInfo& request_info) {
if ([decider_
respondsToSelector:@selector(shouldAllowRequest:requestInfo:)]) {
return [decider_ shouldAllowRequest:request requestInfo:request_info];
}
return WebStatePolicyDecider::PolicyDecision::Allow();
}
void WebStatePolicyDeciderBridge::ShouldAllowResponse(
NSURLResponse* response,
bool for_main_frame,
base::OnceCallback<void(PolicyDecision)> callback) {
if ([decider_ respondsToSelector:@selector
(decidePolicyForNavigationResponse:
forMainFrame:completionHandler:)]) {
__block base::OnceCallback<void(PolicyDecision)> block_callback =
std::move(callback);
[decider_ decidePolicyForNavigationResponse:response
forMainFrame:for_main_frame
completionHandler:^(PolicyDecision result) {
std::move(block_callback).Run(result);
}];
return;
}
std::move(callback).Run(PolicyDecision::Allow());
}
} // namespace web