#ifndef CHROME_BROWSER_APPS_LINK_CAPTURING_LINK_CAPTURING_NAVIGATION_THROTTLE_H_
#define CHROME_BROWSER_APPS_LINK_CAPTURING_LINK_CAPTURING_NAVIGATION_THROTTLE_H_
#include <memory>
#include <optional>
#include "base/functional/callback_forward.h"
#include "content/public/browser/navigation_throttle.h"
#include "ui/base/page_transition_types.h"
#include "url/gurl.h"
class Profile;
namespace content {
class NavigationHandle;
class WebContents;
}
namespace apps {
class LinkCapturingNavigationThrottle : public content::NavigationThrottle {
public:
using ThrottleCheckResult = content::NavigationThrottle::ThrottleCheckResult;
static bool IsCapturableLinkNavigation(ui::PageTransition page_transition,
bool allow_form_submit,
bool is_in_fenced_frame_tree,
bool has_user_gesture);
static ui::PageTransition MaskOutPageTransition(
ui::PageTransition page_transition,
ui::PageTransition mask);
static bool IsEmptyDanglingWebContentsAfterLinkCapture(
content::NavigationHandle* handle);
using LaunchCallback =
base::OnceCallback<void(base::OnceClosure on_launch_complete)>;
class Delegate {
public:
virtual ~Delegate();
virtual bool ShouldCancelThrottleCreation(
content::NavigationThrottleRegistry& registry) = 0;
virtual std::optional<LaunchCallback> CreateLinkCaptureLaunchClosure(
Profile* profile,
content::WebContents* web_contents,
const GURL& url,
bool is_navigation_from_link,
int redirection_chain_size) = 0;
};
static bool MaybeCreateAndAdd(content::NavigationThrottleRegistry& registry,
std::unique_ptr<Delegate> delegate);
using LaunchCallbackForTesting =
base::OnceCallback<void(bool closed_web_contents)>;
static LaunchCallbackForTesting& GetLinkCaptureLaunchCallbackForTesting();
LinkCapturingNavigationThrottle(const LinkCapturingNavigationThrottle&) =
delete;
LinkCapturingNavigationThrottle& operator=(
const LinkCapturingNavigationThrottle&) = delete;
~LinkCapturingNavigationThrottle() override;
const char* GetNameForLogging() override;
ThrottleCheckResult WillStartRequest() override;
ThrottleCheckResult WillRedirectRequest() override;
static bool IsGoogleRedirectorUrl(const GURL& url);
static bool ShouldOverrideUrlIfRedirected(const GURL& previous_url,
const GURL& current_url);
private:
LinkCapturingNavigationThrottle(content::NavigationThrottleRegistry& registry,
std::unique_ptr<Delegate> delegate);
std::unique_ptr<Delegate> delegate_;
GURL starting_url_;
ThrottleCheckResult HandleRequest();
};
}
#endif