| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 l10n_util::GetString(IDS_HISTORY_SEARCH_BUTTON)); | 69 l10n_util::GetString(IDS_HISTORY_SEARCH_BUTTON)); |
| 70 localized_strings.SetString(L"noresults", | 70 localized_strings.SetString(L"noresults", |
| 71 l10n_util::GetString(IDS_HISTORY_NO_RESULTS)); | 71 l10n_util::GetString(IDS_HISTORY_NO_RESULTS)); |
| 72 localized_strings.SetString(L"noitems", | 72 localized_strings.SetString(L"noitems", |
| 73 l10n_util::GetString(IDS_HISTORY_NO_ITEMS)); | 73 l10n_util::GetString(IDS_HISTORY_NO_ITEMS)); |
| 74 localized_strings.SetString(L"deleteday", | 74 localized_strings.SetString(L"deleteday", |
| 75 l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_LINK)); | 75 l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_LINK)); |
| 76 localized_strings.SetString(L"deletedaywarning", | 76 localized_strings.SetString(L"deletedaywarning", |
| 77 l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING)); | 77 l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING)); |
| 78 | 78 |
| 79 localized_strings.SetString(L"textdirection", |
| 80 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? |
| 81 L"rtl" : L"ltr"); |
| 82 |
| 79 static const StringPiece history_html( | 83 static const StringPiece history_html( |
| 80 ResourceBundle::GetSharedInstance().GetRawDataResource( | 84 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 81 IDR_HISTORY_HTML)); | 85 IDR_HISTORY_HTML)); |
| 82 const std::string full_html = jstemplate_builder::GetTemplateHtml( | 86 const std::string full_html = jstemplate_builder::GetTemplateHtml( |
| 83 history_html, &localized_strings, "t"); | 87 history_html, &localized_strings, "t"); |
| 84 | 88 |
| 85 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 89 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| 86 html_bytes->data.resize(full_html.size()); | 90 html_bytes->data.resize(full_html.size()); |
| 87 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); | 91 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); |
| 88 | 92 |
| 89 SendResponse(request_id, html_bytes); | 93 SendResponse(request_id, html_bytes); |
| 90 } | 94 } |
| 91 | 95 |
| 92 //////////////////////////////////////////////////////////////////////////////// | 96 //////////////////////////////////////////////////////////////////////////////// |
| 93 // | 97 // |
| 94 // HistoryHandler | 98 // HistoryHandler |
| 95 // | 99 // |
| 96 //////////////////////////////////////////////////////////////////////////////// | 100 //////////////////////////////////////////////////////////////////////////////// |
| 97 BrowsingHistoryHandler::BrowsingHistoryHandler(DOMUI* dom_ui) | 101 BrowsingHistoryHandler::BrowsingHistoryHandler(DOMUI* dom_ui) |
| 98 : DOMMessageHandler(dom_ui), | 102 : DOMMessageHandler(dom_ui), |
| 99 search_text_(), | 103 search_text_(), |
| 100 remover_(NULL) { | 104 remover_(NULL) { |
| 101 dom_ui_->RegisterMessageCallback("getHistory", | 105 dom_ui_->RegisterMessageCallback("getHistory", |
| 102 NewCallback(this, &BrowsingHistoryHandler::HandleGetHistory)); | 106 NewCallback(this, &BrowsingHistoryHandler::HandleGetHistory)); |
| 103 dom_ui_->RegisterMessageCallback("searchHistory", | 107 dom_ui_->RegisterMessageCallback("searchHistory", |
| 104 NewCallback(this, &BrowsingHistoryHandler::HandleSearchHistory)); | 108 NewCallback(this, &BrowsingHistoryHandler::HandleSearchHistory)); |
| 105 dom_ui_->RegisterMessageCallback("deleteDay", | 109 dom_ui_->RegisterMessageCallback("deleteDay", |
| 106 NewCallback(this, &BrowsingHistoryHandler::HandleDeleteDay)); | 110 NewCallback(this, &BrowsingHistoryHandler::HandleDeleteDay)); |
| 107 | 111 |
| 108 // Create our favicon data source. | 112 // Create our favicon data source. |
| 109 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 113 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 110 NewRunnableMethod(&chrome_url_data_manager, | 114 NewRunnableMethod(&chrome_url_data_manager, |
| 111 &ChromeURLDataManager::AddDataSource, | 115 &ChromeURLDataManager::AddDataSource, |
| 112 new FavIconSource(dom_ui_->get_profile()))); | 116 new FavIconSource(dom_ui_->get_profile()))); |
| 113 | 117 |
| 114 // Get notifications when history is cleared. | 118 // Get notifications when history is cleared. |
| 115 NotificationService* service = NotificationService::current(); | 119 NotificationService* service = NotificationService::current(); |
| 116 service->AddObserver(this, NotificationType::HISTORY_URLS_DELETED, | 120 service->AddObserver(this, NotificationType::HISTORY_URLS_DELETED, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 136 int day = 0; | 140 int day = 0; |
| 137 ExtractIntegerValue(value, &day); | 141 ExtractIntegerValue(value, &day); |
| 138 | 142 |
| 139 // Set our query options. | 143 // Set our query options. |
| 140 history::QueryOptions options; | 144 history::QueryOptions options; |
| 141 options.begin_time = Time::Now().LocalMidnight(); | 145 options.begin_time = Time::Now().LocalMidnight(); |
| 142 options.begin_time -= TimeDelta::FromDays(day); | 146 options.begin_time -= TimeDelta::FromDays(day); |
| 143 options.end_time = Time::Now().LocalMidnight(); | 147 options.end_time = Time::Now().LocalMidnight(); |
| 144 options.end_time -= TimeDelta::FromDays(day - 1); | 148 options.end_time -= TimeDelta::FromDays(day - 1); |
| 145 | 149 |
| 150 // As we're querying per-day, we can turn entry repeats off. |
| 151 options.most_recent_visit_only = true; |
| 152 |
| 146 // Need to remember the query string for our results. | 153 // Need to remember the query string for our results. |
| 147 search_text_ = std::wstring(); | 154 search_text_ = std::wstring(); |
| 148 | 155 |
| 149 HistoryService* hs = | 156 HistoryService* hs = |
| 150 dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 157 dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 151 hs->QueryHistory(search_text_, | 158 hs->QueryHistory(search_text_, |
| 152 options, | 159 options, |
| 153 &cancelable_consumer_, | 160 &cancelable_consumer_, |
| 154 NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); | 161 NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); |
| 155 } | 162 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } else { | 259 } else { |
| 253 page_value->SetString(L"dateShort", | 260 page_value->SetString(L"dateShort", |
| 254 base::TimeFormatShortDate(page.visit_time())); | 261 base::TimeFormatShortDate(page.visit_time())); |
| 255 page_value->SetString(L"snippet", page.snippet().text()); | 262 page_value->SetString(L"snippet", page.snippet().text()); |
| 256 } | 263 } |
| 257 page_value->SetBoolean(L"starred", | 264 page_value->SetBoolean(L"starred", |
| 258 dom_ui_->get_profile()->GetBookmarkModel()->IsBookmarked(page.url())); | 265 dom_ui_->get_profile()->GetBookmarkModel()->IsBookmarked(page.url())); |
| 259 results_value.Append(page_value); | 266 results_value.Append(page_value); |
| 260 } | 267 } |
| 261 | 268 |
| 262 StringValue temp(search_text_); | 269 DictionaryValue info_value; |
| 263 dom_ui_->CallJavascriptFunction(L"historyResult", temp, results_value); | 270 info_value.SetString(L"term", search_text_); |
| 271 info_value.SetBoolean(L"finished", results->reached_beginning()); |
| 272 |
| 273 dom_ui_->CallJavascriptFunction(L"historyResult", info_value, results_value); |
| 264 } | 274 } |
| 265 | 275 |
| 266 void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, | 276 void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, |
| 267 int* month, std::wstring* query) { | 277 int* month, std::wstring* query) { |
| 268 *month = 0; | 278 *month = 0; |
| 269 | 279 |
| 270 if (value && value->GetType() == Value::TYPE_LIST) { | 280 if (value && value->GetType() == Value::TYPE_LIST) { |
| 271 const ListValue* list_value = static_cast<const ListValue*>(value); | 281 const ListValue* list_value = static_cast<const ListValue*>(value); |
| 272 Value* list_member; | 282 Value* list_member; |
| 273 | 283 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 } | 345 } |
| 336 | 346 |
| 337 void BrowsingHistoryHandler::Observe(NotificationType type, | 347 void BrowsingHistoryHandler::Observe(NotificationType type, |
| 338 const NotificationSource& source, | 348 const NotificationSource& source, |
| 339 const NotificationDetails& details) { | 349 const NotificationDetails& details) { |
| 340 if (type != NotificationType::HISTORY_URLS_DELETED) { | 350 if (type != NotificationType::HISTORY_URLS_DELETED) { |
| 341 NOTREACHED(); | 351 NOTREACHED(); |
| 342 return; | 352 return; |
| 343 } | 353 } |
| 344 | 354 |
| 345 // Some URLs were deleted from history. Reload the most visited list. | 355 // Some URLs were deleted from history. Reload the list. |
| 346 HandleGetHistory(NULL); | 356 dom_ui_->CallJavascriptFunction(L"historyDeleted"); |
| 347 } | 357 } |
| 348 | 358 |
| 349 //////////////////////////////////////////////////////////////////////////////// | 359 //////////////////////////////////////////////////////////////////////////////// |
| 350 // | 360 // |
| 351 // HistoryUIContents | 361 // HistoryUIContents |
| 352 // | 362 // |
| 353 //////////////////////////////////////////////////////////////////////////////// | 363 //////////////////////////////////////////////////////////////////////////////// |
| 354 | 364 |
| 355 HistoryUI::HistoryUI(DOMUIContents* contents) : DOMUI(contents) { | 365 HistoryUI::HistoryUI(DOMUIContents* contents) : DOMUI(contents) { |
| 356 } | 366 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 370 // static | 380 // static |
| 371 GURL HistoryUI::GetBaseURL() { | 381 GURL HistoryUI::GetBaseURL() { |
| 372 std::string url = DOMUIContents::GetScheme(); | 382 std::string url = DOMUIContents::GetScheme(); |
| 373 url += "://"; | 383 url += "://"; |
| 374 url += kHistoryHost; | 384 url += kHistoryHost; |
| 375 return GURL(url); | 385 return GURL(url); |
| 376 } | 386 } |
| 377 | 387 |
| 378 // static | 388 // static |
| 379 const GURL HistoryUI::GetHistoryURLWithSearchText( | 389 const GURL HistoryUI::GetHistoryURLWithSearchText( |
| 380 const std::wstring& text) { | 390 const std::wstring& text) { |
| 381 return GURL(GetBaseURL().spec() + "#q=" + | 391 return GURL(GetBaseURL().spec() + "#q=" + |
| 382 EscapeQueryParamValue(WideToUTF8(text))); | 392 EscapeQueryParamValue(WideToUTF8(text))); |
| 383 } | 393 } |
| OLD | NEW |