Commit 7e73aa7c authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Prevent creation of Drive initiated message hosts when flag is off

Bug: 1150731
Change-Id: Ia55338e87250fd28f19c28343b6bf3a65dfacf10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2549160
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Reviewed-by: default avatarSergei Datsenko <dats@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830090}
parent b8b892b5
......@@ -161,6 +161,10 @@ CreateDriveFsInitiatedNativeMessageHost(
mojo::PendingReceiver<drivefs::mojom::NativeMessagingPort>
extension_receiver,
mojo::PendingRemote<drivefs::mojom::NativeMessagingHost> drivefs_remote) {
if (!base::FeatureList::IsEnabled(
chromeos::features::kDriveFsBidirectionalNativeMessaging)) {
return nullptr;
}
return std::make_unique<DriveFsNativeMessageHost>(
std::move(extension_receiver), std::move(drivefs_remote));
}
......@@ -196,6 +200,11 @@ ConnectToDriveFsNativeMessageExtension(
extensions::MessageService::Get(profile);
auto native_message_host = CreateDriveFsInitiatedNativeMessageHost(
std::move(extension_receiver), std::move(drivefs_remote));
if (!native_message_host) {
return drivefs::mojom::DriveFsDelegate::ExtensionConnectionStatus::
kExtensionNotFound;
}
auto native_message_port = std::make_unique<extensions::NativeMessagePort>(
message_service->GetChannelDelegate(), port_id,
std::move(native_message_host));
......
......@@ -72,13 +72,14 @@ class DriveFsNativeMessageHostTest
(const std::string& message),
(override));
base::test::ScopedFeatureList scoped_feature_list_;
base::test::TaskEnvironment task_environment_;
drivefs::mojom::ExtensionConnectionParamsPtr params_;
mojo::Receiver<drivefs::mojom::NativeMessagingHost> receiver_{this};
mojo::Remote<drivefs::mojom::NativeMessagingPort> extension_port_;
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(DriveFsNativeMessageHostTest);
};
......@@ -159,5 +160,26 @@ TEST_F(DriveFsNativeMessageHostTest, Error) {
run_loop.Run();
}
class DriveFsNativeMessageHostTestWithoutFlag
: public DriveFsNativeMessageHostTest {
public:
DriveFsNativeMessageHostTestWithoutFlag() {
scoped_feature_list_.InitAndDisableFeature(
chromeos::features::kDriveFsBidirectionalNativeMessaging);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(DriveFsNativeMessageHostTestWithoutFlag);
};
TEST_F(DriveFsNativeMessageHostTestWithoutFlag,
DriveFsCannotInitiateMessaging) {
ASSERT_FALSE(CreateDriveFsInitiatedNativeMessageHost(
extension_port_.BindNewPipeAndPassReceiver(),
receiver_.BindNewPipeAndPassRemote()));
}
} // namespace
} // namespace drive
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