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