Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: ios/chrome/browser/ui/webui/history/history_ui.mm

Issue 2494853003: Remove some unused history resources on iOS (Closed)
Patch Set: add back URL constants Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
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 "ios/chrome/browser/ui/webui/history/history_ui.h"
6
7 #include "base/command_line.h"
8 #include "base/memory/ref_counted_memory.h"
9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "components/browsing_data/core/history_notice_utils.h"
12 #include "components/grit/components_scaled_resources.h"
13 #include "components/keyed_service/core/service_access_type.h"
14 #include "components/prefs/pref_service.h"
15 #include "components/search/search.h"
16 #include "components/signin/core/browser/signin_manager.h"
17 #include "components/strings/grit/components_strings.h"
18 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
19 #include "ios/chrome/browser/chrome_switches.h"
20 #include "ios/chrome/browser/chrome_url_constants.h"
21 #include "ios/chrome/browser/pref_names.h"
22 #include "ios/chrome/browser/signin/signin_manager_factory.h"
23 #include "ios/chrome/browser/ui/webui/history/browsing_history_handler.h"
24 #include "ios/chrome/browser/ui/webui/history/metrics_handler.h"
25 #include "ios/chrome/grit/ios_resources.h"
26 #include "ios/web/public/web_state/web_state.h"
27 #include "ios/web/public/web_ui_ios_data_source.h"
28 #include "ios/web/public/webui/web_ui_ios.h"
29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h"
31
32 static const char kStringsJsFile[] = "strings.js";
33 static const char kHistoryJsFile[] = "history.js";
34 static const char kOtherDevicesJsFile[] = "other_devices.js";
35
36 namespace {
37
38 const char kIncognitoModeShortcut[] =
39 "("
40 "\xE2\x87\xA7" // Shift symbol (U+21E7 'UPWARDS WHITE ARROW').
41 "\xE2\x8C\x98" // Command symbol (U+2318 'PLACE OF INTEREST SIGN').
42 "N)";
43
44 web::WebUIIOSDataSource* CreateHistoryUIHTMLSource(
45 ios::ChromeBrowserState* browser_state) {
46 // Check if the browser state is authenticated. Incognito tabs may not have
47 // a sign in manager, and are considered not authenticated.
48 SigninManagerBase* signin_manager =
49 ios::SigninManagerFactory::GetForBrowserState(browser_state);
50 bool is_authenticated =
51 signin_manager != nullptr && signin_manager->IsAuthenticated();
52
53 web::WebUIIOSDataSource* source =
54 web::WebUIIOSDataSource::Create(kChromeUIHistoryFrameHost);
55 source->AddBoolean("isUserSignedIn", is_authenticated);
56 source->AddLocalizedString("collapseSessionMenuItemText",
57 IDS_HISTORY_OTHER_SESSIONS_COLLAPSE_SESSION);
58 source->AddLocalizedString("expandSessionMenuItemText",
59 IDS_HISTORY_OTHER_SESSIONS_EXPAND_SESSION);
60 source->AddLocalizedString("restoreSessionMenuItemText",
61 IDS_HISTORY_OTHER_SESSIONS_OPEN_ALL);
62 source->AddLocalizedString("xMore", IDS_HISTORY_OTHER_DEVICES_X_MORE);
63 source->AddLocalizedString("loading", IDS_HISTORY_LOADING);
64 source->AddLocalizedString("title", IDS_HISTORY_TITLE);
65 source->AddLocalizedString("newest", IDS_HISTORY_NEWEST);
66 source->AddLocalizedString("newer", IDS_HISTORY_NEWER);
67 source->AddLocalizedString("older", IDS_HISTORY_OLDER);
68 source->AddLocalizedString("searchResultsFor", IDS_HISTORY_SEARCHRESULTSFOR);
69 source->AddLocalizedString("searchResult", IDS_HISTORY_SEARCH_RESULT);
70 source->AddLocalizedString("searchResults", IDS_HISTORY_SEARCH_RESULTS);
71 source->AddLocalizedString("foundSearchResults",
72 IDS_HISTORY_FOUND_SEARCH_RESULTS);
73 source->AddLocalizedString("history", IDS_HISTORY_BROWSERESULTS);
74 source->AddLocalizedString("cont", IDS_HISTORY_CONTINUED);
75 source->AddLocalizedString("searchButton", IDS_HISTORY_SEARCH_BUTTON);
76 source->AddLocalizedString("noSearchResults", IDS_HISTORY_NO_SEARCH_RESULTS);
77 source->AddLocalizedString("noResults", IDS_HISTORY_NO_RESULTS);
78 source->AddLocalizedString("historyInterval", IDS_HISTORY_INTERVAL);
79 source->AddLocalizedString("removeSelected",
80 IDS_HISTORY_REMOVE_SELECTED_ITEMS);
81 source->AddLocalizedString("clearAllHistory",
82 IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG);
83
84 base::string16 delete_warning =
85 l10n_util::GetStringFUTF16(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING,
86 base::UTF8ToUTF16(kIncognitoModeShortcut));
87 source->AddString("deleteWarning", delete_warning);
88
89 source->AddLocalizedString("removeBookmark", IDS_HISTORY_REMOVE_BOOKMARK);
90 source->AddLocalizedString("actionMenuDescription",
91 IDS_HISTORY_ACTION_MENU_DESCRIPTION);
92 source->AddLocalizedString("removeFromHistory", IDS_HISTORY_REMOVE_PAGE);
93 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE);
94 source->AddLocalizedString("rangeLabel", IDS_HISTORY_RANGE_LABEL);
95 source->AddLocalizedString("rangeAllTime", IDS_HISTORY_RANGE_ALL_TIME);
96 source->AddLocalizedString("rangeWeek", IDS_HISTORY_RANGE_WEEK);
97 source->AddLocalizedString("rangeMonth", IDS_HISTORY_RANGE_MONTH);
98 source->AddLocalizedString("rangeToday", IDS_HISTORY_RANGE_TODAY);
99 source->AddLocalizedString("rangeNext", IDS_HISTORY_RANGE_NEXT);
100 source->AddLocalizedString("rangePrevious", IDS_HISTORY_RANGE_PREVIOUS);
101 source->AddLocalizedString("numberVisits", IDS_HISTORY_NUMBER_VISITS);
102 source->AddLocalizedString("filterBlocked", IDS_HISTORY_FILTER_BLOCKED);
103 source->AddLocalizedString("blockedVisitText",
104 IDS_HISTORY_BLOCKED_VISIT_TEXT);
105 source->AddLocalizedString("hasSyncedResults",
106 IDS_HISTORY_HAS_SYNCED_RESULTS);
107 source->AddLocalizedString("noSyncedResults", IDS_HISTORY_NO_SYNCED_RESULTS);
108 source->AddString(
109 "otherFormsOfBrowsingHistory",
110 l10n_util::GetStringFUTF16(IDS_HISTORY_OTHER_FORMS_OF_HISTORY,
111 base::ASCIIToUTF16(kHistoryMyActivityURL)));
112 source->AddLocalizedString("cancel", IDS_CANCEL);
113 source->AddLocalizedString("deleteConfirm",
114 IDS_HISTORY_DELETE_PRIOR_VISITS_CONFIRM_BUTTON);
115 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch(
116 switches::kHistoryEnableGroupByDomain);
117 source->AddBoolean("groupByDomain", group_by_domain);
118 source->AddBoolean("allowDeletingHistory", true);
119 source->AddBoolean("isInstantExtendedApiEnabled",
120 search::IsInstantExtendedAPIEnabled());
121 source->AddBoolean("isSupervisedProfile", false);
122 source->AddBoolean("hideDeleteVisitUI", false);
123 source->SetJsonPath(kStringsJsFile);
124 source->AddResourcePath(kHistoryJsFile, IDR_IOS_HISTORY_JS);
125 source->AddResourcePath(kOtherDevicesJsFile,
126 IDR_IOS_HISTORY_OTHER_DEVICES_JS);
127 source->SetDefaultResource(IDR_IOS_HISTORY_HTML);
128 source->DisableDenyXFrameOptions();
129
130 return source;
131 }
132
133 } // namespace
134
135 HistoryUI::HistoryUI(web::WebUIIOS* web_ui) : web::WebUIIOSController(web_ui) {
136 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
137 web_ui->AddMessageHandler(new MetricsHandler());
138
139 // TODO(crbug.com/595332): Since the API to query other forms of browsing
140 // history is not ready yet, make it possible to test the history UI as if
141 // it were. If the user opens chrome://history/?reset_ofbh, we will assume
142 // that other forms of browsing history exist (for all accounts), and we will
143 // also reset the one-time notice shown in the Clear Browsing Data dialog.
144 // This code should be removed as soon as the API is ready.
145 GURL url = web_ui->GetWebState()->GetVisibleURL();
146 if (url.has_query() && url.query() == "reset_ofbh") {
147 ios::ChromeBrowserState::FromWebUIIOS(web_ui)->GetPrefs()->SetInteger(
148 prefs::kClearBrowsingDataHistoryNoticeShownTimes, 0);
149 browsing_data::testing::g_override_other_forms_of_browsing_history_query =
150 true;
151 }
152
153 // Set up the chrome://history-frame/ source.
154 ios::ChromeBrowserState* browser_state =
155 ios::ChromeBrowserState::FromWebUIIOS(web_ui);
156 web::WebUIIOSDataSource::Add(browser_state,
157 CreateHistoryUIHTMLSource(browser_state));
158 }
159
160 HistoryUI::~HistoryUI() {}
161
162 // static
163 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes(
164 ui::ScaleFactor scale_factor) {
165 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
166 IDR_HISTORY_FAVICON, scale_factor);
167 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/webui/history/history_ui.h ('k') | ios/chrome/browser/ui/webui/history/metrics_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698