Skip to content

Commit

Permalink
Merge pull request #2342 from brave/use_pdfium
Browse files Browse the repository at this point in the history
Use pdfium
  • Loading branch information
bsclifton committed May 31, 2019
2 parents dee7af4 + ab13729 commit a90dad3
Show file tree
Hide file tree
Showing 35 changed files with 22 additions and 853 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@a85d71af4e416cf8188dc297320b0d777aafa315",
"vendor/extension-whitelist": "https://github.com/brave/extension-whitelist.git@463e5e4e06e0ca84927176e8c72f6076ae9b6829",
"vendor/extension-whitelist": "https://github.com/brave/extension-whitelist.git@a3a9a768900909739db99d79541fc56c2984407d",
"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
59 changes: 1 addition & 58 deletions browser/extensions/brave_component_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,14 @@

namespace extensions {

// static
bool BraveComponentLoader::IsPdfjsDisabled() {
#if defined(OS_ANDROID)
return true;
#else
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
return command_line.HasSwitch(switches::kDisablePDFJSExtension);
#endif
}

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) {
// TODO(bridiver) - this doesn't belong here
#if !defined(OS_ANDROID)
ObserveOpenPdfExternallySetting();
#endif
profile_prefs_(profile_prefs) {
}

BraveComponentLoader::~BraveComponentLoader() {
Expand Down Expand Up @@ -105,12 +89,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 @@ -130,39 +108,4 @@ void BraveComponentLoader::AddDefaultComponentExtensions(
}
}

#if !defined(OS_ANDROID)
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)));
}
}
#endif

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
23 changes: 1 addition & 22 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,34 +39,15 @@ class BraveComponentLoader : public ComponentLoader {
// hangouts is set. If the buildflag is not set, it won't add though.
void ForceAddHangoutServicesExtension();

static bool IsPdfjsDisabled();

private:
#if BUILDFLAG(ENABLE_HANGOUT_SERVICES_EXTENSION)
void AddHangoutServicesExtension() override;
#endif // BUILDFLAG(ENABLE_HANGOUT_SERVICES_EXTENSION)
friend class ::BraveComponentLoaderTest;
#if !defined(OS_ANDROID)
void ObserveOpenPdfExternallySetting();
#endif
// 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
94 changes: 0 additions & 94 deletions browser/extensions/brave_component_loader_browsertest.cc

This file was deleted.

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_component_updater::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
28 changes: 0 additions & 28 deletions browser/extensions/brave_extension_provider_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,6 @@ IN_PROC_BROWSER_TEST_F(BraveExtensionProviderTest, WhitelistedExtension) {
ASSERT_TRUE(extension);
}

IN_PROC_BROWSER_TEST_F(BraveExtensionProviderTest, PDFJSInstalls) {
base::FilePath test_data_dir;
GetTestDataDir(&test_data_dir);
InstallExtensionSilently(extension_service(),
test_data_dir.AppendASCII("pdfjs.crx"));

content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
GURL url = embedded_test_server()->GetURL("/test.pdf");
ui_test_utils::NavigateToURL(browser(), url);
ASSERT_TRUE(WaitForLoadStop(contents));

// Test.pdf is just a PDF file for an icon with title test.ico
base::string16 expected_title(base::ASCIIToUTF16("test.ico - test.pdf"));
content::TitleWatcher title_watcher(
browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());

// Make sure pdfjs embed exists
bool pdfjs_exists;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
browser()->tab_strip_model()->GetWebContentsAt(0),
"window.domAutomationController.send("
"!!document.body.querySelector(\"#chrome-pdfjs-logo-bg\"))", &pdfjs_exists));
ASSERT_TRUE(pdfjs_exists);
}

// Load an extension page with an ad image, and make sure it is NOT blocked.
// It would otherwise be blocked though if it wasn't an extension.
IN_PROC_BROWSER_TEST_F(BraveExtensionProviderTest, AdsNotBlockedByDefaultBlockerInExtension) {
Expand Down
2 changes: 0 additions & 2 deletions browser/ui/webui/brave_settings_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ void BraveSettingsUI::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.

This file was deleted.

Loading

0 comments on commit a90dad3

Please sign in to comment.