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

Support Widevine and 2 component updaters #189

Merged
merged 9 commits into from
Jun 27, 2018
17 changes: 17 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@
<message name="IDS_SETTINGS_IMPORT_COOKIES_CHECKBOX" desc="Checkbox for importing cookies">
Cookies
</message>
<message name="IDS_WIDEVINE_NOT_INSTALLED_EXPLANATORY_TEXT" desc="Explanatory animated text that appears (and then disappears) in the address line when Widevine is blocked">
Widevine is not installed
</message>
<message name="IDS_WIDEVINE_NOT_INSTALLED_MESSAGE" desc="Tooltip on the icon when Wideivne is not installed. 'Widevine' is the name of a plugin and should not be translated.">
Widevine is not installed.
</message>
<message name="IDS_INSTALL_AND_RUN_WIDEVINE" desc="Button to install and register Widevine with the component updater. 'Widevine' is the name of a plugin and should not be translated.">
Install and run Widevine
</message>
<message name="IDS_NOT_INSTALLED_WIDEVINE_TITLE" desc="Bubble info header text when Widevine is not installed. 'Widevine' is the name of a plugin and should not be translated.">
Widevine is not installed
</message>
<message name="IDS_WIDEVINE_INSTALL_MESSAGE" desc="Bubble info text when Widevine is not installed. 'Widevine' is the name of a plugin and should not be translated.">
Google Widevine is a piece of Digital Rights Management (DRM) code that we at Brave Software do not own and cannot inspect. The Google Widevine code is loaded from Google servers, not from our servers. It is loaded only when you enable this option. We discourage the use of DRM, but we respect user choice and acknowledge that some Brave users would like to use services that require it.

By installing this extension, you are agreeing to the Google Widevine Terms of Use. You agree that Brave is not responsible for any damages or losses in connection with your use of Google Widevine.
</message>
</messages>
<includes>
<include name="IDR_BRAVE_TAG_SERVICES_POLYFILL" file="resources/js/tag_services_polyfill.js" type="BINDATA" />
Expand Down
24 changes: 18 additions & 6 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,31 @@ BraveBrowserProcessImpl::BraveBrowserProcessImpl(
}

component_updater::ComponentUpdateService*
BraveBrowserProcessImpl::component_updater() {
if (component_updater_)
return component_updater_.get();
BraveBrowserProcessImpl::component_updater(
std::unique_ptr<component_updater::ComponentUpdateService> &component_updater,
bool use_brave_server) {
if (component_updater)
return component_updater.get();

if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
return nullptr;

component_updater_ = component_updater::ComponentUpdateServiceFactory(
component_updater = component_updater::ComponentUpdateServiceFactory(
component_updater::MakeBraveComponentUpdaterConfigurator(
base::CommandLine::ForCurrentProcess(),
g_browser_process->local_state()));
g_browser_process->local_state(), use_brave_server));

return component_updater.get();
}

component_updater::ComponentUpdateService*
BraveBrowserProcessImpl::component_updater() {
return component_updater(component_updater_, true);
}

return component_updater_.get();
component_updater::ComponentUpdateService*
BraveBrowserProcessImpl::google_component_updater() {
return component_updater(google_component_updater_, false);
}

brave_shields::AdBlockService*
Expand Down
9 changes: 9 additions & 0 deletions browser/brave_browser_process_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {

// BrowserProcess implementation.
component_updater::ComponentUpdateService* component_updater() override;
component_updater::ComponentUpdateService* google_component_updater();

brave_shields::AdBlockService* ad_block_service();
brave_shields::AdBlockRegionalService* ad_block_regional_service();
Expand All @@ -41,6 +42,14 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
https_everywhere_service_;
std::unique_ptr<brave::BraveStatsUpdater> brave_stats_updater_;

component_updater::ComponentUpdateService* component_updater(
std::unique_ptr<component_updater::ComponentUpdateService> &,
bool use_brave_server);
std::unique_ptr<component_updater::ComponentUpdateService>
google_component_updater_;
std::unique_ptr<component_updater::ComponentUpdateService>
brave_component_updater_;

DISALLOW_COPY_AND_ASSIGN(BraveBrowserProcessImpl);
};

Expand Down
3 changes: 3 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "brave/browser/brave_profile_prefs.h"

#include "brave/common/pref_names.h"
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/common/pref_names.h"
Expand All @@ -16,6 +17,8 @@ namespace brave {
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
brave_shields::BraveShieldsWebContentsObserver::RegisterProfilePrefs(registry);

registry->RegisterBooleanPref(kWidevineOptedIn, false);

// No sign into Brave functionality
registry->SetDefaultPrefValue(prefs::kSigninAllowed, base::Value(false));

Expand Down
3 changes: 3 additions & 0 deletions browser/brave_profile_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/common/pref_names.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
Expand All @@ -14,4 +15,6 @@ using BraveProfilePrefsBrowserTest = InProcessBrowserTest;
IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, DownloadPromptDefault) {
EXPECT_TRUE(
browser()->profile()->GetPrefs()->GetBoolean(prefs::kPromptForDownload));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kWidevineOptedIn));
}
33 changes: 26 additions & 7 deletions browser/component_updater/brave_component_updater_configurator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "base/strings/sys_string_conversions.h"
#include "base/version.h"
#include "brave/common/network_constants.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/pref_names.h"
Expand All @@ -36,7 +37,8 @@ namespace {
class BraveConfigurator : public update_client::Configurator {
public:
BraveConfigurator(const base::CommandLine* cmdline,
PrefService* pref_service);
PrefService* pref_service,
bool use_brave_server);

// update_client::Configurator overrides.
int InitialDelay() const override;
Expand Down Expand Up @@ -70,6 +72,7 @@ class BraveConfigurator : public update_client::Configurator {

ConfiguratorImpl configurator_impl_;
PrefService* pref_service_; // This member is not owned by this class.
bool use_brave_server_;

~BraveConfigurator() override {}
};
Expand All @@ -79,14 +82,22 @@ class BraveConfigurator : public update_client::Configurator {
// a custom message signing protocol and it does not depend on using HTTPS.
BraveConfigurator::BraveConfigurator(
const base::CommandLine* cmdline,
PrefService* pref_service)
PrefService* pref_service,
bool use_brave_server)
: configurator_impl_(cmdline, false),
pref_service_(pref_service) {
pref_service_(pref_service),
use_brave_server_(use_brave_server) {
DCHECK(pref_service_);
}

int BraveConfigurator::InitialDelay() const {
return configurator_impl_.InitialDelay();
if (use_brave_server_) {
return configurator_impl_.InitialDelay();
}
// This just makes it so as soon as the Google component update
// is used it checks for Widevine, which is currently the only
// place we use it.
return 10;
}

int BraveConfigurator::NextCheckDelay() const {
Expand All @@ -102,6 +113,10 @@ int BraveConfigurator::UpdateDelay() const {
}

std::vector<GURL> BraveConfigurator::UpdateUrl() const {
if (use_brave_server_) {
return std::vector<GURL>
{GURL(kBraveUpdatesExtensionsEndpoint)};
}
return configurator_impl_.UpdateUrl();
}

Expand Down Expand Up @@ -167,7 +182,10 @@ bool BraveConfigurator::EnabledBackgroundDownloader() const {
}

bool BraveConfigurator::EnabledCupSigning() const {
return false;
if (use_brave_server_) {
return false;
}
return configurator_impl_.EnabledCupSigning();
}

PrefService* BraveConfigurator::GetPrefService() const {
Expand Down Expand Up @@ -198,8 +216,9 @@ void RegisterPrefsForBraveComponentUpdaterConfigurator(
scoped_refptr<update_client::Configurator>
MakeBraveComponentUpdaterConfigurator(
const base::CommandLine* cmdline,
PrefService* pref_service) {
return base::MakeRefCounted<BraveConfigurator>(cmdline, pref_service);
PrefService* pref_service,
bool use_brave_server) {
return base::MakeRefCounted<BraveConfigurator>(cmdline, pref_service, use_brave_server);
}

} // namespace component_updater
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ void RegisterPrefsForBraveComponentUpdaterConfigurator(
scoped_refptr<update_client::Configurator>
MakeBraveComponentUpdaterConfigurator(
const base::CommandLine* cmdline,
PrefService* pref_service);
PrefService* pref_service,
bool use_brave_server);

} // namespace component_updater

Expand Down
18 changes: 0 additions & 18 deletions browser/net/brave_static_redirect_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@

namespace brave {

bool IsUpdaterURL(const GURL& gurl) {
static std::vector<URLPattern> updater_patterns({
URLPattern(URLPattern::SCHEME_HTTPS, std::string(component_updater::kUpdaterDefaultUrl) + "*"),
URLPattern(URLPattern::SCHEME_HTTP, std::string(component_updater::kUpdaterFallbackUrl) + "*"),
URLPattern(URLPattern::SCHEME_HTTPS, std::string(component_updater::kUpdaterDefaultUrlAlt) + "*"),
URLPattern(URLPattern::SCHEME_HTTP, std::string(component_updater::kUpdaterFallbackUrlAlt) + "*"),
});
return std::any_of(updater_patterns.begin(), updater_patterns.end(),
[&gurl](URLPattern pattern){
return pattern.MatchesURL(gurl);
});
}

int OnBeforeURLRequest_StaticRedirectWork(
net::URLRequest* request,
GURL* new_url,
Expand All @@ -45,11 +32,6 @@ int OnBeforeURLRequest_StaticRedirectWork(
return net::OK;
}

if (IsUpdaterURL(request->url())) {
replacements.SetQueryStr(request->url().query_piece());
*new_url = GURL(kBraveUpdatesExtensionsEndpoint).ReplaceComponents(replacements);
return net::OK;
}
return net::OK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,4 @@ TEST_F(BraveStaticRedirectNetworkDelegateHelperTest, ModifySafeBrowsingURLV5) {
EXPECT_EQ(ret, net::OK);
}


TEST_F(BraveStaticRedirectNetworkDelegateHelperTest, ModifyComponentUpdaterURL) {
net::TestDelegate test_delegate;
std::string query_string("?foo=bar");
GURL url(std::string(component_updater::kUpdaterDefaultUrl) + query_string);
std::unique_ptr<net::URLRequest> request =
context()->CreateRequest(url, net::IDLE, &test_delegate,
TRAFFIC_ANNOTATION_FOR_TESTS);
std::shared_ptr<brave::BraveRequestInfo>
before_url_context(new brave::BraveRequestInfo());
brave::ResponseCallback callback;
GURL new_url;
GURL expected_url(std::string(kBraveUpdatesExtensionsEndpoint + query_string));
int ret =
OnBeforeURLRequest_StaticRedirectWork(request.get(), &new_url, callback,
before_url_context);
EXPECT_EQ(new_url, expected_url);
EXPECT_EQ(ret, net::OK);
}


} // namespace
8 changes: 8 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ source_set("ui") {
sources = [
"brave_browser_command_controller.cc",
"brave_browser_command_controller.h",
"brave_browser_content_setting_bubble_model_delegate.cc",
"brave_browser_content_setting_bubble_model_delegate.h",
"brave_pages.cc",
"brave_pages.h",
"content_settings/brave_content_setting_bubble_model.cc",
"content_settings/brave_content_setting_bubble_model.h",
"content_settings/brave_content_setting_image_models.cc",
"content_settings/brave_content_setting_image_models.h",
"content_settings/brave_widevine_blocked_image_model.cc",
"content_settings/brave_widevine_blocked_image_model.h",
"content_settings/brave_widevine_content_setting_bubble_model.cc",
"content_settings/brave_widevine_content_setting_bubble_model.h",
"toolbar/brave_app_menu_model.cc",
"toolbar/brave_app_menu_model.h",
"views/importer/brave_import_lock_dialog_view.cc",
Expand Down
26 changes: 26 additions & 0 deletions browser/ui/brave_browser_content_setting_bubble_model_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/brave_browser_content_setting_bubble_model_delegate.h"

#include "brave/common/url_constants.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"

BraveBrowserContentSettingBubbleModelDelegate::
BraveBrowserContentSettingBubbleModelDelegate(Browser* browser) :
BrowserContentSettingBubbleModelDelegate(browser),
browser_(browser) {
}

BraveBrowserContentSettingBubbleModelDelegate::
~BraveBrowserContentSettingBubbleModelDelegate() {
}

void
BraveBrowserContentSettingBubbleModelDelegate::ShowWidevineLearnMorePage() {
GURL learn_more_url = GURL(kWidevineTOS);
chrome::AddSelectedTabWithURL(browser_, learn_more_url,
ui::PAGE_TRANSITION_LINK);
}
24 changes: 24 additions & 0 deletions browser/ui/brave_browser_content_setting_bubble_model_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_BRAVE_BROWSER_CONTENT_SETTING_BUBBLE_MODEL_DELEGATE_H_
#define BRAVE_BROWSER_UI_BRAVE_BROWSER_CONTENT_SETTING_BUBBLE_MODEL_DELEGATE_H_

#include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"

class BraveBrowserContentSettingBubbleModelDelegate
: public BrowserContentSettingBubbleModelDelegate {
public:
explicit BraveBrowserContentSettingBubbleModelDelegate(Browser* browser);
~BraveBrowserContentSettingBubbleModelDelegate() override;

void ShowWidevineLearnMorePage();

private:
Browser* const browser_;

DISALLOW_COPY_AND_ASSIGN(BraveBrowserContentSettingBubbleModelDelegate);
};

#endif // BRAVE_BROWSER_UI_BRAVE_BROWSER_CONTENT_SETTING_BUBBLE_MODEL_DELEGATE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ class Profile;

class BraveContentSettingPluginBubbleModel : public ContentSettingSimpleBubbleModel {
public:
BraveContentSettingPluginBubbleModel(Delegate* delegate,
content::WebContents* web_contents,
Profile* profile);
BraveContentSettingPluginBubbleModel(
ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents,
Profile* profile);

private:
void OnLearnMoreClicked() override;
Expand Down
14 changes: 14 additions & 0 deletions browser/ui/content_settings/brave_content_setting_image_models.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/content_settings/brave_content_setting_image_models.h"

#include "brave/browser/ui/content_settings/brave_widevine_blocked_image_model.h"

void BraveGenerateContentSettingImageModels(
std::vector<std::unique_ptr<ContentSettingImageModel>>& result) {
result.push_back(std::make_unique<BraveWidevineBlockedImageModel>(
BraveWidevineBlockedImageModel::ImageType::PLUGINS,
CONTENT_SETTINGS_TYPE_PLUGINS));
}
11 changes: 11 additions & 0 deletions browser/ui/content_settings/brave_content_setting_image_models.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <memory>
#include <vector>

class ContentSettingImageModel;

void BraveGenerateContentSettingImageModels(
std::vector<std::unique_ptr<ContentSettingImageModel>>&);
Loading