Chromium Code Reviews| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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->SetJsonPath(kStringsJsFile); | 140 source->SetJsonPath(kStringsJsFile); |
| 141 source->AddResourcePath(kHistoryJsFile, IDR_HISTORY_JS); | 141 source->AddResourcePath(kHistoryJsFile, IDR_HISTORY_JS); |
| 142 source->SetDefaultResource(IDR_HISTORY_HTML); | 142 source->SetDefaultResource(IDR_HISTORY_HTML); |
| 143 source->SetUseJsonJSFormatV2(); | 143 source->SetUseJsonJSFormatV2(); |
| 144 source->AddLocalizedString("displayfiltersites", IDS_GROUP_BY_DOMAIN_LABEL); | 144 source->AddLocalizedString("displayfiltersites", IDS_GROUP_BY_DOMAIN_LABEL); |
| 145 source->AddLocalizedString("rangeweek", IDS_HISTORY_RANGE_WEEK); | 145 source->AddLocalizedString("rangeweek", IDS_HISTORY_RANGE_WEEK); |
| 146 source->AddLocalizedString("rangemonth", IDS_HISTORY_RANGE_MONTH); | 146 source->AddLocalizedString("rangemonth", IDS_HISTORY_RANGE_MONTH); |
| 147 source->AddLocalizedString("displayfiltersites", IDS_GROUP_BY_DOMAIN_LABEL); | 147 source->AddLocalizedString("rangetoday", IDS_HISTORY_RANGE_TODAY); |
| 148 source->AddLocalizedString("numbervisits", IDS_HISTORY_NUMBER_VISITS); | 148 source->AddLocalizedString("numbervisits", IDS_HISTORY_NUMBER_VISITS); |
| 149 source->AddBoolean("groupByDomain", | 149 source->AddBoolean("groupByDomain", |
| 150 CommandLine::ForCurrentProcess()->HasSwitch( | 150 CommandLine::ForCurrentProcess()->HasSwitch( |
| 151 switches::kHistoryEnableGroupByDomain)); | 151 switches::kHistoryEnableGroupByDomain)); |
| 152 | 152 |
| 153 return source; | 153 return source; |
| 154 } | 154 } |
| 155 | 155 |
| 156 string16 getRelativeDateLocalized(const base::Time& visit_time) { | 156 string16 getRelativeDateLocalized(const base::Time& visit_time) { |
| 157 base::Time midnight_today = base::Time::Now().LocalMidnight(); | 157 base::Time midnight_today = base::Time::Now().LocalMidnight(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), | 255 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), |
| 256 this, &BrowsingHistoryHandler::WebHistoryTimeout); | 256 this, &BrowsingHistoryHandler::WebHistoryTimeout); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) { | 260 void BrowsingHistoryHandler::HandleQueryHistory(const ListValue* args) { |
| 261 history::QueryOptions options; | 261 history::QueryOptions options; |
| 262 | 262 |
| 263 // Parse the arguments from JavaScript. There are six required arguments: | 263 // Parse the arguments from JavaScript. There are six required arguments: |
| 264 // - the text to search for (may be empty) | 264 // - the text to search for (may be empty) |
| 265 // - the offset from which the search should start in multiple of the range. | |
| 265 // - the range (number) of days to search for, used only for grouped | 266 // - the range (number) of days to search for, used only for grouped |
| 266 // searches. | 267 // searches. |
| 267 // - the end time of the range to search (see QueryOptions.end_time) | 268 // - the end time of the range to search (see QueryOptions.end_time) |
| 268 // - the search cursor, an opaque value from a previous query result, which | 269 // - the search cursor, an opaque value from a previous query result, which |
| 269 // allows this query to pick up where the previous one left off. May be | 270 // allows this query to pick up where the previous one left off. May be |
| 270 // null or undefined. | 271 // null or undefined. |
| 271 // - the maximum number of results to return (may be 0, meaning that there | 272 // - the maximum number of results to return (may be 0, meaning that there |
| 272 // is no maximum). | 273 // is no maximum). |
| 273 string16 search_text = ExtractStringValue(args); | 274 string16 search_text = ExtractStringValue(args); |
| 274 int range; | 275 int offset; |
| 275 if (!args->GetInteger(1, &range)) { | 276 if (!args->GetInteger(1, &offset)) { |
| 276 NOTREACHED() << "Failed to convert argument 1. "; | 277 NOTREACHED() << "Failed to convert argument 1. "; |
| 277 return; | 278 return; |
| 278 } | 279 } |
| 280 int range; | |
| 281 if (!args->GetInteger(2, &range)) { | |
| 282 NOTREACHED() << "Failed to convert argument 2. "; | |
| 283 return; | |
| 284 } | |
| 285 | |
| 286 double end_time; | |
| 287 if (!args->GetDouble(3, &end_time)) { | |
| 288 NOTREACHED() << "Failed to convert argument 3. "; | |
| 289 return; | |
| 290 } | |
| 291 if (end_time) | |
| 292 options.end_time = base::Time::FromJsTime(end_time); | |
| 279 | 293 |
| 280 switch (range) { | 294 switch (range) { |
| 281 case BrowsingHistoryHandler::MONTH: | 295 case BrowsingHistoryHandler::MONTH: |
| 282 SetQueryTimeInMonths(&options); | 296 SetQueryTimeInMonths(offset, &options); |
| 283 break; | 297 break; |
| 284 case BrowsingHistoryHandler::WEEK: | 298 case BrowsingHistoryHandler::WEEK: |
| 285 SetQueryTimeInWeeks(&options); | 299 SetQueryTimeInWeeks(offset, &options); |
| 286 break; | 300 break; |
| 287 case BrowsingHistoryHandler::NOT_GROUPED: | 301 case BrowsingHistoryHandler::NOT_GROUPED: |
| 288 break; | 302 break; |
| 289 } | 303 } |
| 290 | 304 |
| 291 double end_time; | |
| 292 if (!args->GetDouble(2, &end_time)) { | |
| 293 NOTREACHED() << "Failed to convert argument 2. "; | |
| 294 return; | |
| 295 } | |
| 296 if (end_time) | |
| 297 options.end_time = base::Time::FromJsTime(end_time); | |
| 298 | |
| 299 const Value* cursor_value; | 305 const Value* cursor_value; |
| 300 | 306 |
| 301 // Get the cursor. It must be either null, or a list. | 307 // Get the cursor. It must be either null, or a list. |
| 302 if (!args->Get(3, &cursor_value) || | 308 if (!args->Get(4, &cursor_value) || |
| 303 (!cursor_value->IsType(Value::TYPE_NULL) && | 309 (!cursor_value->IsType(Value::TYPE_NULL) && |
| 304 !history::QueryCursor::FromValue(cursor_value, &options.cursor))) { | 310 !history::QueryCursor::FromValue(cursor_value, &options.cursor))) { |
| 305 NOTREACHED() << "Failed to convert argument 3. "; | 311 NOTREACHED() << "Failed to convert argument 4. "; |
| 306 return; | 312 return; |
| 307 } | 313 } |
| 308 | 314 |
| 309 if (!ExtractIntegerValueAtIndex(args, 4, &options.max_count)) { | 315 if (!ExtractIntegerValueAtIndex(args, 5, &options.max_count)) { |
| 310 NOTREACHED() << "Failed to convert argument 4."; | 316 NOTREACHED() << "Failed to convert argument 5."; |
| 311 return; | 317 return; |
| 312 } | 318 } |
| 313 | 319 |
| 314 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; | 320 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; |
| 315 QueryHistory(search_text, options); | 321 QueryHistory(search_text, options); |
| 316 } | 322 } |
| 317 | 323 |
| 318 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { | 324 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { |
| 319 if (delete_task_tracker_.HasTrackedTasks()) { | 325 if (delete_task_tracker_.HasTrackedTasks()) { |
| 320 web_ui()->CallJavascriptFunction("deleteFailed"); | 326 web_ui()->CallJavascriptFunction("deleteFailed"); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 } | 529 } |
| 524 | 530 |
| 525 void BrowsingHistoryHandler::RemoveComplete() { | 531 void BrowsingHistoryHandler::RemoveComplete() { |
| 526 urls_to_be_deleted_.clear(); | 532 urls_to_be_deleted_.clear(); |
| 527 | 533 |
| 528 // Notify the page that the deletion request succeeded. | 534 // Notify the page that the deletion request succeeded. |
| 529 web_ui()->CallJavascriptFunction("deleteComplete"); | 535 web_ui()->CallJavascriptFunction("deleteComplete"); |
| 530 } | 536 } |
| 531 | 537 |
| 532 void BrowsingHistoryHandler::SetQueryTimeInWeeks( | 538 void BrowsingHistoryHandler::SetQueryTimeInWeeks( |
| 533 history::QueryOptions* options) { | 539 int offset, history::QueryOptions* options) { |
| 534 // LocalMidnight returns the beginning of the current day so get the | 540 // LocalMidnight returns the beginning of the current day so get the |
| 535 // beginning of the next one. | 541 // beginning of the next one. |
| 536 base::Time midnight_today = base::Time::Now().LocalMidnight() + | 542 base::Time midnight_today = base::Time::Now().LocalMidnight() + |
| 537 base::TimeDelta::FromDays(1); | 543 base::TimeDelta::FromDays(1); |
| 538 options->end_time = midnight_today; | 544 options->end_time = midnight_today - |
| 539 options->begin_time = midnight_today - base::TimeDelta::FromDays(7); | 545 base::TimeDelta::FromDays(7 * offset); |
| 546 options->begin_time = midnight_today - | |
| 547 base::TimeDelta::FromDays(7 * (offset + 1)); | |
| 540 } | 548 } |
| 541 | 549 |
| 542 void BrowsingHistoryHandler::SetQueryTimeInMonths( | 550 void BrowsingHistoryHandler::SetQueryTimeInMonths( |
| 543 history::QueryOptions* options) { | 551 int offset, history::QueryOptions* options) { |
| 544 // Configure the begin point of the search to the start of the | 552 // Configure the begin point of the search to the start of the |
| 545 // current month. | 553 // current month. |
| 546 base::Time::Exploded exploded; | 554 base::Time::Exploded exploded; |
| 547 base::Time::Now().LocalMidnight().LocalExplode(&exploded); | 555 base::Time::Now().LocalMidnight().LocalExplode(&exploded); |
| 548 exploded.day_of_month = 1; | 556 exploded.day_of_month = 1; |
| 549 options->begin_time = base::Time::FromLocalExploded(exploded); | |
| 550 | 557 |
| 551 // Set the end time of this first search to null (which will | 558 if (offset == 0) { |
| 552 // show results from the future, should the user's clock have | 559 options->begin_time = base::Time::FromLocalExploded(exploded); |
| 553 // been set incorrectly). | 560 |
| 554 options->end_time = base::Time(); | 561 // Set the end time of this first search to null (which will |
| 562 // show results from the future, should the user's clock have | |
| 563 // been set incorrectly). | |
| 564 options->end_time = base::Time(); | |
|
James Hawkins
2013/01/28 17:48:15
This block of code (all the green) is somewhat hai
Sergiu
2013/01/30 16:09:39
I've refactored this making it simple, hopefully i
| |
| 565 } else { | |
| 566 // Set the end-time of this search to the end of the month that is | |
| 567 // |offset| months before the search end point. The end time is not | |
| 568 // inclusive, so we should set it to midnight on the first day of the | |
| 569 // following month. | |
| 570 exploded.month -= offset - 1; | |
| 571 while (exploded.month < 1) { | |
| 572 exploded.month += 12; | |
| 573 exploded.year--; | |
| 574 } | |
| 575 options->end_time = base::Time::FromLocalExploded(exploded); | |
| 576 | |
| 577 // Set the begin-time of the search to the start of the month | |
| 578 // that is |offset| months prior to search_start_. | |
| 579 if (exploded.month > 1) { | |
| 580 exploded.month--; | |
| 581 } else { | |
| 582 exploded.month = 12; | |
| 583 exploded.year--; | |
| 584 } | |
| 585 options->begin_time = base::Time::FromLocalExploded(exploded); | |
| 586 } | |
| 555 } | 587 } |
| 556 | 588 |
| 557 // Helper function for Observe that determines if there are any differences | 589 // Helper function for Observe that determines if there are any differences |
| 558 // between the URLs noticed for deletion and the ones we are expecting. | 590 // between the URLs noticed for deletion and the ones we are expecting. |
| 559 static bool DeletionsDiffer(const history::URLRows& deleted_rows, | 591 static bool DeletionsDiffer(const history::URLRows& deleted_rows, |
| 560 const std::set<GURL>& urls_to_be_deleted) { | 592 const std::set<GURL>& urls_to_be_deleted) { |
| 561 if (deleted_rows.size() != urls_to_be_deleted.size()) | 593 if (deleted_rows.size() != urls_to_be_deleted.size()) |
| 562 return true; | 594 return true; |
| 563 for (history::URLRows::const_iterator i = deleted_rows.begin(); | 595 for (history::URLRows::const_iterator i = deleted_rows.begin(); |
| 564 i != deleted_rows.end(); ++i) { | 596 i != deleted_rows.end(); ++i) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 634 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
| 603 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 635 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
| 604 } | 636 } |
| 605 | 637 |
| 606 // static | 638 // static |
| 607 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 639 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
| 608 ui::ScaleFactor scale_factor) { | 640 ui::ScaleFactor scale_factor) { |
| 609 return ResourceBundle::GetSharedInstance(). | 641 return ResourceBundle::GetSharedInstance(). |
| 610 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 642 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
| 611 } | 643 } |
| OLD | NEW |