1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53

fuchsia_web / webengine / browser / navigation_policy_throttle.h [blame]

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FUCHSIA_WEB_WEBENGINE_BROWSER_NAVIGATION_POLICY_THROTTLE_H_
#define FUCHSIA_WEB_WEBENGINE_BROWSER_NAVIGATION_POLICY_THROTTLE_H_

#include <fuchsia/web/cpp/fidl.h>

#include "base/memory/raw_ptr.h"
#include "content/public/browser/navigation_throttle.h"
#include "fuchsia_web/webengine/web_engine_export.h"

class NavigationPolicyHandler;

class WEB_ENGINE_EXPORT NavigationPolicyThrottle
    : public content::NavigationThrottle {
 public:
  explicit NavigationPolicyThrottle(content::NavigationHandle* handle,
                                    NavigationPolicyHandler* policy_handler);
  ~NavigationPolicyThrottle() override;

  NavigationPolicyThrottle(const NavigationPolicyThrottle&) = delete;
  NavigationPolicyThrottle& operator=(const NavigationPolicyThrottle&) = delete;

  void OnNavigationPolicyProviderDisconnected(ThrottleCheckResult check_result);

  // content::NavigationThrottle implementation.
  ThrottleCheckResult WillStartRequest() override;
  ThrottleCheckResult WillRedirectRequest() override;
  ThrottleCheckResult WillFailRequest() override;
  ThrottleCheckResult WillProcessResponse() override;
  const char* GetNameForLogging() override;

 private:
  void OnRequestedNavigationEvaluated(
      fuchsia::web::NavigationDecision decision);

  content::NavigationThrottle::ThrottleCheckResult HandleNavigationPhase(
      fuchsia::web::NavigationPhase phase);

  raw_ptr<NavigationPolicyHandler> policy_handler_;
  raw_ptr<content::NavigationHandle> navigation_handle_;

  // Indicates if the navigation is currently paused.
  bool is_paused_ = false;

  // Used for `EvaluateRequestedNavigation()` results callbacks that may outlive
  // this object.
  base::WeakPtrFactory<NavigationPolicyThrottle> weak_factory_{this};
};

#endif  // FUCHSIA_WEB_WEBENGINE_BROWSER_NAVIGATION_POLICY_THROTTLE_H_