Skip to content

Commit

Permalink
Install PDF.js from component updater
Browse files Browse the repository at this point in the history
This also fixes a problem where PDF.js was not always installed.
This also fixes PDF.js disabling command line.
This also fixes intermittent PDF.js failures in tests.

Fix brave/brave-browser#1375
Fix brave/brave-browser#1253
Fix brave/brave-browser#1072
  • Loading branch information
bbondy committed Oct 10, 2018
1 parent 60fe265 commit 0f7eb50
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 21 deletions.
17 changes: 16 additions & 1 deletion browser/component_updater/brave_component_installer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ bool RewriteManifestFile(
return true;
}

std::string GetManifestString(const base::DictionaryValue& manifest,
const std::string &public_key) {
std::unique_ptr<base::DictionaryValue> final_manifest(manifest.DeepCopy());
final_manifest->SetString(extensions::manifest_keys::kPublicKey, public_key);

std::string manifest_json;
JSONStringValueSerializer serializer(&manifest_json);
serializer.set_pretty_print(true);
if (!serializer.Serialize(*final_manifest)) {
return "";
}
return manifest_json;
}


} // namespace

namespace brave {
Expand Down Expand Up @@ -107,7 +122,7 @@ void BraveComponentInstallerPolicy::ComponentReady(
const base::Version& version,
const base::FilePath& install_dir,
std::unique_ptr<base::DictionaryValue> manifest) {
ready_callback_.Run(install_dir);
ready_callback_.Run(install_dir, GetManifestString(*manifest, base64_public_key_));
}

base::FilePath BraveComponentInstallerPolicy::GetRelativeInstallDir() const {
Expand Down
3 changes: 2 additions & 1 deletion browser/component_updater/brave_component_installer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace base {
class FilePath;
} // namespace base

using ReadyCallback = base::Callback<void(const base::FilePath&)>;
using ReadyCallback = base::Callback<void(const base::FilePath&,
const std::string& manifest)>;

namespace brave {

Expand Down
3 changes: 2 additions & 1 deletion browser/extensions/brave_component_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ void BraveComponentExtension::OnComponentRegistered(const std::string& component

void BraveComponentExtension::OnComponentReady(
const std::string& component_id,
const base::FilePath& install_dir) {
const base::FilePath& install_dir,
const std::string& manifest) {
}
3 changes: 2 additions & 1 deletion browser/extensions/brave_component_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class BraveComponentExtension : public ComponentsUI {
protected:
virtual void OnComponentRegistered(const std::string& component_id);
virtual void OnComponentReady(const std::string& component_id,
const base::FilePath& install_dir);
const base::FilePath& install_dir,
const std::string& manifest);

private:
std::string component_name_;
Expand Down
33 changes: 33 additions & 0 deletions browser/extensions/brave_component_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include "brave/browser/extensions/brave_component_loader.h"

#include "base/command_line.h"
#include "brave/browser/brave_browser_process_impl.h"
#include "brave/browser/component_updater/brave_component_installer.h"
#include "brave/browser/extensions/brave_component_extension.h"
#include "brave/common/brave_switches.h"
#include "brave/common/extensions/extension_constants.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_rewards/extension/grit/brave_rewards_resources.h"
#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h"
Expand All @@ -24,6 +28,31 @@ BraveComponentLoader::BraveComponentLoader(
BraveComponentLoader::~BraveComponentLoader() {
}

void BraveComponentLoader::OnComponentRegistered(std::string extension_id) {
ComponentsUI demand_updater;
// This weird looking call is ok, it is just like this to not need
// to patch for friend access.
demand_updater.OnDemandUpdate(g_browser_process->component_updater(),
extension_id);
}

void BraveComponentLoader::OnComponentReady(std::string extension_id,
const base::FilePath& install_dir,
const std::string& manifest) {
Add(manifest, install_dir);
}

void BraveComponentLoader::AddExtension(const std::string& extension_id,
const std::string& name, const std::string& public_key) {
brave::RegisterComponent(g_browser_process->component_updater(),
name,
public_key,
base::Bind(&BraveComponentLoader::OnComponentRegistered,
base::Unretained(this), extension_id),
base::Bind(&BraveComponentLoader::OnComponentReady,
base::Unretained(this), extension_id));
}

void BraveComponentLoader::AddDefaultComponentExtensions(
bool skip_session_components) {
ComponentLoader::AddDefaultComponentExtensions(skip_session_components);
Expand All @@ -37,6 +66,10 @@ void BraveComponentLoader::AddDefaultComponentExtensions(
Add(IDR_BRAVE_EXTENSON, brave_extension_path);
}

if (!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 Down
8 changes: 8 additions & 0 deletions browser/extensions/brave_component_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef BRAVE_BROWSER_EXTENSIONS_BRAVE_COMPONENT_LOADER_H_
#define BRAVE_BROWSER_EXTENSIONS_BRAVE_COMPONENT_LOADER_H_

#include "base/files/file_path.h"
#include "chrome/browser/extensions/component_loader.h"

namespace extensions {
Expand All @@ -23,6 +24,13 @@ class BraveComponentLoader : public ComponentLoader {
// be loaded unless we are in signed user session (ChromeOS). For all other
// platforms this |skip_session_components| is expected to be unset.
void AddDefaultComponentExtensions(bool skip_session_components) override;
void OnComponentRegistered(std::string extension_id);
void OnComponentReady(std::string extension_id,
const base::FilePath& install_dir,
const std::string& manifest);
void AddExtension(const std::string& id,
const std::string& name, const std::string& public_key);


DISALLOW_COPY_AND_ASSIGN(BraveComponentLoader);
};
Expand Down
3 changes: 2 additions & 1 deletion browser/extensions/brave_tor_client_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ void BraveTorClientUpdater::InitExecutablePath(

void BraveTorClientUpdater::OnComponentReady(
const std::string& component_id,
const base::FilePath& install_dir) {
const base::FilePath& install_dir,
const std::string& manifest) {
GetTaskRunner()->PostTask(
FROM_HERE, base::Bind(&BraveTorClientUpdater::InitExecutablePath,
base::Unretained(this), install_dir));
Expand Down
3 changes: 2 additions & 1 deletion browser/extensions/brave_tor_client_updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class BraveTorClientUpdater : public BraveComponentExtension {

protected:
void OnComponentReady(const std::string& component_id,
const base::FilePath& install_dir) override;
const base::FilePath& install_dir,
const std::string& manifest) override;

private:
friend class ::BraveTorClientUpdaterTest;
Expand Down
2 changes: 1 addition & 1 deletion browser/extensions/brave_tor_client_updater_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class BraveTorClientUpdaterTest : public ExtensionBrowserTest {
return false;

g_brave_browser_process->tor_client_updater()->OnComponentReady(
tor_client_updater->id(), tor_client_updater->path());
tor_client_updater->id(), tor_client_updater->path(), "");
WaitForTorClientUpdaterThread();

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace extensions {
bool IsComponentExtensionWhitelisted(const std::string& extension_id) {
const char* const kAllowed[] = {
brave_extension_id,
pdfjs_extension_id,
brave_rewards_extension_id,
brave_webtorrent_extension_id
};
Expand Down
5 changes: 4 additions & 1 deletion common/extensions/extension_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
const char brave_extension_id[] = "mnojpmjdmbbfmejpflffifhffcmidifd";
const char brave_rewards_extension_id[] = "jidkidbbcafjabdphckchenhfomhnfma";
const char brave_webtorrent_extension_id[] = "lgjmpdmojkpocjcopdikifhejkkjglho";
const char pdfjs_extension_id[] = "oemmndcbldboiebfnladdacbdfmadadm";
const char widevine_extension_id[] = "oimompecagnajdejgnnjijobebaeigek";

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";
5 changes: 4 additions & 1 deletion common/extensions/extension_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
extern const char brave_extension_id[];
extern const char brave_rewards_extension_id[];
extern const char brave_webtorrent_extension_id[];
extern const char pdfjs_extension_id[];
extern const char widevine_extension_id[];

extern const char pdfjs_extension_id[];
extern const char pdfjs_extension_name[];
extern const char pdfjs_extension_public_key[];
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ void AdBlockRegionalService::OnComponentRegistered(

void AdBlockRegionalService::OnComponentReady(
const std::string& component_id,
const base::FilePath& install_dir) {
const base::FilePath& install_dir,
const std::string& manifest) {
base::FilePath dat_file_path =
install_dir.AppendASCII(g_ad_block_regional_dat_file_version_)
.AppendASCII(uuid_)
Expand Down
3 changes: 2 additions & 1 deletion components/brave_shields/browser/ad_block_regional_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class AdBlockRegionalService : public AdBlockBaseService {
bool Init() override;
void OnComponentRegistered(const std::string& component_id) override;
void OnComponentReady(const std::string& component_id,
const base::FilePath& install_dir) override;
const base::FilePath& install_dir,
const std::string& manifest) override;

private:
friend class ::AdBlockServiceTest;
Expand Down
3 changes: 2 additions & 1 deletion components/brave_shields/browser/ad_block_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ bool AdBlockService::Init() {
}

void AdBlockService::OnComponentReady(const std::string& component_id,
const base::FilePath& install_dir) {
const base::FilePath& install_dir,
const std::string& manifest) {
base::FilePath dat_file_path =
install_dir.AppendASCII(g_ad_block_dat_file_version_)
.AppendASCII(DAT_FILE);
Expand Down
3 changes: 2 additions & 1 deletion components/brave_shields/browser/ad_block_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class AdBlockService : public AdBlockBaseService {
protected:
bool Init() override;
void OnComponentReady(const std::string& component_id,
const base::FilePath& install_dir) override;
const base::FilePath& install_dir,
const std::string& manifest) override;

private:
friend class ::AdBlockServiceTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class AdBlockServiceTest : public ExtensionBrowserTest {
return false;

g_brave_browser_process->ad_block_service()->OnComponentReady(
ad_block_extension->id(), ad_block_extension->path());
ad_block_extension->id(), ad_block_extension->path(), "");
WaitForDefaultAdBlockServiceThread();

return true;
Expand All @@ -116,7 +116,7 @@ class AdBlockServiceTest : public ExtensionBrowserTest {
return false;

g_brave_browser_process->ad_block_regional_service()->OnComponentReady(
ad_block_extension->id(), ad_block_extension->path());
ad_block_extension->id(), ad_block_extension->path(), "");
WaitForRegionalAdBlockServiceThread();

return true;
Expand Down
3 changes: 2 additions & 1 deletion components/brave_shields/browser/https_everywhere_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ void HTTPSEverywhereService::InitDB(const base::FilePath& install_dir) {

void HTTPSEverywhereService::OnComponentReady(
const std::string& component_id,
const base::FilePath& install_dir) {
const base::FilePath& install_dir,
const std::string& manifest) {
GetTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&HTTPSEverywhereService::InitDB,
Expand Down
3 changes: 2 additions & 1 deletion components/brave_shields/browser/https_everywhere_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class HTTPSEverywhereService : public BaseBraveShieldsService {
bool Init() override;
void Cleanup() override;
void OnComponentReady(const std::string& component_id,
const base::FilePath& install_dir) override;
const base::FilePath& install_dir,
const std::string& manifest) override;

void AddHTTPSEUrlToRedirectList(const uint64_t& request_id);
bool ShouldHTTPSERedirect(const uint64_t& request_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class HTTPSEverywhereServiceTest : public ExtensionBrowserTest {
return false;

g_brave_browser_process->https_everywhere_service()->OnComponentReady(
httpse_extension->id(), httpse_extension->path());
httpse_extension->id(), httpse_extension->path(), "");
WaitForHTTPSEverywhereServiceThread();

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void TrackingProtectionService::OnDATFileDataReady() {

void TrackingProtectionService::OnComponentReady(
const std::string& component_id,
const base::FilePath& install_dir) {
const base::FilePath& install_dir,
const std::string& manifest) {
base::FilePath dat_file_path =
install_dir.AppendASCII(DAT_FILE_VERSION).AppendASCII(DAT_FILE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class TrackingProtectionService : public BaseBraveShieldsService {
bool Init() override;
void Cleanup() override;
void OnComponentReady(const std::string& component_id,
const base::FilePath& install_dir) override;
const base::FilePath& install_dir,
const std::string& manifest) override;

private:
friend class ::TrackingProtectionServiceTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class TrackingProtectionServiceTest : public ExtensionBrowserTest {
return false;

g_brave_browser_process->tracking_protection_service()->OnComponentReady(
tracking_protection_extension->id(), tracking_protection_extension->path());
tracking_protection_extension->id(), tracking_protection_extension->path(), "");
WaitForTrackingProtectionServiceThread();

return true;
Expand Down

0 comments on commit 0f7eb50

Please sign in to comment.