-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Disable navigator.connection attribute by default.
- Loading branch information
Showing
10 changed files
with
207 additions
and
1 deletion.
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
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
10 changes: 10 additions & 0 deletions
10
chromium_src/third_party/blink/renderer/bindings/modules/v8/v8_navigator.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,10 @@ | ||
/* Copyright (c) 2021 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 "third_party/blink/renderer/platform/bindings/idl_member_installer.h" | ||
|
||
#define InstallAttributes BraveInstallAttributes | ||
#include "../gen/third_party/blink/renderer/bindings/modules/v8/v8_navigator.cc" | ||
#undef InstallAttributes |
53 changes: 53 additions & 0 deletions
53
chromium_src/third_party/blink/renderer/platform/bindings/idl_member_installer.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,53 @@ | ||
/* Copyright (c) 2021 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 "src/third_party/blink/renderer/platform/bindings/idl_member_installer.cc" | ||
|
||
#include "base/strings/string_piece.h" | ||
#include "third_party/blink/public/common/features.h" | ||
|
||
namespace blink { | ||
|
||
namespace bindings { | ||
|
||
constexpr char kConnection[] = "connection"; | ||
|
||
// static | ||
void IDLMemberInstaller::BraveInstallAttributes( | ||
v8::Isolate* isolate, | ||
const DOMWrapperWorld& world, | ||
v8::Local<v8::Template> instance_template, | ||
v8::Local<v8::Template> prototype_template, | ||
v8::Local<v8::Template> interface_template, | ||
v8::Local<v8::Signature> signature, | ||
base::span<const AttributeConfig> configs) { | ||
for (const auto& config : configs) { | ||
if (!base::FeatureList::IsEnabled( | ||
blink::features::kNavigatorConnectionAttribute) && | ||
base::StringPiece(config.name).compare(kConnection) == 0) { | ||
continue; | ||
} | ||
InstallAttribute(isolate, world, instance_template, prototype_template, | ||
interface_template, signature, config); | ||
} | ||
} | ||
|
||
// static | ||
void IDLMemberInstaller::BraveInstallAttributes( | ||
v8::Isolate* isolate, | ||
const DOMWrapperWorld& world, | ||
v8::Local<v8::Object> instance_object, | ||
v8::Local<v8::Object> prototype_object, | ||
v8::Local<v8::Object> interface_object, | ||
v8::Local<v8::Signature> signature, | ||
base::span<const AttributeConfig> configs) { | ||
IDLMemberInstaller::InstallAttributes(isolate, world, instance_object, | ||
prototype_object, interface_object, | ||
signature, configs); | ||
} | ||
|
||
} // namespace bindings | ||
|
||
} // namespace blink |
28 changes: 28 additions & 0 deletions
28
chromium_src/third_party/blink/renderer/platform/bindings/idl_member_installer.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,28 @@ | ||
/* Copyright (c) 2021 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_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_IDL_MEMBER_INSTALLER_H_ | ||
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_IDL_MEMBER_INSTALLER_H_ | ||
|
||
#define BRAVE_IDL_MEMBER_INSTALLER_H_ \ | ||
static void BraveInstallAttributes( \ | ||
v8::Isolate* isolate, const DOMWrapperWorld& world, \ | ||
v8::Local<v8::Template> instance_template, \ | ||
v8::Local<v8::Template> prototype_template, \ | ||
v8::Local<v8::Template> interface_template, \ | ||
v8::Local<v8::Signature> signature, \ | ||
base::span<const AttributeConfig> configs); \ | ||
static void BraveInstallAttributes( \ | ||
v8::Isolate* isolate, const DOMWrapperWorld& world, \ | ||
v8::Local<v8::Object> instance_object, \ | ||
v8::Local<v8::Object> prototype_object, \ | ||
v8::Local<v8::Object> interface_object, \ | ||
v8::Local<v8::Signature> signature, \ | ||
base::span<const AttributeConfig> configs); | ||
|
||
#include "src/third_party/blink/renderer/platform/bindings/idl_member_installer.h" | ||
#undef BRAVE_IDL_MEMBER_INSTALLER_H_ | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_IDL_MEMBER_INSTALLER_H_ |
12 changes: 12 additions & 0 deletions
12
patches/third_party-blink-renderer-platform-bindings-idl_member_installer.h.patch
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,12 @@ | ||
diff --git a/third_party/blink/renderer/platform/bindings/idl_member_installer.h b/third_party/blink/renderer/platform/bindings/idl_member_installer.h | ||
index 095f734a2af6f8348414746208315e45a4c9222e..4a9907328353620abd594698613159e093757319 100644 | ||
--- a/third_party/blink/renderer/platform/bindings/idl_member_installer.h | ||
+++ b/third_party/blink/renderer/platform/bindings/idl_member_installer.h | ||
@@ -184,6 +184,7 @@ class PLATFORM_EXPORT IDLMemberInstaller final { | ||
v8::Local<v8::Object> interface_object, | ||
v8::Local<v8::Signature> signature, | ||
base::span<const ExposedConstructConfig> configs); | ||
+ BRAVE_IDL_MEMBER_INSTALLER_H_ | ||
}; | ||
|
||
} // namespace bindings |
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
84 changes: 84 additions & 0 deletions
84
renderer/test/navigator_connection_attribute_browsertest.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,84 @@ | ||
/* Copyright (c) 2021 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 "base/path_service.h" | ||
#include "base/strings/string_util.h" | ||
#include "base/test/scoped_feature_list.h" | ||
#include "brave/common/brave_paths.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/tabs/tab_strip_model.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "content/public/browser/render_frame_host.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "content/public/test/browser_test.h" | ||
#include "content/public/test/browser_test_utils.h" | ||
#include "net/dns/mock_host_resolver.h" | ||
#include "net/test/embedded_test_server/embedded_test_server.h" | ||
#include "third_party/blink/public/common/features.h" | ||
#include "url/gurl.h" | ||
|
||
class NavigatorConnectionAttributeBrowserTest | ||
: public InProcessBrowserTest, | ||
public ::testing::WithParamInterface<bool> { | ||
public: | ||
NavigatorConnectionAttributeBrowserTest() | ||
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { | ||
brave::RegisterPathProvider(); | ||
base::FilePath test_data_dir; | ||
base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); | ||
https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_OK); | ||
https_server_.ServeFilesFromDirectory(test_data_dir); | ||
} | ||
|
||
~NavigatorConnectionAttributeBrowserTest() override = default; | ||
|
||
bool IsNavigatorConnectionAttributeEnabled() { return GetParam(); } | ||
|
||
void SetUp() override { | ||
if (IsNavigatorConnectionAttributeEnabled()) { | ||
scoped_feature_list_.InitAndEnableFeature( | ||
blink::features::kNavigatorConnectionAttribute); | ||
} | ||
InProcessBrowserTest::SetUp(); | ||
} | ||
|
||
void SetUpOnMainThread() override { | ||
InProcessBrowserTest::SetUpOnMainThread(); | ||
|
||
EXPECT_TRUE(https_server_.Start()); | ||
// Map all hosts to localhost. | ||
host_resolver()->AddRule("*", "127.0.0.1"); | ||
} | ||
|
||
content::WebContents* web_contents() { | ||
return browser()->tab_strip_model()->GetActiveWebContents(); | ||
} | ||
|
||
content::RenderFrameHost* main_frame() { | ||
return web_contents()->GetMainFrame(); | ||
} | ||
|
||
protected: | ||
net::EmbeddedTestServer https_server_; | ||
base::test::ScopedFeatureList scoped_feature_list_; | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_P(NavigatorConnectionAttributeBrowserTest, | ||
IsAttributeAvailable) { | ||
EXPECT_EQ(IsNavigatorConnectionAttributeEnabled(), | ||
base::FeatureList::IsEnabled( | ||
blink::features::kNavigatorConnectionAttribute)); | ||
|
||
const GURL url = https_server_.GetURL("/simple.html"); | ||
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url)); | ||
|
||
auto result = content::EvalJs(main_frame(), "'connection' in navigator"); | ||
EXPECT_EQ(result.value.GetBool(), IsNavigatorConnectionAttributeEnabled()); | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P(NavigatorConnectionAttributeBrowserTest, | ||
NavigatorConnectionAttributeBrowserTest, | ||
::testing::Bool()); |