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" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 source->AddString( | 132 source->AddString( |
133 "deletewarning", | 133 "deletewarning", |
134 l10n_util::GetStringFUTF16(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING, | 134 l10n_util::GetStringFUTF16(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING, |
135 UTF8ToUTF16(kIncognitoModeShortcut))); | 135 UTF8ToUTF16(kIncognitoModeShortcut))); |
136 source->AddLocalizedString("actionMenuDescription", | 136 source->AddLocalizedString("actionMenuDescription", |
137 IDS_HISTORY_ACTION_MENU_DESCRIPTION); | 137 IDS_HISTORY_ACTION_MENU_DESCRIPTION); |
138 source->AddLocalizedString("removeFromHistory", IDS_HISTORY_REMOVE_PAGE); | 138 source->AddLocalizedString("removeFromHistory", IDS_HISTORY_REMOVE_PAGE); |
139 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE); | 139 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE); |
140 source->AddLocalizedString("displayfiltersites", IDS_GROUP_BY_DOMAIN_LABEL); | 140 source->AddLocalizedString("displayfiltersites", IDS_GROUP_BY_DOMAIN_LABEL); |
141 source->AddLocalizedString("rangelabel", IDS_HISTORY_RANGE_LABEL); | 141 source->AddLocalizedString("rangelabel", IDS_HISTORY_RANGE_LABEL); |
142 source->AddLocalizedString("rangealltime", IDS_HISTORY_RANGE_ALLTIME); | 142 source->AddLocalizedString("rangealltime", IDS_HISTORY_RANGE_ALL_TIME); |
143 source->AddLocalizedString("rangeweek", IDS_HISTORY_RANGE_WEEK); | 143 source->AddLocalizedString("rangeweek", IDS_HISTORY_RANGE_WEEK); |
144 source->AddLocalizedString("rangemonth", IDS_HISTORY_RANGE_MONTH); | 144 source->AddLocalizedString("rangemonth", IDS_HISTORY_RANGE_MONTH); |
145 source->AddLocalizedString("displayfiltersites", IDS_GROUP_BY_DOMAIN_LABEL); | 145 source->AddLocalizedString("rangetoday", IDS_HISTORY_RANGE_TODAY); |
146 source->AddLocalizedString("numbervisits", IDS_HISTORY_NUMBER_VISITS); | 146 source->AddLocalizedString("numbervisits", IDS_HISTORY_NUMBER_VISITS); |
147 source->AddBoolean("groupByDomain", | 147 source->AddBoolean("groupByDomain", |
148 CommandLine::ForCurrentProcess()->HasSwitch( | 148 CommandLine::ForCurrentProcess()->HasSwitch( |
149 switches::kHistoryEnableGroupByDomain)); | 149 switches::kHistoryEnableGroupByDomain)); |
150 source->SetJsonPath(kStringsJsFile); | 150 source->SetJsonPath(kStringsJsFile); |
151 source->AddResourcePath(kHistoryJsFile, IDR_HISTORY_JS); | 151 source->AddResourcePath(kHistoryJsFile, IDR_HISTORY_JS); |
152 source->SetDefaultResource(IDR_HISTORY_HTML); | 152 source->SetDefaultResource(IDR_HISTORY_HTML); |
153 source->SetUseJsonJSFormatV2(); | 153 source->SetUseJsonJSFormatV2(); |
154 source->DisableDenyXFrameOptions(); | 154 source->DisableDenyXFrameOptions(); |
155 | 155 |
156 return source; | 156 return source; |
157 } | 157 } |
158 | 158 |
159 // Returns a localized version of |visit_time| including a relative | 159 // Returns a localized version of |visit_time| including a relative |
160 // indicator (e.g. today, yesterday). | 160 // indicator (e.g. today, yesterday). |
161 string16 getRelativeDateLocalized(const base::Time& visit_time) { | 161 string16 getRelativeDateLocalized(const base::Time& visit_time) { |
162 base::Time midnight = base::Time::Now().LocalMidnight(); | 162 base::Time midnight = base::Time::Now().LocalMidnight(); |
163 string16 date_str = TimeFormat::RelativeDate(visit_time, &midnight); | 163 string16 date_str = TimeFormat::RelativeDate(visit_time, &midnight); |
164 if (date_str.empty()) { | 164 if (date_str.empty()) { |
165 date_str = base::TimeFormatFriendlyDate(visit_time); | 165 date_str = base::TimeFormatFriendlyDate(visit_time); |
166 } else { | 166 } else { |
167 date_str = l10n_util::GetStringFUTF16( | 167 date_str = l10n_util::GetStringFUTF16( |
168 IDS_HISTORY_DATE_WITH_RELATIVE_TIME, | 168 IDS_HISTORY_DATE_WITH_RELATIVE_TIME, |
169 date_str, | 169 date_str, |
170 base::TimeFormatFriendlyDate(visit_time)); | 170 base::TimeFormatFriendlyDate(visit_time)); |
171 } | 171 } |
172 return date_str; | 172 return date_str; |
173 } | 173 } |
174 | 174 |
| 175 // Sets the correct year when substracting months from a date. |
| 176 void normalizeMonths(base::Time::Exploded* exploded) { |
| 177 // Decrease a year at a time until we have a proper date. |
| 178 while (exploded->month < 1) { |
| 179 exploded->month += 12; |
| 180 exploded->year--; |
| 181 } |
| 182 } |
| 183 |
175 } // namespace | 184 } // namespace |
176 | 185 |
177 //////////////////////////////////////////////////////////////////////////////// | 186 //////////////////////////////////////////////////////////////////////////////// |
178 // | 187 // |
179 // BrowsingHistoryHandler | 188 // BrowsingHistoryHandler |
180 // | 189 // |
181 //////////////////////////////////////////////////////////////////////////////// | 190 //////////////////////////////////////////////////////////////////////////////// |
182 BrowsingHistoryHandler::BrowsingHistoryHandler() {} | 191 BrowsingHistoryHandler::BrowsingHistoryHandler() {} |
183 | 192 |
184 BrowsingHistoryHandler::~BrowsingHistoryHandler() { | 193 BrowsingHistoryHandler::~BrowsingHistoryHandler() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // Start a timer so we know when to give up. | 267 // Start a timer so we know when to give up. |
259 web_history_timer_.Start( | 268 web_history_timer_.Start( |
260 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), | 269 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), |
261 this, &BrowsingHistoryHandler::WebHistoryTimeout); | 270 this, &BrowsingHistoryHandler::WebHistoryTimeout); |
262 } | 271 } |
263 } | 272 } |
264 | 273 |
265 void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) { | 274 void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) { |
266 history::QueryOptions options; | 275 history::QueryOptions options; |
267 | 276 |
268 // Parse the arguments from JavaScript. There are four required arguments: | 277 // Parse the arguments from JavaScript. There are five required arguments: |
269 // - the text to search for (may be empty) | 278 // - the text to search for (may be empty) |
| 279 // - the offset from which the search should start (in multiples of week or |
| 280 // month, set by the next argument). |
270 // - the range (BrowsingHistoryHandler::Range) Enum value that sets the range | 281 // - the range (BrowsingHistoryHandler::Range) Enum value that sets the range |
271 // of the query. | 282 // of the query. |
272 // - the search cursor, an opaque value from a previous query result, which | 283 // - the search cursor, an opaque value from a previous query result, which |
273 // allows this query to pick up where the previous one left off. May be | 284 // allows this query to pick up where the previous one left off. May be |
274 // null or undefined. | 285 // null or undefined. |
275 // - the maximum number of results to return (may be 0, meaning that there | 286 // - the maximum number of results to return (may be 0, meaning that there |
276 // is no maximum). | 287 // is no maximum). |
277 string16 search_text = ExtractStringValue(args); | 288 string16 search_text = ExtractStringValue(args); |
| 289 int offset; |
| 290 if (!args->GetInteger(1, &offset)) { |
| 291 NOTREACHED() << "Failed to convert argument 1. "; |
| 292 return; |
| 293 } |
278 int range; | 294 int range; |
279 if (!args->GetInteger(1, &range)) { | 295 if (!args->GetInteger(2, &range)) { |
280 NOTREACHED() << "Failed to convert argument 1. "; | 296 NOTREACHED() << "Failed to convert argument 2. "; |
281 return; | 297 return; |
282 } | 298 } |
283 | 299 |
284 if (range == BrowsingHistoryHandler::MONTH) | 300 if (range == BrowsingHistoryHandler::MONTH) |
285 SetQueryTimeInMonths(&options); | 301 SetQueryTimeInMonths(offset, &options); |
286 else if (range == BrowsingHistoryHandler::WEEK) | 302 else if (range == BrowsingHistoryHandler::WEEK) |
287 SetQueryTimeInWeeks(&options); | 303 SetQueryTimeInWeeks(offset, &options); |
288 | 304 |
289 const Value* cursor_value; | 305 const Value* cursor_value; |
290 | 306 |
291 // Get the cursor. It must be either null, or a list. | 307 // Get the cursor. It must be either null, or a list. |
292 if (!args->Get(2, &cursor_value) || | 308 if (!args->Get(3, &cursor_value) || |
293 (!cursor_value->IsType(Value::TYPE_NULL) && | 309 (!cursor_value->IsType(Value::TYPE_NULL) && |
294 !history::QueryCursor::FromValue(cursor_value, &options.cursor))) { | 310 !history::QueryCursor::FromValue(cursor_value, &options.cursor))) { |
295 NOTREACHED() << "Failed to convert argument 2. "; | 311 NOTREACHED() << "Failed to convert argument 3. "; |
296 return; | 312 return; |
297 } | 313 } |
298 | 314 |
299 if (!ExtractIntegerValueAtIndex(args, 3, &options.max_count)) { | 315 if (!ExtractIntegerValueAtIndex(args, 4, &options.max_count)) { |
300 NOTREACHED() << "Failed to convert argument 3."; | 316 NOTREACHED() << "Failed to convert argument 4."; |
301 return; | 317 return; |
302 } | 318 } |
303 | 319 |
304 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; | 320 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; |
305 QueryHistory(search_text, options); | 321 QueryHistory(search_text, options); |
306 } | 322 } |
307 | 323 |
308 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { | 324 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { |
309 if (delete_task_tracker_.HasTrackedTasks()) { | 325 if (delete_task_tracker_.HasTrackedTasks()) { |
310 web_ui()->CallJavascriptFunction("deleteFailed"); | 326 web_ui()->CallJavascriptFunction("deleteFailed"); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 } | 550 } |
535 | 551 |
536 void BrowsingHistoryHandler::RemoveWebHistoryComplete( | 552 void BrowsingHistoryHandler::RemoveWebHistoryComplete( |
537 history::WebHistoryService::Request* request, bool success) { | 553 history::WebHistoryService::Request* request, bool success) { |
538 // Notify the page that the deletion request is complete. | 554 // Notify the page that the deletion request is complete. |
539 base::FundamentalValue success_value(success); | 555 base::FundamentalValue success_value(success); |
540 web_ui()->CallJavascriptFunction("webHistoryDeleteComplete", success_value); | 556 web_ui()->CallJavascriptFunction("webHistoryDeleteComplete", success_value); |
541 } | 557 } |
542 | 558 |
543 void BrowsingHistoryHandler::SetQueryTimeInWeeks( | 559 void BrowsingHistoryHandler::SetQueryTimeInWeeks( |
544 history::QueryOptions* options) { | 560 int offset, history::QueryOptions* options) { |
545 // LocalMidnight returns the beginning of the current day so get the | 561 // LocalMidnight returns the beginning of the current day so get the |
546 // beginning of the next one. | 562 // beginning of the next one. |
547 base::Time midnight = base::Time::Now().LocalMidnight() + | 563 base::Time midnight = base::Time::Now().LocalMidnight() + |
548 base::TimeDelta::FromDays(1); | 564 base::TimeDelta::FromDays(1); |
549 options->end_time = midnight; | 565 options->end_time = midnight - |
550 options->begin_time = midnight - base::TimeDelta::FromDays(7); | 566 base::TimeDelta::FromDays(7 * offset); |
| 567 options->begin_time = midnight - |
| 568 base::TimeDelta::FromDays(7 * (offset + 1)); |
551 } | 569 } |
552 | 570 |
553 void BrowsingHistoryHandler::SetQueryTimeInMonths( | 571 void BrowsingHistoryHandler::SetQueryTimeInMonths( |
554 history::QueryOptions* options) { | 572 int offset, history::QueryOptions* options) { |
555 // Configure the begin point of the search to the start of the | 573 // Configure the begin point of the search to the start of the |
556 // current month. | 574 // current month. |
557 base::Time::Exploded exploded; | 575 base::Time::Exploded exploded; |
558 base::Time::Now().LocalMidnight().LocalExplode(&exploded); | 576 base::Time::Now().LocalMidnight().LocalExplode(&exploded); |
559 exploded.day_of_month = 1; | 577 exploded.day_of_month = 1; |
560 options->begin_time = base::Time::FromLocalExploded(exploded); | |
561 | 578 |
562 // Set the end time of this first search to null (which will | 579 if (offset == 0) { |
563 // show results from the future, should the user's clock have | 580 options->begin_time = base::Time::FromLocalExploded(exploded); |
564 // been set incorrectly). | 581 |
565 options->end_time = base::Time(); | 582 // Set the end time of this first search to null (which will |
| 583 // show results from the future, should the user's clock have |
| 584 // been set incorrectly). |
| 585 options->end_time = base::Time(); |
| 586 } else { |
| 587 // Go back |offset| months in the past. The end time is not inclusive, so |
| 588 // use the first day of the |offset| - 1 and |offset| months (e.g. for |
| 589 // the last month, |offset| = 1, use the first days of the last month and |
| 590 // the current month. |
| 591 exploded.month -= offset - 1; |
| 592 // Set the correct year. |
| 593 normalizeMonths(&exploded); |
| 594 options->end_time = base::Time::FromLocalExploded(exploded); |
| 595 |
| 596 exploded.month -= 1; |
| 597 // Set the correct year |
| 598 normalizeMonths(&exploded); |
| 599 options->begin_time = base::Time::FromLocalExploded(exploded); |
| 600 } |
566 } | 601 } |
567 | 602 |
568 // Helper function for Observe that determines if there are any differences | 603 // Helper function for Observe that determines if there are any differences |
569 // between the URLs noticed for deletion and the ones we are expecting. | 604 // between the URLs noticed for deletion and the ones we are expecting. |
570 static bool DeletionsDiffer(const history::URLRows& deleted_rows, | 605 static bool DeletionsDiffer(const history::URLRows& deleted_rows, |
571 const std::set<GURL>& urls_to_be_deleted) { | 606 const std::set<GURL>& urls_to_be_deleted) { |
572 if (deleted_rows.size() != urls_to_be_deleted.size()) | 607 if (deleted_rows.size() != urls_to_be_deleted.size()) |
573 return true; | 608 return true; |
574 for (history::URLRows::const_iterator i = deleted_rows.begin(); | 609 for (history::URLRows::const_iterator i = deleted_rows.begin(); |
575 i != deleted_rows.end(); ++i) { | 610 i != deleted_rows.end(); ++i) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 648 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
614 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 649 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
615 } | 650 } |
616 | 651 |
617 // static | 652 // static |
618 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 653 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
619 ui::ScaleFactor scale_factor) { | 654 ui::ScaleFactor scale_factor) { |
620 return ResourceBundle::GetSharedInstance(). | 655 return ResourceBundle::GetSharedInstance(). |
621 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 656 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
622 } | 657 } |
OLD | NEW |