Upload upstream chromium 114.0.5735.31
[platform/framework/web/chromium-efl.git] / components / search_engines / template_url_starter_pack_data.cc
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/search_engines/template_url_starter_pack_data.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/search_engines/search_engine_type.h"
9 #include "components/search_engines/template_url_data.h"
10 #include "components/search_engines/template_url_data_util.h"
11 #include "components/strings/grit/components_strings.h"
12 #include "ui/base/l10n/l10n_util.h"
13
14 namespace TemplateURLStarterPackData {
15
16 // Update this whenever a change is made to any starter pack data.
17 const int kCurrentDataVersion = 5;
18
19 // Only update this if there's an incompatible change that requires force
20 // updating the user's starter pack data. This will overwrite any of the
21 // user's changes to the starter pack entries.
22 const int kFirstCompatibleDataVersion = 5;
23
24 const StarterPackEngine bookmarks = {
25     .name_message_id = IDS_SEARCH_ENGINES_STARTER_PACK_BOOKMARKS_NAME,
26     .keyword_message_id = IDS_SEARCH_ENGINES_STARTER_PACK_BOOKMARKS_KEYWORD,
27     .favicon_url = nullptr,
28     .search_url = "chrome://bookmarks/?q={searchTerms}",
29     .destination_url = "chrome://bookmarks",
30     .id = StarterPackID::kBookmarks,
31     .type = SEARCH_ENGINE_STARTER_PACK_BOOKMARKS,
32 };
33
34 const StarterPackEngine history = {
35     .name_message_id = IDS_SEARCH_ENGINES_STARTER_PACK_HISTORY_NAME,
36     .keyword_message_id = IDS_SEARCH_ENGINES_STARTER_PACK_HISTORY_KEYWORD,
37     .favicon_url = nullptr,
38     .search_url = "chrome://history/?q={searchTerms}",
39     .destination_url = "chrome://history",
40     .id = StarterPackID::kHistory,
41     .type = SEARCH_ENGINE_STARTER_PACK_HISTORY,
42 };
43
44 const StarterPackEngine tabs = {
45     .name_message_id = IDS_SEARCH_ENGINES_STARTER_PACK_TABS_NAME,
46     .keyword_message_id = IDS_SEARCH_ENGINES_STARTER_PACK_TABS_KEYWORD,
47     .favicon_url = nullptr,
48     // This search_url is a placeholder URL to make templateURL happy.
49     // chrome://tabs does not currently exist and the tab search engine will
50     // only provide suggestions from the OpenTabProvider.
51     .search_url = "chrome://tabs/?q={searchTerms}",
52     .destination_url = "http://support.google.com/chrome/?p=tab_search",
53     .id = StarterPackID::kTabs,
54     .type = SEARCH_ENGINE_STARTER_PACK_TABS,
55 };
56
57 const StarterPackEngine* engines[] = {
58     &bookmarks,
59     &history,
60     &tabs,
61 };
62
63 int GetDataVersion() {
64   return kCurrentDataVersion;
65 }
66
67 int GetFirstCompatibleDataVersion() {
68   return kFirstCompatibleDataVersion;
69 }
70
71 std::vector<std::unique_ptr<TemplateURLData>> GetStarterPackEngines() {
72   std::vector<std::unique_ptr<TemplateURLData>> t_urls;
73
74   for (auto* engine : engines) {
75     t_urls.push_back(TemplateURLDataFromStarterPackEngine(*engine));
76   }
77   return t_urls;
78 }
79
80 std::u16string GetDestinationUrlForStarterPackID(int id) {
81   for (auto* engine : engines) {
82     if (engine->id == id) {
83       return base::UTF8ToUTF16(engine->destination_url);
84     }
85   }
86
87   return u"";
88 }
89
90 }  // namespace TemplateURLStarterPackData