Skip to content

Commit

Permalink
WIP - removal of pdf.js
Browse files Browse the repository at this point in the history
  • Loading branch information
bsclifton committed Apr 25, 2019
1 parent 069e0a6 commit 7338878
Show file tree
Hide file tree
Showing 21 changed files with 6 additions and 271 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use_relative_paths = True
deps = {
"vendor/ad-block": "https://github.com/brave/ad-block.git@11ab48c4b2bd5355e789d4c87005ab2c14eecc09",
"vendor/autoplay-whitelist": "https://github.com/brave/autoplay-whitelist.git@458053a3c95b403cbe0872f289a2aafa106ee9d8",
"vendor/extension-whitelist": "https://github.com/brave/extension-whitelist.git@463e5e4e06e0ca84927176e8c72f6076ae9b6829",
"vendor/extension-whitelist": "https://github.com/brave/extension-whitelist.git@c9c442343ff4711726e4792569bbac8ff3d980b9",
"vendor/tracking-protection": "https://github.com/brave/tracking-protection.git@29b1f86b11a8c7438fd7d57b446a77a84946712a",
"vendor/hashset-cpp": "https://github.com/brave/hashset-cpp.git@4b55fe39bb25bb0d8b11a43d547d75f00c6c46fb",
"vendor/bloom-filter-cpp": "https://github.com/brave/bloom-filter-cpp.git@9be5c63b14e094156e00c8b28f205e7794f0b92c",
Expand Down
50 changes: 1 addition & 49 deletions browser/extensions/brave_component_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,14 @@

namespace extensions {

// static
bool BraveComponentLoader::IsPdfjsDisabled() {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
return command_line.HasSwitch(switches::kDisablePDFJSExtension);
}

BraveComponentLoader::BraveComponentLoader(
ExtensionServiceInterface* extension_service,
PrefService* profile_prefs,
PrefService* local_state,
Profile* profile)
: ComponentLoader(extension_service, profile_prefs, local_state, profile),
profile_(profile),
profile_prefs_(profile_prefs),
testing_callbacks_(nullptr) {
ObserveOpenPdfExternallySetting();
profile_prefs_(profile_prefs) {
}

BraveComponentLoader::~BraveComponentLoader() {
Expand Down Expand Up @@ -101,12 +92,6 @@ void BraveComponentLoader::AddDefaultComponentExtensions(
Add(IDR_BRAVE_EXTENSION, brave_extension_path);
}

if (!profile_prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally) &&
!command_line.HasSwitch(switches::kDisablePDFJSExtension)) {
AddExtension(pdfjs_extension_id, pdfjs_extension_name,
pdfjs_extension_public_key);
}

#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
if (!command_line.HasSwitch(switches::kDisableBraveRewardsExtension)) {
base::FilePath brave_rewards_path(FILE_PATH_LITERAL(""));
Expand All @@ -126,37 +111,4 @@ void BraveComponentLoader::AddDefaultComponentExtensions(
}
}

void BraveComponentLoader::ObserveOpenPdfExternallySetting() {
// Observe the setting change only in regular profiles since the PDF settings
// page is not available in Guest/Tor profiles.
DCHECK(profile_ && profile_prefs_);
if (!profile_->IsGuestSession()) {
registrar_.Init(profile_prefs_);
registrar_.Add(prefs::kPluginsAlwaysOpenPdfExternally,
base::Bind(&BraveComponentLoader::UpdatePdfExtension,
base::Unretained(this)));
}
}

void BraveComponentLoader::UpdatePdfExtension(const std::string& pref_name) {
DCHECK(pref_name == prefs::kPluginsAlwaysOpenPdfExternally);
DCHECK(profile_prefs_);
if (profile_prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally) ||
IsPdfjsDisabled()) {
if (testing_callbacks_)
testing_callbacks_->OnPdfExtensionAction(TestingCallbacks::WILL_REMOVE);
Remove(pdfjs_extension_id);
} else if (!Exists(pdfjs_extension_id)) {
if (testing_callbacks_)
testing_callbacks_->OnPdfExtensionAction(TestingCallbacks::WILL_ADD);
AddExtension(pdfjs_extension_id, pdfjs_extension_name,
pdfjs_extension_public_key);
}
}

void BraveComponentLoader::set_testing_callbacks(
TestingCallbacks* testing_callbacks) {
testing_callbacks_ = testing_callbacks;
}

} // namespace extensions
21 changes: 1 addition & 20 deletions browser/extensions/brave_component_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "chrome/browser/extensions/component_loader.h"
#include "components/prefs/pref_change_registrar.h"

class BraveComponentLoaderTest;

namespace extensions {

// For registering, loading, and unloading component extensions.
Expand Down Expand Up @@ -41,30 +39,13 @@ class BraveComponentLoader : public ComponentLoader {
// hangouts is set. If the buildflag is not set, it won't add though.
void ForceAddHangoutServicesExtension();

static bool IsPdfjsDisabled();

private:
void AddHangoutServicesExtension() override;
friend class ::BraveComponentLoaderTest;
void ObserveOpenPdfExternallySetting();
// Callback for changes to the AlwaysOpenPdfExternally setting.
void UpdatePdfExtension(const std::string& pref_name);

struct TestingCallbacks {
enum PdfExtensionAction {
NONE,
WILL_ADD,
WILL_REMOVE,
};
virtual void OnPdfExtensionAction(PdfExtensionAction action) = 0;
};

void set_testing_callbacks(TestingCallbacks* testing_callbacks);

Profile* profile_;
PrefService* profile_prefs_;
PrefChangeRegistrar registrar_;
TestingCallbacks* testing_callbacks_;

DISALLOW_COPY_AND_ASSIGN(BraveComponentLoader);
};

Expand Down
6 changes: 3 additions & 3 deletions browser/extensions/brave_extension_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ bool IsBlacklisted(const extensions::Extension* extension) {
{// Used for tests, corresponds to
// brave/test/data/should-be-blocked-extension.
"mlklomjnahgiddgfdgjhibinlfibfffc",
// Chromium PDF Viewer.
"mhjfbmdgcfjbbpaeojofohoefgiehjai"});
});

