| 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/options/clear_browser_data_handler.h" | 5 #include "chrome/browser/ui/webui/options/clear_browser_data_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "chrome/app/chrome_command_ids.h" | 19 #include "chrome/app/chrome_command_ids.h" |
| 19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/browsing_data/autofill_counter.h" | 21 #include "chrome/browser/browsing_data/autofill_counter.h" |
| 21 #include "chrome/browser/browsing_data/browsing_data_counter.h" | 22 #include "chrome/browser/browsing_data/browsing_data_counter.h" |
| 22 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" | 23 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
| 23 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 24 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 24 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 25 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 25 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 26 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 26 #include "chrome/browser/browsing_data/cache_counter.h" | 27 #include "chrome/browser/browsing_data/cache_counter.h" |
| 27 #include "chrome/browser/browsing_data/history_counter.h" | 28 #include "chrome/browser/browsing_data/history_counter.h" |
| 28 #include "chrome/browser/browsing_data/passwords_counter.h" | 29 #include "chrome/browser/browsing_data/passwords_counter.h" |
| 30 #include "chrome/browser/history/web_history_service_factory.h" |
| 29 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 31 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/sync/profile_sync_service_factory.h" | 33 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 32 #include "chrome/browser/ui/accelerator_utils.h" | 34 #include "chrome/browser/ui/accelerator_utils.h" |
| 33 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/grit/generated_resources.h" | 36 #include "chrome/grit/generated_resources.h" |
| 35 #include "chrome/grit/locale_settings.h" | 37 #include "chrome/grit/locale_settings.h" |
| 38 #include "components/browsing_data_ui/history_notice_utils.h" |
| 36 #include "components/google/core/browser/google_util.h" | 39 #include "components/google/core/browser/google_util.h" |
| 37 #include "components/prefs/pref_service.h" | 40 #include "components/prefs/pref_service.h" |
| 38 #include "content/public/browser/notification_details.h" | 41 #include "content/public/browser/notification_details.h" |
| 39 #include "content/public/browser/web_ui.h" | 42 #include "content/public/browser/web_ui.h" |
| 40 #include "ui/base/accelerators/accelerator.h" | 43 #include "ui/base/accelerators/accelerator.h" |
| 41 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| 42 #include "ui/events/keycodes/keyboard_codes.h" | 45 #include "ui/events/keycodes/keyboard_codes.h" |
| 43 | 46 |
| 44 namespace { | 47 namespace { |
| 45 | 48 |
| 46 const char kClearBrowsingDataLearnMoreUrl[] = | 49 const char kClearBrowsingDataLearnMoreUrl[] = |
| 47 "https://support.google.com/chrome/?p=settings_clear_browsing_data"; | 50 "https://support.google.com/chrome/?p=settings_clear_browsing_data"; |
| 48 | 51 |
| 52 const char kMyActivityUrlInFooter[] = |
| 53 "https://history.google.com/history/?utm_source=chrome_cbd"; |
| 54 |
| 55 const char kMyActivityUrlInDialog[] = |
| 56 "https://history.google.com/history/?utm_source=chrome_n"; |
| 57 |
| 58 const int kMaxTimesHistoryNoticeShown = 1; |
| 59 |
| 49 } // namespace | 60 } // namespace |
| 50 | 61 |
| 51 namespace options { | 62 namespace options { |
| 52 | 63 |
| 53 ClearBrowserDataHandler::ClearBrowserDataHandler() | 64 ClearBrowserDataHandler::ClearBrowserDataHandler() |
| 54 : remover_(nullptr), | 65 : remover_(nullptr), |
| 55 sync_service_(nullptr) { | 66 sync_service_(nullptr), |
| 67 should_show_history_notice_(false), |
| 68 should_show_history_deletion_dialog_(false), |
| 69 weak_ptr_factory_(this) { |
| 56 } | 70 } |
| 57 | 71 |
| 58 ClearBrowserDataHandler::~ClearBrowserDataHandler() { | 72 ClearBrowserDataHandler::~ClearBrowserDataHandler() { |
| 59 if (remover_) | 73 if (remover_) |
| 60 remover_->RemoveObserver(this); | 74 remover_->RemoveObserver(this); |
| 61 if (sync_service_) | 75 if (sync_service_) |
| 62 sync_service_->RemoveObserver(this); | 76 sync_service_->RemoveObserver(this); |
| 63 } | 77 } |
| 64 | 78 |
| 65 void ClearBrowserDataHandler::InitializeHandler() { | 79 void ClearBrowserDataHandler::InitializeHandler() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 83 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 97 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
| 84 if (sync_service_) | 98 if (sync_service_) |
| 85 sync_service_->AddObserver(this); | 99 sync_service_->AddObserver(this); |
| 86 } | 100 } |
| 87 } | 101 } |
| 88 | 102 |
| 89 void ClearBrowserDataHandler::InitializePage() { | 103 void ClearBrowserDataHandler::InitializePage() { |
| 90 web_ui()->CallJavascriptFunction( | 104 web_ui()->CallJavascriptFunction( |
| 91 "ClearBrowserDataOverlay.createFooter", | 105 "ClearBrowserDataOverlay.createFooter", |
| 92 base::FundamentalValue(AreCountersEnabled()), | 106 base::FundamentalValue(AreCountersEnabled()), |
| 93 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive())); | 107 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
| 108 base::FundamentalValue(should_show_history_notice_)); |
| 109 RefreshHistoryNotice(); |
| 94 UpdateInfoBannerVisibility(); | 110 UpdateInfoBannerVisibility(); |
| 95 OnBrowsingHistoryPrefChanged(); | 111 OnBrowsingHistoryPrefChanged(); |
| 96 bool removal_in_progress = !!remover_; | 112 bool removal_in_progress = !!remover_; |
| 97 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.setClearing", | 113 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.setClearing", |
| 98 base::FundamentalValue(removal_in_progress)); | 114 base::FundamentalValue(removal_in_progress)); |
| 99 | 115 |
| 100 web_ui()->CallJavascriptFunction( | 116 web_ui()->CallJavascriptFunction( |
| 101 "ClearBrowserDataOverlay.markInitializationComplete"); | 117 "ClearBrowserDataOverlay.markInitializationComplete"); |
| 102 } | 118 } |
| 103 | 119 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 134 void ClearBrowserDataHandler::GetLocalizedValues( | 150 void ClearBrowserDataHandler::GetLocalizedValues( |
| 135 base::DictionaryValue* localized_strings) { | 151 base::DictionaryValue* localized_strings) { |
| 136 DCHECK(localized_strings); | 152 DCHECK(localized_strings); |
| 137 | 153 |
| 138 static OptionsStringResource resources[] = { | 154 static OptionsStringResource resources[] = { |
| 139 { "clearBrowserDataLabel", IDS_CLEAR_BROWSING_DATA_LABEL }, | 155 { "clearBrowserDataLabel", IDS_CLEAR_BROWSING_DATA_LABEL }, |
| 140 { "clearBrowserDataSyncWarning", IDS_CLEAR_BROWSING_DATA_SYNCED_DELETION }, | 156 { "clearBrowserDataSyncWarning", IDS_CLEAR_BROWSING_DATA_SYNCED_DELETION }, |
| 141 { "clearBrowserDataSupportString", AreCountersEnabled() | 157 { "clearBrowserDataSupportString", AreCountersEnabled() |
| 142 ? IDS_CLEAR_BROWSING_DATA_SOME_STUFF_REMAINS_SIMPLE | 158 ? IDS_CLEAR_BROWSING_DATA_SOME_STUFF_REMAINS_SIMPLE |
| 143 : IDS_CLEAR_BROWSING_DATA_SOME_STUFF_REMAINS }, | 159 : IDS_CLEAR_BROWSING_DATA_SOME_STUFF_REMAINS }, |
| 160 { "clearBrowserDataHistoryNoticeTitle", |
| 161 IDS_CLEAR_BROWSING_DATA_HISTORY_NOTICE_TITLE }, |
| 144 { "deleteBrowsingHistoryCheckbox", IDS_DEL_BROWSING_HISTORY_CHKBOX }, | 162 { "deleteBrowsingHistoryCheckbox", IDS_DEL_BROWSING_HISTORY_CHKBOX }, |
| 145 { "deleteDownloadHistoryCheckbox", IDS_DEL_DOWNLOAD_HISTORY_CHKBOX }, | 163 { "deleteDownloadHistoryCheckbox", IDS_DEL_DOWNLOAD_HISTORY_CHKBOX }, |
| 146 { "deleteCacheCheckbox", IDS_DEL_CACHE_CHKBOX }, | 164 { "deleteCacheCheckbox", IDS_DEL_CACHE_CHKBOX }, |
| 147 { "deleteCookiesCheckbox", IDS_DEL_COOKIES_CHKBOX }, | 165 { "deleteCookiesCheckbox", IDS_DEL_COOKIES_CHKBOX }, |
| 148 { "deleteCookiesFlashCheckbox", IDS_DEL_COOKIES_FLASH_CHKBOX }, | 166 { "deleteCookiesFlashCheckbox", IDS_DEL_COOKIES_FLASH_CHKBOX }, |
| 149 { "deletePasswordsCheckbox", IDS_DEL_PASSWORDS_CHKBOX }, | 167 { "deletePasswordsCheckbox", IDS_DEL_PASSWORDS_CHKBOX }, |
| 150 { "deleteFormDataCheckbox", IDS_DEL_FORM_DATA_CHKBOX }, | 168 { "deleteFormDataCheckbox", IDS_DEL_FORM_DATA_CHKBOX }, |
| 151 { "deleteHostedAppsDataCheckbox", IDS_DEL_HOSTED_APPS_DATA_CHKBOX }, | 169 { "deleteHostedAppsDataCheckbox", IDS_DEL_HOSTED_APPS_DATA_CHKBOX }, |
| 152 { "deauthorizeContentLicensesCheckbox", | 170 { "deauthorizeContentLicensesCheckbox", |
| 153 IDS_DEAUTHORIZE_CONTENT_LICENSES_CHKBOX }, | 171 IDS_DEAUTHORIZE_CONTENT_LICENSES_CHKBOX }, |
| 154 { "clearBrowserDataCommit", IDS_CLEAR_BROWSING_DATA_COMMIT }, | 172 { "clearBrowserDataCommit", IDS_CLEAR_BROWSING_DATA_COMMIT }, |
| 155 { "flashStorageUrl", IDS_FLASH_STORAGE_URL }, | 173 { "flashStorageUrl", IDS_FLASH_STORAGE_URL }, |
| 156 }; | 174 }; |
| 157 | 175 |
| 158 RegisterStrings(localized_strings, resources, arraysize(resources)); | 176 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 159 RegisterTitle(localized_strings, "clearBrowserDataOverlay", | 177 RegisterTitle(localized_strings, "clearBrowserDataOverlay", |
| 160 IDS_CLEAR_BROWSING_DATA_TITLE); | 178 IDS_CLEAR_BROWSING_DATA_TITLE); |
| 161 localized_strings->SetString("clearBrowsingDataLearnMoreUrl", | 179 localized_strings->SetString("clearBrowsingDataLearnMoreUrl", |
| 162 kClearBrowsingDataLearnMoreUrl); | 180 kClearBrowsingDataLearnMoreUrl); |
| 181 localized_strings->SetString( |
| 182 "clearBrowserDataHistoryFooter", |
| 183 l10n_util::GetStringFUTF16( |
| 184 IDS_CLEAR_BROWSING_DATA_HISTORY_FOOTER, |
| 185 base::ASCIIToUTF16(kMyActivityUrlInFooter))); |
| 186 localized_strings->SetString( |
| 187 "clearBrowserDataHistoryNotice", |
| 188 l10n_util::GetStringFUTF16( |
| 189 IDS_CLEAR_BROWSING_DATA_HISTORY_NOTICE, |
| 190 base::ASCIIToUTF16(kMyActivityUrlInDialog))); |
| 163 | 191 |
| 164 base::ListValue* time_list = new base::ListValue; | 192 base::ListValue* time_list = new base::ListValue; |
| 165 for (int i = 0; i < 5; i++) { | 193 for (int i = 0; i < 5; i++) { |
| 166 base::string16 label_string; | 194 base::string16 label_string; |
| 167 switch (i) { | 195 switch (i) { |
| 168 case 0: | 196 case 0: |
| 169 label_string = l10n_util::GetStringUTF16(IDS_CLEAR_DATA_HOUR); | 197 label_string = l10n_util::GetStringUTF16(IDS_CLEAR_DATA_HOUR); |
| 170 break; | 198 break; |
| 171 case 1: | 199 case 1: |
| 172 label_string = l10n_util::GetStringUTF16(IDS_CLEAR_DATA_DAY); | 200 label_string = l10n_util::GetStringUTF16(IDS_CLEAR_DATA_DAY); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 // Store the clear browsing data time. Next time the clear browsing data | 318 // Store the clear browsing data time. Next time the clear browsing data |
| 291 // dialog is open, this time is used to decide whether to display an info | 319 // dialog is open, this time is used to decide whether to display an info |
| 292 // banner or not. | 320 // banner or not. |
| 293 prefs->SetInt64(prefs::kLastClearBrowsingDataTime, | 321 prefs->SetInt64(prefs::kLastClearBrowsingDataTime, |
| 294 base::Time::Now().ToInternalValue()); | 322 base::Time::Now().ToInternalValue()); |
| 295 } | 323 } |
| 296 | 324 |
| 297 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { | 325 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { |
| 298 remover_->RemoveObserver(this); | 326 remover_->RemoveObserver(this); |
| 299 remover_ = nullptr; | 327 remover_ = nullptr; |
| 300 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.doneClearing"); | 328 |
| 329 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 330 int notice_shown_times = |
| 331 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); |
| 332 |
| 333 // When the deletion is complete, we might show an additional dialog with |
| 334 // a notice about other forms of browsing history. This is the case if |
| 335 const bool show_notice = |
| 336 // 1. The dialog is relevant for the user. |
| 337 should_show_history_deletion_dialog_ && |
| 338 // 2. The selected data types contained browsing history. |
| 339 prefs->GetBoolean(prefs::kDeleteBrowsingHistory) && |
| 340 // 3. The notice has been shown less than |kMaxTimesHistoryNoticeShown|. |
| 341 notice_shown_times < kMaxTimesHistoryNoticeShown; |
| 342 |
| 343 if (show_notice) { |
| 344 // Increment the preference. |
| 345 prefs->SetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes, |
| 346 notice_shown_times + 1); |
| 347 } |
| 348 |
| 349 web_ui()->CallJavascriptFunction( |
| 350 "ClearBrowserDataOverlay.doneClearing", |
| 351 base::FundamentalValue(show_notice)); |
| 301 } | 352 } |
| 302 | 353 |
| 303 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() { | 354 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() { |
| 304 web_ui()->CallJavascriptFunction( | 355 web_ui()->CallJavascriptFunction( |
| 305 "ClearBrowserDataOverlay.setAllowDeletingHistory", | 356 "ClearBrowserDataOverlay.setAllowDeletingHistory", |
| 306 base::FundamentalValue(*allow_deleting_browser_history_)); | 357 base::FundamentalValue(*allow_deleting_browser_history_)); |
| 307 } | 358 } |
| 308 | 359 |
| 309 void ClearBrowserDataHandler::AddCounter( | 360 void ClearBrowserDataHandler::AddCounter( |
| 310 scoped_ptr<BrowsingDataCounter> counter) { | 361 scoped_ptr<BrowsingDataCounter> counter) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 321 scoped_ptr<BrowsingDataCounter::Result> result) { | 372 scoped_ptr<BrowsingDataCounter::Result> result) { |
| 322 DCHECK(AreCountersEnabled()); | 373 DCHECK(AreCountersEnabled()); |
| 323 web_ui()->CallJavascriptFunction( | 374 web_ui()->CallJavascriptFunction( |
| 324 "ClearBrowserDataOverlay.updateCounter", | 375 "ClearBrowserDataOverlay.updateCounter", |
| 325 base::StringValue(result->source()->GetPrefName()), | 376 base::StringValue(result->source()->GetPrefName()), |
| 326 base::StringValue(GetCounterTextFromResult(result.get()))); | 377 base::StringValue(GetCounterTextFromResult(result.get()))); |
| 327 } | 378 } |
| 328 | 379 |
| 329 void ClearBrowserDataHandler::OnStateChanged() { | 380 void ClearBrowserDataHandler::OnStateChanged() { |
| 330 web_ui()->CallJavascriptFunction( | 381 web_ui()->CallJavascriptFunction( |
| 331 "ClearBrowserDataOverlay.updateSyncWarning", | 382 "ClearBrowserDataOverlay.updateSyncWarningAndHistoryFooter", |
| 332 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive())); | 383 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
| 384 base::FundamentalValue(should_show_history_notice_)); |
| 385 } |
| 386 |
| 387 void ClearBrowserDataHandler::RefreshHistoryNotice() { |
| 388 browsing_data_ui::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( |
| 389 sync_service_, |
| 390 WebHistoryServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())), |
| 391 base::Bind(&ClearBrowserDataHandler::UpdateHistoryNotice, |
| 392 weak_ptr_factory_.GetWeakPtr())); |
| 393 |
| 394 // If the dialog with history notice has been shown less than |
| 395 // |kMaxTimesHistoryNoticeShown| times, we might have to show it when the |
| 396 // user deletes history. Find out if the conditions are met. |
| 397 int notice_shown_times = Profile::FromWebUI(web_ui())->GetPrefs()-> |
| 398 GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); |
| 399 |
| 400 if (notice_shown_times < kMaxTimesHistoryNoticeShown) { |
| 401 browsing_data_ui::ShouldPopupDialogAboutOtherFormsOfBrowsingHistory( |
| 402 sync_service_, |
| 403 WebHistoryServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())), |
| 404 base::Bind(&ClearBrowserDataHandler::UpdateHistoryDeletionDialog, |
| 405 weak_ptr_factory_.GetWeakPtr())); |
| 406 } |
| 407 } |
| 408 |
| 409 void ClearBrowserDataHandler::UpdateHistoryNotice(bool show) { |
| 410 should_show_history_notice_ = show; |
| 411 OnStateChanged(); |
| 412 } |
| 413 |
| 414 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) { |
| 415 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). |
| 416 should_show_history_deletion_dialog_ = show; |
| 333 } | 417 } |
| 334 | 418 |
| 335 } // namespace options | 419 } // namespace options |
| OLD | NEW |