| OLD | NEW |
| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // | 42 // |
| 43 //////////////////////////////////////////////////////////////////////////////// | 43 //////////////////////////////////////////////////////////////////////////////// |
| 44 | 44 |
| 45 HistoryUIHTMLSource::HistoryUIHTMLSource() | 45 HistoryUIHTMLSource::HistoryUIHTMLSource() |
| 46 : DataSource(kHistoryHost, MessageLoop::current()) { | 46 : DataSource(kHistoryHost, MessageLoop::current()) { |
| 47 } | 47 } |
| 48 | 48 |
| 49 void HistoryUIHTMLSource::StartDataRequest(const std::string& path, | 49 void HistoryUIHTMLSource::StartDataRequest(const std::string& path, |
| 50 int request_id) { | 50 int request_id) { |
| 51 DictionaryValue localized_strings; | 51 DictionaryValue localized_strings; |
| 52 localized_strings.SetString(L"title", | 52 localized_strings.SetString(ASCIIToUTF16("title"), |
| 53 l10n_util::GetString(IDS_HISTORY_TITLE)); | 53 WideToUTF16Hack(l10n_util::GetString(IDS_HISTORY_TITLE))); |
| 54 localized_strings.SetString(L"loading", | 54 localized_strings.SetString(ASCIIToUTF16("loading"), |
| 55 l10n_util::GetString(IDS_HISTORY_LOADING)); | 55 WideToUTF16Hack(l10n_util::GetString(IDS_HISTORY_LOADING))); |
| 56 localized_strings.SetString(L"newest", | 56 localized_strings.SetString(ASCIIToUTF16("newest"), |
| 57 l10n_util::GetString(IDS_HISTORY_NEWEST)); | 57 WideToUTF16Hack(l10n_util::GetString(IDS_HISTORY_NEWEST))); |
| 58 localized_strings.SetString(L"newer", | 58 localized_strings.SetString(ASCIIToUTF16("newer"), |
| 59 l10n_util::GetString(IDS_HISTORY_NEWER)); | 59 WideToUTF16Hack(l10n_util::GetString(IDS_HISTORY_NEWER))); |
| 60 localized_strings.SetString(L"older", | 60 localized_strings.SetString(ASCIIToUTF16("older"), |
| 61 l10n_util::GetString(IDS_HISTORY_OLDER)); | 61 WideToUTF16Hack(l10n_util::GetString(IDS_HISTORY_OLDER))); |
| 62 localized_strings.SetString(L"searchresultsfor", | 62 localized_strings.SetString(ASCIIToUTF16("searchresultsfor"), |
| 63 l10n_util::GetString(IDS_HISTORY_SEARCHRESULTSFOR)); | 63 WideToUTF16Hack(l10n_util::GetString(IDS_HISTORY_SEARCHRESULTSFOR))); |
| 64 localized_strings.SetString(L"history", | 64 localized_strings.SetString(ASCIIToUTF16("history"), |
| 65 l10n_util::GetString(IDS_HISTORY_BROWSERESULTS)); | 65 WideToUTF16Hack(l10n_util::GetString(IDS_HISTORY_BROWSERESULTS))); |
| 66 localized_strings.SetString(L"cont", | 66 localized_strings.SetString(ASCIIToUTF16("cont"), |
| 67 l10n_util::GetString(IDS_HISTORY_CONTINUED)); | 67 WideToUTF16Hack(l10n_util::GetString(IDS_HISTORY_CONTINUED))); |
| 68 localized_strings.SetString(L"searchbutton", | 68 localized_strings.SetString(ASCIIToUTF16("searchbutton"), |
| 69 l10n_util::GetString(IDS_HISTORY_SEARCH_BUTTON)); | 69 WideToUTF16Hack(l10n_util::GetString(IDS_HISTORY_SEARCH_BUTTON))); |
| 70 localized_strings.SetString(L"noresults", | 70 localized_strings.SetString(ASCIIToUTF16("noresults"), |
| 71 l10n_util::GetString(IDS_HISTORY_NO_RESULTS)); | 71 WideToUTF16Hack(l10n_util::GetString(IDS_HISTORY_NO_RESULTS))); |
| 72 localized_strings.SetString(L"noitems", | 72 localized_strings.SetString(ASCIIToUTF16("noitems"), |
| 73 l10n_util::GetString(IDS_HISTORY_NO_ITEMS)); | 73 WideToUTF16Hack(l10n_util::GetString(IDS_HISTORY_NO_ITEMS))); |
| 74 localized_strings.SetString(L"deleteday", | 74 localized_strings.SetString(ASCIIToUTF16("deleteday"), |
| 75 l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_LINK)); | 75 WideToUTF16Hack( |
| 76 localized_strings.SetString(L"deletedaywarning", | 76 l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_LINK))); |
| 77 l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING)); | 77 localized_strings.SetString(ASCIIToUTF16("deletedaywarning"), |
| 78 WideToUTF16Hack( |
| 79 l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING))); |
| 78 | 80 |
| 79 static const StringPiece history_html( | 81 static const StringPiece history_html( |
| 80 ResourceBundle::GetSharedInstance().GetRawDataResource( | 82 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 81 IDR_HISTORY_HTML)); | 83 IDR_HISTORY_HTML)); |
| 82 const std::string full_html = jstemplate_builder::GetTemplateHtml( | 84 const std::string full_html = jstemplate_builder::GetTemplateHtml( |
| 83 history_html, &localized_strings, "t"); | 85 history_html, &localized_strings, "t"); |
| 84 | 86 |
| 85 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 87 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| 86 html_bytes->data.resize(full_html.size()); | 88 html_bytes->data.resize(full_html.size()); |
| 87 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); | 89 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 221 |
| 220 ListValue results_value; | 222 ListValue results_value; |
| 221 Time midnight_today = Time::Now().LocalMidnight(); | 223 Time midnight_today = Time::Now().LocalMidnight(); |
| 222 | 224 |
| 223 for (size_t i = 0; i < results->size(); ++i) { | 225 for (size_t i = 0; i < results->size(); ++i) { |
| 224 history::URLResult const &page = (*results)[i]; | 226 history::URLResult const &page = (*results)[i]; |
| 225 DictionaryValue* page_value = new DictionaryValue(); | 227 DictionaryValue* page_value = new DictionaryValue(); |
| 226 SetURLAndTitle(page_value, page.title(), page.url()); | 228 SetURLAndTitle(page_value, page.title(), page.url()); |
| 227 | 229 |
| 228 // Need to pass the time in epoch time (fastest JS conversion). | 230 // Need to pass the time in epoch time (fastest JS conversion). |
| 229 page_value->SetInteger(L"time", | 231 page_value->SetInteger(ASCIIToUTF16("time"), |
| 230 static_cast<int>(page.visit_time().ToTimeT())); | 232 static_cast<int>(page.visit_time().ToTimeT())); |
| 231 | 233 |
| 232 // Until we get some JS i18n infrastructure, we also need to | 234 // Until we get some JS i18n infrastructure, we also need to |
| 233 // pass the dates in as strings. This could use some | 235 // pass the dates in as strings. This could use some |
| 234 // optimization. | 236 // optimization. |
| 235 | 237 |
| 236 // Only pass in the strings we need (search results need a shortdate | 238 // Only pass in the strings we need (search results need a shortdate |
| 237 // and snippet, browse results need day and time information). | 239 // and snippet, browse results need day and time information). |
| 238 if (search_text_.empty()) { | 240 if (search_text_.empty()) { |
| 239 // Figure out the relative date string. | 241 // Figure out the relative date string. |
| 240 std::wstring date_str = TimeFormat::RelativeDate(page.visit_time(), | 242 std::wstring date_str = TimeFormat::RelativeDate(page.visit_time(), |
| 241 &midnight_today); | 243 &midnight_today); |
| 242 if (date_str.empty()) { | 244 if (date_str.empty()) { |
| 243 date_str = base::TimeFormatFriendlyDate(page.visit_time()); | 245 date_str = base::TimeFormatFriendlyDate(page.visit_time()); |
| 244 } else { | 246 } else { |
| 245 date_str = l10n_util::GetStringF( | 247 date_str = l10n_util::GetStringF( |
| 246 IDS_HISTORY_DATE_WITH_RELATIVE_TIME, | 248 IDS_HISTORY_DATE_WITH_RELATIVE_TIME, |
| 247 date_str, base::TimeFormatFriendlyDate(page.visit_time())); | 249 date_str, base::TimeFormatFriendlyDate(page.visit_time())); |
| 248 } | 250 } |
| 249 page_value->SetString(L"dateRelativeDay", date_str); | 251 page_value->SetString(ASCIIToUTF16("dateRelativeDay"), |
| 250 page_value->SetString(L"dateTimeOfDay", | 252 WideToUTF16Hack(date_str)); |
| 251 base::TimeFormatTimeOfDay(page.visit_time())); | 253 page_value->SetString( |
| 254 ASCIIToUTF16("dateTimeOfDay"), |
| 255 WideToUTF16Hack(base::TimeFormatTimeOfDay(page.visit_time()))); |
| 252 } else { | 256 } else { |
| 253 page_value->SetString(L"dateShort", | 257 page_value->SetString( |
| 254 base::TimeFormatShortDate(page.visit_time())); | 258 ASCIIToUTF16("dateShort"), |
| 255 page_value->SetString(L"snippet", page.snippet().text()); | 259 WideToUTF16Hack(base::TimeFormatShortDate(page.visit_time()))); |
| 260 page_value->SetString( |
| 261 ASCIIToUTF16("snippet"), WideToUTF16Hack(page.snippet().text())); |
| 256 } | 262 } |
| 257 page_value->SetBoolean(L"starred", | 263 page_value->SetBoolean(ASCIIToUTF16("starred"), |
| 258 dom_ui_->get_profile()->GetBookmarkModel()->IsBookmarked(page.url())); | 264 dom_ui_->get_profile()->GetBookmarkModel()->IsBookmarked(page.url())); |
| 259 results_value.Append(page_value); | 265 results_value.Append(page_value); |
| 260 } | 266 } |
| 261 | 267 |
| 262 StringValue temp(search_text_); | 268 StringValue temp(search_text_); |
| 263 dom_ui_->CallJavascriptFunction(L"historyResult", temp, results_value); | 269 dom_ui_->CallJavascriptFunction(L"historyResult", temp, results_value); |
| 264 } | 270 } |
| 265 | 271 |
| 266 void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, | 272 void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, |
| 267 int* month, std::wstring* query) { | 273 int* month, std::wstring* query) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 url += kHistoryHost; | 380 url += kHistoryHost; |
| 375 return GURL(url); | 381 return GURL(url); |
| 376 } | 382 } |
| 377 | 383 |
| 378 // static | 384 // static |
| 379 const GURL HistoryUI::GetHistoryURLWithSearchText( | 385 const GURL HistoryUI::GetHistoryURLWithSearchText( |
| 380 const std::wstring& text) { | 386 const std::wstring& text) { |
| 381 return GURL(GetBaseURL().spec() + "#q=" + | 387 return GURL(GetBaseURL().spec() + "#q=" + |
| 382 EscapeQueryParamValue(WideToUTF8(text))); | 388 EscapeQueryParamValue(WideToUTF8(text))); |
| 383 } | 389 } |
| OLD | NEW |