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

Unified Diff: chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc

Issue 1896463003: WebUI: Add JavaScript lifecycle-control to WebUIMessageHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc
diff --git a/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc b/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc
index 4245c3bcdfbd65fe0dfbcff7856bc73c4fda2921..8263bfa72b9e6a225595ba98cf2e1b2228edd293 100644
--- a/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc
+++ b/chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler.cc
@@ -22,13 +22,12 @@ namespace chromeos {
namespace settings {
EasyUnlockSettingsHandler::EasyUnlockSettingsHandler(Profile* profile)
- : profile_(profile), observers_registered_(false) {
+ : profile_(profile) {
profile_pref_registrar_.Init(profile->GetPrefs());
}
EasyUnlockSettingsHandler::~EasyUnlockSettingsHandler() {
- if (observers_registered_)
- EasyUnlockService::Get(profile_)->RemoveObserver(this);
+ EasyUnlockService::Get(profile_)->RemoveObserver(this);
}
EasyUnlockSettingsHandler* EasyUnlockSettingsHandler::Create(
@@ -73,27 +72,28 @@ void EasyUnlockSettingsHandler::RegisterMessages() {
base::Unretained(this)));
}
-void EasyUnlockSettingsHandler::RenderViewReused() {
- // When the page is reloaded, we clear our observers and re-register when
- // the new page's DOM is ready.
- if (!observers_registered_)
- return;
+void EasyUnlockSettingsHandler::OnJavascriptAllowed() {
+ EasyUnlockService::Get(profile_)->AddObserver(this);
+ profile_pref_registrar_.Add(
+ prefs::kEasyUnlockPairing,
+ base::Bind(&EasyUnlockSettingsHandler::SendEnabledStatus,
+ base::Unretained(this)));
+}
+
+void EasyUnlockSettingsHandler::OnJavascriptDisallowed() {
EasyUnlockService::Get(profile_)->RemoveObserver(this);
profile_pref_registrar_.RemoveAll();
-
- observers_registered_ = false;
}
void EasyUnlockSettingsHandler::OnTurnOffOperationStatusChanged() {
- web_ui()->CallJavascriptFunction(
- "cr.webUIListenerCallback",
- base::StringValue("easy-unlock-turn-off-flow-status"),
- base::StringValue(GetTurnOffFlowStatus()));
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("easy-unlock-turn-off-flow-status"),
+ base::StringValue(GetTurnOffFlowStatus()));
}
void EasyUnlockSettingsHandler::SendEnabledStatus() {
- web_ui()->CallJavascriptFunction(
+ CallJavascriptFunction(
"cr.webUIListenerCallback",
base::StringValue("easy-unlock-enabled-status"),
base::FundamentalValue(EasyUnlockService::Get(profile_)->IsEnabled()));
@@ -127,18 +127,7 @@ std::string EasyUnlockSettingsHandler::GetTurnOffFlowStatus() {
void EasyUnlockSettingsHandler::HandleGetEnabledStatus(
const base::ListValue* args) {
- // This method is called when the DOM is first ready. Therefore we initialize
- // our observers here.
- if (!observers_registered_) {
- EasyUnlockService::Get(profile_)->AddObserver(this);
-
- profile_pref_registrar_.Add(
- prefs::kEasyUnlockPairing,
- base::Bind(&EasyUnlockSettingsHandler::SendEnabledStatus,
- base::Unretained(this)));
-
- observers_registered_ = true;
- }
+ AllowJavascript();
CHECK_EQ(1U, args->GetSize());
const base::Value* callback_id;

Powered by Google App Engine
This is Rietveld 408576698