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