-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20840 from brave/reset_wallet_permissions
Reset wallet permissions when wallet is being reset
- Loading branch information
Showing
15 changed files
with
210 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
browser/brave_wallet/brave_wallet_service_delegate_base.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/brave_wallet/brave_wallet_service_delegate_base.h" | ||
|
||
#include "brave/components/brave_wallet/browser/permission_utils.h" | ||
#include "brave/components/permissions/contexts/brave_wallet_permission_context.h" | ||
#include "content/public/browser/browser_context.h" | ||
|
||
namespace brave_wallet { | ||
|
||
BraveWalletServiceDelegateBase::BraveWalletServiceDelegateBase( | ||
content::BrowserContext* context) | ||
: context_(context) {} | ||
|
||
BraveWalletServiceDelegateBase::~BraveWalletServiceDelegateBase() = default; | ||
|
||
bool BraveWalletServiceDelegateBase::HasPermission(mojom::CoinType coin, | ||
const url::Origin& origin, | ||
const std::string& account) { | ||
bool has_permission = false; | ||
auto type = CoinTypeToPermissionType(coin); | ||
if (!type) { | ||
return false; | ||
} | ||
|
||
bool success = permissions::BraveWalletPermissionContext::HasPermission( | ||
*type, context_, origin, account, &has_permission); | ||
return success && has_permission; | ||
} | ||
|
||
bool BraveWalletServiceDelegateBase::ResetPermission( | ||
mojom::CoinType coin, | ||
const url::Origin& origin, | ||
const std::string& account) { | ||
auto type = CoinTypeToPermissionType(coin); | ||
if (!type) { | ||
return false; | ||
} | ||
|
||
return permissions::BraveWalletPermissionContext::ResetPermission( | ||
*type, context_, origin, account); | ||
} | ||
|
||
bool BraveWalletServiceDelegateBase::IsPermissionDenied( | ||
mojom::CoinType coin, | ||
const url::Origin& origin) { | ||
auto type = CoinTypeToPermissionType(coin); | ||
if (!type) { | ||
return false; | ||
} | ||
|
||
return permissions::BraveWalletPermissionContext::IsPermissionDenied( | ||
*type, context_, origin); | ||
} | ||
|
||
void BraveWalletServiceDelegateBase::ResetAllPermissions() { | ||
permissions::BraveWalletPermissionContext::ResetAllPermissions(context_); | ||
} | ||
|
||
} // namespace brave_wallet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_SERVICE_DELEGATE_BASE_H_ | ||
#define BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_SERVICE_DELEGATE_BASE_H_ | ||
|
||
#include <string> | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "brave/components/brave_wallet/browser/brave_wallet_service_delegate.h" | ||
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h" | ||
|
||
namespace content { | ||
class BrowserContext; | ||
} | ||
|
||
namespace url { | ||
class Origin; | ||
} | ||
|
||
namespace brave_wallet { | ||
|
||
// Shared BraveWalletServiceDelegate implementation between Desktop and Android. | ||
class BraveWalletServiceDelegateBase : public BraveWalletServiceDelegate { | ||
public: | ||
explicit BraveWalletServiceDelegateBase(content::BrowserContext* context); | ||
BraveWalletServiceDelegateBase(const BraveWalletServiceDelegateBase&) = | ||
delete; | ||
BraveWalletServiceDelegateBase& operator=( | ||
const BraveWalletServiceDelegateBase&) = delete; | ||
~BraveWalletServiceDelegateBase() override; | ||
|
||
bool HasPermission(mojom::CoinType coin, | ||
const url::Origin& origin, | ||
const std::string& account) override; | ||
bool ResetPermission(mojom::CoinType coin, | ||
const url::Origin& origin, | ||
const std::string& account) override; | ||
bool IsPermissionDenied(mojom::CoinType coin, | ||
const url::Origin& origin) override; | ||
void ResetAllPermissions() override; | ||
|
||
protected: | ||
raw_ptr<content::BrowserContext> context_ = nullptr; | ||
}; | ||
|
||
} // namespace brave_wallet | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_SERVICE_DELEGATE_BASE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.