-
Notifications
You must be signed in to change notification settings - Fork 883
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 #114 from brave/disabling_tracking_apis
Disabling getBattery | bluetooth | credential.get/store | navigator.usb apis
- Loading branch information
Showing
15 changed files
with
364 additions
and
0 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
14 changes: 14 additions & 0 deletions
14
chromium_src/third_party/blink/renderer/modules/battery/navigator_battery.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,14 @@ | ||
#include "third_party/blink/renderer/modules/battery/navigator_battery.h" | ||
|
||
#include "gin/converter.h" | ||
#include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h" | ||
#include "net/proxy_resolution/proxy_resolver_v8.h" | ||
|
||
namespace blink { | ||
ScriptPromise NavigatorBattery::getBattery(ScriptState* script_state, | ||
Navigator& navigator) { | ||
v8::Isolate* isolate = script_state->GetIsolate(); | ||
return blink::ScriptPromise::Reject(script_state, | ||
v8::Exception::TypeError(gin::StringToV8(isolate, "This api has been disabled."))); | ||
} | ||
} // namespace blink |
59 changes: 59 additions & 0 deletions
59
chromium_src/third_party/blink/renderer/modules/battery/navigator_batterytest.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 @@ | ||
/* 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 "base/path_service.h" | ||
#include "brave/browser/brave_content_browser_client.h" | ||
#include "brave/common/brave_paths.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/common/chrome_content_client.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "content/public/test/browser_test_utils.h" | ||
|
||
const char kBatteryTest[] = "/battery.html"; | ||
|
||
class NavigatorGetBatteryDisabledTest : public InProcessBrowserTest { | ||
public: | ||
void SetUpOnMainThread() override { | ||
InProcessBrowserTest::SetUpOnMainThread(); | ||
|
||
content_client_.reset(new ChromeContentClient); | ||
content::SetContentClient(content_client_.get()); | ||
browser_content_client_.reset(new BraveContentBrowserClient()); | ||
content::SetBrowserClientForTesting(browser_content_client_.get()); | ||
content::SetupCrossSiteRedirector(embedded_test_server()); | ||
|
||
brave::RegisterPathProvider(); | ||
base::FilePath test_data_dir; | ||
PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); | ||
embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | ||
|
||
ASSERT_TRUE(embedded_test_server()->Start()); | ||
} | ||
|
||
void TearDown() override { | ||
browser_content_client_.reset(); | ||
content_client_.reset(); | ||
} | ||
|
||
private: | ||
std::unique_ptr<ChromeContentClient> content_client_; | ||
std::unique_ptr<BraveContentBrowserClient> browser_content_client_; | ||
base::ScopedTempDir temp_user_data_dir_; | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(NavigatorGetBatteryDisabledTest, IsDisabled) { | ||
GURL url = embedded_test_server()->GetURL(kBatteryTest); | ||
ui_test_utils::NavigateToURL(browser(), url); | ||
content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | ||
ASSERT_TRUE(content::WaitForLoadStop(contents)); | ||
EXPECT_EQ(url, contents->GetURL()); | ||
|
||
bool getBatteryBlocked; | ||
ASSERT_TRUE(ExecuteScriptAndExtractBool( | ||
contents, | ||
"window.domAutomationController.send(getBatteryBlocked())", | ||
&getBatteryBlocked)); | ||
EXPECT_TRUE(getBatteryBlocked); | ||
} |
59 changes: 59 additions & 0 deletions
59
chromium_src/third_party/blink/renderer/modules/bluetooth/navigator_bluetoothtest.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 @@ | ||
/* 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 "base/path_service.h" | ||
#include "brave/browser/brave_content_browser_client.h" | ||
#include "brave/common/brave_paths.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/common/chrome_content_client.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "content/public/test/browser_test_utils.h" | ||
|
||
const char kBluetoothTest[] = "/bluetooth.html"; | ||
|
||
class NavigatorBluetoothDisabledTest : public InProcessBrowserTest { | ||
public: | ||
void SetUpOnMainThread() override { | ||
InProcessBrowserTest::SetUpOnMainThread(); | ||
|
||
content_client_.reset(new ChromeContentClient); | ||
content::SetContentClient(content_client_.get()); | ||
browser_content_client_.reset(new BraveContentBrowserClient()); | ||
content::SetBrowserClientForTesting(browser_content_client_.get()); | ||
content::SetupCrossSiteRedirector(embedded_test_server()); | ||
|
||
brave::RegisterPathProvider(); | ||
base::FilePath test_data_dir; | ||
PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); | ||
embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | ||
|
||
ASSERT_TRUE(embedded_test_server()->Start()); | ||
} | ||
|
||
void TearDown() override { | ||
browser_content_client_.reset(); | ||
content_client_.reset(); | ||
} | ||
|
||
private: | ||
std::unique_ptr<ChromeContentClient> content_client_; | ||
std::unique_ptr<BraveContentBrowserClient> browser_content_client_; | ||
base::ScopedTempDir temp_user_data_dir_; | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(NavigatorBluetoothDisabledTest, IsDisabled) { | ||
GURL url = embedded_test_server()->GetURL(kBluetoothTest); | ||
ui_test_utils::NavigateToURL(browser(), url); | ||
content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | ||
ASSERT_TRUE(content::WaitForLoadStop(contents)); | ||
EXPECT_EQ(url, contents->GetURL()); | ||
|
||
bool bluetoothBlocked; | ||
ASSERT_TRUE(ExecuteScriptAndExtractBool( | ||
contents, | ||
"window.domAutomationController.send(bluetoothBlocked())", | ||
&bluetoothBlocked)); | ||
EXPECT_TRUE(bluetoothBlocked); | ||
} |
54 changes: 54 additions & 0 deletions
54
chromium_src/third_party/blink/renderer/modules/credentialmanager/credentials_container.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,54 @@ | ||
#include "third_party/blink/renderer/modules/credentialmanager/credentials_container.h" | ||
|
||
#include "gin/converter.h" | ||
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h" | ||
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" | ||
#include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h" | ||
#include "v8/include/v8.h" | ||
|
||
namespace blink { | ||
|
||
CredentialsContainer::CredentialsContainer() = default; | ||
|
||
ScriptPromise CredentialsContainer::get( | ||
ScriptState* script_state, | ||
const CredentialRequestOptions& options) { | ||
ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | ||
ScriptPromise promise = resolver->Promise(); | ||
v8::Isolate* isolate = script_state->GetIsolate(); | ||
resolver->Resolve(v8::Null(isolate)); | ||
return promise; | ||
} | ||
|
||
ScriptPromise CredentialsContainer::store(ScriptState* script_state, | ||
Credential* credential) { | ||
ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | ||
ScriptPromise promise = resolver->Promise(); | ||
v8::Isolate* isolate = script_state->GetIsolate(); | ||
resolver->Resolve(v8::Null(isolate)); | ||
return promise; | ||
} | ||
|
||
ScriptPromise CredentialsContainer::preventSilentAccess( | ||
ScriptState* script_state) { | ||
ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | ||
ScriptPromise promise = resolver->Promise(); | ||
resolver->Resolve(); | ||
return promise; | ||
} | ||
|
||
CredentialsContainer* CredentialsContainer::Create() { | ||
return new CredentialsContainer(); | ||
} | ||
|
||
ScriptPromise CredentialsContainer::create( | ||
ScriptState* script_state, | ||
const CredentialCreationOptions& options, | ||
ExceptionState& exception_state) { | ||
ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | ||
ScriptPromise promise = resolver->Promise(); | ||
v8::Isolate* isolate = script_state->GetIsolate(); | ||
resolver->Resolve(v8::Null(isolate)); | ||
return promise; | ||
} | ||
} // namespace blink |
91 changes: 91 additions & 0 deletions
91
...ium_src/third_party/blink/renderer/modules/credentialmanager/credentials_containertest.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,91 @@ | ||
/* 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 "base/path_service.h" | ||
#include "brave/browser/brave_content_browser_client.h" | ||
#include "brave/common/brave_paths.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/common/chrome_content_client.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "content/public/test/browser_test_utils.h" | ||
|
||
const char kCredentialsGetTest[] = "/credentialsget.html"; | ||
const char kCredentialsStoreTest[] = "/credentialsstore.html"; | ||
const char kCredentialsPreventSilentAccessTest[] = "/credentialspreventsilentaccess.html"; | ||
|
||
class CredentialsContainersTest : public InProcessBrowserTest { | ||
public: | ||
void SetUpOnMainThread() override { | ||
InProcessBrowserTest::SetUpOnMainThread(); | ||
|
||
content_client_.reset(new ChromeContentClient); | ||
content::SetContentClient(content_client_.get()); | ||
browser_content_client_.reset(new BraveContentBrowserClient()); | ||
content::SetBrowserClientForTesting(browser_content_client_.get()); | ||
content::SetupCrossSiteRedirector(embedded_test_server()); | ||
|
||
brave::RegisterPathProvider(); | ||
base::FilePath test_data_dir; | ||
PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); | ||
embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | ||
|
||
ASSERT_TRUE(embedded_test_server()->Start()); | ||
} | ||
|
||
void TearDown() override { | ||
browser_content_client_.reset(); | ||
content_client_.reset(); | ||
} | ||
|
||
private: | ||
std::unique_ptr<ChromeContentClient> content_client_; | ||
std::unique_ptr<BraveContentBrowserClient> browser_content_client_; | ||
base::ScopedTempDir temp_user_data_dir_; | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(CredentialsContainersTest, GetDisabled) { | ||
GURL url = embedded_test_server()->GetURL(kCredentialsGetTest); | ||
ui_test_utils::NavigateToURL(browser(), url); | ||
content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | ||
ASSERT_TRUE(content::WaitForLoadStop(contents)); | ||
EXPECT_EQ(url, contents->GetURL()); | ||
|
||
bool credentialsGetBlocked; | ||
ASSERT_TRUE(ExecuteScriptAndExtractBool( | ||
contents, | ||
"window.domAutomationController.send(credentialsGetBlocked())", | ||
&credentialsGetBlocked)); | ||
EXPECT_TRUE(credentialsGetBlocked); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(CredentialsContainersTest, StoreDisabled) { | ||
GURL url = embedded_test_server()->GetURL(kCredentialsStoreTest); | ||
ui_test_utils::NavigateToURL(browser(), url); | ||
content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | ||
ASSERT_TRUE(content::WaitForLoadStop(contents)); | ||
EXPECT_EQ(url, contents->GetURL()); | ||
|
||
bool credentialsStoreBlocked; | ||
ASSERT_TRUE(ExecuteScriptAndExtractBool( | ||
contents, | ||
"window.domAutomationController.send(credentialsStoreBlocked())", | ||
&credentialsStoreBlocked)); | ||
EXPECT_TRUE(credentialsStoreBlocked); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(CredentialsContainersTest, PreventSilentAccessDisabled) { | ||
GURL url = embedded_test_server()->GetURL(kCredentialsPreventSilentAccessTest); | ||
ui_test_utils::NavigateToURL(browser(), url); | ||
content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | ||
ASSERT_TRUE(content::WaitForLoadStop(contents)); | ||
EXPECT_EQ(url, contents->GetURL()); | ||
|
||
bool credentialsPreventSilentAccess; | ||
ASSERT_TRUE(ExecuteScriptAndExtractBool( | ||
contents, | ||
"window.domAutomationController.send(credentialspreventSilentAccessBlocked())", | ||
&credentialsPreventSilentAccess)); | ||
EXPECT_TRUE(credentialsPreventSilentAccess); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script> | ||
function getBatteryBlocked() { | ||
try { | ||
navigator.get_battery(); | ||
} catch (err) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
</script> |
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,15 @@ | ||
<script> | ||
function bluetoothBlocked() { | ||
let options = { | ||
filters: [ | ||
{namePrefix: 'Prefix'} | ||
] | ||
} | ||
try { | ||
navigator.bluetooth.requestDevice(options).resolve('Waiting'); | ||
} catch (e) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
</script> |
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,10 @@ | ||
<script> | ||
var result = false; | ||
navigator.credentials.get().then(function(data){ | ||
result = data; | ||
}); | ||
|
||
function credentialsGetBlocked() { | ||
return result == null; | ||
} | ||
</script> |
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,11 @@ | ||
<script> | ||
var result = false; | ||
|
||
navigator.credentials.preventSilentAccess().then(function(){ | ||
result = true; | ||
}) | ||
|
||
function credentialspreventSilentAccessBlocked() { | ||
return result; | ||
} | ||
</script> |
Oops, something went wrong.