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 1, 2019
1 parent 501f4e0 commit d937140
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 324 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@d5c7128599889e4e2a797b402a517c664d53fad2",
"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
20 changes: 0 additions & 20 deletions browser/extensions/brave_component_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "chrome/browser/extensions/component_loader.h"
#include "components/prefs/pref_change_registrar.h"

class BravePDFExtensionTest;

namespace extensions {

// For registering, loading, and unloading component extensions.
Expand All @@ -37,31 +35,13 @@ class BraveComponentLoader : public ComponentLoader {
// ForceAddHangoutServicesExtension ignores whether or not a preference for
// 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 ::BravePDFExtensionTest;
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 @@ -47,8 +47,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 @@ -20,9 +20,6 @@ const char kDisableBraveUpdate[] = "disable-brave-update";
// This switch disables the ChromeGoogleURLTrackerClient
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 @@ -17,8 +17,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 @@ -12,13 +12,3 @@ const char hangouts_extension_id[] = "nkeimhogjdpnpccoofpliimaahmaaome";
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/";
5 changes: 0 additions & 5 deletions common/extensions/extension_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@ 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[];

#endif // BRAVE_COMMON_EXTENSIONS_EXTENSION_CONSTANTS_H_
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.

Loading

0 comments on commit d937140

Please sign in to comment.