diff options
-rw-r--r-- | chrome/browser/search_engines/template_url_model.cc | 12 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_prepopulate_data.cc | 12 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_prepopulate_data.h | 8 | ||||
-rw-r--r-- | chrome/browser/views/first_run_search_engine_view.cc | 100 | ||||
-rw-r--r-- | chrome/browser/views/first_run_search_engine_view.h | 32 | ||||
-rw-r--r-- | chrome/browser/views/first_run_view.h | 4 | ||||
-rw-r--r-- | chrome/browser/views/keyword_editor_view.cc | 11 | ||||
-rw-r--r-- | chrome/browser/views/keyword_editor_view.h | 18 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 4 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 1 |
10 files changed, 115 insertions, 87 deletions
diff --git a/chrome/browser/search_engines/template_url_model.cc b/chrome/browser/search_engines/template_url_model.cc index 0f3b6f3..d6a8171 100644 --- a/chrome/browser/search_engines/template_url_model.cc +++ b/chrome/browser/search_engines/template_url_model.cc @@ -801,6 +801,10 @@ void TemplateURLModel::SaveDefaultSearchProviderToPrefs( t_url ? Int64ToWString(t_url->id()) : std::wstring(); prefs->SetString(prefs::kDefaultSearchProviderID, id_string); + const std::wstring prepopulate_id = + t_url ? Int64ToWString(t_url->prepopulate_id()) : std::wstring(); + prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id); + prefs->ScheduleSavePersistentPrefs(); } @@ -830,12 +834,18 @@ bool TemplateURLModel::LoadDefaultSearchProviderFromPrefs( std::wstring id_string = prefs->GetString(prefs::kDefaultSearchProviderID); + std::wstring prepopulate_id = + prefs->GetString(prefs::kDefaultSearchProviderPrepopulateID); + *default_provider = new TemplateURL(); (*default_provider)->set_short_name(name); (*default_provider)->SetURL(search_url, 0, 0); (*default_provider)->SetSuggestionsURL(suggest_url, 0, 0); if (!id_string.empty()) (*default_provider)->set_id(StringToInt64(WideToUTF16Hack(id_string))); + if (!prepopulate_id.empty()) + (*default_provider)->set_prepopulate_id(StringToInt(WideToUTF16Hack( + prepopulate_id))); return true; } @@ -847,6 +857,8 @@ void TemplateURLModel::RegisterPrefs(PrefService* prefs) { prefs->RegisterStringPref( prefs::kDefaultSearchProviderID, std::wstring()); prefs->RegisterStringPref( + prefs::kDefaultSearchProviderPrepopulateID, std::wstring()); + prefs->RegisterStringPref( prefs::kDefaultSearchProviderSuggestURL, std::wstring()); prefs->RegisterStringPref( prefs::kDefaultSearchProviderSearchURL, std::wstring()); diff --git a/chrome/browser/search_engines/template_url_prepopulate_data.cc b/chrome/browser/search_engines/template_url_prepopulate_data.cc index 7688150..445381a 100644 --- a/chrome/browser/search_engines/template_url_prepopulate_data.cc +++ b/chrome/browser/search_engines/template_url_prepopulate_data.cc @@ -2284,7 +2284,7 @@ int CountryCharsToCountryIDWithUpdate(char c1, char c2) { #if defined(OS_WIN) // For reference, a list of GeoIDs can be found at -// http://msdn.microsoft.com/en-us/library/ms776390.aspx . +// http://msdn.microsoft.com/en-us/library/dd374073.aspx . int GeoIDToCountryID(GEOID geo_id) { const int kISOBufferSize = 3; // Two plus one for the terminator. wchar_t isobuf[kISOBufferSize] = { 0 }; @@ -2829,12 +2829,14 @@ void GetPrepopulatedEngines(PrefService* prefs, } } -UMASearchEngineType GetSearchEngineType(const TemplateURL* search_engine) { +SearchEngineType GetSearchEngineType(const TemplateURL* search_engine) { switch (search_engine->prepopulate_id()) { case 1: return SEARCH_ENGINE_GOOGLE; case 2: - return SEARCH_ENGINE_YAHOO; + // Construction of country id = 'J' << 8 | 'P' = 19024 + return (GetCountryIDFromPrefs(NULL) == 19024) ? SEARCH_ENGINE_YAHOOJP : + SEARCH_ENGINE_YAHOO; case 3: return SEARCH_ENGINE_BING; case 4: @@ -2845,6 +2847,8 @@ UMASearchEngineType GetSearchEngineType(const TemplateURL* search_engine) { return SEARCH_ENGINE_SEZNAM; case 26: return SEARCH_ENGINE_CENTRUM; + case 30: + return SEARCH_ENGINE_NETSPRINT; case 62: return SEARCH_ENGINE_VIRGILIO; case 83: @@ -2854,4 +2858,6 @@ UMASearchEngineType GetSearchEngineType(const TemplateURL* search_engine) { } } + + } // namespace TemplateURLPrepopulateData diff --git a/chrome/browser/search_engines/template_url_prepopulate_data.h b/chrome/browser/search_engines/template_url_prepopulate_data.h index d53934b..c0a7adb 100644 --- a/chrome/browser/search_engines/template_url_prepopulate_data.h +++ b/chrome/browser/search_engines/template_url_prepopulate_data.h @@ -13,17 +13,19 @@ class TemplateURL; namespace TemplateURLPrepopulateData { // Enum to record the user's default search engine choice in UMA: -enum UMASearchEngineType { +enum SearchEngineType { SEARCH_ENGINE_OTHER = 0, // At the top in case of future list changes. SEARCH_ENGINE_GOOGLE, SEARCH_ENGINE_YAHOO, + SEARCH_ENGINE_YAHOOJP, SEARCH_ENGINE_BING, SEARCH_ENGINE_ASK, SEARCH_ENGINE_YANDEX, - SEARCH_ENGINE_MAILRU, SEARCH_ENGINE_SEZNAM, SEARCH_ENGINE_CENTRUM, + SEARCH_ENGINE_NETSPRINT, SEARCH_ENGINE_VIRGILIO, + SEARCH_ENGINE_MAILRU, SEARCH_ENGINE_MAX // Bounding max value needed for UMA histogram macro. }; @@ -47,7 +49,7 @@ void GetPrepopulatedEngines(PrefService* prefs, // for a small set of search engines, we use this simple switch statement // instead of embedding a UMA type as part of the struct of every search // engine. -UMASearchEngineType GetSearchEngineType(const TemplateURL* search_engine); +SearchEngineType GetSearchEngineType(const TemplateURL* search_engine); } // namespace TemplateURLPrepopulateData diff --git a/chrome/browser/views/first_run_search_engine_view.cc b/chrome/browser/views/first_run_search_engine_view.cc index 48eed28..7c6c95c 100644 --- a/chrome/browser/views/first_run_search_engine_view.cc +++ b/chrome/browser/views/first_run_search_engine_view.cc @@ -4,12 +4,16 @@ #include "chrome/browser/views/first_run_search_engine_view.h" +#include <map> + #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/i18n/rtl.h" +#include "chrome/browser/options_window.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" +#include "chrome/browser/search_engines/template_url_prepopulate_data.h" #include "gfx/font.h" #include "grit/browser_resources.h" #include "grit/chromium_strings.h" @@ -25,6 +29,8 @@ #include "views/view_text_utils.h" #include "views/window/window.h" +using TemplateURLPrepopulateData::SearchEngineType; + namespace { // These strings mark the embedded link in IDS_FIRSTRUN_SEARCH_SUBTEXT. @@ -43,33 +49,51 @@ const int kSmallLogoHeight = 80; // Used to pad text label height so it fits nicely in view. const int kLabelPadding = 25; -// Maps the prepopulated id of a search engine to its logo. -struct SearchEngineLogo { - // The unique id for a prepopulated search engine; see PrepopulatedEngine - // struct in template_url_prepopulate_data.cc. - int search_engine_id; - - // The IDR that represents the logo image for a given search engine. - int logo_idr; -}; - -// Mapping of prepopulate_id to logo for each search engine. -SearchEngineLogo kSearchEngineLogos[] = { - { 1, IDR_SEARCH_ENGINE_LOGO_GOOGLE }, - { 2, IDR_SEARCH_ENGINE_LOGO_YAHOO }, - { 3, IDR_SEARCH_ENGINE_LOGO_BING }, -}; - int GetSearchEngineLogo(const TemplateURL* template_url) { - TemplateURL::IDType id = template_url->prepopulate_id(); - if (id > 0) { - for (size_t i = 0; i < arraysize(kSearchEngineLogos); ++i) { - if (kSearchEngineLogos[i].search_engine_id == id) { - return kSearchEngineLogos[i].logo_idr; - } - } + typedef std::map<SearchEngineType, int> LogoMap; + static LogoMap type_to_logo; + if (type_to_logo.empty()) { + type_to_logo.insert(std::make_pair<SearchEngineType, int>( + TemplateURLPrepopulateData::SEARCH_ENGINE_GOOGLE, + IDR_SEARCH_ENGINE_LOGO_GOOGLE)); + type_to_logo.insert(std::make_pair<SearchEngineType, int>( + TemplateURLPrepopulateData::SEARCH_ENGINE_YAHOO, + IDR_SEARCH_ENGINE_LOGO_YAHOO)); + type_to_logo.insert(std::make_pair<SearchEngineType, int>( + TemplateURLPrepopulateData::SEARCH_ENGINE_YAHOOJP, + IDR_SEARCH_ENGINE_LOGO_YAHOOJP)); + type_to_logo.insert(std::make_pair<SearchEngineType, int>( + TemplateURLPrepopulateData::SEARCH_ENGINE_BING, + IDR_SEARCH_ENGINE_LOGO_BING)); + type_to_logo.insert(std::make_pair<SearchEngineType, int>( + TemplateURLPrepopulateData::SEARCH_ENGINE_ASK, + IDR_SEARCH_ENGINE_LOGO_ASK)); + type_to_logo.insert(std::make_pair<SearchEngineType, int>( + TemplateURLPrepopulateData::SEARCH_ENGINE_YANDEX, + IDR_SEARCH_ENGINE_LOGO_YANDEX)); + type_to_logo.insert(std::make_pair<SearchEngineType, int>( + TemplateURLPrepopulateData::SEARCH_ENGINE_SEZNAM, + IDR_SEARCH_ENGINE_LOGO_SEZNAM)); + type_to_logo.insert(std::make_pair<SearchEngineType, int>( + TemplateURLPrepopulateData::SEARCH_ENGINE_CENTRUM, + IDR_SEARCH_ENGINE_LOGO_CENTRUMCZ)); + type_to_logo.insert(std::make_pair<SearchEngineType, int>( + TemplateURLPrepopulateData::SEARCH_ENGINE_NETSPRINT, + IDR_SEARCH_ENGINE_LOGO_NETSPRINT)); + type_to_logo.insert(std::make_pair<SearchEngineType, int>( + TemplateURLPrepopulateData::SEARCH_ENGINE_VIRGILIO, + IDR_SEARCH_ENGINE_LOGO_VIRGILIO)); + type_to_logo.insert(std::make_pair<SearchEngineType, int>( + TemplateURLPrepopulateData::SEARCH_ENGINE_MAILRU, + IDR_SEARCH_ENGINE_LOGO_MAILRU)); } - // |id| is either not found, or does not exist. + + LogoMap::iterator logo = type_to_logo.find( + TemplateURLPrepopulateData::GetSearchEngineType(template_url)); + if (logo != type_to_logo.end()) + return logo->second; + + // Logo does not exist: return kNoLogo; } @@ -127,7 +151,7 @@ void SearchEngineChoice::SetChoiceViewBounds(int x, int y, int width, } FirstRunSearchEngineView::FirstRunSearchEngineView( - SearchEngineViewObserver* observer, Profile* profile) + SearchEngineSelectionObserver* observer, Profile* profile) : profile_(profile), observer_(observer), text_direction_is_rtl_(base::i18n::IsRTL()) { @@ -219,15 +243,6 @@ void FirstRunSearchEngineView::OnTemplateURLModelChanged() { SchedulePaint(); } -void FirstRunSearchEngineView::OnKeywordEditorClosing(bool default_set) { - // If the search engine has been set in the KeywordEditor, pass NULL - // to the observer to show that we did not choose a search engine in this - // dialog, and to notify that we're done with the selection process. - if (default_set) - observer_->SearchEngineChosen(NULL); - // Else, the user cancelled the KeywordEditor, so continue with this dialog. -} - gfx::Size FirstRunSearchEngineView::GetPreferredSize() { return views::Window::GetLocalizedContentsSize( IDS_FIRSTRUN_SEARCH_ENGINE_SELECTION_WIDTH_CHARS, @@ -239,8 +254,11 @@ void FirstRunSearchEngineView::LinkActivated(views::Link* source, // The KeywordEditor is going to modify search_engines_model_, so // relinquish our observership so we don't try to redraw. search_engines_model_->RemoveObserver(this); - // Launch search engine editing window from browser options dialog. - KeywordEditorView::ShowAndObserve(profile_, this); + // Launch search engine editing window from browser options dialog. We pass + // the observer to the KeywordEditor, who will tell the observer when a + // search engine has been chosen. + KeywordEditorView::ShowAndObserve(profile_, observer_); + GetWindow()->Close(); } void FirstRunSearchEngineView::SetupControls() { @@ -306,6 +324,9 @@ void FirstRunSearchEngineView::SetupControls() { } void FirstRunSearchEngineView::Layout() { + // Disable the close button. + GetWindow()->EnableClose(false); + // General vertical spacing between elements: const int kVertSpacing = 8; // Vertical spacing between the logo + button section and the separators: @@ -443,8 +464,3 @@ std::wstring FirstRunSearchEngineView::GetWindowTitle() const { return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE); } -void FirstRunSearchEngineView::WindowClosing() { - // User decided not to choose a search engine after all. - observer_->SearchEngineChosen(NULL); -} - diff --git a/chrome/browser/views/first_run_search_engine_view.h b/chrome/browser/views/first_run_search_engine_view.h index 3ceedab..aa5a03b 100644 --- a/chrome/browser/views/first_run_search_engine_view.h +++ b/chrome/browser/views/first_run_search_engine_view.h @@ -66,6 +66,14 @@ class SearchEngineChoice : public views::NativeButton { DISALLOW_COPY_AND_ASSIGN(SearchEngineChoice); }; +// This class receives a callback when the search engine dialog closes. +class SearchEngineSelectionObserver { + public: + virtual ~SearchEngineSelectionObserver() {} + // Called when the user has chosen a search engine. + virtual void SearchEngineChosen(const TemplateURL* default_search) = 0; +}; + // This class displays a large search engine choice dialog view during // initial first run import. class FirstRunSearchEngineView @@ -73,25 +81,14 @@ class FirstRunSearchEngineView public views::ButtonListener, public views::LinkController, public views::WindowDelegate, - public KeywordEditorViewObserver, public TemplateURLModelObserver { public: - // This class receives a callback when the search engine dialog closes. - class SearchEngineViewObserver { - public: - virtual ~SearchEngineViewObserver() {} - // Called when the user has chosen a search engine. If the user closes - // the dialog without providing us with a search engine (because the search - // engine has been chosen using the KeywordEditor dialog link, or because - // the user has cancelled), we pass NULL as the default_search parameter. - virtual void SearchEngineChosen(const TemplateURL* default_search) = 0; - }; - // |observer| is the FirstRunView that waits for us to pass back a search // engine choice; |profile| allows us to get the set of imported search // engines, and display the KeywordEditorView on demand. - FirstRunSearchEngineView(SearchEngineViewObserver* observer, + FirstRunSearchEngineView(SearchEngineSelectionObserver* observer, Profile* profile); + virtual ~FirstRunSearchEngineView(); // Overridden from views::View: @@ -104,7 +101,6 @@ class FirstRunSearchEngineView // Overridden from views::WindowDelegate: virtual std::wstring GetWindowTitle() const; - virtual void WindowClosing(); views::View* GetContentsView() { return this; } bool CanResize() const { return false; } bool CanMaximize() const { return false; } @@ -119,12 +115,6 @@ class FirstRunSearchEngineView // to present to the user. virtual void OnTemplateURLModelChanged(); - // Overridden from KeywordEditorViewObserver. If the user chooses to edit - // search engines from the traditional KeywordEditorView (by clicking the - // 'search engine options' link in this view), we must wait for that user - // to finish before completing the import process and launching the browser. - virtual void OnKeywordEditorClosing(bool default_set); - private: // Initializes the labels and controls in the view. void SetupControls(); @@ -139,7 +129,7 @@ class FirstRunSearchEngineView Profile* profile_; // Gets called back when one of the choice buttons is pressed. - SearchEngineViewObserver* observer_; + SearchEngineSelectionObserver* observer_; bool text_direction_is_rtl_; diff --git a/chrome/browser/views/first_run_view.h b/chrome/browser/views/first_run_view.h index 7ada990..05a8a09 100644 --- a/chrome/browser/views/first_run_view.h +++ b/chrome/browser/views/first_run_view.h @@ -26,7 +26,7 @@ class TemplateURL; class FirstRunView : public FirstRunViewBase, public views::LinkController, public FirstRunCustomizeView::CustomizeViewObserver, - public FirstRunSearchEngineView::SearchEngineViewObserver { + public SearchEngineSelectionObserver { public: explicit FirstRunView(Profile* profile, bool homepage_defined, int import_items, int dont_import_items, @@ -54,7 +54,7 @@ class FirstRunView : public FirstRunViewBase, virtual void CustomizeAccepted(); virtual void CustomizeCanceled(); - // Overridden from SearchEngineViewObserver: + // Overridden from SearchEngineSelectionObserver: virtual void SearchEngineChosen(const TemplateURL* default_search); private: diff --git a/chrome/browser/views/keyword_editor_view.cc b/chrome/browser/views/keyword_editor_view.cc index 4a77c75..8fcca5b 100644 --- a/chrome/browser/views/keyword_editor_view.cc +++ b/chrome/browser/views/keyword_editor_view.cc @@ -15,6 +15,7 @@ #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/search_engines/template_url_table_model.h" #include "chrome/browser/views/browser_dialogs.h" +#include "chrome/browser/views/first_run_search_engine_view.h" #include "chrome/common/pref_names.h" #include "gfx/point.h" #include "googleurl/src/gurl.h" @@ -59,7 +60,7 @@ void KeywordEditorView::Show(Profile* profile) { // static void KeywordEditorView::ShowAndObserve(Profile* profile, - KeywordEditorViewObserver* observer) { + SearchEngineSelectionObserver* observer) { // If this panel is opened from an Incognito window, closing that window can // leave this with a stale pointer. Use the original profile instead. // See http://crbug.com/23359. @@ -83,7 +84,7 @@ void KeywordEditorView::ShowAndObserve(Profile* profile, } KeywordEditorView::KeywordEditorView(Profile* profile, - KeywordEditorViewObserver* observer) + SearchEngineSelectionObserver* observer) : profile_(profile), observer_(observer), controller_(new KeywordEditorController(profile)), @@ -137,14 +138,16 @@ int KeywordEditorView::GetDialogButtons() const { bool KeywordEditorView::Accept() { if (observer_) - observer_->OnKeywordEditorClosing(default_chosen_); + observer_->SearchEngineChosen( + profile_->GetTemplateURLModel()->GetDefaultSearchProvider()); open_window = NULL; return true; } bool KeywordEditorView::Cancel() { if (observer_) - observer_->OnKeywordEditorClosing(default_chosen_); + observer_->SearchEngineChosen( + profile_->GetTemplateURLModel()->GetDefaultSearchProvider()); open_window = NULL; return true; } diff --git a/chrome/browser/views/keyword_editor_view.h b/chrome/browser/views/keyword_editor_view.h index 18369c4..1b925cb3 100644 --- a/chrome/browser/views/keyword_editor_view.h +++ b/chrome/browser/views/keyword_editor_view.h @@ -26,18 +26,11 @@ namespace { class BorderView; } +class SearchEngineSelectionObserver; class SkBitmap; class TemplateURLModel; class TemplateURLTableModel; -class KeywordEditorViewObserver { - public: - // Called when the user has finished setting keyword data. - // |default_chosen| is true if user has selected a default search engine - // through this dialog. - virtual void OnKeywordEditorClosing(bool default_chosen) = 0; -}; - // KeywordEditorView allows the user to edit keywords. class KeywordEditorView : public views::View, @@ -54,10 +47,11 @@ class KeywordEditorView : public views::View, // Shows the KeywordEditorView for the specified profile, and passes in // an observer to be called back on view close. static void ShowAndObserve(Profile* profile, - KeywordEditorViewObserver* observer); + SearchEngineSelectionObserver* observer); KeywordEditorView(Profile* profile, - KeywordEditorViewObserver* observer); + SearchEngineSelectionObserver* observer); + virtual ~KeywordEditorView(); // Overridden from EditSearchEngineControllerDelegate. @@ -67,7 +61,7 @@ class KeywordEditorView : public views::View, const std::wstring& keyword, const std::wstring& url); - // Overriden to invoke Layout. + // Overridden to invoke Layout. virtual gfx::Size GetPreferredSize(); // views::DialogDelegate methods: @@ -103,7 +97,7 @@ class KeywordEditorView : public views::View, Profile* profile_; // Observer gets a callback when the KeywordEditorView closes. - KeywordEditorViewObserver* observer_; + SearchEngineSelectionObserver* observer_; scoped_ptr<KeywordEditorController> controller_; diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index e54c822..6e4b97a 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -145,6 +145,10 @@ const wchar_t kDefaultSearchProviderName[] = L"default_search_provider.name"; // The id of the default search provider. const wchar_t kDefaultSearchProviderID[] = L"default_search_provider.id"; +// The prepopulate id of the default search provider. +const wchar_t kDefaultSearchProviderPrepopulateID[] = + L"default_search_provider.prepopulate_id"; + // Boolean which specifies whether we should ask the user if we should download // a file (true) or just download it automatically. const wchar_t kPromptForDownload[] = L"download.prompt_for_download"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 1da45d1..f22ed71 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -54,6 +54,7 @@ extern const wchar_t kDefaultSearchProviderSearchURL[]; extern const wchar_t kDefaultSearchProviderSuggestURL[]; extern const wchar_t kDefaultSearchProviderName[]; extern const wchar_t kDefaultSearchProviderID[]; +extern const wchar_t kDefaultSearchProviderPrepopulateID[]; extern const wchar_t kPromptForDownload[]; extern const wchar_t kAlternateErrorPagesEnabled[]; extern const wchar_t kDnsPrefetchingEnabled[]; |