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/history2_ui.h" | 5 #include "chrome/browser/ui/webui/history2_ui.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 : search_text_() { | 89 : search_text_() { |
90 } | 90 } |
91 | 91 |
92 BrowsingHistoryHandler2::~BrowsingHistoryHandler2() { | 92 BrowsingHistoryHandler2::~BrowsingHistoryHandler2() { |
93 cancelable_search_consumer_.CancelAllRequests(); | 93 cancelable_search_consumer_.CancelAllRequests(); |
94 cancelable_delete_consumer_.CancelAllRequests(); | 94 cancelable_delete_consumer_.CancelAllRequests(); |
95 } | 95 } |
96 | 96 |
97 WebUIMessageHandler* BrowsingHistoryHandler2::Attach(WebUI* web_ui) { | 97 WebUIMessageHandler* BrowsingHistoryHandler2::Attach(WebUI* web_ui) { |
98 // Create our favicon data source. | 98 // Create our favicon data source. |
99 Profile* profile = web_ui->GetProfile(); | 99 Profile* profile = Profile::FromWebUI(web_ui); |
100 profile->GetChromeURLDataManager()->AddDataSource( | 100 profile->GetChromeURLDataManager()->AddDataSource( |
101 new FaviconSource(profile, FaviconSource::FAVICON)); | 101 new FaviconSource(profile, FaviconSource::FAVICON)); |
102 | 102 |
103 // Get notifications when history is cleared. | 103 // Get notifications when history is cleared. |
104 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 104 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
105 Source<Profile>(web_ui->GetProfile()->GetOriginalProfile())); | 105 Source<Profile>(profile->GetOriginalProfile())); |
106 return WebUIMessageHandler::Attach(web_ui); | 106 return WebUIMessageHandler::Attach(web_ui); |
107 } | 107 } |
108 | 108 |
109 void BrowsingHistoryHandler2::RegisterMessages() { | 109 void BrowsingHistoryHandler2::RegisterMessages() { |
110 web_ui_->RegisterMessageCallback("getHistory", | 110 web_ui_->RegisterMessageCallback("getHistory", |
111 NewCallback(this, &BrowsingHistoryHandler2::HandleGetHistory)); | 111 NewCallback(this, &BrowsingHistoryHandler2::HandleGetHistory)); |
112 web_ui_->RegisterMessageCallback("searchHistory", | 112 web_ui_->RegisterMessageCallback("searchHistory", |
113 NewCallback(this, &BrowsingHistoryHandler2::HandleSearchHistory)); | 113 NewCallback(this, &BrowsingHistoryHandler2::HandleSearchHistory)); |
114 web_ui_->RegisterMessageCallback("removeURLsOnOneDay", | 114 web_ui_->RegisterMessageCallback("removeURLsOnOneDay", |
115 NewCallback(this, &BrowsingHistoryHandler2::HandleRemoveURLsOnOneDay)); | 115 NewCallback(this, &BrowsingHistoryHandler2::HandleRemoveURLsOnOneDay)); |
(...skipping 13 matching lines...) Expand all Loading... |
129 history::QueryOptions options; | 129 history::QueryOptions options; |
130 options.begin_time = base::Time::Now().LocalMidnight(); | 130 options.begin_time = base::Time::Now().LocalMidnight(); |
131 options.begin_time -= base::TimeDelta::FromDays(day); | 131 options.begin_time -= base::TimeDelta::FromDays(day); |
132 options.end_time = base::Time::Now().LocalMidnight(); | 132 options.end_time = base::Time::Now().LocalMidnight(); |
133 options.end_time -= base::TimeDelta::FromDays(day - 1); | 133 options.end_time -= base::TimeDelta::FromDays(day - 1); |
134 | 134 |
135 // Need to remember the query string for our results. | 135 // Need to remember the query string for our results. |
136 search_text_ = string16(); | 136 search_text_ = string16(); |
137 | 137 |
138 HistoryService* hs = | 138 HistoryService* hs = |
139 web_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 139 Profile::FromWebUI(web_ui_)->GetHistoryService(Profile::EXPLICIT_ACCESS); |
140 hs->QueryHistory(search_text_, | 140 hs->QueryHistory(search_text_, |
141 options, | 141 options, |
142 &cancelable_search_consumer_, | 142 &cancelable_search_consumer_, |
143 NewCallback(this, &BrowsingHistoryHandler2::QueryComplete)); | 143 NewCallback(this, &BrowsingHistoryHandler2::QueryComplete)); |
144 } | 144 } |
145 | 145 |
146 void BrowsingHistoryHandler2::HandleSearchHistory(const ListValue* args) { | 146 void BrowsingHistoryHandler2::HandleSearchHistory(const ListValue* args) { |
147 // Anything in-flight is invalid. | 147 // Anything in-flight is invalid. |
148 cancelable_search_consumer_.CancelAllRequests(); | 148 cancelable_search_consumer_.CancelAllRequests(); |
149 | 149 |
150 // Get arguments (if any). | 150 // Get arguments (if any). |
151 int month = 0; | 151 int month = 0; |
152 string16 query; | 152 string16 query; |
153 ExtractSearchHistoryArguments(args, &month, &query); | 153 ExtractSearchHistoryArguments(args, &month, &query); |
154 | 154 |
155 // Set the query ranges for the given month. | 155 // Set the query ranges for the given month. |
156 history::QueryOptions options = CreateMonthQueryOptions(month); | 156 history::QueryOptions options = CreateMonthQueryOptions(month); |
157 | 157 |
158 // When searching, limit the number of results returned. | 158 // When searching, limit the number of results returned. |
159 options.max_count = kMaxSearchResults; | 159 options.max_count = kMaxSearchResults; |
160 | 160 |
161 // Need to remember the query string for our results. | 161 // Need to remember the query string for our results. |
162 search_text_ = query; | 162 search_text_ = query; |
163 HistoryService* hs = | 163 HistoryService* hs = |
164 web_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 164 Profile::FromWebUI(web_ui_)->GetHistoryService(Profile::EXPLICIT_ACCESS); |
165 hs->QueryHistory(search_text_, | 165 hs->QueryHistory(search_text_, |
166 options, | 166 options, |
167 &cancelable_search_consumer_, | 167 &cancelable_search_consumer_, |
168 NewCallback(this, &BrowsingHistoryHandler2::QueryComplete)); | 168 NewCallback(this, &BrowsingHistoryHandler2::QueryComplete)); |
169 } | 169 } |
170 | 170 |
171 void BrowsingHistoryHandler2::HandleRemoveURLsOnOneDay(const ListValue* args) { | 171 void BrowsingHistoryHandler2::HandleRemoveURLsOnOneDay(const ListValue* args) { |
172 if (cancelable_delete_consumer_.HasPendingRequests()) { | 172 if (cancelable_delete_consumer_.HasPendingRequests()) { |
173 web_ui_->CallJavascriptFunction("deleteFailed"); | 173 web_ui_->CallJavascriptFunction("deleteFailed"); |
174 return; | 174 return; |
(...skipping 16 matching lines...) Expand all Loading... |
191 if ((*v)->GetType() != Value::TYPE_STRING) | 191 if ((*v)->GetType() != Value::TYPE_STRING) |
192 continue; | 192 continue; |
193 const StringValue* string_value = static_cast<const StringValue*>(*v); | 193 const StringValue* string_value = static_cast<const StringValue*>(*v); |
194 string16 string16_value; | 194 string16 string16_value; |
195 if (!string_value->GetAsString(&string16_value)) | 195 if (!string_value->GetAsString(&string16_value)) |
196 continue; | 196 continue; |
197 urls.insert(GURL(string16_value)); | 197 urls.insert(GURL(string16_value)); |
198 } | 198 } |
199 | 199 |
200 HistoryService* hs = | 200 HistoryService* hs = |
201 web_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 201 Profile::FromWebUI(web_ui_)->GetHistoryService(Profile::EXPLICIT_ACCESS); |
202 hs->ExpireHistoryBetween( | 202 hs->ExpireHistoryBetween( |
203 urls, begin_time, end_time, &cancelable_delete_consumer_, | 203 urls, begin_time, end_time, &cancelable_delete_consumer_, |
204 NewCallback(this, &BrowsingHistoryHandler2::RemoveComplete)); | 204 NewCallback(this, &BrowsingHistoryHandler2::RemoveComplete)); |
205 } | 205 } |
206 | 206 |
207 void BrowsingHistoryHandler2::HandleClearBrowsingData(const ListValue* args) { | 207 void BrowsingHistoryHandler2::HandleClearBrowsingData(const ListValue* args) { |
208 // TODO(beng): This is an improper direct dependency on Browser. Route this | 208 // TODO(beng): This is an improper direct dependency on Browser. Route this |
209 // through some sort of delegate. | 209 // through some sort of delegate. |
210 Browser* browser = BrowserList::FindBrowserWithProfile(web_ui_->GetProfile()); | 210 Profile* profile = Profile::FromWebUI(web_ui_); |
| 211 Browser* browser = BrowserList::FindBrowserWithProfile(profile); |
211 if (browser) | 212 if (browser) |
212 browser->OpenClearBrowsingDataDialog(); | 213 browser->OpenClearBrowsingDataDialog(); |
213 } | 214 } |
214 | 215 |
215 void BrowsingHistoryHandler2::QueryComplete( | 216 void BrowsingHistoryHandler2::QueryComplete( |
216 HistoryService::Handle request_handle, | 217 HistoryService::Handle request_handle, |
217 history::QueryResults* results) { | 218 history::QueryResults* results) { |
218 | 219 |
219 ListValue results_value; | 220 ListValue results_value; |
220 base::Time midnight_today = base::Time::Now().LocalMidnight(); | 221 base::Time midnight_today = base::Time::Now().LocalMidnight(); |
(...skipping 26 matching lines...) Expand all Loading... |
247 base::TimeFormatFriendlyDate(page.visit_time())); | 248 base::TimeFormatFriendlyDate(page.visit_time())); |
248 } | 249 } |
249 page_value->SetString("dateRelativeDay", date_str); | 250 page_value->SetString("dateRelativeDay", date_str); |
250 page_value->SetString("dateTimeOfDay", | 251 page_value->SetString("dateTimeOfDay", |
251 base::TimeFormatTimeOfDay(page.visit_time())); | 252 base::TimeFormatTimeOfDay(page.visit_time())); |
252 } else { | 253 } else { |
253 page_value->SetString("dateShort", | 254 page_value->SetString("dateShort", |
254 base::TimeFormatShortDate(page.visit_time())); | 255 base::TimeFormatShortDate(page.visit_time())); |
255 page_value->SetString("snippet", page.snippet().text()); | 256 page_value->SetString("snippet", page.snippet().text()); |
256 } | 257 } |
| 258 Profile* profile = Profile::FromWebUI(web_ui_); |
257 page_value->SetBoolean("starred", | 259 page_value->SetBoolean("starred", |
258 web_ui_->GetProfile()->GetBookmarkModel()->IsBookmarked(page.url())); | 260 profile->GetBookmarkModel()->IsBookmarked(page.url())); |
259 results_value.Append(page_value); | 261 results_value.Append(page_value); |
260 } | 262 } |
261 | 263 |
262 DictionaryValue info_value; | 264 DictionaryValue info_value; |
263 info_value.SetString("term", search_text_); | 265 info_value.SetString("term", search_text_); |
264 info_value.SetBoolean("finished", results->reached_beginning()); | 266 info_value.SetBoolean("finished", results->reached_beginning()); |
265 | 267 |
266 web_ui_->CallJavascriptFunction("historyResult", info_value, results_value); | 268 web_ui_->CallJavascriptFunction("historyResult", info_value, results_value); |
267 } | 269 } |
268 | 270 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 const GURL HistoryUI2::GetHistoryURLWithSearchText(const string16& text) { | 373 const GURL HistoryUI2::GetHistoryURLWithSearchText(const string16& text) { |
372 return GURL(std::string(chrome::kChromeUIHistory2URL) + "#q=" + | 374 return GURL(std::string(chrome::kChromeUIHistory2URL) + "#q=" + |
373 EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 375 EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
374 } | 376 } |
375 | 377 |
376 // static | 378 // static |
377 RefCountedMemory* HistoryUI2::GetFaviconResourceBytes() { | 379 RefCountedMemory* HistoryUI2::GetFaviconResourceBytes() { |
378 return ResourceBundle::GetSharedInstance(). | 380 return ResourceBundle::GetSharedInstance(). |
379 LoadDataResourceBytes(IDR_HISTORY_FAVICON); | 381 LoadDataResourceBytes(IDR_HISTORY_FAVICON); |
380 } | 382 } |
OLD | NEW |