if (std::find(blacklisted_extensions.begin(), blacklisted_extensions.end(),
extension->id()) != blacklisted_extensions.end())
Expand Down Expand Up @@ -58,7 +57,6 @@ bool BraveExtensionProvider::IsVetted(const std::string id) {
brave_sync_extension_id,
brave_webtorrent_extension_id,
crl_set_extension_id,
pdfjs_extension_id,
hangouts_extension_id,
widevine_extension_id,
brave_shields::kLocalDataFilesComponentId,
Expand All @@ -79,6 +77,8 @@ bool BraveExtensionProvider::IsVetted(const std::string id) {
"bhlmpjhncoojbkemjkeppfahkglffilp",
// Test ID: Brave Tor Client Updater
"ngicbhhaldfdgmjhilmnleppfpmkgbbk",
// Chromium PDF Viewer.
"mhjfbmdgcfjbbpaeojofohoefgiehjai",
});
if (std::find(vetted_extensions.begin(), vetted_extensions.end(), id) !=
vetted_extensions.end())
Expand Down
2 changes: 0 additions & 2 deletions browser/ui/webui/brave_md_settings_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ void BraveMdSettingsUI::AddResources(content::WebUIDataSource* html_source,
kBraveSettingsResources[i].value);
}

html_source->AddBoolean("isPdfjsDisabled",
extensions::BraveComponentLoader::IsPdfjsDisabled());
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
html_source->AddBoolean("isSyncDisabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace extensions {
bool IsComponentExtensionWhitelisted(const std::string& extension_id) {
const char* const kAllowed[] = {
brave_extension_id,
pdfjs_extension_id,
brave_rewards_extension_id,
brave_sync_extension_id,
brave_webtorrent_extension_id
Expand Down
11 changes: 0 additions & 11 deletions chromium_src/chrome/common/extensions/chrome_manifest_handlers.cc

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ source_set("common") {
"extensions/brave_extensions_api_provider.h",
"extensions/extension_constants.cc",
"extensions/extension_constants.h",
"extensions/manifest_handlers/pdfjs_manifest_override.cc",
"extensions/manifest_handlers/pdfjs_manifest_override.h",
"importer/brave_importer_utils.cc",
"importer/brave_importer_utils.h",
"importer/brave_ledger.cc",
Expand Down
3 changes: 0 additions & 3 deletions common/brave_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ const char kDisableBraveUpdate[] = "disable-brave-update";
const char kDisableChromeGoogleURLTrackingClient[] =
"disable-chrome-google-url-tracking-client";

// Allows disabling the PDFJS extension.
const char kDisablePDFJSExtension[] = "disable-pdfjs-extension";

// Allows disabling the Tor client updater extension.
const char kDisableTorClientUpdaterExtension[] =
"disable-tor-client-updater-extension";
Expand Down
2 changes: 0 additions & 2 deletions common/brave_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ extern const char kDisableBraveUpdate[];

extern const char kDisableChromeGoogleURLTrackingClient[];

extern const char kDisablePDFJSExtension[];

extern const char kDisableTorClientUpdaterExtension[];

extern const char kDisableWebTorrentExtension[];
Expand Down
10 changes: 0 additions & 10 deletions common/extensions/extension_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ const char widevine_extension_id[] = "oimompecagnajdejgnnjijobebaeigek";
const char brave_sync_extension_id[] = "nomlkjnggnifocmealianaaiobmebgil";
const char crl_set_extension_id[] = "hfnkpimlhhgieaddgfemjhofmfblmnib";

const char pdfjs_extension_id[] = "oemmndcbldboiebfnladdacbdfmadadm";
const char pdfjs_extension_name[] = "PDF Viewer (PDF.js)";
const char pdfjs_extension_public_key[] =
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDb5PIb8ayK6vHvEIY1nJKRSCDE8iJ1T43qFN"
"+5dvCVQrmyEkgqB9ZuZNT24Lwot96HV51VoITHKRNIVKI2Nrbfn0M49t7qtaP34g/"
"GXJ7mAIbSzsY4+i+"
"Wsz8EL2SNEIw6uH8RmXG7nZ29NJ7sk7jn17QmMsO2UJ01UT8hfOOOEQIDAQAB";
const char pdfjs_extension_origin[] =
"chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/";

const char ipfs_companion_extension_id[] = "nibjojkomfdiaoajekhjakgkdhaomnch";
const char ipfs_companion_extension_name[] = "IPFS Companion";
const char ipfs_companion_extension_public_key[] =
Expand Down
5 changes: 0 additions & 5 deletions common/extensions/extension_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ extern const char widevine_extension_id[];
extern const char brave_sync_extension_id[];
extern const char crl_set_extension_id[];

extern const char pdfjs_extension_id[];
extern const char pdfjs_extension_name[];
extern const char pdfjs_extension_public_key[];
extern const char pdfjs_extension_origin[];

extern const char ipfs_companion_extension_id[];
extern const char ipfs_companion_extension_name[];
extern const char ipfs_companion_extension_public_key[];
Expand Down
26 changes: 0 additions & 26 deletions common/extensions/manifest_handlers/pdfjs_manifest_override.cc

This file was deleted.

26 changes: 0 additions & 26 deletions common/extensions/manifest_handlers/pdfjs_manifest_override.h

This file was deleted.

23 changes: 0 additions & 23 deletions patches/chrome-browser-extensions-install_verifier.cc.patch

This file was deleted.

14 changes: 0 additions & 14 deletions patches/chrome-browser-plugins-plugin_utils.cc.patch

This file was deleted.

This file was deleted.

This file was deleted.

Binary file removed test/data/pdfjs.crx
Binary file not shown.
Loading

0 comments on commit 7338878

Please sign in to comment.