Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install ipfs as a normal extension #2328

Merged
merged 7 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
Uses Hangouts component to enable screen sharing and other features in the browser.
</message>
<message name="IDS_SETTINGS_IPFS_COMPANION_ENABLED_DESC" desc="The description for IPFS companion switch in settings">
Uses IPFS companion component to support IPFS in the browser.
Uses IPFS companion extension to support IPFS in the browser.
</message>
<message name="IDS_SETTINGS_MANAGE_EXTENSIONS_LABEL" desc="The label of manage extensions link in settings">
Manage extensions
Expand Down
8 changes: 0 additions & 8 deletions browser/extensions/brave_component_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ void BraveComponentLoader::OnComponentRegistered(std::string extension_id) {
// to patch for friend access.
demand_updater.OnDemandUpdate(g_browser_process->component_updater(),
extension_id);
if (testing_callbacks_) {
testing_callbacks_->OnComponentRegistered(extension_id);
}
}

void BraveComponentLoader::OnComponentReady(std::string extension_id,
Expand Down Expand Up @@ -127,11 +124,6 @@ void BraveComponentLoader::AddDefaultComponentExtensions(
brave_webtorrent_path.Append(FILE_PATH_LITERAL("brave_webtorrent"));
Add(IDR_BRAVE_WEBTORRENT, brave_webtorrent_path);
}

if (profile_prefs_->GetBoolean(kIPFSCompanionEnabled)) {
AddExtension(ipfs_companion_extension_id, ipfs_companion_extension_name,
ipfs_companion_extension_public_key);
}
}

void BraveComponentLoader::ObserveOpenPdfExternallySetting() {
Expand Down
1 change: 0 additions & 1 deletion browser/extensions/brave_component_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class BraveComponentLoader : public ComponentLoader {
WILL_REMOVE,
};
virtual void OnPdfExtensionAction(PdfExtensionAction action) = 0;
virtual void OnComponentRegistered(std::string extension_id) = 0;
};

void set_testing_callbacks(TestingCallbacks* testing_callbacks);
Expand Down
34 changes: 0 additions & 34 deletions browser/extensions/brave_component_loader_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

using ::testing::_;
using ::testing::AnyNumber;
using extensions::BraveComponentLoader;

class BraveComponentLoaderTest : public extensions::ExtensionFunctionalTest,
Expand All @@ -35,8 +32,6 @@ class BraveComponentLoaderTest : public extensions::ExtensionFunctionalTest,
BraveComponentLoader* loader =
static_cast<BraveComponentLoader*>(service->component_loader());
loader->set_testing_callbacks(this);
// Do this again so OnComponentRegistered callback will be called.
loader->AddDefaultComponentExtensions(false);
}

// BraveComponentLoader::TestingCallbacks
Expand All @@ -45,8 +40,6 @@ class BraveComponentLoaderTest : public extensions::ExtensionFunctionalTest,
pdf_extension_action_ = action;
}

MOCK_METHOD1(OnComponentRegistered, void(std::string));

TestingCallbacks::PdfExtensionAction pdf_extension_action() {
return pdf_extension_action_;
}
Expand All @@ -55,33 +48,6 @@ class BraveComponentLoaderTest : public extensions::ExtensionFunctionalTest,
TestingCallbacks::PdfExtensionAction pdf_extension_action_;
};

class BraveIPFSExtensionTest: public BraveComponentLoaderTest {
public:
BraveIPFSExtensionTest() {}
~BraveIPFSExtensionTest() override = default;
};

IN_PROC_BROWSER_TEST_F(BraveIPFSExtensionTest, DisabledByDefault) {
ASSERT_FALSE(
profile()->GetPrefs()->GetBoolean(kIPFSCompanionEnabled));
EXPECT_CALL(*this, OnComponentRegistered(_)).Times(AnyNumber());
EXPECT_CALL(*this,
OnComponentRegistered(ipfs_companion_extension_id)).Times(0);
}

IN_PROC_BROWSER_TEST_F(BraveIPFSExtensionTest,
PRE_IPFSCompanionEnabledDoesRegisterComponent) {
profile()->GetPrefs()->SetBoolean(kIPFSCompanionEnabled, true);
}

