-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 1549: Return constant results for navigator.plugins and navigat…
…or.mimeTypes auditors: @diracdeltas, @bridiver
- Loading branch information
Showing
11 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
chromium_src/content/browser/renderer_host/render_process_host_impl.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,9 @@ | ||
/* 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/content/browser/renderer_host/brave_plugin_registry_impl.h" | ||
|
||
#define PluginRegistryImpl BravePluginRegistryImpl | ||
#include "../../../../../content/browser/renderer_host/render_process_host_impl.cc" | ||
#undef PluginRegistryImpl |
126 changes: 126 additions & 0 deletions
126
chromium_src/third_party/blink/renderer/modules/plugins/navigator_pluginstest.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,126 @@ | ||
/* 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/content_settings/host_content_settings_map_factory.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 "components/content_settings/core/browser/host_content_settings_map.h" | ||
#include "components/content_settings/core/common/content_settings.h" | ||
#include "components/content_settings/core/common/content_settings_types.h" | ||
#include "content/public/test/browser_test_utils.h" | ||
|
||
const char kNavigatorPluginsTest[] = "/navigatorplugins.html"; | ||
const char kNavigatorMimeTypesTest[] = "/navigatormimetypes.html"; | ||
const char kNavigatorPluginsTestWithFlash[] = "/navigatorpluginswithflash.html"; | ||
const char kNavigatorMimeTypesTestWithFlash[] = "/navigatormimetypeswithflash.html"; | ||
|
||
class NavigatorPluginsTest : 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; | ||
base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); | ||
embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | ||
|
||
ASSERT_TRUE(embedded_test_server()->Start()); | ||
} | ||
|
||
HostContentSettingsMap * content_settings() { | ||
return HostContentSettingsMapFactory::GetForProfile(browser()->profile()); | ||
} | ||
|
||
void AllowFlash(GURL url) { | ||
content_settings()->SetContentSettingCustomScope( | ||
ContentSettingsPattern::FromString(url.spec()), | ||
ContentSettingsPattern::Wildcard(), | ||
CONTENT_SETTINGS_TYPE_PLUGINS, | ||
std::string(), | ||
CONTENT_SETTING_ALLOW); | ||
} | ||
|
||
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(NavigatorPluginsTest, ConstPluginsWithoutFlash) { | ||
GURL url = embedded_test_server()->GetURL(kNavigatorPluginsTest); | ||
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 constantPlugins; | ||
ASSERT_TRUE(ExecuteScriptAndExtractBool( | ||
contents, | ||
"window.domAutomationController.send(constantPlugins())", | ||
&constantPlugins)); | ||
EXPECT_TRUE(constantPlugins); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(NavigatorPluginsTest, ConstMimeTypesWithoutFlash) { | ||
GURL url = embedded_test_server()->GetURL(kNavigatorMimeTypesTest); | ||
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 constantMimeTypes; | ||
ASSERT_TRUE(ExecuteScriptAndExtractBool( | ||
contents, | ||
"window.domAutomationController.send(constantMimeTypes())", | ||
&constantMimeTypes)); | ||
EXPECT_TRUE(constantMimeTypes); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(NavigatorPluginsTest, ConstPluginsWithFlash) { | ||
GURL url = embedded_test_server()->GetURL(kNavigatorPluginsTestWithFlash); | ||
AllowFlash(url); | ||
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 constantPlugins; | ||
ASSERT_TRUE(ExecuteScriptAndExtractBool( | ||
contents, | ||
"window.domAutomationController.send(constantPlugins())", | ||
&constantPlugins)); | ||
EXPECT_TRUE(constantPlugins); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(NavigatorPluginsTest, ConstMimeTypesWithFlash) { | ||
GURL url = embedded_test_server()->GetURL(kNavigatorMimeTypesTestWithFlash); | ||
AllowFlash(url); | ||
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 constantMimeTypes; | ||
ASSERT_TRUE(ExecuteScriptAndExtractBool( | ||
contents, | ||
"window.domAutomationController.send(constantMimeTypes())", | ||
&constantMimeTypes)); | ||
EXPECT_TRUE(constantMimeTypes); | ||
} |
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,8 @@ | ||
source_set("browser") { | ||
visibility = [ "//content/browser" ] | ||
|
||
sources = [ | ||
"renderer_host/brave_plugin_registry_impl.cc", | ||
"renderer_host/brave_plugin_registry_impl.h", | ||
] | ||
} |
38 changes: 38 additions & 0 deletions
38
content/browser/renderer_host/brave_plugin_registry_impl.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,38 @@ | ||
/* 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/content/browser/renderer_host/brave_plugin_registry_impl.h" | ||
|
||
#include "base/strings/utf_string_conversions.h" | ||
|
||
namespace content { | ||
|
||
BravePluginRegistryImpl::BravePluginRegistryImpl(ResourceContext* resource_context) | ||
: PluginRegistryImpl(resource_context) {} | ||
|
||
BravePluginRegistryImpl::~BravePluginRegistryImpl() {} | ||
|
||
void BravePluginRegistryImpl::GetPluginsComplete(GetPluginsCallback callback, | ||
std::vector<blink::mojom::PluginInfoPtr> plugins) { | ||
std::vector<blink::mojom::PluginInfoPtr> filtered_plugins; | ||
|
||
for(std::vector<blink::mojom::PluginInfoPtr>::iterator it = plugins.begin(); | ||
it != plugins.end(); ++it) { | ||
if ((*it) && (*it)->name == base::ASCIIToUTF16("Shockwave Flash")) { | ||
filtered_plugins.push_back(std::move(*it)); | ||
} | ||
} | ||
std::move(callback).Run(std::move(filtered_plugins)); | ||
} | ||
|
||
void BravePluginRegistryImpl::GetPlugins(bool refresh, | ||
const url::Origin& main_frame_origin, | ||
GetPluginsCallback callback) { | ||
PluginRegistryImpl::GetPlugins(refresh, main_frame_origin, | ||
base::BindOnce( | ||
&BravePluginRegistryImpl::GetPluginsComplete, base::Unretained(this), | ||
std::move(callback))); | ||
} | ||
|
||
} // namespace content |
29 changes: 29 additions & 0 deletions
29
content/browser/renderer_host/brave_plugin_registry_impl.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,29 @@ | ||
/* 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_CONTENT_BROWSER_RENDERER_HOST_PLUGIN_REGISTRY_IMPL_H_ | ||
#define BRAVE_CONTENT_BROWSER_RENDERER_HOST_PLUGIN_REGISTRY_IMPL_H_ | ||
|
||
#include "content/browser/renderer_host/plugin_registry_impl.h" | ||
|
||
namespace content { | ||
|
||
class ResourceContext; | ||
|
||
class BravePluginRegistryImpl : public PluginRegistryImpl { | ||
public: | ||
BravePluginRegistryImpl(ResourceContext* resource_context); | ||
~BravePluginRegistryImpl() override; | ||
|
||
void GetPlugins(bool refresh, | ||
const url::Origin& main_frame_origin, | ||
GetPluginsCallback callback) override; | ||
private: | ||
void GetPluginsComplete(GetPluginsCallback callback, | ||
std::vector<blink::mojom::PluginInfoPtr> plugins); | ||
}; | ||
|
||
} // namespace content | ||
|
||
#endif // BRAVE_CONTENT_BROWSER_RENDERER_HOST_PLUGIN_REGISTRY_IMPL_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,15 @@ | ||
diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn | ||
index b9925142f676f2a66fb50c7679e28ab91f81031b..ef53b8d144ee6a80ae0c2d56de60c49d07802100 100644 | ||
--- a/content/browser/BUILD.gn | ||
+++ b/content/browser/BUILD.gn | ||
@@ -1864,6 +1864,10 @@ jumbo_source_set("browser") { | ||
"webui/web_ui_url_loader_factory_internal.h", | ||
] | ||
|
||
+ deps += [ | ||
+ "//brave/content/browser", | ||
+ ] | ||
+ | ||
if (toolkit_views) { | ||
deps += [ "//ui/events" ] | ||
} |
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,5 @@ | ||
<script> | ||
function constantMimeTypes() { | ||
return navigator.mimeTypes.length == 0; | ||
} | ||
</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,5 @@ | ||
<script> | ||
function constantMimeTypes() { | ||
return navigator.mimeTypes.length == 2; | ||
} | ||
</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,5 @@ | ||
<script> | ||
function constantPlugins() { | ||
return navigator.plugins.length == 0; | ||
} | ||
</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,5 @@ | ||
<script> | ||
function constantPlugins() { | ||
return navigator.plugins.length == 1; | ||
} | ||
</script> |