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

Side by Side Diff: chrome/browser/dom_ui/history_ui.cc

Issue 28104: Enable history and downloads by default, port NewTabUI from DOMUIHost to DOMU... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/dom_ui/history_ui.h ('k') | chrome/browser/dom_ui/new_tab_ui.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/dom_ui/history_ui.h" 5 #include "chrome/browser/dom_ui/history_ui.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_piece.h" 8 #include "base/string_piece.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/thread.h" 10 #include "base/thread.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/time_format.h" 12 #include "base/time_format.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/metrics/user_metrics.h" 14 #include "chrome/browser/metrics/user_metrics.h"
15 #include "chrome/browser/history/history_types.h" 15 #include "chrome/browser/history/history_types.h"
16 #include "chrome/browser/profile.h" 16 #include "chrome/browser/profile.h"
17 #include "chrome/common/jstemplate_builder.h" 17 #include "chrome/common/jstemplate_builder.h"
18 #include "chrome/common/l10n_util.h" 18 #include "chrome/common/l10n_util.h"
19 #include "chrome/common/notification_service.h" 19 #include "chrome/common/notification_service.h"
20 #include "chrome/common/resource_bundle.h" 20 #include "chrome/common/resource_bundle.h"
21 #include "chrome/common/time_format.h" 21 #include "chrome/common/time_format.h"
22 #include "net/base/escape.h"
23
22 #include "grit/browser_resources.h" 24 #include "grit/browser_resources.h"
23 #include "grit/chromium_strings.h" 25 #include "grit/chromium_strings.h"
24 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
25 27
26 using base::Time; 28 using base::Time;
27 using base::TimeDelta; 29 using base::TimeDelta;
28 30
29 // HistoryUI is accessible from chrome-ui://history. 31 // HistoryUI is accessible from chrome-ui://history.
30 static const char kHistoryHost[] = "history"; 32 static const char kHistoryHost[] = "history";
31 33
32 // Maximum number of search results to return in a given search. We should 34 // Maximum number of search results to return in a given search. We should
33 // eventually remove this. 35 // eventually remove this.
34 static const int kMaxSearchResults = 100; 36 static const int kMaxSearchResults = 100;
35 37
36 //////////////////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////////////////
37 // 39 //
38 // HistoryHTMLSource 40 // HistoryHTMLSource
39 // 41 //
40 //////////////////////////////////////////////////////////////////////////////// 42 ////////////////////////////////////////////////////////////////////////////////
41 43
42 HistoryUIHTMLSource::HistoryUIHTMLSource() 44 HistoryUIHTMLSource::HistoryUIHTMLSource()
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 options.end_time = Time::Now().LocalMidnight(); 140 options.end_time = Time::Now().LocalMidnight();
139 options.end_time -= TimeDelta::FromDays(day - 1); 141 options.end_time -= TimeDelta::FromDays(day - 1);
140 142
141 // Need to remember the query string for our results. 143 // Need to remember the query string for our results.
142 search_text_ = std::wstring(); 144 search_text_ = std::wstring();
143 145
144 HistoryService* hs = 146 HistoryService* hs =
145 dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); 147 dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
146 hs->QueryHistory(search_text_, 148 hs->QueryHistory(search_text_,
147 options, 149 options,
148 &cancelable_consumer_, 150 &cancelable_consumer_,
149 NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); 151 NewCallback(this, &BrowsingHistoryHandler::QueryComplete));
150 } 152 }
151 153
152 void BrowsingHistoryHandler::HandleSearchHistory(const Value* value) { 154 void BrowsingHistoryHandler::HandleSearchHistory(const Value* value) {
153 // Anything in-flight is invalid. 155 // Anything in-flight is invalid.
154 cancelable_consumer_.CancelAllRequests(); 156 cancelable_consumer_.CancelAllRequests();
155 157
156 // Get arguments (if any). 158 // Get arguments (if any).
157 int month = 0; 159 int month = 0;
158 std::wstring query; 160 std::wstring query;
159 ExtractSearchHistoryArguments(value, &month, &query); 161 ExtractSearchHistoryArguments(value, &month, &query);
160 162
161 // Set the query ranges for the given month. 163 // Set the query ranges for the given month.
162 history::QueryOptions options = CreateMonthQueryOptions(month); 164 history::QueryOptions options = CreateMonthQueryOptions(month);
163 165
164 // When searching, limit the number of results returned and only show the 166 // When searching, limit the number of results returned and only show the
165 // most recent matches. 167 // most recent matches.
166 options.max_count = kMaxSearchResults; 168 options.max_count = kMaxSearchResults;
167 options.most_recent_visit_only = true; 169 options.most_recent_visit_only = true;
168 170
169 // Need to remember the query string for our results. 171 // Need to remember the query string for our results.
170 search_text_ = query; 172 search_text_ = query;
171 HistoryService* hs = 173 HistoryService* hs =
172 dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); 174 dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
173 hs->QueryHistory(search_text_, 175 hs->QueryHistory(search_text_,
174 options, 176 options,
175 &cancelable_consumer_, 177 &cancelable_consumer_,
176 NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); 178 NewCallback(this, &BrowsingHistoryHandler::QueryComplete));
177 } 179 }
178 180
179 void BrowsingHistoryHandler::HandleDeleteDay(const Value* value) { 181 void BrowsingHistoryHandler::HandleDeleteDay(const Value* value) {
180 // Anything in-flight is invalid. 182 // Anything in-flight is invalid.
181 cancelable_consumer_.CancelAllRequests(); 183 cancelable_consumer_.CancelAllRequests();
182 184
183 // Get time. 185 // Get time.
184 Time time; 186 Time time;
185 bool success = Time::FromString(ExtractStringValue(value).c_str(), &time); 187 bool success = Time::FromString(ExtractStringValue(value).c_str(), &time);
(...skipping 24 matching lines...) Expand all
210 212
211 ListValue results_value; 213 ListValue results_value;
212 Time midnight_today = Time::Now().LocalMidnight(); 214 Time midnight_today = Time::Now().LocalMidnight();
213 215
214 for (size_t i = 0; i < results->size(); ++i) { 216 for (size_t i = 0; i < results->size(); ++i) {
215 history::URLResult const &page = (*results)[i]; 217 history::URLResult const &page = (*results)[i];
216 DictionaryValue* page_value = new DictionaryValue(); 218 DictionaryValue* page_value = new DictionaryValue();
217 SetURLAndTitle(page_value, page.title(), page.url()); 219 SetURLAndTitle(page_value, page.title(), page.url());
218 220
219 // Need to pass the time in epoch time (fastest JS conversion). 221 // Need to pass the time in epoch time (fastest JS conversion).
220 page_value->SetInteger(L"time", 222 page_value->SetInteger(L"time",
221 static_cast<int>(page.visit_time().ToTimeT())); 223 static_cast<int>(page.visit_time().ToTimeT()));
222 224
223 // Until we get some JS i18n infrastructure, we also need to 225 // Until we get some JS i18n infrastructure, we also need to
224 // pass the dates in as strings. This could use some 226 // pass the dates in as strings. This could use some
225 // optimization. 227 // optimization.
226 228
227 // Only pass in the strings we need (search results need a shortdate 229 // Only pass in the strings we need (search results need a shortdate
228 // and snippet, browse results need day and time information). 230 // and snippet, browse results need day and time information).
229 if (search_text_.empty()) { 231 if (search_text_.empty()) {
230 // Figure out the relative date string. 232 // Figure out the relative date string.
231 std::wstring date_str = TimeFormat::RelativeDate(page.visit_time(), 233 std::wstring date_str = TimeFormat::RelativeDate(page.visit_time(),
232 &midnight_today); 234 &midnight_today);
233 if (date_str.empty()) { 235 if (date_str.empty()) {
234 date_str = base::TimeFormatFriendlyDate(page.visit_time()); 236 date_str = base::TimeFormatFriendlyDate(page.visit_time());
235 } else { 237 } else {
236 date_str = l10n_util::GetStringF( 238 date_str = l10n_util::GetStringF(
237 IDS_HISTORY_DATE_WITH_RELATIVE_TIME, 239 IDS_HISTORY_DATE_WITH_RELATIVE_TIME,
238 date_str, base::TimeFormatFriendlyDate(page.visit_time())); 240 date_str, base::TimeFormatFriendlyDate(page.visit_time()));
239 } 241 }
240 page_value->SetString(L"dateRelativeDay", date_str); 242 page_value->SetString(L"dateRelativeDay", date_str);
241 page_value->SetString(L"dateTimeOfDay", 243 page_value->SetString(L"dateTimeOfDay",
242 base::TimeFormatTimeOfDay(page.visit_time())); 244 base::TimeFormatTimeOfDay(page.visit_time()));
243 } else { 245 } else {
244 page_value->SetString(L"dateShort", 246 page_value->SetString(L"dateShort",
245 base::TimeFormatShortDate(page.visit_time())); 247 base::TimeFormatShortDate(page.visit_time()));
246 page_value->SetString(L"snippet", page.snippet().text()); 248 page_value->SetString(L"snippet", page.snippet().text());
247 } 249 }
248 250
249 results_value.Append(page_value); 251 results_value.Append(page_value);
250 } 252 }
251 253
252 StringValue temp(search_text_); 254 StringValue temp(search_text_);
253 dom_ui_->CallJavascriptFunction(L"historyResult", temp, results_value); 255 dom_ui_->CallJavascriptFunction(L"historyResult", temp, results_value);
254 } 256 }
255 257
256 void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, 258 void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value,
257 int* month, std::wstring* query) { 259 int* month, std::wstring* query) {
258 *month = 0; 260 *month = 0;
259 261
260 if (value && value->GetType() == Value::TYPE_LIST) { 262 if (value && value->GetType() == Value::TYPE_LIST) {
261 const ListValue* list_value = static_cast<const ListValue*>(value); 263 const ListValue* list_value = static_cast<const ListValue*>(value);
262 Value* list_member; 264 Value* list_member;
263 265
264 // Get search string. 266 // Get search string.
265 if (list_value->Get(0, &list_member) && 267 if (list_value->Get(0, &list_member) &&
266 list_member->GetType() == Value::TYPE_STRING) { 268 list_member->GetType() == Value::TYPE_STRING) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 html_source)); 359 html_source));
358 } 360 }
359 361
360 // static 362 // static
361 GURL HistoryUI::GetBaseURL() { 363 GURL HistoryUI::GetBaseURL() {
362 std::string url = DOMUIContents::GetScheme(); 364 std::string url = DOMUIContents::GetScheme();
363 url += "://"; 365 url += "://";
364 url += kHistoryHost; 366 url += kHistoryHost;
365 return GURL(url); 367 return GURL(url);
366 } 368 }
369
370 // static
371 const GURL HistoryUI::GetHistoryURLWithSearchText(
372 const std::wstring& text) {
373 return GURL(GetBaseURL().spec() + "/?q=" +
374 EscapeQueryParamValue(WideToUTF8(text)));
375 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/history_ui.h ('k') | chrome/browser/dom_ui/new_tab_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698