IN_PROC_BROWSER_TEST_F(BraveIPFSExtensionTest,
IPFSCompanionEnabledDoesRegisterComponent) {
ASSERT_TRUE(
profile()->GetPrefs()->GetBoolean(kIPFSCompanionEnabled));
EXPECT_CALL(*this, OnComponentRegistered(_)).Times(AnyNumber());
EXPECT_CALL(*this, OnComponentRegistered(ipfs_companion_extension_id));
}

class BravePDFExtensionTest : public BraveComponentLoaderTest {
public:
BravePDFExtensionTest() {}
Expand Down
10 changes: 6 additions & 4 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ source_set("ui") {
"//brave/app/theme:brave_unscaled_resources",
"//brave/app/theme:brave_theme_resources",
"//brave/app/vector_icons:vector_icons",
"//brave/browser/devtools",
"//brave/browser/tor",
"//brave/browser/resources/md_extensions:resources",
"//brave/browser/resources/settings:resources",
"//brave/common",
"//brave/components/brave_adblock_ui:generated_resources",
"//brave/components/brave_extension:static_resources",
Expand All @@ -127,14 +131,12 @@ source_set("ui") {
"//brave/components/brave_sync:static_resources",
"//brave/components/brave_sync:generated_resources",
"//brave/components/brave_welcome_ui:generated_resources",
"//brave/browser/devtools",
"//brave/browser/tor",
"//brave/browser/resources/md_extensions:resources",
"//brave/browser/resources/settings:resources",
"//chrome/app:command_ids",
"//chrome/browser/extensions",
"//chrome/common",
"//content/public/browser",
"//content/public/common",
"//extensions/browser",
"//skia",
"//ui/accessibility",
"//ui/base",
Expand Down
27 changes: 18 additions & 9 deletions browser/ui/webui/settings/brave_default_extensions_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/webstore_install_with_prompt.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/web_ui.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"

void BraveDefaultExtensionsHandler::RegisterMessages() {
Expand Down Expand Up @@ -83,6 +85,15 @@ void BraveDefaultExtensionsHandler::SetHangoutsEnabled(
}
}

bool BraveDefaultExtensionsHandler::IsExtensionInstalled(
const std::string extension_id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you probably want const std::string& here?

extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(
static_cast<content::BrowserContext*>(profile_));
return registry && registry->GetInstalledExtension(extension_id);
}


void BraveDefaultExtensionsHandler::SetIPFSCompanionEnabled(
const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);
Expand All @@ -91,19 +102,17 @@ void BraveDefaultExtensionsHandler::SetIPFSCompanionEnabled(
args->GetBoolean(0, &enabled);

extensions::ExtensionService* service =
extensions::ExtensionSystem::Get(profile_)->extension_service();

extensions::ExtensionSystem::Get(profile_)->extension_service();
if (enabled) {
extensions::ComponentLoader* loader = service->component_loader();
if (!loader->Exists(ipfs_companion_extension_id)) {
static_cast<extensions::BraveComponentLoader*>(loader)->
AddExtension(ipfs_companion_extension_id,
ipfs_companion_extension_name,
ipfs_companion_extension_public_key);
if (!IsExtensionInstalled(ipfs_companion_extension_id)) {
scoped_refptr<extensions::WebstoreInstallWithPrompt> installer =
new extensions::WebstoreInstallWithPrompt(
ipfs_companion_extension_id, profile_, base::DoNothing());
installer->BeginInstall();
}
service->EnableExtension(ipfs_companion_extension_id);
} else {
service->DisableExtension(ipfs_companion_extension_id,
extensions::disable_reason::DisableReason::DISABLE_BLOCKED_BY_POLICY);
extensions::disable_reason::DisableReason::DISABLE_USER_ACTION);
}
}
2 changes: 2 additions & 0 deletions browser/ui/webui/settings/brave_default_extensions_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler {
void SetHangoutsEnabled(const base::ListValue* args);
void SetIPFSCompanionEnabled(const base::ListValue* args);

bool IsExtensionInstalled(const std::string extension_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be a const method?


Profile* profile_ = nullptr;

DISALLOW_COPY_AND_ASSIGN(BraveDefaultExtensionsHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace extensions {
pdfjs_extension_id,
brave_rewards_extension_id,
brave_sync_extension_id,
brave_webtorrent_extension_id,
ipfs_companion_extension_id
brave_webtorrent_extension_id
};

for (size_t i = 0; i < base::size(kAllowed); ++i) {
Expand Down