| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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("rangenone", IDS_HISTORY_RANGE_NONE); | 142 source->AddLocalizedString("rangenone", IDS_HISTORY_RANGE_NONE); |
| 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 the current date including a relative | 159 // Returns a localized version of the current date 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 four 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 multiple of the range. |
| 270 // - the range (number) of days to search for, used only for grouped | 280 // - the range (number) of days to search for, used only for grouped |
| 271 // searches. | 281 // searches. |
| 272 // - the search cursor, an opaque value from a previous query result, which | 282 // - 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 | 283 // allows this query to pick up where the previous one left off. May be |
| 274 // null or undefined. | 284 // null or undefined. |
| 275 // - the maximum number of results to return (may be 0, meaning that there | 285 // - the maximum number of results to return (may be 0, meaning that there |
| 276 // is no maximum). | 286 // is no maximum). |
| 277 string16 search_text = ExtractStringValue(args); | 287 string16 search_text = ExtractStringValue(args); |
| 288 int offset; |
| 289 if (!args->GetInteger(1, &offset)) { |
| 290 NOTREACHED() << "Failed to convert argument 1. "; |
| 291 return; |
| 292 } |
| 278 int range; | 293 int range; |
| 279 if (!args->GetInteger(1, &range)) { | 294 if (!args->GetInteger(2, &range)) { |
| 280 NOTREACHED() << "Failed to convert argument 1. "; | 295 NOTREACHED() << "Failed to convert argument 2. "; |
| 281 return; | 296 return; |
| 282 } | 297 } |
| 283 | 298 |
| 284 switch (range) { | 299 switch (range) { |
| 285 case BrowsingHistoryHandler::MONTH: | 300 case BrowsingHistoryHandler::MONTH: |
| 286 SetQueryTimeInMonths(&options); | 301 SetQueryTimeInMonths(offset, &options); |
| 287 break; | 302 break; |
| 288 case BrowsingHistoryHandler::WEEK: | 303 case BrowsingHistoryHandler::WEEK: |
| 289 SetQueryTimeInWeeks(&options); | 304 SetQueryTimeInWeeks(offset, &options); |
| 290 break; | 305 break; |
| 291 case BrowsingHistoryHandler::NOT_GROUPED: | 306 case BrowsingHistoryHandler::NOT_GROUPED: |
| 292 break; | 307 break; |
| 293 } | 308 } |
| 294 | 309 |
| 295 const Value* cursor_value; | 310 const Value* cursor_value; |
| 296 | 311 |
| 297 // Get the cursor. It must be either null, or a list. | 312 // Get the cursor. It must be either null, or a list. |
| 298 if (!args->Get(2, &cursor_value) || | 313 if (!args->Get(3, &cursor_value) || |
| 299 (!cursor_value->IsType(Value::TYPE_NULL) && | 314 (!cursor_value->IsType(Value::TYPE_NULL) && |
| 300 !history::QueryCursor::FromValue(cursor_value, &options.cursor))) { | 315 !history::QueryCursor::FromValue(cursor_value, &options.cursor))) { |
| 301 NOTREACHED() << "Failed to convert argument 2. "; | 316 NOTREACHED() << "Failed to convert argument 3. "; |
| 302 return; | 317 return; |
| 303 } | 318 } |
| 304 | 319 |
| 305 if (!ExtractIntegerValueAtIndex(args, 3, &options.max_count)) { | 320 if (!ExtractIntegerValueAtIndex(args, 4, &options.max_count)) { |
| 306 NOTREACHED() << "Failed to convert argument 3."; | 321 NOTREACHED() << "Failed to convert argument 4."; |
| 307 return; | 322 return; |
| 308 } | 323 } |
| 309 | 324 |
| 310 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; | 325 options.duplicate_policy = history::QueryOptions::REMOVE_DUPLICATES_PER_DAY; |
| 311 QueryHistory(search_text, options); | 326 QueryHistory(search_text, options); |
| 312 } | 327 } |
| 313 | 328 |
| 314 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { | 329 void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const ListValue* args) { |
| 315 if (delete_task_tracker_.HasTrackedTasks()) { | 330 if (delete_task_tracker_.HasTrackedTasks()) { |
| 316 web_ui()->CallJavascriptFunction("deleteFailed"); | 331 web_ui()->CallJavascriptFunction("deleteFailed"); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 } | 549 } |
| 535 | 550 |
| 536 void BrowsingHistoryHandler::RemoveWebHistoryComplete( | 551 void BrowsingHistoryHandler::RemoveWebHistoryComplete( |
| 537 history::WebHistoryService::Request* request, bool success) { | 552 history::WebHistoryService::Request* request, bool success) { |
| 538 // Notify the page that the deletion request is complete. | 553 // Notify the page that the deletion request is complete. |
| 539 base::FundamentalValue success_value(success); | 554 base::FundamentalValue success_value(success); |
| 540 web_ui()->CallJavascriptFunction("webHistoryDeleteComplete", success_value); | 555 web_ui()->CallJavascriptFunction("webHistoryDeleteComplete", success_value); |
| 541 } | 556 } |
| 542 | 557 |
| 543 void BrowsingHistoryHandler::SetQueryTimeInWeeks( | 558 void BrowsingHistoryHandler::SetQueryTimeInWeeks( |
| 544 history::QueryOptions* options) { | 559 int offset, history::QueryOptions* options) { |
| 545 // LocalMidnight returns the beginning of the current day so get the | 560 // LocalMidnight returns the beginning of the current day so get the |
| 546 // beginning of the next one. | 561 // beginning of the next one. |
| 547 base::Time midnight = base::Time::Now().LocalMidnight() + | 562 base::Time midnight = base::Time::Now().LocalMidnight() + |
| 548 base::TimeDelta::FromDays(1); | 563 base::TimeDelta::FromDays(1); |
| 549 options->end_time = midnight; | 564 options->end_time = midnight - |
| 550 options->begin_time = midnight - base::TimeDelta::FromDays(7); | 565 base::TimeDelta::FromDays(7 * offset); |
| 566 options->begin_time = midnight - |
| 567 base::TimeDelta::FromDays(7 * (offset + 1)); |
| 551 } | 568 } |
| 552 | 569 |
| 553 void BrowsingHistoryHandler::SetQueryTimeInMonths( | 570 void BrowsingHistoryHandler::SetQueryTimeInMonths( |
| 554 history::QueryOptions* options) { | 571 int offset, history::QueryOptions* options) { |
| 555 // Configure the begin point of the search to the start of the | 572 // Configure the begin point of the search to the start of the |
| 556 // current month. | 573 // current month. |
| 557 base::Time::Exploded exploded; | 574 base::Time::Exploded exploded; |
| 558 base::Time::Now().LocalMidnight().LocalExplode(&exploded); | 575 base::Time::Now().LocalMidnight().LocalExplode(&exploded); |
| 559 exploded.day_of_month = 1; | 576 exploded.day_of_month = 1; |
| 560 options->begin_time = base::Time::FromLocalExploded(exploded); | |
| 561 | 577 |
| 562 // Set the end time of this first search to null (which will | 578 if (offset == 0) { |
| 563 // show results from the future, should the user's clock have | 579 options->begin_time = base::Time::FromLocalExploded(exploded); |
| 564 // been set incorrectly). | 580 |
| 565 options->end_time = base::Time(); | 581 // Set the end time of this first search to null (which will |
| 582 // show results from the future, should the user's clock have |
| 583 // been set incorrectly). |
| 584 options->end_time = base::Time(); |
| 585 } else { |
| 586 // Go back |offset| months in the past. The end time is not inclusive, so |
| 587 // use the first day of the |offset| - 1 and |offset| months (e.g. for |
| 588 // the last month, |offset| = 1, use the first days of the last month and |
| 589 // the current month. |
| 590 exploded.month -= offset - 1; |
| 591 // Set the correct year. |
| 592 normalizeMonths(&exploded); |
| 593 options->end_time = base::Time::FromLocalExploded(exploded); |
| 594 |
| 595 exploded.month -= 1; |
| 596 // Set the correct year |
| 597 normalizeMonths(&exploded); |
| 598 options->begin_time = base::Time::FromLocalExploded(exploded); |
| 599 } |
| 566 } | 600 } |
| 567 | 601 |
| 568 // Helper function for Observe that determines if there are any differences | 602 // Helper function for Observe that determines if there are any differences |
| 569 // between the URLs noticed for deletion and the ones we are expecting. | 603 // between the URLs noticed for deletion and the ones we are expecting. |
| 570 static bool DeletionsDiffer(const history::URLRows& deleted_rows, | 604 static bool DeletionsDiffer(const history::URLRows& deleted_rows, |
| 571 const std::set<GURL>& urls_to_be_deleted) { | 605 const std::set<GURL>& urls_to_be_deleted) { |
| 572 if (deleted_rows.size() != urls_to_be_deleted.size()) | 606 if (deleted_rows.size() != urls_to_be_deleted.size()) |
| 573 return true; | 607 return true; |
| 574 for (history::URLRows::const_iterator i = deleted_rows.begin(); | 608 for (history::URLRows::const_iterator i = deleted_rows.begin(); |
| 575 i != deleted_rows.end(); ++i) { | 609 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=" + | 647 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
| 614 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 648 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
| 615 } | 649 } |
| 616 | 650 |
| 617 // static | 651 // static |
| 618 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 652 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
| 619 ui::ScaleFactor scale_factor) { | 653 ui::ScaleFactor scale_factor) { |
| 620 return ResourceBundle::GetSharedInstance(). | 654 return ResourceBundle::GetSharedInstance(). |
| 621 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 655 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
| 622 } | 656 } |
| OLD | NEW |