Skip to content

Commit

Permalink
Merge pull request #647 from brave/qwant_search_provider
Browse files Browse the repository at this point in the history
Consider Qwant search provider as a initial provider in tor window
  • Loading branch information
simonhong authored and darkdh committed Oct 17, 2018
1 parent 8d2e3b0 commit 5b72784
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion browser/search_engine_provider_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void RegisterAlternativeSearchEngineProviderProfilePrefs(
registry->RegisterBooleanPref(kUseAlternativeSearchEngineProvider, false);
registry->RegisterIntegerPref(
kAlternativeSearchEngineProviderInTor,
TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_DUCKDUCKGO);
TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_INVALID);
}

void InitializeSearchEngineProviderIfNeeded(Profile* profile) {
Expand Down
34 changes: 28 additions & 6 deletions browser/tor_window_search_engine_provider_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "brave/browser/search_engine_provider_util.h"
#include "brave/common/pref_names.h"
#include "brave/components/search_engines/brave_prepopulated_engines.h"
#include "chrome/browser/profiles/profile.h"
#include "components/search_engines/template_url_prepopulate_data.h"
#include "components/search_engines/template_url_service.h"
Expand All @@ -18,14 +19,13 @@ TorWindowSearchEngineProviderController(Profile* profile)

alternative_search_engine_provider_in_tor_.Init(
kAlternativeSearchEngineProviderInTor,
otr_profile_->GetOriginalProfile()->GetPrefs());
profile->GetOriginalProfile()->GetPrefs());

// Configure previously used provider because guest profile is off the recored
// profile.
// Configure previously used provider because effective tor profile is
// off the recored profile.
auto provider_data =
TemplateURLPrepopulateData::GetPrepopulatedEngine(
profile->GetPrefs(),
alternative_search_engine_provider_in_tor_.GetValue());
profile->GetPrefs(), GetInitialSearchEngineProvider());
TemplateURL provider_url(*provider_data);
otr_template_url_service_->SetUserSelectedDefaultSearchProvider(
&provider_url);
Expand All @@ -42,5 +42,27 @@ TorWindowSearchEngineProviderController::

void TorWindowSearchEngineProviderController::OnTemplateURLServiceChanged() {
alternative_search_engine_provider_in_tor_.SetValue(
otr_template_url_service_->GetDefaultSearchProvider()->data().prepopulate_id);
otr_template_url_service_->GetDefaultSearchProvider()->
data().prepopulate_id);
}

int TorWindowSearchEngineProviderController::
GetInitialSearchEngineProvider() const {
int initial_id = alternative_search_engine_provider_in_tor_.GetValue();

bool region_for_qwant =
TemplateURLPrepopulateData::GetPrepopulatedDefaultSearch(
otr_profile_->GetPrefs())->prepopulate_id ==
TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_QWANT;

// If this is first run, |initial_id| is invalid. Then, use qwant or ddg
// depends on default prepopulate data.
if (initial_id ==
TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_INVALID) {
initial_id = region_for_qwant ?
TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_QWANT :
TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_DUCKDUCKGO;
}

return initial_id;
}
2 changes: 2 additions & 0 deletions browser/tor_window_search_engine_provider_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class TorWindowSearchEngineProviderController

void ConfigureSearchEngineProvider() override {}

int GetInitialSearchEngineProvider() const;

IntegerPrefMember alternative_search_engine_provider_in_tor_;

DISALLOW_COPY_AND_ASSIGN(TorWindowSearchEngineProviderController);
Expand Down
2 changes: 2 additions & 0 deletions components/search_engines/brave_prepopulated_engines.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ extern const int kBraveCurrentDataVersion;
// additions by Chromium, so starting our ids from 500. Potential problem:
// Chromium adds one of these engines to their list with a different id.
enum BravePrepopulatedEngineID : unsigned int {
PREPOPULATED_ENGINE_ID_INVALID = 0,

// These engine IDs are already defined in prepopulated_engines.json
PREPOPULATED_ENGINE_ID_GOOGLE = 1,
PREPOPULATED_ENGINE_ID_YAHOO = 2,
Expand Down

0 comments on commit 5b72784

Please sign in to comment.