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

Consider Qwant search provider as a initial provider in tor window #647

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain why GetOriginalProfile from regular profile? That will just return itself

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|profile| is off the record profile.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I just checked the caller.


// 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