Skip to content

Commit

Permalink
Explicit wallet disable => no dapp detection
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed Oct 2, 2019
1 parent 355732d commit 9189967
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
10 changes: 9 additions & 1 deletion browser/extensions/api/brave_wallet_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,22 @@ BraveWalletPromptToEnableWalletFunction::Run() {
}

ExtensionFunction::ResponseAction
BraveWalletIsEnabledFunction::Run() {
BraveWalletIsInstalledFunction::Run() {
Profile* profile = Profile::FromBrowserContext(browser_context());
auto* registry = extensions::ExtensionRegistry::Get(profile);
bool enabled = !brave::IsTorProfile(profile) &&
registry->ready_extensions().GetByID(ethereum_remote_client_extension_id);
return RespondNow(OneArgument(std::make_unique<base::Value>(enabled)));
}

ExtensionFunction::ResponseAction
BraveWalletIsEnabledFunction::Run() {
Profile* profile = Profile::FromBrowserContext(browser_context());
bool enabled = !brave::IsTorProfile(profile) &&
profile->GetPrefs()->GetBoolean(kBraveWalletEnabled);
return RespondNow(OneArgument(std::make_unique<base::Value>(enabled)));
}

// Returns 32 bytes of output from HKDF-SHA256.
// This is done so that ethereum-remote-client never actually directly has
// access to the master seed, but it does have a deterministic seed.
Expand Down
10 changes: 10 additions & 0 deletions browser/extensions/api/brave_wallet_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class BraveWalletIsEnabledFunction : public UIThreadExtensionFunction {
ResponseAction Run() override;
};

class BraveWalletIsInstalledFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveWallet.isInstalled", UNKNOWN)

protected:
~BraveWalletIsInstalledFunction() override {}

ResponseAction Run() override;
};

class BraveWalletGetWalletSeedFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveWallet.getWalletSeed", UNKNOWN)
Expand Down
3 changes: 3 additions & 0 deletions browser/extensions/brave_wallet_apitest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest,
const Extension* extension =
LoadExtension(extension_dir_.AppendASCII("braveShieldsWithWallet"));
ASSERT_TRUE(extension);
ASSERT_TRUE(browsertest_util::ExecuteScriptInBackgroundPageNoWait(
browser()->profile(), brave_extension_id,
"testBasics()"));
ASSERT_TRUE(catcher.GetNextResult()) << message_;
}

Expand Down
18 changes: 17 additions & 1 deletion common/extensions/api/brave_wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,26 @@
"type": "integer"
}
]
}, {
"name": "isInstalled",
"type": "function",
"description": "Called to determine if brave wallet extension is installed",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "enabled",
"type": "boolean"
}
]
}
]
}, {
"name": "isEnabled",
"type": "function",
"description": "Called to determine if brave wallet is alrady enabled",
"description": "Called to determine if brave wallet is enabled and can be used",
"parameters": [
{
"type": "function",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ export default function dappDetectionReducer (state = {}, action: Actions) {
case webNavigationTypes.ON_COMMITTED: {
if (chrome.braveWallet && action.isMainFrame) {
chrome.braveWallet.isEnabled((enabled) => {
if (enabled) {
return
}
chrome.tabs.executeScript(action.tabId, {
file: 'out/content_dapps.bundle.js',
allFrames: false,
runAt: 'document_start',
frameId: 0
chrome.braveWallet.isInstalled((installed) => {
if (installed || !enabled) {
return
}
chrome.tabs.executeScript(action.tabId, {
file: 'out/content_dapps.bundle.js',
allFrames: false,
runAt: 'document_start',
frameId: 0
})
})
})
}
Expand Down
1 change: 1 addition & 0 deletions components/definitions/chromel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ declare namespace chrome.braveShields {
declare namespace chrome.braveWallet {
const promptToEnableWallet: (tabId: number | undefined) => void
const isEnabled: (callback: (enabled: boolean) => void) => void
const isInstalled: (callback: (enabled: boolean) => void) => void
}

declare namespace chrome.test {
Expand Down

0 comments on commit 9189967

Please sign in to comment.