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
   54
   55
   56
   57

fuchsia_web / webengine / browser / navigation_policy_handler.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_HANDLER_H_
#define FUCHSIA_WEB_WEBENGINE_BROWSER_NAVIGATION_POLICY_HANDLER_H_

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

#include "base/containers/flat_set.h"
#include "fuchsia_web/webengine/web_engine_export.h"

class NavigationPolicyThrottle;

namespace content {
class NavigationHandle;
}  // namespace content

class WEB_ENGINE_EXPORT NavigationPolicyHandler {
 public:
  NavigationPolicyHandler(
      fuchsia::web::NavigationPolicyProviderParams params,
      fidl::InterfaceHandle<fuchsia::web::NavigationPolicyProvider> delegate);
  ~NavigationPolicyHandler();

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

  void RegisterNavigationThrottle(
      NavigationPolicyThrottle* navigation_throttle);
  void RemoveNavigationThrottle(NavigationPolicyThrottle* navigation_throttle);

  bool is_provider_connected();

  // Sends the request to evaluate the `requested_navigation` to the
  // `NavigationPolicyProvider`.
  void EvaluateRequestedNavigation(
      fuchsia::web::RequestedNavigation requested_navigation,
      fuchsia::web::NavigationPolicyProvider::
          EvaluateRequestedNavigationCallback callback);

  // Determines whether or not the client is interested in evaluating |handle|.
  bool ShouldEvaluateNavigation(content::NavigationHandle* handle,
                                fuchsia::web::NavigationPhase phase);

 private:
  void OnNavigationPolicyProviderDisconnected(zx_status_t status);

  fuchsia::web::NavigationPolicyProviderParams params_;
  fuchsia::web::NavigationPolicyProviderPtr provider_;

  // Keeps track of the NavigationThrottles associated with the Frame that owns
  // |this|.
  base::flat_set<NavigationPolicyThrottle*> navigation_throttles_;
};

#endif  // FUCHSIA_WEB_WEBENGINE_BROWSER_NAVIGATION_POLICY_HANDLER_H_