-
Notifications
You must be signed in to change notification settings - Fork 840
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 #2678 from brave/dapp_detection
Add dapp detection
- Loading branch information
Showing
37 changed files
with
721 additions
and
85 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* Copyright (c) 2019 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/brave_wallet/brave_wallet_utils.h" | ||
|
||
#include "base/callback.h" | ||
#include "brave/browser/brave_wallet/wallet_installation_permission_request.h" | ||
#include "brave/common/pref_names.h" | ||
#include "chrome/browser/permissions/permission_request_manager.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/prefs/pref_service.h" | ||
|
||
namespace { | ||
base::Closure g_quit_closure_for_test; | ||
} // namespace | ||
|
||
void RequestWalletInstallationPermission(content::WebContents* web_contents) { | ||
DCHECK(web_contents); | ||
|
||
if (g_quit_closure_for_test) | ||
g_quit_closure_for_test.Run(); | ||
|
||
PermissionRequestManager::FromWebContents(web_contents)->AddRequest( | ||
new WalletInstallationPermissionRequest(web_contents)); | ||
} | ||
|
||
void SetQuitClosureForDappDetectionTest(const base::Closure& quit_closure) { | ||
g_quit_closure_for_test = quit_closure; | ||
} |
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,20 @@ | ||
/* Copyright (c) 2019 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_UTILS_H_ | ||
#define BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_UTILS_H_ | ||
|
||
#include "base/callback_forward.h" | ||
|
||
namespace content { | ||
class BrowserContext; | ||
class WebContents; | ||
} // content | ||
|
||
void RequestWalletInstallationPermission(content::WebContents* web_contents); | ||
|
||
void SetQuitClosureForDappDetectionTest(const base::Closure& quit_closure); | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_WALLET_BRAVE_WALLET_UTILS_H_ |
59 changes: 59 additions & 0 deletions
59
browser/brave_wallet/wallet_installation_permission_request.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,59 @@ | ||
/* Copyright (c) 2019 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/brave_wallet/wallet_installation_permission_request.h" | ||
|
||
#include "brave/browser/ui/brave_pages.h" | ||
#include "brave/grit/brave_generated_resources.h" | ||
#include "chrome/app/vector_icons/vector_icons.h" | ||
#include "chrome/browser/ui/browser_finder.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "url/gurl.h" | ||
|
||
WalletInstallationPermissionRequest::WalletInstallationPermissionRequest( | ||
content::WebContents* web_contents) | ||
: web_contents_(web_contents) { | ||
} | ||
|
||
WalletInstallationPermissionRequest::~WalletInstallationPermissionRequest() { | ||
} | ||
|
||
PermissionRequest::IconId | ||
WalletInstallationPermissionRequest::GetIconId() const { | ||
return kExtensionIcon; | ||
} | ||
|
||
base::string16 | ||
WalletInstallationPermissionRequest::GetMessageTextFragment() const { | ||
return l10n_util::GetStringUTF16( | ||
IDS_WALLET_PERMISSION_REQUEST_TEXT_FRAGMENT); | ||
} | ||
|
||
GURL WalletInstallationPermissionRequest::GetOrigin() const { | ||
return web_contents_->GetVisibleURL(); | ||
} | ||
|
||
void WalletInstallationPermissionRequest::PermissionGranted() { | ||
Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | ||
brave::ShowBraveWallet(browser); | ||
} | ||
|
||
void WalletInstallationPermissionRequest::PermissionDenied() { | ||
// Do nothing. | ||
} | ||
|
||
void WalletInstallationPermissionRequest::Cancelled() { | ||
// Do nothing. | ||
} | ||
|
||
void WalletInstallationPermissionRequest::RequestFinished() { | ||
delete this; | ||
} | ||
|
||
PermissionRequestType | ||
WalletInstallationPermissionRequest::GetPermissionRequestType() const { | ||
return PermissionRequestType::PERMISSION_WALLET; | ||
} |
41 changes: 41 additions & 0 deletions
41
browser/brave_wallet/wallet_installation_permission_request.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Copyright (c) 2019 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_BRAVE_WALLET_WALLET_INSTALLATION_PERMISSION_REQUEST_H_ | ||
#define BRAVE_BROWSER_BRAVE_WALLET_WALLET_INSTALLATION_PERMISSION_REQUEST_H_ | ||
|
||
#include "chrome/browser/permissions/permission_request.h" | ||
|
||
namespace content { | ||
class WebContents; | ||
} | ||
|
||
class GURL; | ||
|
||
class WalletInstallationPermissionRequest : public PermissionRequest { | ||
public: | ||
explicit WalletInstallationPermissionRequest( | ||
content::WebContents* web_contents); | ||
~WalletInstallationPermissionRequest() override; | ||
|
||
private: | ||
// PermissionRequest overrides: | ||
PermissionRequest::IconId GetIconId() const override; | ||
base::string16 GetMessageTextFragment() const override; | ||
GURL GetOrigin() const override; | ||
void PermissionGranted() override; | ||
void PermissionDenied() override; | ||
void Cancelled() override; | ||
void RequestFinished() override; | ||
PermissionRequestType GetPermissionRequestType() const override; | ||
|
||
// It's safe to use this raw |web_contents_| because this request is deleted | ||
// by PermissionManager that is tied with this |web_contents_|. | ||
content::WebContents* web_contents_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(WalletInstallationPermissionRequest); | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_WALLET_WALLET_INSTALLATION_PERMISSION_REQUEST_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
Oops, something went wrong.