File: fedcm_config_fetcher.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (127 lines) | stat: -rw-r--r-- 4,682 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_WEBID_FEDCM_CONFIG_FETCHER_H_
#define CONTENT_BROWSER_WEBID_FEDCM_CONFIG_FETCHER_H_

#include <memory>
#include <optional>
#include <set>
#include <vector>

#include "base/containers/flat_set.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "content/browser/webid/fedcm_metrics.h"
#include "content/browser/webid/idp_network_request_manager.h"
#include "third_party/blink/public/mojom/devtools/inspector_issue.mojom.h"

namespace content {
class RenderFrameHost;

// Fetches the config and well-known files for a list of identity providers.
// Validates returned information and calls callback when done.
class CONTENT_EXPORT FedCmConfigFetcher {
 public:
  struct CONTENT_EXPORT FetchError {
    FetchError(const FetchError& info);
    FetchError(blink::mojom::FederatedAuthRequestResult result,
               FedCmRequestIdTokenStatus token_status,
               std::optional<std::string> additional_console_error_message);
    ~FetchError();

    blink::mojom::FederatedAuthRequestResult result;
    FedCmRequestIdTokenStatus token_status;
    std::optional<std::string> additional_console_error_message;
  };

  struct CONTENT_EXPORT FetchResult {
    FetchResult();
    FetchResult(const FetchResult&);
    ~FetchResult();
    GURL identity_provider_config_url;
    bool force_skip_well_known_enforcement = false;
    IdpNetworkRequestManager::WellKnown wellknown;
    IdpNetworkRequestManager::Endpoints endpoints;
    std::optional<IdentityProviderMetadata> metadata;
    std::optional<FetchError> error;
  };

  struct FetchRequest {
    GURL identity_provider_config_url;
    bool force_skip_well_known_enforcement = false;
    FetchRequest(const GURL& url, bool force_skip_well_known_enforcement)
        : identity_provider_config_url(url),
          force_skip_well_known_enforcement(force_skip_well_known_enforcement) {
    }
  };

  using RequesterCallback = base::OnceCallback<void(std::vector<FetchResult>)>;

  // TODO(crbug.com/40283354): Remove |render_frame_host| when the IDP signin
  // status API is enabled by default.
  FedCmConfigFetcher(RenderFrameHost& render_frame_host,
                     IdpNetworkRequestManager* network_manager);
  ~FedCmConfigFetcher();

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

  // Starts fetch of config and well-known files. Start() should be called at
  // most once per FedCmConfigFetcher instance.
  void Start(const std::vector<FetchRequest>& requested_providers,
             blink::mojom::RpMode rp_mode,
             int icon_ideal_size,
             int icon_minimum_size,
             RequesterCallback callback);

  // Given a FetchResult, validates all of the conditions that the config file
  // and the well-known files need to meet. Sets an "error" in the result in
  // case the validation fails.
  void ValidateAndMaybeSetError(FetchResult& result);

 private:
  void OnWellKnownFetched(
      FetchResult& fetch_result,
      IdpNetworkRequestManager::FetchStatus status,
      const IdpNetworkRequestManager::WellKnown& well_known);
  void OnConfigFetched(FetchResult& fetch_result,
                       IdpNetworkRequestManager::FetchStatus status,
                       IdpNetworkRequestManager::Endpoints endpoints,
                       IdentityProviderMetadata idp_metadata);

  // Called when fetching either the config endpoint or the well-known
  // endpoint fails.
  void OnError(FetchResult& fetch_result,
               blink::mojom::FederatedAuthRequestResult result,
               content::FedCmRequestIdTokenStatus token_status,
               std::optional<std::string> additional_console_error_message);

  void RunCallbackIfDone();

  bool ShouldSkipWellKnownEnforcementForIdp(const FetchResult& fetch_result);

  raw_ref<RenderFrameHost> render_frame_host_;

  RequesterCallback callback_;

  // Config endpoints which has not yet been fetched.
  base::flat_set<GURL> pending_config_fetches_;

  // Config endpoints for which associated well-known has not yet been
  // fetched.
  base::flat_set<GURL> pending_well_known_fetches_;

  std::vector<FetchResult> fetch_results_;

  // Fetches the config and well-known files.
  raw_ptr<IdpNetworkRequestManager, DanglingUntriaged> network_manager_;

  base::WeakPtrFactory<FedCmConfigFetcher> weak_ptr_factory_{this};
};

}  // namespace content

#endif  // CONTENT_BROWSER_WEBID_FEDCM_CONFIG_FETCHER_H_