diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 08:15:53 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 08:15:53 +0000 |
commit | 21f4d251210a4408da8a3279510ef7eb44cc1e1a (patch) | |
tree | a235ca4b807641d671b244fc78ed9bb64205b4ac /chrome/browser/dom_ui | |
parent | 0c86dbf56c6f3e82ee748f34dca48aedf962dec2 (diff) | |
download | chromium_src-21f4d251210a4408da8a3279510ef7eb44cc1e1a.zip chromium_src-21f4d251210a4408da8a3279510ef7eb44cc1e1a.tar.gz chromium_src-21f4d251210a4408da8a3279510ef7eb44cc1e1a.tar.bz2 |
Implement edit mode for history page.
BUG=35338
TEST=none
Review URL: http://codereview.chromium.org/660283
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/history_ui.cc | 96 | ||||
-rw-r--r-- | chrome/browser/dom_ui/history_ui.h | 22 |
2 files changed, 71 insertions, 47 deletions
diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc index 0019059..d81bbc1 100644 --- a/chrome/browser/dom_ui/history_ui.cc +++ b/chrome/browser/dom_ui/history_ui.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,11 +16,14 @@ #include "base/time.h" #include "base/values.h" #include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/browser.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/profile.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/notification_service.h" #include "chrome/common/time_format.h" @@ -74,9 +77,15 @@ void HistoryUIHTMLSource::StartDataRequest(const std::string& path, l10n_util::GetString(IDS_HISTORY_NO_RESULTS)); localized_strings.SetString(L"noitems", l10n_util::GetString(IDS_HISTORY_NO_ITEMS)); - localized_strings.SetString(L"deleteday", - l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_LINK)); - localized_strings.SetString(L"deletedaywarning", + localized_strings.SetString(L"edithistory", + l10n_util::GetString(IDS_HISTORY_START_EDITING_HISTORY)); + localized_strings.SetString(L"doneediting", + l10n_util::GetString(IDS_HISTORY_STOP_EDITING_HISTORY)); + localized_strings.SetString(L"removeselected", + l10n_util::GetString(IDS_HISTORY_REMOVE_SELECTED_ITEMS)); + localized_strings.SetString(L"clearallhistory", + l10n_util::GetString(IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG)); + localized_strings.SetString(L"deletewarning", l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING)); SetFontAndTextDirection(&localized_strings); @@ -100,14 +109,11 @@ void HistoryUIHTMLSource::StartDataRequest(const std::string& path, // //////////////////////////////////////////////////////////////////////////////// BrowsingHistoryHandler::BrowsingHistoryHandler() - : search_text_(), - remover_(NULL) { + : search_text_() { } BrowsingHistoryHandler::~BrowsingHistoryHandler() { cancelable_consumer_.CancelAllRequests(); - if (remover_) - remover_->RemoveObserver(this); } DOMMessageHandler* BrowsingHistoryHandler::Attach(DOMUI* dom_ui) { @@ -130,8 +136,10 @@ void BrowsingHistoryHandler::RegisterMessages() { NewCallback(this, &BrowsingHistoryHandler::HandleGetHistory)); dom_ui_->RegisterMessageCallback("searchHistory", NewCallback(this, &BrowsingHistoryHandler::HandleSearchHistory)); - dom_ui_->RegisterMessageCallback("deleteDay", - NewCallback(this, &BrowsingHistoryHandler::HandleDeleteDay)); + dom_ui_->RegisterMessageCallback("removeURLsOnOneDay", + NewCallback(this, &BrowsingHistoryHandler::HandleRemoveURLsOnOneDay)); + dom_ui_->RegisterMessageCallback("clearBrowsingData", + NewCallback(this, &BrowsingHistoryHandler::HandleClearBrowsingData)); } void BrowsingHistoryHandler::HandleGetHistory(const Value* value) { @@ -185,37 +193,50 @@ void BrowsingHistoryHandler::HandleSearchHistory(const Value* value) { NewCallback(this, &BrowsingHistoryHandler::QueryComplete)); } -void BrowsingHistoryHandler::HandleDeleteDay(const Value* value) { - if (BrowsingDataRemover::is_removing()) { +void BrowsingHistoryHandler::HandleRemoveURLsOnOneDay(const Value* value) { + if (cancelable_consumer_.HasPendingRequests()) { dom_ui_->CallJavascriptFunction(L"deleteFailed"); return; } - // Anything in-flight is invalid. - cancelable_consumer_.CancelAllRequests(); + DCHECK(value && value->GetType() == Value::TYPE_LIST); - // Get time. - base::Time time; - bool success = base::Time::FromString(ExtractStringValue(value).c_str(), - &time); - DCHECK(success); - - base::Time begin_time = time.LocalMidnight(); + // Get day to delete data from. + int visit_time = 0; + ExtractIntegerValue(value, &visit_time); + base::Time::Exploded exploded; + base::Time::FromTimeT( + static_cast<time_t>(visit_time)).LocalExplode(&exploded); + exploded.hour = exploded.minute = exploded.second = exploded.millisecond = 0; + base::Time begin_time = base::Time::FromLocalExploded(exploded); base::Time end_time = begin_time + base::TimeDelta::FromDays(1); - remover_ = new BrowsingDataRemover(dom_ui_->GetProfile(), - begin_time, - end_time); - remover_->AddObserver(this); - remover_->Remove(BrowsingDataRemover::REMOVE_HISTORY | - BrowsingDataRemover::REMOVE_CACHE); + // Get URLs. + std::set<GURL> urls; + const ListValue* list_value = static_cast<const ListValue*>(value); + for (ListValue::const_iterator v = list_value->begin() + 1; + v != list_value->end(); ++v) { + if ((*v)->GetType() != Value::TYPE_STRING) + continue; + const StringValue* string_value = static_cast<const StringValue*>(*v); + string16 string16_value; + if (!string_value->GetAsUTF16(&string16_value)) + continue; + urls.insert(GURL(string16_value)); + } + + HistoryService* hs = + dom_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS); + hs->ExpireHistoryBetween(urls, begin_time, end_time, &cancelable_consumer_, + NewCallback(this, &BrowsingHistoryHandler::RemoveComplete)); } -void BrowsingHistoryHandler::OnBrowsingDataRemoverDone() { - dom_ui_->CallJavascriptFunction(L"deleteComplete"); - // No need to remove ourselves as an observer as BrowsingDataRemover deletes - // itself after we return. - remover_ = NULL; +void BrowsingHistoryHandler::HandleClearBrowsingData(const Value* value) { + // Anything in-flight is invalid. + cancelable_consumer_.CancelAllRequests(); + + dom_ui_->tab_contents()->delegate()->GetBrowser()-> + OpenClearBrowsingDataDialog(); } void BrowsingHistoryHandler::QueryComplete( @@ -271,6 +292,11 @@ void BrowsingHistoryHandler::QueryComplete( dom_ui_->CallJavascriptFunction(L"historyResult", info_value, results_value); } +void BrowsingHistoryHandler::RemoveComplete() { + // Some Visits were deleted from history. Reload the list. + dom_ui_->CallJavascriptFunction(L"deleteComplete"); +} + void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, int* month, std::wstring* query) { *month = 0; @@ -292,9 +318,9 @@ void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value, list_member->GetType() == Value::TYPE_STRING) { const StringValue* string_value = static_cast<const StringValue*>(list_member); - std::wstring wstring_value; - string_value->GetAsString(&wstring_value); - *month = StringToInt(WideToUTF16Hack(wstring_value)); + string16 string16_value; + string_value->GetAsUTF16(&string16_value); + *month = StringToInt(string16_value); } } } diff --git a/chrome/browser/dom_ui/history_ui.h b/chrome/browser/dom_ui/history_ui.h index c1d4262..a8fceb3 100644 --- a/chrome/browser/dom_ui/history_ui.h +++ b/chrome/browser/dom_ui/history_ui.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,7 +8,6 @@ #include <string> #include <vector> -#include "chrome/browser/browsing_data_remover.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" #include "chrome/browser/dom_ui/dom_ui.h" #include "chrome/browser/cancelable_request.h" @@ -38,8 +37,7 @@ class HistoryUIHTMLSource : public ChromeURLDataManager::DataSource { // The handler for Javascript messages related to the "history" view. class BrowsingHistoryHandler : public DOMMessageHandler, - public NotificationObserver, - public BrowsingDataRemover::Observer { + public NotificationObserver { public: BrowsingHistoryHandler(); virtual ~BrowsingHistoryHandler(); @@ -54,22 +52,25 @@ class BrowsingHistoryHandler : public DOMMessageHandler, // Callback for the "searchHistory" message. void HandleSearchHistory(const Value* value); - // Callback for the "deleteDay" message. - void HandleDeleteDay(const Value* value); + // Callback for the "removeURLsOnOneDay" message. + void HandleRemoveURLsOnOneDay(const Value* value); + + // Handle for "clearBrowsingData" message. + void HandleClearBrowsingData(const Value* value); // NotificationObserver implementation. virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details); - // BrowsingDataRemover observer implementation. - void OnBrowsingDataRemoverDone(); - private: // Callback from the history system when the history list is available. void QueryComplete(HistoryService::Handle request_handle, history::QueryResults* results); + // Callback from the history system when visits were deleted. + void RemoveComplete(); + // Extract the arguments from the call to HandleSearchHistory. void ExtractSearchHistoryArguments(const Value* value, int* month, @@ -83,9 +84,6 @@ class BrowsingHistoryHandler : public DOMMessageHandler, // Current search text. std::wstring search_text_; - // Browsing history remover - BrowsingDataRemover* remover_; - // Our consumer for the history service. CancelableRequestConsumerT<int, 0> cancelable_consumer_; |