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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 } else { | 422 } else { |
423 exploded.month = 12; | 423 exploded.month = 12; |
424 exploded.year--; | 424 exploded.year--; |
425 } | 425 } |
426 options.begin_time = base::Time::FromLocalExploded(exploded); | 426 options.begin_time = base::Time::FromLocalExploded(exploded); |
427 } | 427 } |
428 | 428 |
429 return options; | 429 return options; |
430 } | 430 } |
431 | 431 |
| 432 // Helper function for Observe that determines if there are any differences |
| 433 // between the URLs noticed for deletion and the ones we are expecting. |
| 434 static bool DeletionsDiffer(const history::URLRows& deleted_rows, |
| 435 const std::set<GURL>& urls_to_be_deleted) { |
| 436 if (deleted_rows.size() != urls_to_be_deleted.size()) |
| 437 return true; |
| 438 for (history::URLRows::const_iterator i = deleted_rows.begin(); |
| 439 i != deleted_rows.end(); ++i) { |
| 440 if (urls_to_be_deleted.find(i->url()) == urls_to_be_deleted.end()) |
| 441 return true; |
| 442 } |
| 443 return false; |
| 444 } |
| 445 |
432 void BrowsingHistoryHandler::Observe( | 446 void BrowsingHistoryHandler::Observe( |
433 int type, | 447 int type, |
434 const content::NotificationSource& source, | 448 const content::NotificationSource& source, |
435 const content::NotificationDetails& details) { | 449 const content::NotificationDetails& details) { |
436 if (type != chrome::NOTIFICATION_HISTORY_URLS_DELETED) { | 450 if (type != chrome::NOTIFICATION_HISTORY_URLS_DELETED) { |
437 NOTREACHED(); | 451 NOTREACHED(); |
438 return; | 452 return; |
439 } | 453 } |
440 history::URLsDeletedDetails* deletedDetails = | 454 history::URLsDeletedDetails* deletedDetails = |
441 content::Details<history::URLsDeletedDetails>(details).ptr(); | 455 content::Details<history::URLsDeletedDetails>(details).ptr(); |
442 if (deletedDetails->urls != urls_to_be_deleted_ || | 456 if (deletedDetails->all_history || |
443 deletedDetails->all_history) { | 457 DeletionsDiffer(deletedDetails->rows, urls_to_be_deleted_)) |
444 // Notify the page that someone else deleted from the history. | |
445 web_ui()->CallJavascriptFunction("historyDeleted"); | 458 web_ui()->CallJavascriptFunction("historyDeleted"); |
446 } | |
447 } | 459 } |
448 | 460 |
449 //////////////////////////////////////////////////////////////////////////////// | 461 //////////////////////////////////////////////////////////////////////////////// |
450 // | 462 // |
451 // HistoryUI | 463 // HistoryUI |
452 // | 464 // |
453 //////////////////////////////////////////////////////////////////////////////// | 465 //////////////////////////////////////////////////////////////////////////////// |
454 | 466 |
455 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 467 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
456 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); | 468 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); |
457 | 469 |
458 HistoryUIHTMLSource* html_source = new HistoryUIHTMLSource(); | 470 HistoryUIHTMLSource* html_source = new HistoryUIHTMLSource(); |
459 | 471 |
460 // Set up the chrome://history-frame/ source. | 472 // Set up the chrome://history-frame/ source. |
461 Profile* profile = Profile::FromWebUI(web_ui); | 473 Profile* profile = Profile::FromWebUI(web_ui); |
462 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 474 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
463 } | 475 } |
464 | 476 |
465 // static | 477 // static |
466 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { | 478 const GURL HistoryUI::GetHistoryURLWithSearchText(const string16& text) { |
467 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 479 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
468 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 480 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
469 } | 481 } |
470 | 482 |
471 // static | 483 // static |
472 RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { | 484 RefCountedMemory* HistoryUI::GetFaviconResourceBytes() { |
473 return ResourceBundle::GetSharedInstance(). | 485 return ResourceBundle::GetSharedInstance(). |
474 LoadDataResourceBytes(IDR_HISTORY_FAVICON); | 486 LoadDataResourceBytes(IDR_HISTORY_FAVICON); |
475 } | 487 } |
OLD | NEW |