-
Notifications
You must be signed in to change notification settings - Fork 903
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
Fix alternative search engine provider feature bugs #529
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
90afd0d
Fix ddg search button value is reseted when reloading
simonhong 32c95ad
Fix private search engine isn't changed when normal's changed.
simonhong 452b0cd
Refactoring and cleanup AlternatePrivateSearchEngineController
simonhong 7d94dfa
Make alternative search engine works in guest window
simonhong e70ff3d
Make tor window uses alternative search engine provider(ddg)
simonhong 4f2480d
Use brave's prepopulated engine for getting ddg data
simonhong 2102cef
Add DISABLED_CheckTorProfileSearchProviderTest
simonhong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* 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/guest_window_search_engine_provider_controller.h" | ||
|
||
#include "base/auto_reset.h" | ||
#include "brave/browser/search_engine_provider_util.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/search_engines/template_url_service.h" | ||
|
||
GuestWindowSearchEngineProviderController:: | ||
GuestWindowSearchEngineProviderController(Profile* profile) | ||
: SearchEngineProviderControllerBase(profile) { | ||
DCHECK_EQ(profile->GetProfileType(), Profile::GUEST_PROFILE); | ||
|
||
// Monitor otr(off the record) profile's search engine changing to tracking | ||
// user's default search engine provider. | ||
// OTR profile's service is used for that. | ||
otr_template_url_service_->AddObserver(this); | ||
ConfigureSearchEngineProvider(); | ||
} | ||
|
||
GuestWindowSearchEngineProviderController:: | ||
~GuestWindowSearchEngineProviderController() { | ||
otr_template_url_service_->RemoveObserver(this); | ||
} | ||
|
||
void GuestWindowSearchEngineProviderController::OnTemplateURLServiceChanged() { | ||
if (ignore_template_url_service_changing_) | ||
return; | ||
|
||
// Prevent search engine changing from settings page for tor profile. | ||
// TODO(simonhong): Revisit when related ux is determined. | ||
if (otr_profile_->IsTorProfile()) { | ||
base::AutoReset<bool> reset(&ignore_template_url_service_changing_, true); | ||
ChangeToAlternativeSearchEngineProvider(); | ||
return; | ||
} | ||
|
||
|
||
// The purpose of below code is turn off alternative prefs | ||
// when user changes to different search engine provider from settings. | ||
// However, this callback is also called during the TemplateURLService | ||
// initialization phase. Because of this, guest view always starts with | ||
// this prefs off state when browser restarted(persisted during the runtime). | ||
// Currently I don't know how to determine who is caller of this callback. | ||
// TODO(simonhong): Revisit here when brave's related ux is determined. | ||
if (UseAlternativeSearchEngineProvider()) | ||
brave::ToggleUseAlternativeSearchEngineProvider(otr_profile_); | ||
} | ||
|
||
void | ||
GuestWindowSearchEngineProviderController::ConfigureSearchEngineProvider() { | ||
base::AutoReset<bool> reset(&ignore_template_url_service_changing_, true); | ||
UseAlternativeSearchEngineProvider() | ||
? ChangeToAlternativeSearchEngineProvider() | ||
: ChangeToNormalWindowSearchEngineProvider(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't allow users to change search engine in tor window?
I thought we only set it to DDG by default for tor and then if users have their own preference, we respect their decisions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, making this optional is next task.