Skip to content

Commit

Permalink
Merge pull request #10785 from brave/maxk-file-system-access-feature
Browse files Browse the repository at this point in the history
Add feature flag to allow enabling FileSystemAccess API.
  • Loading branch information
mkarolin authored Nov 1, 2021
2 parents bc89417 + 8aa596d commit b50d5ad
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 9 deletions.
11 changes: 11 additions & 0 deletions browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "brave/components/translate/core/common/brave_translate_features.h"
#include "brave/components/translate/core/common/buildflags.h"
#include "net/base/features.h"
#include "third_party/blink/public/common/features.h"

#if BUILDFLAG(ENABLE_BRAVE_VPN) && !defined(OS_ANDROID)
#include "brave/components/brave_vpn/features.h"
Expand Down Expand Up @@ -230,6 +231,12 @@ constexpr char kBraveTranslateGoDescription[] =
"and brave translation backed. Also disables suggestions to install google "
"translate extension.";

// A blink feature.
constexpr char kFileSystemAccessAPIName[] = "File System Access API";
constexpr char kFileSystemAccessAPIDescription[] =
"Enables the File System Access API, giving websites access to the file "
"system";

} // namespace

} // namespace flag_descriptions
Expand Down Expand Up @@ -413,6 +420,10 @@ constexpr char kBraveTranslateGoDescription[] =
flag_descriptions::kBraveSyncName, \
flag_descriptions::kBraveSyncDescription, kOsDesktop, \
FEATURE_VALUE_TYPE(brave_sync::features::kBraveSync)}, \
{"file-system-access-api", \
flag_descriptions::kFileSystemAccessAPIName, \
flag_descriptions::kFileSystemAccessAPIDescription, kOsDesktop, \
FEATURE_VALUE_TYPE(blink::features::kFileSystemAccessAPI)}, \
BRAVE_DECENTRALIZED_DNS_FEATURE_ENTRIES \
BRAVE_IPFS_FEATURE_ENTRIES \
BRAVE_NATIVE_WALLET_FEATURE_ENTRIES \
Expand Down
1 change: 1 addition & 0 deletions chromium_src/third_party/blink/common/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+../../../../../third_party/blink/common",
"+../../../../../../third_party/blink/common/client_hints",
"+third_party/blink/common",
"+third_party/blink/public/common/client_hints",
Expand Down
15 changes: 15 additions & 0 deletions chromium_src/third_party/blink/common/features.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* 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/common/features.cc"

namespace blink {
namespace features {

const base::Feature kFileSystemAccessAPI{"FileSystemAccessAPI",
base::FEATURE_DISABLED_BY_DEFAULT};

} // namespace features
} // namespace blink
1 change: 1 addition & 0 deletions chromium_src/third_party/blink/public/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+../../../../../../third_party/blink/public/common",
"+../../../../../../../third_party/blink/public/common/client_hints",
"+../../../../../../third_party/blink/public/platform",
"+third_party/blink/public",
Expand Down
19 changes: 19 additions & 0 deletions chromium_src/third_party/blink/public/common/features.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* 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_PUBLIC_COMMON_FEATURES_H_
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_PUBLIC_COMMON_FEATURES_H_

#include "../../../../../../third_party/blink/public/common/features.h"

namespace blink {
namespace features {

BLINK_COMMON_EXPORT extern const base::Feature kFileSystemAccessAPI;

} // namespace features
} // namespace blink

#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_PUBLIC_COMMON_FEATURES_H_
10 changes: 7 additions & 3 deletions renderer/brave_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "brave/renderer/brave_render_thread_observer.h"
#include "chrome/common/chrome_isolated_world_ids.h"
#include "content/public/renderer/render_thread.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/platform/web_runtime_features.h"
#include "third_party/blink/public/web/modules/service_worker/web_service_worker_context_proxy.h"
#include "url/gurl.h"
Expand All @@ -37,9 +38,12 @@ void BraveContentRendererClient::

// These features don't have dedicated WebRuntimeFeatures wrappers.
blink::WebRuntimeFeatures::EnableFeatureFromString("DigitalGoods", false);
blink::WebRuntimeFeatures::EnableFeatureFromString("FileSystemAccess", false);
blink::WebRuntimeFeatures::EnableFeatureFromString(
"FileSystemAccessAPIExperimental", false);
if (!base::FeatureList::IsEnabled(blink::features::kFileSystemAccessAPI)) {
blink::WebRuntimeFeatures::EnableFeatureFromString("FileSystemAccess",
false);
blink::WebRuntimeFeatures::EnableFeatureFromString(
"FileSystemAccessAPIExperimental", false);
}
blink::WebRuntimeFeatures::EnableFeatureFromString("Serial", false);
}

Expand Down
40 changes: 34 additions & 6 deletions renderer/test/file_system_access_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#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"
Expand All @@ -16,9 +17,11 @@
#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 FileSystemAccessBrowserTest : public InProcessBrowserTest {
class FileSystemAccessBrowserTest : public InProcessBrowserTest,
public ::testing::WithParamInterface<bool> {
public:
FileSystemAccessBrowserTest()
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
Expand All @@ -31,6 +34,16 @@ class FileSystemAccessBrowserTest : public InProcessBrowserTest {

~FileSystemAccessBrowserTest() override = default;

bool IsFileSystemAccessAPIEnabled() { return GetParam(); }

void SetUp() override {
if (IsFileSystemAccessAPIEnabled()) {
scoped_feature_list_.InitAndEnableFeature(
blink::features::kFileSystemAccessAPI);
}
InProcessBrowserTest::SetUp();
}

void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();

Expand All @@ -49,14 +62,29 @@ class FileSystemAccessBrowserTest : public InProcessBrowserTest {

protected:
net::EmbeddedTestServer https_server_;
base::test::ScopedFeatureList scoped_feature_list_;
};

IN_PROC_BROWSER_TEST_F(FileSystemAccessBrowserTest, FilePicker) {
IN_PROC_BROWSER_TEST_P(FileSystemAccessBrowserTest, FilePicker) {
EXPECT_EQ(
IsFileSystemAccessAPIEnabled(),
base::FeatureList::IsEnabled(blink::features::kFileSystemAccessAPI));

const GURL url = https_server_.GetURL("/simple.html");
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));

auto result = content::EvalJs(main_frame(), "self.showOpenFilePicker()");
EXPECT_TRUE(result.error.find("self.showOpenFilePicker is not a function") !=
std::string::npos)
<< result.error;
if (IsFileSystemAccessAPIEnabled()) {
auto result =
content::EvalJs(main_frame(), "typeof self.showOpenFilePicker");
EXPECT_EQ(result.value.GetString(), "function");
} else {
auto result = content::EvalJs(main_frame(), "self.showOpenFilePicker()");
EXPECT_TRUE(base::Contains(result.error,
"self.showOpenFilePicker is not a function"))
<< result.error;
}
}

INSTANTIATE_TEST_SUITE_P(FileSystemAccessBrowserTest,
FileSystemAccessBrowserTest,
::testing::Bool());

0 comments on commit b50d5ad

Please sign in to comment.