OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/history_ui.h" | 5 #include "chrome/browser/ui/webui/history_ui.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/i18n/time_formatting.h" | 11 #include "base/i18n/time_formatting.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
16 #include "base/string_piece.h" | 16 #include "base/string_piece.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/browser/bookmarks/bookmark_model.h" | 21 #include "chrome/browser/bookmarks/bookmark_model.h" |
22 #include "chrome/browser/bookmarks/bookmark_utils.h" | 22 #include "chrome/browser/bookmarks/bookmark_utils.h" |
23 #include "chrome/browser/history/history_notifications.h" | 23 #include "chrome/browser/history/history_notifications.h" |
24 #include "chrome/browser/history/history_types.h" | 24 #include "chrome/browser/history/history_types.h" |
| 25 #include "chrome/browser/history/web_history_service.h" |
25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_list.h" | 28 #include "chrome/browser/ui/browser_list.h" |
28 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 29 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
29 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 30 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
30 #include "chrome/browser/ui/webui/favicon_source.h" | 31 #include "chrome/browser/ui/webui/favicon_source.h" |
31 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
32 #include "chrome/common/time_format.h" | 33 #include "chrome/common/time_format.h" |
33 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
34 #include "content/public/browser/notification_details.h" | 35 #include "content/public/browser/notification_details.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 base::Unretained(this))); | 178 base::Unretained(this))); |
178 web_ui()->RegisterMessageCallback("clearBrowsingData", | 179 web_ui()->RegisterMessageCallback("clearBrowsingData", |
179 base::Bind(&BrowsingHistoryHandler::HandleClearBrowsingData, | 180 base::Bind(&BrowsingHistoryHandler::HandleClearBrowsingData, |
180 base::Unretained(this))); | 181 base::Unretained(this))); |
181 web_ui()->RegisterMessageCallback("removeBookmark", | 182 web_ui()->RegisterMessageCallback("removeBookmark", |
182 base::Bind(&BrowsingHistoryHandler::HandleRemoveBookmark, | 183 base::Bind(&BrowsingHistoryHandler::HandleRemoveBookmark, |
183 base::Unretained(this))); | 184 base::Unretained(this))); |
184 } | 185 } |
185 | 186 |
186 void BrowsingHistoryHandler::HandleGetHistory(const ListValue* args) { | 187 void BrowsingHistoryHandler::HandleGetHistory(const ListValue* args) { |
187 // Anything in-flight is invalid. | |
188 cancelable_search_consumer_.CancelAllRequests(); | |
189 | |
190 // Get arguments (if any). | 188 // Get arguments (if any). |
191 int day = 0; | 189 int day = 0; |
192 bool res = ExtractIntegerValue(args, &day); | 190 bool res = ExtractIntegerValue(args, &day); |
193 DCHECK(res); | 191 DCHECK(res); |
194 | 192 |
195 // Set our query options. | 193 // Set our query options. |
196 history::QueryOptions options; | 194 history::QueryOptions options; |
197 options.begin_time = base::Time::Now().LocalMidnight(); | 195 options.begin_time = base::Time::Now().LocalMidnight(); |
198 options.begin_time -= base::TimeDelta::FromDays(day); | 196 options.begin_time -= base::TimeDelta::FromDays(day); |
199 options.end_time = base::Time::Now().LocalMidnight(); | 197 options.end_time = base::Time::Now().LocalMidnight(); |
200 options.end_time -= base::TimeDelta::FromDays(day - 1); | 198 options.end_time -= base::TimeDelta::FromDays(day - 1); |
201 | 199 |
202 // Need to remember the query string for our results. | 200 QueryHistory(string16(), options); |
203 search_text_ = string16(); | |
204 | |
205 HistoryService* hs = | |
206 Profile::FromWebUI(web_ui())->GetHistoryService(Profile::EXPLICIT_ACCESS); | |
207 hs->QueryHistory(search_text_, | |
208 options, | |
209 &cancelable_search_consumer_, | |
210 base::Bind(&BrowsingHistoryHandler::QueryComplete, | |
211 base::Unretained(this))); | |
212 } | 201 } |
213 | 202 |
214 void BrowsingHistoryHandler::HandleSearchHistory(const ListValue* args) { | 203 void BrowsingHistoryHandler::HandleSearchHistory(const ListValue* args) { |
215 // Anything in-flight is invalid. | |
216 cancelable_search_consumer_.CancelAllRequests(); | |
217 | |
218 // Get arguments (if any). | 204 // Get arguments (if any). |
219 int month = 0; | 205 int month = 0; |
220 string16 query; | 206 string16 query; |
221 ExtractSearchHistoryArguments(args, &month, &query); | 207 ExtractSearchHistoryArguments(args, &month, &query); |
222 | 208 |
223 // Set the query ranges for the given month. | 209 // Set the query ranges for the given month. |
224 history::QueryOptions options = CreateMonthQueryOptions(month); | 210 history::QueryOptions options = CreateMonthQueryOptions(month); |
225 | 211 |
226 // When searching, limit the number of results returned. | 212 // When searching, limit the number of results returned. |
227 options.max_count = kMaxSearchResults; | 213 options.max_count = kMaxSearchResults; |
228 | 214 |
| 215 QueryHistory(query, options); |
| 216 } |
| 217 |
| 218 void BrowsingHistoryHandler::QueryHistory(const string16& text_query, |
| 219 const history::QueryOptions& options) { |
| 220 Profile* profile = Profile::FromWebUI(web_ui()); |
| 221 |
| 222 // Anything in-flight is invalid. |
| 223 cancelable_search_consumer_.CancelAllRequests(); |
| 224 |
229 // Need to remember the query string for our results. | 225 // Need to remember the query string for our results. |
230 search_text_ = query; | 226 search_text_ = text_query; |
231 HistoryService* hs = | 227 |
232 Profile::FromWebUI(web_ui())->GetHistoryService(Profile::EXPLICIT_ACCESS); | 228 HistoryService* hs = profile->GetHistoryService(Profile::EXPLICIT_ACCESS); |
233 hs->QueryHistory(search_text_, | 229 hs->QueryHistory(search_text_, |
234 options, | 230 options, |
235 &cancelable_search_consumer_, | 231 &cancelable_search_consumer_, |
236 base::Bind(&BrowsingHistoryHandler::QueryComplete, | 232 base::Bind(&BrowsingHistoryHandler::QueryComplete, |
237 base::Unretained(this))); | 233 base::Unretained(this))); |
| 234 |
| 235 // TODO(dubroy): Should this be moved into the History Service? |
| 236 history::WebHistoryService* web_history = |
| 237 history::WebHistoryService::GetForProfile(profile); |
| 238 if (web_history) { |
| 239 web_history->QueryHistory( |
| 240 search_text_, |
| 241 options, |
| 242 &cancelable_search_consumer_, |
| 243 base::Bind(&BrowsingHistoryHandler::WebHistoryQueryComplete, |
| 244 base::Unretained(this))); // FIXME: Probably need a weak ptr
here. |
| 245 } |
238 } | 246 } |
239 | 247 |
240 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { | 248 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { |
241 if (cancelable_delete_consumer_.HasPendingRequests()) { | 249 if (cancelable_delete_consumer_.HasPendingRequests()) { |
242 web_ui()->CallJavascriptFunction("deleteFailed"); | 250 web_ui()->CallJavascriptFunction("deleteFailed"); |
243 return; | 251 return; |
244 } | 252 } |
245 | 253 |
246 // Get day to delete data from. | 254 // Get day to delete data from. |
247 int visit_time = 0; | 255 int visit_time = 0; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 results_value.Append(page_value); | 355 results_value.Append(page_value); |
348 } | 356 } |
349 | 357 |
350 DictionaryValue info_value; | 358 DictionaryValue info_value; |
351 info_value.SetString("term", search_text_); | 359 info_value.SetString("term", search_text_); |
352 info_value.SetBoolean("finished", results->reached_beginning()); | 360 info_value.SetBoolean("finished", results->reached_beginning()); |
353 | 361 |
354 web_ui()->CallJavascriptFunction("historyResult", info_value, results_value); | 362 web_ui()->CallJavascriptFunction("historyResult", info_value, results_value); |
355 } | 363 } |
356 | 364 |
| 365 void BrowsingHistoryHandler::WebHistoryQueryComplete() { |
| 366 LOG(WARNING) << "WebHistoryQueryComplete!"; |
| 367 } |
| 368 |
357 void BrowsingHistoryHandler::RemoveComplete() { | 369 void BrowsingHistoryHandler::RemoveComplete() { |
358 urls_to_be_deleted_.clear(); | 370 urls_to_be_deleted_.clear(); |
359 | 371 |
360 // Notify the page that the deletion request succeeded. | 372 // Notify the page that the deletion request succeeded. |
361 web_ui()->CallJavascriptFunction("deleteComplete"); | 373 web_ui()->CallJavascriptFunction("deleteComplete"); |
362 } | 374 } |
363 | 375 |
364 void BrowsingHistoryHandler::ExtractSearchHistoryArguments( | 376 void BrowsingHistoryHandler::ExtractSearchHistoryArguments( |
365 const ListValue* args, | 377 const ListValue* args, |
366 int* month, | 378 int* month, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { | 492 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { |
481 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 493 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
482 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 494 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
483 } | 495 } |
484 | 496 |
485 // static | 497 // static |
486 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { | 498 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { |
487 return ResourceBundle::GetSharedInstance(). | 499 return ResourceBundle::GetSharedInstance(). |
488 LoadDataResourceBytes(IDR_HISTORY_FAVICON); | 500 LoadDataResourceBytes(IDR_HISTORY_FAVICON); |
489 } | 501 } |
OLD | NEW |