Commit 0af02eb8 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Round-trip origin through url::Origin before IPC to PluginRegistry.

This restores the previous (non-crashing) behavior while we contemplate what
the right fix for this is.

Bug: 862282
Change-Id: Ie4fe333f7ff01224db252d2cc6f3e83922122a8d
Reviewed-on: https://chromium-review.googlesource.com/1138821Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575711}
parent 52d4123b
...@@ -1835,6 +1835,7 @@ jumbo_source_set("blink_platform_unittests_sources") { ...@@ -1835,6 +1835,7 @@ jumbo_source_set("blink_platform_unittests_sources") {
"mojo/kurl_security_origin_test.cc", "mojo/kurl_security_origin_test.cc",
"mojo/notification_struct_traits_test.cc", "mojo/notification_struct_traits_test.cc",
"mojo/string16_mojom_traits_test.cc", "mojo/string16_mojom_traits_test.cc",
"plugins/plugin_data_test.cc",
"pod_arena_test.cc", "pod_arena_test.cc",
"pod_free_list_arena_test.cc", "pod_free_list_arena_test.cc",
"pod_interval_tree_test.cc", "pod_interval_tree_test.cc",
......
...@@ -12,3 +12,9 @@ include_rules = [ ...@@ -12,3 +12,9 @@ include_rules = [
"+third_party/blink/renderer/platform/weborigin", "+third_party/blink/renderer/platform/weborigin",
"+third_party/blink/renderer/platform/wtf", "+third_party/blink/renderer/platform/wtf",
] ]
specific_include_rules = {
".*_test\.cc": [
"+third_party/blink/renderer/platform/testing",
],
}
...@@ -95,11 +95,18 @@ void PluginData::UpdatePluginList(const SecurityOrigin* main_frame_origin) { ...@@ -95,11 +95,18 @@ void PluginData::UpdatePluginList(const SecurityOrigin* main_frame_origin) {
ResetPluginData(); ResetPluginData();
main_frame_origin_ = main_frame_origin; main_frame_origin_ = main_frame_origin;
// TODO(jbroman): Remove this. It is intended only as a minimal fix to restore
// previous behavior about origins that url::Origin rejects. This triggers the
// code which maps such origins to url::Origin(), a unique origin.
// https://crbug.com/862282
scoped_refptr<const SecurityOrigin> legacy_origin =
SecurityOrigin::CreateFromUrlOrigin(main_frame_origin->ToUrlOrigin());
mojom::blink::PluginRegistryPtr registry; mojom::blink::PluginRegistryPtr registry;
Platform::Current()->GetInterfaceProvider()->GetInterface( Platform::Current()->GetInterfaceProvider()->GetInterface(
mojo::MakeRequest(&registry)); mojo::MakeRequest(&registry));
Vector<mojom::blink::PluginInfoPtr> plugins; Vector<mojom::blink::PluginInfoPtr> plugins;
registry->GetPlugins(false, main_frame_origin_, &plugins); registry->GetPlugins(false, legacy_origin, &plugins);
for (const auto& plugin : plugins) { for (const auto& plugin : plugins) {
auto* plugin_info = auto* plugin_info =
new PluginInfo(plugin->name, FilePathToWebString(plugin->filename), new PluginInfo(plugin->name, FilePathToWebString(plugin->filename),
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/plugins/plugin_data.h"
#include "base/test/scoped_task_environment.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/plugins/plugin_registry.mojom-blink.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
using testing::Eq;
using testing::Property;
namespace blink {
namespace {
class MockPluginRegistry : public mojom::blink::PluginRegistry {
public:
void GetPlugins(bool refresh,
const scoped_refptr<const SecurityOrigin>& origin,
GetPluginsCallback callback) override {
DidGetPlugins(refresh, *origin);
std::move(callback).Run(Vector<mojom::blink::PluginInfoPtr>());
}
MOCK_METHOD2(DidGetPlugins, void(bool, const SecurityOrigin&));
};
// This behavior may be temporary, as it's odd for such origins to be treated as
// non-unique in Blink and unique in the browser. https://crbug.com/862282
TEST(PluginDataTest, NonStandardUrlSchemeRequestsPluginsWithUniqueOrigin) {
base::test::ScopedTaskEnvironment scoped_task_environment;
MockPluginRegistry mock_plugin_registry;
mojo::Binding<mojom::blink::PluginRegistry> registry_binding(
&mock_plugin_registry);
TestingPlatformSupport::ScopedOverrideMojoInterface override_plugin_registry(
WTF::BindRepeating(
[](mojo::Binding<mojom::blink::PluginRegistry>* registry_binding,
const char* interface, mojo::ScopedMessagePipeHandle pipe) {
if (!strcmp(interface, mojom::blink::PluginRegistry::Name_)) {
registry_binding->Bind(
mojom::blink::PluginRegistryRequest(std::move(pipe)));
return;
}
},
WTF::Unretained(&registry_binding)));
EXPECT_CALL(
mock_plugin_registry,
DidGetPlugins(false, Property(&SecurityOrigin::IsOpaque, Eq(true))));
scoped_refptr<SecurityOrigin> non_standard_origin =
SecurityOrigin::CreateFromString("nonstandard:foo/bar");
EXPECT_FALSE(non_standard_origin->IsOpaque());
auto* plugin_data = PluginData::Create();
plugin_data->UpdatePluginList(non_standard_origin.get());
}
} // namespace
} // namespace blink
...@@ -63,6 +63,11 @@ class TestingPlatformSupport::TestingInterfaceProvider ...@@ -63,6 +63,11 @@ class TestingPlatformSupport::TestingInterfaceProvider
void GetInterface(const char* name, void GetInterface(const char* name,
mojo::ScopedMessagePipeHandle handle) override { mojo::ScopedMessagePipeHandle handle) override {
auto& override_callback = GetOverrideCallback();
if (!override_callback.is_null()) {
override_callback.Run(name, std::move(handle));
return;
}
if (std::string(name) == mojom::blink::MimeRegistry::Name_) { if (std::string(name) == mojom::blink::MimeRegistry::Name_) {
mojo::MakeStrongBinding( mojo::MakeStrongBinding(
std::make_unique<MockMimeRegistry>(), std::make_unique<MockMimeRegistry>(),
...@@ -70,8 +75,23 @@ class TestingPlatformSupport::TestingInterfaceProvider ...@@ -70,8 +75,23 @@ class TestingPlatformSupport::TestingInterfaceProvider
return; return;
} }
} }
static ScopedOverrideMojoInterface::GetInterfaceCallback&
GetOverrideCallback() {
DEFINE_THREAD_SAFE_STATIC_LOCAL(
ScopedOverrideMojoInterface::GetInterfaceCallback, callback, ());
return callback;
}
}; };
TestingPlatformSupport::ScopedOverrideMojoInterface::
ScopedOverrideMojoInterface(GetInterfaceCallback callback)
: auto_reset_(&TestingInterfaceProvider::GetOverrideCallback(),
std::move(callback)) {}
TestingPlatformSupport::ScopedOverrideMojoInterface::
~ScopedOverrideMojoInterface() = default;
namespace { namespace {
class DummyThread final : public blink::WebThread { class DummyThread final : public blink::WebThread {
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "base/auto_reset.h"
#include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/platform_export.h"
...@@ -69,6 +71,20 @@ class TestingPlatformSupport : public Platform { ...@@ -69,6 +71,20 @@ class TestingPlatformSupport : public Platform {
virtual void RunUntilIdle(); virtual void RunUntilIdle();
// Overrides the handling of GetInterface on the platform's associated
// interface provider.
class ScopedOverrideMojoInterface {
public:
using GetInterfaceCallback =
base::RepeatingCallback<void(const char*,
mojo::ScopedMessagePipeHandle)>;
explicit ScopedOverrideMojoInterface(GetInterfaceCallback);
~ScopedOverrideMojoInterface();
private:
base::AutoReset<GetInterfaceCallback> auto_reset_;
};
protected: protected:
class TestingInterfaceProvider; class TestingInterfaceProvider;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment