Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Enable safe_browsing_api for muon
Browse files Browse the repository at this point in the history
  • Loading branch information
jumde committed Jan 2, 2018
1 parent f568200 commit aac0a4d
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 83 deletions.
7 changes: 7 additions & 0 deletions atom/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,29 @@ source_set("browser") {
]

deps = [
"../../chromium_src/chrome/browser/prerender",
"//electron:common",
"//electron/muon/app",
# @todo(bridiver) fix circular dep
# "//electron/muon/browser",
"//base",
"//chrome/browser:resource_prefetch_predictor_proto",
"//chrome/common:constants",
"//storage/browser",
"//storage/common",
"//components/prefs",
"//components/metrics",
"//components/safe_browsing/common:safe_browsing_prefs",
":importer",
"//electron/vendor/ad-block/muon:ad_block",
"//electron/vendor/tracking-protection/muon:tp_node_addon",
]

sources = [
"//chrome/browser/loader/safe_browsing_resource_throttle.h",
"//chrome/browser/loader/safe_browsing_resource_throttle.cc",
"//chrome/browser/safe_browsing/url_checker_delegate_impl.cc",
"//chrome/browser/safe_browsing/url_checker_delegate_impl.h",
"api/atom_api_app.cc",
"api/atom_api_app.h",
"api/atom_api_autofill.cc",
Expand Down
99 changes: 98 additions & 1 deletion atom/browser/atom_resource_dispatcher_host_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
#include "atom/browser/web_contents_permission_helper.h"
#include "atom/common/platform_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process_impl.h"
#include "chrome/browser/loader/predictor_resource_throttle.h"
#include "chrome/browser/loader/safe_browsing_resource_throttle.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "components/offline_pages/features/features.h"
#include "components/policy/core/common/cloud/policy_header_io_helper.h"
#include "components/variations/net/variations_http_headers.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_request_info.h"

#include "net/base/escape.h"
#include "net/ssl/client_cert_store.h"
#include "url/gurl.h"
Expand All @@ -24,6 +33,8 @@
#endif

using content::BrowserThread;
using content::ResourceRequestInfo;
using content::ResourceType;

namespace atom {

Expand Down Expand Up @@ -61,7 +72,93 @@ void HandleExternalProtocolInUI(

} // namespace

AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() {
AtomResourceDispatcherHostDelegate::AtomResourceDispatcherHostDelegate() :
safe_browsing_(g_browser_process->safe_browsing_service()) {
}

void AtomResourceDispatcherHostDelegate::RequestBeginning(
net::URLRequest* request,
content::ResourceContext* resource_context,
content::AppCacheService* appcache_service,
ResourceType resource_type,
std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) {
if (safe_browsing_.get())
safe_browsing_->OnResourceRequest(request);

const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);

#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
// TODO(petewil): Unify the safe browsing request and the metrics observer
// request if possible so we only have to cross to the main thread once.
// http://crbug.com/712312.
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::BindOnce(&NotifyUIThreadOfRequestStarted,
info->GetWebContentsGetterForRequest(),
info->GetResourceType()));
#endif // BUILDFLAG(ENABLE_OFFLINE_PAGES)

#if defined(OS_ANDROID)
if (resource_type != content::RESOURCE_TYPE_MAIN_FRAME)
InterceptNavigationDelegate::UpdateUserGestureCarryoverInfo(request);
#endif

#if defined(OS_CHROMEOS)
// Check if we need to add merge session throttle. This throttle will postpone
// loading of XHR requests.
if (resource_type == content::RESOURCE_TYPE_XHR) {
// Add interstitial page while merge session process (cookie
// reconstruction from OAuth2 refresh token in ChromeOS login) is still in
// progress while we are attempting to load a google property.
if (!merge_session_throttling_utils::AreAllSessionMergedAlready() &&
request->url().SchemeIsHTTPOrHTTPS()) {
throttles->push_back(
base::MakeUnique<MergeSessionResourceThrottle>(request));
}
}
#endif

// Don't attempt to append headers to requests that have already started.
// TODO(stevet): Remove this once the request ordering issues are resolved
// in crbug.com/128048.
if (!request->is_pending()) {
net::HttpRequestHeaders headers;
headers.CopyFrom(request->extra_request_headers());
request->SetExtraRequestHeaders(headers);
}

AppendStandardResourceThrottles(request,
resource_context,
resource_type,
throttles);
#if BUILDFLAG(ENABLE_NACL)
AppendComponentUpdaterThrottles(request, *info, resource_context,
resource_type, throttles);
#endif // BUILDFLAG(ENABLE_NACL)
}

void AtomResourceDispatcherHostDelegate::AppendStandardResourceThrottles(
net::URLRequest* request,
content::ResourceContext* resource_context,
ResourceType resource_type,
std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles) {

// Insert either safe browsing or data reduction proxy throttle at the front
// of the list, so one of them gets to decide if the resource is safe.
content::ResourceThrottle* first_throttle = NULL;
#if defined(OS_ANDROID)
first_throttle = DataReductionProxyResourceThrottle::MaybeCreate(
request, resource_context, resource_type, safe_browsing_.get());
#endif // defined(OS_ANDROID)

#if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
if (!first_throttle) {
first_throttle = MaybeCreateSafeBrowsingResourceThrottle(
request, resource_type, safe_browsing_.get());
}
#endif // defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)

if (first_throttle)
throttles->push_back(base::WrapUnique(first_throttle));
}

bool AtomResourceDispatcherHostDelegate::HandleExternalProtocol(
Expand Down
25 changes: 25 additions & 0 deletions atom/browser/atom_resource_dispatcher_host_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@
#define ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_

#include <memory>
#include <vector>

#include "base/memory/ref_counted.h"
#include "content/public/browser/resource_dispatcher_host_delegate.h"

namespace safe_browsing {
class SafeBrowsingService;
}

namespace atom {

class AtomResourceDispatcherHostDelegate
: public content::ResourceDispatcherHostDelegate {
public:
AtomResourceDispatcherHostDelegate();

void RequestBeginning(net::URLRequest* request,
content::ResourceContext* resource_context,
content::AppCacheService* appcache_service,
content::ResourceType resource_type,
std::vector<std::unique_ptr<content::ResourceThrottle>>*
throttles) override;



// content::ResourceDispatcherHostDelegate:
bool HandleExternalProtocol(
const GURL& url,
Expand All @@ -25,6 +40,16 @@ class AtomResourceDispatcherHostDelegate
net::URLRequest* request) override;
std::unique_ptr<net::ClientCertStore> CreateClientCertStore(
content::ResourceContext* resource_context) override;

protected:
virtual void AppendStandardResourceThrottles(
net::URLRequest* request,
content::ResourceContext* resource_context,
content::ResourceType resource_type,
std::vector<std::unique_ptr<content::ResourceThrottle>>* throttles);

private:
scoped_refptr<safe_browsing::SafeBrowsingService> safe_browsing_;
};

} // namespace atom
Expand Down
3 changes: 2 additions & 1 deletion brave/browser/brave_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_filter.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "components/sync_preferences/pref_service_syncable_factory.h"
#include "components/user_prefs/user_prefs.h"
Expand Down Expand Up @@ -449,6 +450,7 @@ void BraveBrowserContext::CreateProfilePrefs(
pref_registry_->RegisterDictionaryPref(prefs::kPartitionPerHostZoomLevels);
pref_registry_->RegisterBooleanPref(prefs::kPrintingEnabled, true);
pref_registry_->RegisterBooleanPref(prefs::kPrintPreviewDisabled, false);
pref_registry_->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
#if BUILDFLAG(ENABLE_PLUGINS)
PluginInfoMessageFilter::RegisterUserPrefs(pref_registry_.get());
PepperFlashSettingsManager::RegisterProfilePrefs(pref_registry_.get());
Expand Down Expand Up @@ -724,4 +726,3 @@ AtomBrowserContext* AtomBrowserContext::From(
}

} // namespace atom

Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,11 @@ void BravePasswordManagerClient::CheckSafeBrowsingReputation(
const GURL& form_action,
const GURL& frame_url) {}

void BravePasswordManagerClient::LogPasswordReuseDetectedEvent() {}

void BravePasswordManagerClient::CheckProtectedPasswordEntry(
const std::string& password_saved_domain,
bool matches_sync_password,
const std::vector<std::string>& matching_domains,
bool password_field_exists) {}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ class BravePasswordManagerClient
void CheckSafeBrowsingReputation(const GURL& form_action,
const GURL& frame_url) override;
void CheckProtectedPasswordEntry(
const std::string& password_saved_domain,
bool matches_sync_password,
const std::vector<std::string>& matching_domains,
bool password_field_exists) override;

void LogPasswordReuseDetectedEvent() override;

#endif
password_manager::PasswordSyncState GetPasswordSyncState() const override;
bool WasLastNavigationHTTPError() const override;
Expand Down
Loading

0 comments on commit aac0a4d

Please sign in to comment.