| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
| 48 | 48 |
| 49 HistoryUIHTMLSource::HistoryUIHTMLSource() | 49 HistoryUIHTMLSource::HistoryUIHTMLSource() |
| 50 : DataSource(chrome::kChromeUIHistoryHost, MessageLoop::current()) { | 50 : DataSource(chrome::kChromeUIHistoryHost, MessageLoop::current()) { |
| 51 } | 51 } |
| 52 | 52 |
| 53 void HistoryUIHTMLSource::StartDataRequest(const std::string& path, | 53 void HistoryUIHTMLSource::StartDataRequest(const std::string& path, |
| 54 bool is_off_the_record, | 54 bool is_off_the_record, |
| 55 int request_id) { | 55 int request_id) { |
| 56 DictionaryValue localized_strings; | 56 DictionaryValue localized_strings; |
| 57 localized_strings.SetString(L"loading", | 57 localized_strings.SetString("loading", |
| 58 l10n_util::GetString(IDS_HISTORY_LOADING)); | 58 l10n_util::GetStringUTF16(IDS_HISTORY_LOADING)); |
| 59 localized_strings.SetString(L"title", | 59 localized_strings.SetString("title", |
| 60 l10n_util::GetString(IDS_HISTORY_TITLE)); | 60 l10n_util::GetStringUTF16(IDS_HISTORY_TITLE)); |
| 61 localized_strings.SetString(L"loading", | 61 localized_strings.SetString("loading", |
| 62 l10n_util::GetString(IDS_HISTORY_LOADING)); | 62 l10n_util::GetStringUTF16(IDS_HISTORY_LOADING)); |
| 63 localized_strings.SetString(L"newest", | 63 localized_strings.SetString("newest", |
| 64 l10n_util::GetString(IDS_HISTORY_NEWEST)); | 64 l10n_util::GetStringUTF16(IDS_HISTORY_NEWEST)); |
| 65 localized_strings.SetString(L"newer", | 65 localized_strings.SetString("newer", |
| 66 l10n_util::GetString(IDS_HISTORY_NEWER)); | 66 l10n_util::GetStringUTF16(IDS_HISTORY_NEWER)); |
| 67 localized_strings.SetString(L"older", | 67 localized_strings.SetString("older", |
| 68 l10n_util::GetString(IDS_HISTORY_OLDER)); | 68 l10n_util::GetStringUTF16(IDS_HISTORY_OLDER)); |
| 69 localized_strings.SetString(L"searchresultsfor", | 69 localized_strings.SetString("searchresultsfor", |
| 70 l10n_util::GetString(IDS_HISTORY_SEARCHRESULTSFOR)); | 70 l10n_util::GetStringUTF16(IDS_HISTORY_SEARCHRESULTSFOR)); |
| 71 localized_strings.SetString(L"history", | 71 localized_strings.SetString("history", |
| 72 l10n_util::GetString(IDS_HISTORY_BROWSERESULTS)); | 72 l10n_util::GetStringUTF16(IDS_HISTORY_BROWSERESULTS)); |
| 73 localized_strings.SetString(L"cont", | 73 localized_strings.SetString("cont", |
| 74 l10n_util::GetString(IDS_HISTORY_CONTINUED)); | 74 l10n_util::GetStringUTF16(IDS_HISTORY_CONTINUED)); |
| 75 localized_strings.SetString(L"searchbutton", | 75 localized_strings.SetString("searchbutton", |
| 76 l10n_util::GetString(IDS_HISTORY_SEARCH_BUTTON)); | 76 l10n_util::GetStringUTF16(IDS_HISTORY_SEARCH_BUTTON)); |
| 77 localized_strings.SetString(L"noresults", | 77 localized_strings.SetString("noresults", |
| 78 l10n_util::GetString(IDS_HISTORY_NO_RESULTS)); | 78 l10n_util::GetStringUTF16(IDS_HISTORY_NO_RESULTS)); |
| 79 localized_strings.SetString(L"noitems", | 79 localized_strings.SetString("noitems", |
| 80 l10n_util::GetString(IDS_HISTORY_NO_ITEMS)); | 80 l10n_util::GetStringUTF16(IDS_HISTORY_NO_ITEMS)); |
| 81 localized_strings.SetString(L"edithistory", | 81 localized_strings.SetString("edithistory", |
| 82 l10n_util::GetString(IDS_HISTORY_START_EDITING_HISTORY)); | 82 l10n_util::GetStringUTF16(IDS_HISTORY_START_EDITING_HISTORY)); |
| 83 localized_strings.SetString(L"doneediting", | 83 localized_strings.SetString("doneediting", |
| 84 l10n_util::GetString(IDS_HISTORY_STOP_EDITING_HISTORY)); | 84 l10n_util::GetStringUTF16(IDS_HISTORY_STOP_EDITING_HISTORY)); |
| 85 localized_strings.SetString(L"removeselected", | 85 localized_strings.SetString("removeselected", |
| 86 l10n_util::GetString(IDS_HISTORY_REMOVE_SELECTED_ITEMS)); | 86 l10n_util::GetStringUTF16(IDS_HISTORY_REMOVE_SELECTED_ITEMS)); |
| 87 localized_strings.SetString(L"clearallhistory", | 87 localized_strings.SetString("clearallhistory", |
| 88 l10n_util::GetString(IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG)); | 88 l10n_util::GetStringUTF16(IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG)); |
| 89 localized_strings.SetString(L"deletewarning", | 89 localized_strings.SetString("deletewarning", |
| 90 l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING)); | 90 l10n_util::GetStringUTF16(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING)); |
| 91 | 91 |
| 92 SetFontAndTextDirection(&localized_strings); | 92 SetFontAndTextDirection(&localized_strings); |
| 93 | 93 |
| 94 static const base::StringPiece history_html( | 94 static const base::StringPiece history_html( |
| 95 ResourceBundle::GetSharedInstance().GetRawDataResource( | 95 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 96 IDR_HISTORY_HTML)); | 96 IDR_HISTORY_HTML)); |
| 97 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( | 97 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( |
| 98 history_html, &localized_strings); | 98 history_html, &localized_strings); |
| 99 | 99 |
| 100 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 100 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 245 |
| 246 ListValue results_value; | 246 ListValue results_value; |
| 247 base::Time midnight_today = base::Time::Now().LocalMidnight(); | 247 base::Time midnight_today = base::Time::Now().LocalMidnight(); |
| 248 | 248 |
| 249 for (size_t i = 0; i < results->size(); ++i) { | 249 for (size_t i = 0; i < results->size(); ++i) { |
| 250 history::URLResult const &page = (*results)[i]; | 250 history::URLResult const &page = (*results)[i]; |
| 251 DictionaryValue* page_value = new DictionaryValue(); | 251 DictionaryValue* page_value = new DictionaryValue(); |
| 252 SetURLAndTitle(page_value, page.title(), page.url()); | 252 SetURLAndTitle(page_value, page.title(), page.url()); |
| 253 | 253 |
| 254 // Need to pass the time in epoch time (fastest JS conversion). | 254 // Need to pass the time in epoch time (fastest JS conversion). |
| 255 page_value->SetInteger(L"time", | 255 page_value->SetInteger("time", |
| 256 static_cast<int>(page.visit_time().ToTimeT())); | 256 static_cast<int>(page.visit_time().ToTimeT())); |
| 257 | 257 |
| 258 // Until we get some JS i18n infrastructure, we also need to | 258 // Until we get some JS i18n infrastructure, we also need to |
| 259 // pass the dates in as strings. This could use some | 259 // pass the dates in as strings. This could use some |
| 260 // optimization. | 260 // optimization. |
| 261 | 261 |
| 262 // Only pass in the strings we need (search results need a shortdate | 262 // Only pass in the strings we need (search results need a shortdate |
| 263 // and snippet, browse results need day and time information). | 263 // and snippet, browse results need day and time information). |
| 264 if (search_text_.empty()) { | 264 if (search_text_.empty()) { |
| 265 // Figure out the relative date string. | 265 // Figure out the relative date string. |
| 266 std::wstring date_str = TimeFormat::RelativeDate(page.visit_time(), | 266 std::wstring date_str = TimeFormat::RelativeDate(page.visit_time(), |
| 267 &midnight_today); | 267 &midnight_today); |
| 268 if (date_str.empty()) { | 268 if (date_str.empty()) { |
| 269 date_str = base::TimeFormatFriendlyDate(page.visit_time()); | 269 date_str = base::TimeFormatFriendlyDate(page.visit_time()); |
| 270 } else { | 270 } else { |
| 271 date_str = l10n_util::GetStringF( | 271 date_str = l10n_util::GetStringF( |
| 272 IDS_HISTORY_DATE_WITH_RELATIVE_TIME, | 272 IDS_HISTORY_DATE_WITH_RELATIVE_TIME, |
| 273 date_str, base::TimeFormatFriendlyDate(page.visit_time())); | 273 date_str, base::TimeFormatFriendlyDate(page.visit_time())); |
| 274 } | 274 } |
| 275 page_value->SetString(L"dateRelativeDay", date_str); | 275 page_value->SetString("dateRelativeDay", WideToUTF16Hack(date_str)); |
| 276 page_value->SetString(L"dateTimeOfDay", | 276 page_value->SetString("dateTimeOfDay", |
| 277 base::TimeFormatTimeOfDay(page.visit_time())); | 277 WideToUTF16Hack(base::TimeFormatTimeOfDay(page.visit_time()))); |
| 278 } else { | 278 } else { |
| 279 page_value->SetString(L"dateShort", | 279 page_value->SetString("dateShort", |
| 280 base::TimeFormatShortDate(page.visit_time())); | 280 WideToUTF16Hack(base::TimeFormatShortDate(page.visit_time()))); |
| 281 page_value->SetStringFromUTF16(L"snippet", page.snippet().text()); | 281 page_value->SetString("snippet", page.snippet().text()); |
| 282 } | 282 } |
| 283 page_value->SetBoolean(L"starred", | 283 page_value->SetBoolean("starred", |
| 284 dom_ui_->GetProfile()->GetBookmarkModel()->IsBookmarked(page.url())); | 284 dom_ui_->GetProfile()->GetBookmarkModel()->IsBookmarked(page.url())); |
| 285 results_value.Append(page_value); | 285 results_value.Append(page_value); |
| 286 } | 286 } |
| 287 | 287 |
| 288 DictionaryValue info_value; | 288 DictionaryValue info_value; |
| 289 info_value.SetStringFromUTF16(L"term", search_text_); | 289 info_value.SetString("term", search_text_); |
| 290 info_value.SetBoolean(L"finished", results->reached_beginning()); | 290 info_value.SetBoolean("finished", results->reached_beginning()); |
| 291 | 291 |
| 292 dom_ui_->CallJavascriptFunction(L"historyResult", info_value, results_value); | 292 dom_ui_->CallJavascriptFunction(L"historyResult", info_value, results_value); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void BrowsingHistoryHandler::RemoveComplete() { | 295 void BrowsingHistoryHandler::RemoveComplete() { |
| 296 // Some Visits were deleted from history. Reload the list. | 296 // Some Visits were deleted from history. Reload the list. |
| 297 dom_ui_->CallJavascriptFunction(L"deleteComplete"); | 297 dom_ui_->CallJavascriptFunction(L"deleteComplete"); |
| 298 } | 298 } |
| 299 | 299 |
| 300 void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, | 300 void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { | 405 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { |
| 406 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 406 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
| 407 EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 407 EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
| 408 } | 408 } |
| 409 | 409 |
| 410 // static | 410 // static |
| 411 RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { | 411 RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { |
| 412 return ResourceBundle::GetSharedInstance(). | 412 return ResourceBundle::GetSharedInstance(). |
| 413 LoadDataResourceBytes(IDR_HISTORY_FAVICON); | 413 LoadDataResourceBytes(IDR_HISTORY_FAVICON); |
| 414 } | 414 } |
| OLD | NEW |