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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 : search_text_() { | 126 : search_text_() { |
127 } | 127 } |
128 | 128 |
129 BrowsingHistoryHandler::~BrowsingHistoryHandler() { | 129 BrowsingHistoryHandler::~BrowsingHistoryHandler() { |
130 cancelable_search_consumer_.CancelAllRequests(); | 130 cancelable_search_consumer_.CancelAllRequests(); |
131 cancelable_delete_consumer_.CancelAllRequests(); | 131 cancelable_delete_consumer_.CancelAllRequests(); |
132 } | 132 } |
133 | 133 |
134 WebUIMessageHandler* BrowsingHistoryHandler::Attach(WebUI* web_ui) { | 134 WebUIMessageHandler* BrowsingHistoryHandler::Attach(WebUI* web_ui) { |
135 // Create our favicon data source. | 135 // Create our favicon data source. |
136 Profile* profile = web_ui->GetProfile(); | 136 Profile* profile = Profile::FromWebUI(web_ui); |
137 profile->GetChromeURLDataManager()->AddDataSource( | 137 profile->GetChromeURLDataManager()->AddDataSource( |
138 new FaviconSource(profile, FaviconSource::FAVICON)); | 138 new FaviconSource(profile, FaviconSource::FAVICON)); |
139 | 139 |
140 // Get notifications when history is cleared. | 140 // Get notifications when history is cleared. |
141 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 141 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
142 Source<Profile>(profile->GetOriginalProfile())); | 142 Source<Profile>(profile->GetOriginalProfile())); |
143 return WebUIMessageHandler::Attach(web_ui); | 143 return WebUIMessageHandler::Attach(web_ui); |
144 } | 144 } |
145 | 145 |
146 void BrowsingHistoryHandler::RegisterMessages() { | 146 void BrowsingHistoryHandler::RegisterMessages() { |
(...skipping 19 matching lines...) Expand all Loading... |
166 history::QueryOptions options; | 166 history::QueryOptions options; |
167 options.begin_time = base::Time::Now().LocalMidnight(); | 167 options.begin_time = base::Time::Now().LocalMidnight(); |
168 options.begin_time -= base::TimeDelta::FromDays(day); | 168 options.begin_time -= base::TimeDelta::FromDays(day); |
169 options.end_time = base::Time::Now().LocalMidnight(); | 169 options.end_time = base::Time::Now().LocalMidnight(); |
170 options.end_time -= base::TimeDelta::FromDays(day - 1); | 170 options.end_time -= base::TimeDelta::FromDays(day - 1); |
171 | 171 |
172 // Need to remember the query string for our results. | 172 // Need to remember the query string for our results. |
173 search_text_ = string16(); | 173 search_text_ = string16(); |
174 | 174 |
175 HistoryService* hs = | 175 HistoryService* hs = |
176 web_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 176 Profile::FromWebUI(web_ui_)->GetHistoryService(Profile::EXPLICIT_ACCESS); |
177 hs->QueryHistory(search_text_, | 177 hs->QueryHistory(search_text_, |
178 options, | 178 options, |
179 &cancelable_search_consumer_, | 179 &cancelable_search_consumer_, |
180 NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); | 180 NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); |
181 } | 181 } |
182 | 182 |
183 void BrowsingHistoryHandler::HandleSearchHistory(const ListValue* args) { | 183 void BrowsingHistoryHandler::HandleSearchHistory(const ListValue* args) { |
184 // Anything in-flight is invalid. | 184 // Anything in-flight is invalid. |
185 cancelable_search_consumer_.CancelAllRequests(); | 185 cancelable_search_consumer_.CancelAllRequests(); |
186 | 186 |
187 // Get arguments (if any). | 187 // Get arguments (if any). |
188 int month = 0; | 188 int month = 0; |
189 string16 query; | 189 string16 query; |
190 ExtractSearchHistoryArguments(args, &month, &query); | 190 ExtractSearchHistoryArguments(args, &month, &query); |
191 | 191 |
192 // Set the query ranges for the given month. | 192 // Set the query ranges for the given month. |
193 history::QueryOptions options = CreateMonthQueryOptions(month); | 193 history::QueryOptions options = CreateMonthQueryOptions(month); |
194 | 194 |
195 // When searching, limit the number of results returned. | 195 // When searching, limit the number of results returned. |
196 options.max_count = kMaxSearchResults; | 196 options.max_count = kMaxSearchResults; |
197 | 197 |
198 // Need to remember the query string for our results. | 198 // Need to remember the query string for our results. |
199 search_text_ = query; | 199 search_text_ = query; |
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->QueryHistory(search_text_, | 202 hs->QueryHistory(search_text_, |
203 options, | 203 options, |
204 &cancelable_search_consumer_, | 204 &cancelable_search_consumer_, |
205 NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); | 205 NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); |
206 } | 206 } |
207 | 207 |
208 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { | 208 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { |
209 if (cancelable_delete_consumer_.HasPendingRequests()) { | 209 if (cancelable_delete_consumer_.HasPendingRequests()) { |
210 web_ui_->CallJavascriptFunction("deleteFailed"); | 210 web_ui_->CallJavascriptFunction("deleteFailed"); |
211 return; | 211 return; |
(...skipping 16 matching lines...) Expand all Loading... |
228 if ((*v)->GetType() != Value::TYPE_STRING) | 228 if ((*v)->GetType() != Value::TYPE_STRING) |
229 continue; | 229 continue; |
230 const StringValue* string_value = static_cast<const StringValue*>(*v); | 230 const StringValue* string_value = static_cast<const StringValue*>(*v); |
231 string16 string16_value; | 231 string16 string16_value; |
232 if (!string_value->GetAsString(&string16_value)) | 232 if (!string_value->GetAsString(&string16_value)) |
233 continue; | 233 continue; |
234 urls.insert(GURL(string16_value)); | 234 urls.insert(GURL(string16_value)); |
235 } | 235 } |
236 | 236 |
237 HistoryService* hs = | 237 HistoryService* hs = |
238 web_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 238 Profile::FromWebUI(web_ui_)->GetHistoryService(Profile::EXPLICIT_ACCESS); |
239 hs->ExpireHistoryBetween( | 239 hs->ExpireHistoryBetween( |
240 urls, begin_time, end_time, &cancelable_delete_consumer_, | 240 urls, begin_time, end_time, &cancelable_delete_consumer_, |
241 NewCallback(this, &BrowsingHistoryHandler::RemoveComplete)); | 241 NewCallback(this, &BrowsingHistoryHandler::RemoveComplete)); |
242 } | 242 } |
243 | 243 |
244 void BrowsingHistoryHandler::HandleClearBrowsingData(const ListValue* args) { | 244 void BrowsingHistoryHandler::HandleClearBrowsingData(const ListValue* args) { |
245 // TODO(beng): This is an improper direct dependency on Browser. Route this | 245 // TODO(beng): This is an improper direct dependency on Browser. Route this |
246 // through some sort of delegate. | 246 // through some sort of delegate. |
247 Browser* browser = BrowserList::FindBrowserWithProfile(web_ui_->GetProfile()); | 247 Profile* profile = Profile::FromWebUI(web_ui_); |
| 248 Browser* browser = BrowserList::FindBrowserWithProfile(profile); |
248 if (browser) | 249 if (browser) |
249 browser->OpenClearBrowsingDataDialog(); | 250 browser->OpenClearBrowsingDataDialog(); |
250 } | 251 } |
251 | 252 |
252 void BrowsingHistoryHandler::QueryComplete( | 253 void BrowsingHistoryHandler::QueryComplete( |
253 HistoryService::Handle request_handle, | 254 HistoryService::Handle request_handle, |
254 history::QueryResults* results) { | 255 history::QueryResults* results) { |
255 | 256 |
256 ListValue results_value; | 257 ListValue results_value; |
257 base::Time midnight_today = base::Time::Now().LocalMidnight(); | 258 base::Time midnight_today = base::Time::Now().LocalMidnight(); |
(...skipping 26 matching lines...) Expand all Loading... |
284 base::TimeFormatFriendlyDate(page.visit_time())); | 285 base::TimeFormatFriendlyDate(page.visit_time())); |
285 } | 286 } |
286 page_value->SetString("dateRelativeDay", date_str); | 287 page_value->SetString("dateRelativeDay", date_str); |
287 page_value->SetString("dateTimeOfDay", | 288 page_value->SetString("dateTimeOfDay", |
288 base::TimeFormatTimeOfDay(page.visit_time())); | 289 base::TimeFormatTimeOfDay(page.visit_time())); |
289 } else { | 290 } else { |
290 page_value->SetString("dateShort", | 291 page_value->SetString("dateShort", |
291 base::TimeFormatShortDate(page.visit_time())); | 292 base::TimeFormatShortDate(page.visit_time())); |
292 page_value->SetString("snippet", page.snippet().text()); | 293 page_value->SetString("snippet", page.snippet().text()); |
293 } | 294 } |
| 295 Profile* profile = Profile::FromWebUI(web_ui_); |
294 page_value->SetBoolean("starred", | 296 page_value->SetBoolean("starred", |
295 web_ui_->GetProfile()->GetBookmarkModel()->IsBookmarked(page.url())); | 297 profile->GetBookmarkModel()->IsBookmarked(page.url())); |
296 results_value.Append(page_value); | 298 results_value.Append(page_value); |
297 } | 299 } |
298 | 300 |
299 DictionaryValue info_value; | 301 DictionaryValue info_value; |
300 info_value.SetString("term", search_text_); | 302 info_value.SetString("term", search_text_); |
301 info_value.SetBoolean("finished", results->reached_beginning()); | 303 info_value.SetBoolean("finished", results->reached_beginning()); |
302 | 304 |
303 web_ui_->CallJavascriptFunction("historyResult", info_value, results_value); | 305 web_ui_->CallJavascriptFunction("historyResult", info_value, results_value); |
304 } | 306 } |
305 | 307 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { | 399 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { |
398 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 400 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
399 EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 401 EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
400 } | 402 } |
401 | 403 |
402 // static | 404 // static |
403 RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { | 405 RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { |
404 return ResourceBundle::GetSharedInstance(). | 406 return ResourceBundle::GetSharedInstance(). |
405 LoadDataResourceBytes(IDR_HISTORY_FAVICON); | 407 LoadDataResourceBytes(IDR_HISTORY_FAVICON); |
406 } | 408 } |
OLD | NEW |