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/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
| 28 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
28 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 29 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
29 #include "chrome/browser/ui/webui/favicon_source.h" | 30 #include "chrome/browser/ui/webui/favicon_source.h" |
30 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
31 #include "chrome/common/time_format.h" | 32 #include "chrome/common/time_format.h" |
32 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
33 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
34 #include "content/public/browser/notification_source.h" | 35 #include "content/public/browser/notification_source.h" |
35 #include "content/public/browser/user_metrics.h" | 36 #include "content/public/browser/user_metrics.h" |
36 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
37 #include "content/public/browser/web_contents_delegate.h" | 38 #include "content/public/browser/web_contents_delegate.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 152 } |
152 | 153 |
153 BrowsingHistoryHandler::~BrowsingHistoryHandler() { | 154 BrowsingHistoryHandler::~BrowsingHistoryHandler() { |
154 cancelable_search_consumer_.CancelAllRequests(); | 155 cancelable_search_consumer_.CancelAllRequests(); |
155 cancelable_delete_consumer_.CancelAllRequests(); | 156 cancelable_delete_consumer_.CancelAllRequests(); |
156 } | 157 } |
157 | 158 |
158 void BrowsingHistoryHandler::RegisterMessages() { | 159 void BrowsingHistoryHandler::RegisterMessages() { |
159 // Create our favicon data source. | 160 // Create our favicon data source. |
160 Profile* profile = Profile::FromWebUI(web_ui()); | 161 Profile* profile = Profile::FromWebUI(web_ui()); |
161 profile->GetChromeURLDataManager()->AddDataSource( | 162 ChromeURLDataManager::AddDataSource(profile, |
162 new FaviconSource(profile, FaviconSource::FAVICON)); | 163 new FaviconSource(profile, FaviconSource::FAVICON)); |
163 | 164 |
164 // Get notifications when history is cleared. | 165 // Get notifications when history is cleared. |
165 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 166 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
166 content::Source<Profile>(profile->GetOriginalProfile())); | 167 content::Source<Profile>(profile->GetOriginalProfile())); |
167 | 168 |
168 web_ui()->RegisterMessageCallback("getHistory", | 169 web_ui()->RegisterMessageCallback("getHistory", |
169 base::Bind(&BrowsingHistoryHandler::HandleGetHistory, | 170 base::Bind(&BrowsingHistoryHandler::HandleGetHistory, |
170 base::Unretained(this))); | 171 base::Unretained(this))); |
171 web_ui()->RegisterMessageCallback("searchHistory", | 172 web_ui()->RegisterMessageCallback("searchHistory", |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 // | 467 // |
467 //////////////////////////////////////////////////////////////////////////////// | 468 //////////////////////////////////////////////////////////////////////////////// |
468 | 469 |
469 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 470 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
470 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); | 471 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); |
471 | 472 |
472 HistoryUIHTMLSource* html_source = new HistoryUIHTMLSource(); | 473 HistoryUIHTMLSource* html_source = new HistoryUIHTMLSource(); |
473 | 474 |
474 // Set up the chrome://history-frame/ source. | 475 // Set up the chrome://history-frame/ source. |
475 Profile* profile = Profile::FromWebUI(web_ui); | 476 Profile* profile = Profile::FromWebUI(web_ui); |
476 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 477 ChromeURLDataManager::AddDataSource(profile, html_source); |
477 } | 478 } |
478 | 479 |
479 // static | 480 // static |
480 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { | 481 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { |
481 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 482 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
482 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 483 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
483 } | 484 } |
484 | 485 |
485 // static | 486 // static |
486 RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { | 487 RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { |
487 return ResourceBundle::GetSharedInstance(). | 488 return ResourceBundle::GetSharedInstance(). |
488 LoadDataResourceBytes(IDR_HISTORY_FAVICON); | 489 LoadDataResourceBytes(IDR_HISTORY_FAVICON); |
489 } | 490 } |
OLD | NEW |