| 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" |
| 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/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/metrics/user_metrics.h" | 15 #include "chrome/browser/metrics/user_metrics.h" |
| 15 #include "chrome/browser/history/history_types.h" | 16 #include "chrome/browser/history/history_types.h" |
| 16 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 17 #include "chrome/common/jstemplate_builder.h" | 18 #include "chrome/common/jstemplate_builder.h" |
| 18 #include "chrome/common/l10n_util.h" | 19 #include "chrome/common/l10n_util.h" |
| 19 #include "chrome/common/notification_service.h" | 20 #include "chrome/common/notification_service.h" |
| 20 #include "chrome/common/resource_bundle.h" | 21 #include "chrome/common/resource_bundle.h" |
| 21 #include "chrome/common/time_format.h" | 22 #include "chrome/common/time_format.h" |
| 22 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 &ChromeURLDataManager::AddDataSource, | 111 &ChromeURLDataManager::AddDataSource, |
| 111 new FavIconSource(dom_ui_->get_profile()))); | 112 new FavIconSource(dom_ui_->get_profile()))); |
| 112 | 113 |
| 113 // Get notifications when history is cleared. | 114 // Get notifications when history is cleared. |
| 114 NotificationService* service = NotificationService::current(); | 115 NotificationService* service = NotificationService::current(); |
| 115 service->AddObserver(this, NotificationType::HISTORY_URLS_DELETED, | 116 service->AddObserver(this, NotificationType::HISTORY_URLS_DELETED, |
| 116 Source<Profile>(dom_ui_->get_profile())); | 117 Source<Profile>(dom_ui_->get_profile())); |
| 117 } | 118 } |
| 118 | 119 |
| 119 BrowsingHistoryHandler::~BrowsingHistoryHandler() { | 120 BrowsingHistoryHandler::~BrowsingHistoryHandler() { |
| 121 cancelable_consumer_.CancelAllRequests(); |
| 122 |
| 120 NotificationService* service = NotificationService::current(); | 123 NotificationService* service = NotificationService::current(); |
| 121 service->RemoveObserver(this, NotificationType::HISTORY_URLS_DELETED, | 124 service->RemoveObserver(this, NotificationType::HISTORY_URLS_DELETED, |
| 122 Source<Profile>(dom_ui_->get_profile())); | 125 Source<Profile>(dom_ui_->get_profile())); |
| 123 | 126 |
| 124 if (remover_) | 127 if (remover_.get()) |
| 125 remover_->RemoveObserver(this); | 128 remover_->RemoveObserver(this); |
| 126 } | 129 } |
| 127 | 130 |
| 128 void BrowsingHistoryHandler::HandleGetHistory(const Value* value) { | 131 void BrowsingHistoryHandler::HandleGetHistory(const Value* value) { |
| 129 // Anything in-flight is invalid. | 132 // Anything in-flight is invalid. |
| 130 cancelable_consumer_.CancelAllRequests(); | 133 cancelable_consumer_.CancelAllRequests(); |
| 131 | 134 |
| 132 // Get arguments (if any). | 135 // Get arguments (if any). |
| 133 int day = 0; | 136 int day = 0; |
| 134 ExtractIntegerValue(value, &day); | 137 ExtractIntegerValue(value, &day); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 search_text_ = query; | 175 search_text_ = query; |
| 173 HistoryService* hs = | 176 HistoryService* hs = |
| 174 dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 177 dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 175 hs->QueryHistory(search_text_, | 178 hs->QueryHistory(search_text_, |
| 176 options, | 179 options, |
| 177 &cancelable_consumer_, | 180 &cancelable_consumer_, |
| 178 NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); | 181 NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); |
| 179 } | 182 } |
| 180 | 183 |
| 181 void BrowsingHistoryHandler::HandleDeleteDay(const Value* value) { | 184 void BrowsingHistoryHandler::HandleDeleteDay(const Value* value) { |
| 185 if (BrowsingDataRemover::is_removing()) { |
| 186 dom_ui_->CallJavascriptFunction(L"deleteFailed"); |
| 187 return; |
| 188 } |
| 189 |
| 182 // Anything in-flight is invalid. | 190 // Anything in-flight is invalid. |
| 183 cancelable_consumer_.CancelAllRequests(); | 191 cancelable_consumer_.CancelAllRequests(); |
| 184 | 192 |
| 185 // Get time. | 193 // Get time. |
| 186 Time time; | 194 Time time; |
| 187 bool success = Time::FromString(ExtractStringValue(value).c_str(), &time); | 195 bool success = Time::FromString(ExtractStringValue(value).c_str(), &time); |
| 188 DCHECK(success); | 196 DCHECK(success); |
| 189 | 197 |
| 190 Time begin_time = time.LocalMidnight(); | 198 Time begin_time = time.LocalMidnight(); |
| 191 Time end_time = begin_time + TimeDelta::FromDays(1); | 199 Time end_time = begin_time + TimeDelta::FromDays(1); |
| 192 | 200 |
| 193 if (!remover_) { | 201 remover_.reset(new BrowsingDataRemover(dom_ui_->get_profile(), |
| 194 remover_ = new BrowsingDataRemover(dom_ui_->get_profile(), | 202 begin_time, |
| 195 begin_time, | 203 end_time)); |
| 196 end_time); | 204 remover_->AddObserver(this); |
| 197 remover_->AddObserver(this); | |
| 198 } | |
| 199 | |
| 200 remover_->Remove(BrowsingDataRemover::REMOVE_HISTORY | | 205 remover_->Remove(BrowsingDataRemover::REMOVE_HISTORY | |
| 201 BrowsingDataRemover::REMOVE_COOKIES | | 206 BrowsingDataRemover::REMOVE_COOKIES | |
| 202 BrowsingDataRemover::REMOVE_CACHE); | 207 BrowsingDataRemover::REMOVE_CACHE); |
| 203 } | 208 } |
| 204 | 209 |
| 205 void BrowsingHistoryHandler::OnBrowsingDataRemoverDone() { | 210 void BrowsingHistoryHandler::OnBrowsingDataRemoverDone() { |
| 206 dom_ui_->CallJavascriptFunction(L"deleteComplete"); | 211 dom_ui_->CallJavascriptFunction(L"deleteComplete"); |
| 212 remover_->RemoveObserver(this); |
| 213 remover_.release(); |
| 207 } | 214 } |
| 208 | 215 |
| 209 void BrowsingHistoryHandler::QueryComplete( | 216 void BrowsingHistoryHandler::QueryComplete( |
| 210 HistoryService::Handle request_handle, | 217 HistoryService::Handle request_handle, |
| 211 history::QueryResults* results) { | 218 history::QueryResults* results) { |
| 212 | 219 |
| 213 ListValue results_value; | 220 ListValue results_value; |
| 214 Time midnight_today = Time::Now().LocalMidnight(); | 221 Time midnight_today = Time::Now().LocalMidnight(); |
| 215 | 222 |
| 216 for (size_t i = 0; i < results->size(); ++i) { | 223 for (size_t i = 0; i < results->size(); ++i) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 240 date_str, base::TimeFormatFriendlyDate(page.visit_time())); | 247 date_str, base::TimeFormatFriendlyDate(page.visit_time())); |
| 241 } | 248 } |
| 242 page_value->SetString(L"dateRelativeDay", date_str); | 249 page_value->SetString(L"dateRelativeDay", date_str); |
| 243 page_value->SetString(L"dateTimeOfDay", | 250 page_value->SetString(L"dateTimeOfDay", |
| 244 base::TimeFormatTimeOfDay(page.visit_time())); | 251 base::TimeFormatTimeOfDay(page.visit_time())); |
| 245 } else { | 252 } else { |
| 246 page_value->SetString(L"dateShort", | 253 page_value->SetString(L"dateShort", |
| 247 base::TimeFormatShortDate(page.visit_time())); | 254 base::TimeFormatShortDate(page.visit_time())); |
| 248 page_value->SetString(L"snippet", page.snippet().text()); | 255 page_value->SetString(L"snippet", page.snippet().text()); |
| 249 } | 256 } |
| 250 | 257 page_value->SetBoolean(L"starred", |
| 258 dom_ui_->get_profile()->GetBookmarkModel()->IsBookmarked(page.url())); |
| 251 results_value.Append(page_value); | 259 results_value.Append(page_value); |
| 252 } | 260 } |
| 253 | 261 |
| 254 StringValue temp(search_text_); | 262 StringValue temp(search_text_); |
| 255 dom_ui_->CallJavascriptFunction(L"historyResult", temp, results_value); | 263 dom_ui_->CallJavascriptFunction(L"historyResult", temp, results_value); |
| 256 } | 264 } |
| 257 | 265 |
| 258 void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, | 266 void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, |
| 259 int* month, std::wstring* query) { | 267 int* month, std::wstring* query) { |
| 260 *month = 0; | 268 *month = 0; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 GURL HistoryUI::GetBaseURL() { | 371 GURL HistoryUI::GetBaseURL() { |
| 364 std::string url = DOMUIContents::GetScheme(); | 372 std::string url = DOMUIContents::GetScheme(); |
| 365 url += "://"; | 373 url += "://"; |
| 366 url += kHistoryHost; | 374 url += kHistoryHost; |
| 367 return GURL(url); | 375 return GURL(url); |
| 368 } | 376 } |
| 369 | 377 |
| 370 // static | 378 // static |
| 371 const GURL HistoryUI::GetHistoryURLWithSearchText( | 379 const GURL HistoryUI::GetHistoryURLWithSearchText( |
| 372 const std::wstring& text) { | 380 const std::wstring& text) { |
| 373 return GURL(GetBaseURL().spec() + "/?q=" + | 381 return GURL(GetBaseURL().spec() + "#q=" + |
| 374 EscapeQueryParamValue(WideToUTF8(text))); | 382 EscapeQueryParamValue(WideToUTF8(text))); |
| 375 } | 383 } |
| OLD | NEW |