blob: 2433228a4a10e2583dd34c559421f89bc5acb12e [file] [log] [blame]
// Copyright 2020 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.h"
namespace web {
// A test WebStatePolicyDecider that defers calling the callback passed to
// ShouldAllowResponse rather than calling it synchronously.
class AsyncWebStatePolicyDecider : public WebStatePolicyDecider {
explicit AsyncWebStatePolicyDecider(WebState* web_state);
~AsyncWebStatePolicyDecider() override;
// WebStatePolicyDecider override:
void ShouldAllowResponse(
NSURLResponse* response,
bool for_main_frame,
base::OnceCallback<void(PolicyDecision)> callback) override;
// True if a call to ShouldAllowResponse() has been received but
// InvokeCallback() has not yet been called.
bool ReadyToInvokeCallback() const;
// Runs the callback passed to the last call to ShouldAllowResponse().
void InvokeCallback(WebStatePolicyDecider::PolicyDecision decision);
base::OnceCallback<void(PolicyDecision)> callback_;
} // namespace web