Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: chrome/browser/ui/webui/options/clear_browser_data_handler.cc

Issue 1995113002: Rename WebUI::CallJavascriptFunction to WebUI::CallJavascriptFunctionUnsafe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 AddCounter(base::WrapUnique(new AutofillCounter())); 96 AddCounter(base::WrapUnique(new AutofillCounter()));
97 97
98 sync_service_ = 98 sync_service_ =
99 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); 99 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
100 if (sync_service_) 100 if (sync_service_)
101 sync_service_->AddObserver(this); 101 sync_service_->AddObserver(this);
102 } 102 }
103 } 103 }
104 104
105 void ClearBrowserDataHandler::InitializePage() { 105 void ClearBrowserDataHandler::InitializePage() {
106 web_ui()->CallJavascriptFunction( 106 web_ui()->CallJavascriptFunctionUnsafe(
107 "ClearBrowserDataOverlay.createFooter", 107 "ClearBrowserDataOverlay.createFooter",
108 base::FundamentalValue(AreCountersEnabled()), 108 base::FundamentalValue(AreCountersEnabled()),
109 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), 109 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()),
110 base::FundamentalValue(should_show_history_notice_)); 110 base::FundamentalValue(should_show_history_notice_));
111 RefreshHistoryNotice(); 111 RefreshHistoryNotice();
112 UpdateInfoBannerVisibility(); 112 UpdateInfoBannerVisibility();
113 OnBrowsingHistoryPrefChanged(); 113 OnBrowsingHistoryPrefChanged();
114 bool removal_in_progress = !!remover_; 114 bool removal_in_progress = !!remover_;
115 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.setClearing", 115 web_ui()->CallJavascriptFunctionUnsafe(
116 base::FundamentalValue(removal_in_progress)); 116 "ClearBrowserDataOverlay.setClearing",
117 base::FundamentalValue(removal_in_progress));
117 118
118 web_ui()->CallJavascriptFunction( 119 web_ui()->CallJavascriptFunctionUnsafe(
119 "ClearBrowserDataOverlay.markInitializationComplete"); 120 "ClearBrowserDataOverlay.markInitializationComplete");
120 } 121 }
121 122
122 void ClearBrowserDataHandler::UpdateInfoBannerVisibility() { 123 void ClearBrowserDataHandler::UpdateInfoBannerVisibility() {
123 base::string16 text; 124 base::string16 text;
124 125
125 Profile* profile = Profile::FromWebUI(web_ui()); 126 Profile* profile = Profile::FromWebUI(web_ui());
126 auto availability = IncognitoModePrefs::GetAvailability(profile->GetPrefs()); 127 auto availability = IncognitoModePrefs::GetAvailability(profile->GetPrefs());
127 if (availability == IncognitoModePrefs::ENABLED) { 128 if (availability == IncognitoModePrefs::ENABLED) {
128 base::Time last_clear_time = base::Time::FromInternalValue( 129 base::Time last_clear_time = base::Time::FromInternalValue(
129 profile->GetPrefs()->GetInt64(prefs::kLastClearBrowsingDataTime)); 130 profile->GetPrefs()->GetInt64(prefs::kLastClearBrowsingDataTime));
130 131
131 const base::TimeDelta since_clear = base::Time::Now() - last_clear_time; 132 const base::TimeDelta since_clear = base::Time::Now() - last_clear_time;
132 if (since_clear < base::TimeDelta::FromHours(base::Time::kHoursPerDay)) { 133 if (since_clear < base::TimeDelta::FromHours(base::Time::kHoursPerDay)) {
133 ui::Accelerator acc = chrome::GetPrimaryChromeAcceleratorForCommandId( 134 ui::Accelerator acc = chrome::GetPrimaryChromeAcceleratorForCommandId(
134 IDC_NEW_INCOGNITO_WINDOW); 135 IDC_NEW_INCOGNITO_WINDOW);
135 DCHECK_NE(ui::VKEY_UNKNOWN, acc.key_code()); 136 DCHECK_NE(ui::VKEY_UNKNOWN, acc.key_code());
136 text = l10n_util::GetStringFUTF16(IDS_CLEAR_BROWSING_DATA_INFO_BAR_TEXT, 137 text = l10n_util::GetStringFUTF16(IDS_CLEAR_BROWSING_DATA_INFO_BAR_TEXT,
137 acc.GetShortcutText()); 138 acc.GetShortcutText());
138 } 139 }
139 } 140 }
140 141
141 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.setBannerText", 142 web_ui()->CallJavascriptFunctionUnsafe(
142 base::StringValue(text)); 143 "ClearBrowserDataOverlay.setBannerText", base::StringValue(text));
143 } 144 }
144 145
145 void ClearBrowserDataHandler::OnPageOpened(const base::ListValue* value) { 146 void ClearBrowserDataHandler::OnPageOpened(const base::ListValue* value) {
146 for (BrowsingDataCounter* counter : counters_) { 147 for (BrowsingDataCounter* counter : counters_) {
147 DCHECK(AreCountersEnabled()); 148 DCHECK(AreCountersEnabled());
148 counter->Restart(); 149 counter->Restart();
149 } 150 }
150 } 151 }
151 152
152 void ClearBrowserDataHandler::GetLocalizedValues( 153 void ClearBrowserDataHandler::GetLocalizedValues(
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 347
347 if (show_notice) { 348 if (show_notice) {
348 // Increment the preference. 349 // Increment the preference.
349 prefs->SetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes, 350 prefs->SetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes,
350 notice_shown_times + 1); 351 notice_shown_times + 1);
351 } 352 }
352 353
353 UMA_HISTOGRAM_BOOLEAN( 354 UMA_HISTOGRAM_BOOLEAN(
354 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); 355 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice);
355 356
356 web_ui()->CallJavascriptFunction( 357 web_ui()->CallJavascriptFunctionUnsafe("ClearBrowserDataOverlay.doneClearing",
357 "ClearBrowserDataOverlay.doneClearing", 358 base::FundamentalValue(show_notice));
358 base::FundamentalValue(show_notice));
359 } 359 }
360 360
361 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() { 361 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() {
362 web_ui()->CallJavascriptFunction( 362 web_ui()->CallJavascriptFunctionUnsafe(
363 "ClearBrowserDataOverlay.setAllowDeletingHistory", 363 "ClearBrowserDataOverlay.setAllowDeletingHistory",
364 base::FundamentalValue(*allow_deleting_browser_history_)); 364 base::FundamentalValue(*allow_deleting_browser_history_));
365 } 365 }
366 366
367 void ClearBrowserDataHandler::AddCounter( 367 void ClearBrowserDataHandler::AddCounter(
368 std::unique_ptr<BrowsingDataCounter> counter) { 368 std::unique_ptr<BrowsingDataCounter> counter) {
369 DCHECK(AreCountersEnabled()); 369 DCHECK(AreCountersEnabled());
370 370
371 counter->Init( 371 counter->Init(
372 Profile::FromWebUI(web_ui()), 372 Profile::FromWebUI(web_ui()),
373 base::Bind(&ClearBrowserDataHandler::UpdateCounterText, 373 base::Bind(&ClearBrowserDataHandler::UpdateCounterText,
374 base::Unretained(this))); 374 base::Unretained(this)));
375 counters_.push_back(std::move(counter)); 375 counters_.push_back(std::move(counter));
376 } 376 }
377 377
378 void ClearBrowserDataHandler::UpdateCounterText( 378 void ClearBrowserDataHandler::UpdateCounterText(
379 std::unique_ptr<BrowsingDataCounter::Result> result) { 379 std::unique_ptr<BrowsingDataCounter::Result> result) {
380 DCHECK(AreCountersEnabled()); 380 DCHECK(AreCountersEnabled());
381 web_ui()->CallJavascriptFunction( 381 web_ui()->CallJavascriptFunctionUnsafe(
382 "ClearBrowserDataOverlay.updateCounter", 382 "ClearBrowserDataOverlay.updateCounter",
383 base::StringValue(result->source()->GetPrefName()), 383 base::StringValue(result->source()->GetPrefName()),
384 base::StringValue(GetCounterTextFromResult(result.get()))); 384 base::StringValue(GetCounterTextFromResult(result.get())));
385 } 385 }
386 386
387 void ClearBrowserDataHandler::OnStateChanged() { 387 void ClearBrowserDataHandler::OnStateChanged() {
388 web_ui()->CallJavascriptFunction( 388 web_ui()->CallJavascriptFunctionUnsafe(
389 "ClearBrowserDataOverlay.updateSyncWarningAndHistoryFooter", 389 "ClearBrowserDataOverlay.updateSyncWarningAndHistoryFooter",
390 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), 390 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()),
391 base::FundamentalValue(should_show_history_notice_)); 391 base::FundamentalValue(should_show_history_notice_));
392 } 392 }
393 393
394 void ClearBrowserDataHandler::RefreshHistoryNotice() { 394 void ClearBrowserDataHandler::RefreshHistoryNotice() {
395 browsing_data_ui::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( 395 browsing_data_ui::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory(
396 sync_service_, 396 sync_service_,
397 WebHistoryServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())), 397 WebHistoryServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())),
398 base::Bind(&ClearBrowserDataHandler::UpdateHistoryNotice, 398 base::Bind(&ClearBrowserDataHandler::UpdateHistoryNotice,
(...skipping 22 matching lines...) Expand all
421 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", 421 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated",
422 should_show_history_notice_); 422 should_show_history_notice_);
423 } 423 }
424 424
425 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) { 425 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) {
426 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). 426 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes).
427 should_show_history_deletion_dialog_ = show; 427 should_show_history_deletion_dialog_ = show;
428 } 428 }
429 429
430 } // namespace options 430 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698