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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
// 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 CHROME_BROWSER_UI_VIEWS_SUPERVISED_USER_PARENT_PERMISSION_DIALOG_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_SUPERVISED_USER_PARENT_PERMISSION_DIALOG_VIEW_H_
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "chrome/browser/extensions/install_prompt_permissions.h"
#include "chrome/browser/supervised_user/supervised_user_extensions_metrics_recorder.h"
#include "chrome/browser/ui/supervised_user/parent_permission_dialog.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
#include "google_apis/gaia/gaia_id.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/view.h"
#include "ui/views/window/dialog_delegate.h"
class GaiaAuthFetcher;
namespace extensions {
class Extension;
} // namespace extensions
namespace signin {
class AccessTokenFetcher;
struct AccessTokenInfo;
class IdentityManager;
} // namespace signin
namespace views {
class Label;
}
class ParentPermissionInputSection;
// Modal dialog that shows a dialog that prompts a parent for permission by
// asking them to enter their google account credentials. This is created only
// when the dialog is ready to be shown (after the state has been
// asynchronously fetched).
class ParentPermissionDialogView : public views::DialogDelegateView,
public GaiaAuthConsumer {
METADATA_HEADER(ParentPermissionDialogView, views::DialogDelegateView)
public:
class Observer {
public:
// Tells observers that their references to the view are becoming invalid.
virtual void OnParentPermissionDialogViewDestroyed() = 0;
};
struct Params;
ParentPermissionDialogView(std::unique_ptr<Params> params,
Observer* observer);
ParentPermissionDialogView(const ParentPermissionDialogView&) = delete;
ParentPermissionDialogView& operator=(const ParentPermissionDialogView&) =
delete;
~ParentPermissionDialogView() override;
// Closes the dialog.
void CloseDialog();
// Shows the parent permission dialog.
void ShowDialog();
// Removes the observer reference.
void RemoveObserver();
void SetSelectedParentPermissionEmail(const std::u16string& email_address);
std::u16string GetSelectedParentPermissionEmail() const;
void SetParentPermissionCredential(const std::u16string& credential);
std::u16string GetParentPermissionCredential() const;
bool GetInvalidCredentialReceived() const;
void SetIdentityManagerForTesting(signin::IdentityManager* identity_manager);
void SetRepromptAfterIncorrectCredential(bool reprompt);
bool GetRepromptAfterIncorrectCredential() const;
private:
// views::View:
void AddedToWidget() override;
void OnThemeChanged() override;
// views::DialogDelegate:
bool Cancel() override;
bool Accept() override;
// views::WidgetDelegate:
std::u16string GetAccessibleWindowTitle() const override;
// Changes the widget size to accommodate the contents' preferred size.
void ResizeWidget();
// Creates the contents area that contains permissions and other extension
// info.
void CreateContents();
void ShowDialogInternal();
void AddInvalidCredentialLabel();
void LoadParentEmailAddresses();
void CloseWithReason(views::Widget::ClosedReason reason);
// Given an email address of the child's parent, return the parents'
// obfuscated gaia id.
GaiaId GetParentObfuscatedGaiaID(const std::u16string& parent_email) const;
// Starts the Reauth-scoped OAuth access token fetch process.
void StartReauthAccessTokenFetch(const GaiaId& parent_obfuscated_gaia_id,
const std::string& parent_credential);
// Handles the result of the access token
void OnAccessTokenFetchComplete(const GaiaId& parent_obfuscated_gaia_id,
const std::string& parent_credential,
GoogleServiceAuthError error,
signin::AccessTokenInfo access_token_info);
// Starts the Parent Reauth proof token fetch process.
void StartParentReauthProofTokenFetch(const std::string& child_access_token,
const GaiaId& parent_obfuscated_gaia_id,
const std::string& credential);
// GaiaAuthConsumer
void OnReAuthProofTokenSuccess(
const std::string& reauth_proof_token) override;
void OnReAuthProofTokenFailure(
const GaiaAuthConsumer::ReAuthProofTokenStatus error) override;
// The first time it is called, logs the result to UMA and passes it to the
// callback. No effect if called subsequent times.
void SendResultOnce(ParentPermissionDialog::Result result);
// Sets the |extension| to be optionally displayed in the dialog. This
// causes the view to show several extension properties including the
// permissions and the extension name.
void InitializeExtensionData(
scoped_refptr<const extensions::Extension> extension);
// Permissions ot be displayed in the prompt. Only populated
// if an extension has been set.
extensions::InstallPromptPermissions prompt_permissions_;
// The email address of the parents to display in the dialog.
std::vector<std::u16string> parent_permission_email_addresses_;
bool reprompt_after_incorrect_credential_ = true;
// Contains the parent-permission-input related views widgets.
std::unique_ptr<ParentPermissionInputSection>
parent_permission_input_section_;
raw_ptr<views::Label> invalid_credential_label_ = nullptr;
bool invalid_credential_received_ = false;
// The currently selected parent email.
std::u16string selected_parent_permission_email_;
// The currently entered parent credential.
std::u16string parent_permission_credential_;
// Parameters for the dialog.
std::unique_ptr<Params> params_;
// Used to ensure we don't try to show same dialog twice.
bool is_showing_ = false;
// Used to fetch the Reauth token.
std::unique_ptr<GaiaAuthFetcher> reauth_token_fetcher_;
// Used to fetch OAuth2 access tokens.
raw_ptr<signin::IdentityManager> identity_manager_ = nullptr;
std::unique_ptr<signin::AccessTokenFetcher> oauth2_access_token_fetcher_;
raw_ptr<Observer> observer_;
SupervisedUserExtensionsMetricsRecorder supervised_user_metrics_recorder_;
base::WeakPtrFactory<ParentPermissionDialogView> weak_factory_{this};
};
// Allows tests to observe the create of the testing instance of
// ParentPermissionDialogView
class TestParentPermissionDialogViewObserver {
public:
// Implementers should pass "this" as constructor argument.
TestParentPermissionDialogViewObserver(
TestParentPermissionDialogViewObserver* observer);
~TestParentPermissionDialogViewObserver();
virtual void OnTestParentPermissionDialogViewCreated(
ParentPermissionDialogView* view) = 0;
};
#endif // CHROME_BROWSER_UI_VIEWS_SUPERVISED_USER_PARENT_PERMISSION_DIALOG_VIEW_H_
|