OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
26 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 26 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
27 #include "chrome/browser/ui/webui/favicon_source.h" | 27 #include "chrome/browser/ui/webui/favicon_source.h" |
28 #include "chrome/common/jstemplate_builder.h" | 28 #include "chrome/common/jstemplate_builder.h" |
29 #include "chrome/common/time_format.h" | 29 #include "chrome/common/time_format.h" |
30 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
31 #include "content/browser/browser_thread.h" | 31 #include "content/browser/browser_thread.h" |
32 #include "content/browser/tab_contents/tab_contents.h" | 32 #include "content/browser/tab_contents/tab_contents.h" |
33 #include "content/browser/tab_contents/tab_contents_delegate.h" | 33 #include "content/browser/tab_contents/tab_contents_delegate.h" |
34 #include "content/browser/user_metrics.h" | 34 #include "content/browser/user_metrics.h" |
| 35 #include "content/common/notification_source.h" |
35 #include "grit/browser_resources.h" | 36 #include "grit/browser_resources.h" |
36 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
37 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
38 #include "grit/locale_settings.h" | 39 #include "grit/locale_settings.h" |
39 #include "grit/theme_resources.h" | 40 #include "grit/theme_resources.h" |
40 #include "net/base/escape.h" | 41 #include "net/base/escape.h" |
41 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
42 #include "ui/base/resource/resource_bundle.h" | 43 #include "ui/base/resource/resource_bundle.h" |
43 | 44 |
44 // Maximum number of search results to return in a given search. We should | 45 // Maximum number of search results to return in a given search. We should |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 cancelable_search_consumer_.CancelAllRequests(); | 129 cancelable_search_consumer_.CancelAllRequests(); |
129 cancelable_delete_consumer_.CancelAllRequests(); | 130 cancelable_delete_consumer_.CancelAllRequests(); |
130 } | 131 } |
131 | 132 |
132 WebUIMessageHandler* BrowsingHistoryHandler::Attach(WebUI* web_ui) { | 133 WebUIMessageHandler* BrowsingHistoryHandler::Attach(WebUI* web_ui) { |
133 // Create our favicon data source. | 134 // Create our favicon data source. |
134 Profile* profile = web_ui->GetProfile(); | 135 Profile* profile = web_ui->GetProfile(); |
135 profile->GetChromeURLDataManager()->AddDataSource( | 136 profile->GetChromeURLDataManager()->AddDataSource( |
136 new FaviconSource(profile, FaviconSource::FAVICON)); | 137 new FaviconSource(profile, FaviconSource::FAVICON)); |
137 | 138 |
| 139 // Get notifications when history is cleared. |
| 140 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, |
| 141 Source<Profile>(profile->GetOriginalProfile())); |
138 return WebUIMessageHandler::Attach(web_ui); | 142 return WebUIMessageHandler::Attach(web_ui); |
139 } | 143 } |
140 | 144 |
141 void BrowsingHistoryHandler::RegisterMessages() { | 145 void BrowsingHistoryHandler::RegisterMessages() { |
142 web_ui_->RegisterMessageCallback("getHistory", | 146 web_ui_->RegisterMessageCallback("getHistory", |
143 NewCallback(this, &BrowsingHistoryHandler::HandleGetHistory)); | 147 NewCallback(this, &BrowsingHistoryHandler::HandleGetHistory)); |
144 web_ui_->RegisterMessageCallback("searchHistory", | 148 web_ui_->RegisterMessageCallback("searchHistory", |
145 NewCallback(this, &BrowsingHistoryHandler::HandleSearchHistory)); | 149 NewCallback(this, &BrowsingHistoryHandler::HandleSearchHistory)); |
146 web_ui_->RegisterMessageCallback("removeURLsOnOneDay", | 150 web_ui_->RegisterMessageCallback("removeURLsOnOneDay", |
147 NewCallback(this, &BrowsingHistoryHandler::HandleRemoveURLsOnOneDay)); | 151 NewCallback(this, &BrowsingHistoryHandler::HandleRemoveURLsOnOneDay)); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } else { | 357 } else { |
354 exploded.month = 12; | 358 exploded.month = 12; |
355 exploded.year--; | 359 exploded.year--; |
356 } | 360 } |
357 options.begin_time = base::Time::FromLocalExploded(exploded); | 361 options.begin_time = base::Time::FromLocalExploded(exploded); |
358 } | 362 } |
359 | 363 |
360 return options; | 364 return options; |
361 } | 365 } |
362 | 366 |
| 367 void BrowsingHistoryHandler::Observe(NotificationType type, |
| 368 const NotificationSource& source, |
| 369 const NotificationDetails& details) { |
| 370 if (type != NotificationType::HISTORY_URLS_DELETED) { |
| 371 NOTREACHED(); |
| 372 return; |
| 373 } |
| 374 |
| 375 // Some URLs were deleted from history. Reload the list. |
| 376 web_ui_->CallJavascriptFunction("historyDeleted"); |
| 377 } |
| 378 |
363 //////////////////////////////////////////////////////////////////////////////// | 379 //////////////////////////////////////////////////////////////////////////////// |
364 // | 380 // |
365 // HistoryUI | 381 // HistoryUI |
366 // | 382 // |
367 //////////////////////////////////////////////////////////////////////////////// | 383 //////////////////////////////////////////////////////////////////////////////// |
368 | 384 |
369 HistoryUI::HistoryUI(TabContents* contents) : ChromeWebUI(contents) { | 385 HistoryUI::HistoryUI(TabContents* contents) : ChromeWebUI(contents) { |
370 AddMessageHandler((new BrowsingHistoryHandler())->Attach(this)); | 386 AddMessageHandler((new BrowsingHistoryHandler())->Attach(this)); |
371 | 387 |
372 HistoryUIHTMLSource* html_source = new HistoryUIHTMLSource(); | 388 HistoryUIHTMLSource* html_source = new HistoryUIHTMLSource(); |
373 | 389 |
374 // Set up the chrome://history/ source. | 390 // Set up the chrome://history/ source. |
375 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); | 391 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); |
376 } | 392 } |
377 | 393 |
378 // static | 394 // static |
379 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { | 395 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { |
380 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 396 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
381 EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 397 EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
382 } | 398 } |
383 | 399 |
384 // static | 400 // static |
385 RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { | 401 RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { |
386 return ResourceBundle::GetSharedInstance(). | 402 return ResourceBundle::GetSharedInstance(). |
387 LoadDataResourceBytes(IDR_HISTORY_FAVICON); | 403 LoadDataResourceBytes(IDR_HISTORY_FAVICON); |
388 } | 404 } |
OLD | NEW |