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

Unified Diff: chrome/browser/ui/webui/settings/profile_info_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/profile_info_handler.cc
diff --git a/chrome/browser/ui/webui/settings/profile_info_handler.cc b/chrome/browser/ui/webui/settings/profile_info_handler.cc
index f0928665bf3b78ba8119a9f73bf4946b86cf947f..6116ba9b8aedec4a31da8dd053f9bbe8523dda62 100644
--- a/chrome/browser/ui/webui/settings/profile_info_handler.cc
+++ b/chrome/browser/ui/webui/settings/profile_info_handler.cc
@@ -31,8 +31,7 @@ namespace settings {
const char ProfileInfoHandler::kProfileInfoChangedEventName[] =
"profile-info-changed";
-ProfileInfoHandler::ProfileInfoHandler(Profile* profile)
- : profile_(profile), observers_registered_(false) {}
+ProfileInfoHandler::ProfileInfoHandler(Profile* profile) : profile_(profile) {}
void ProfileInfoHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
@@ -40,10 +39,18 @@ void ProfileInfoHandler::RegisterMessages() {
base::Unretained(this)));
}
-void ProfileInfoHandler::RenderViewReused() {
- if (!observers_registered_)
- return;
+void ProfileInfoHandler::OnJavascriptAllowed() {
+ g_browser_process->profile_manager()
+ ->GetProfileAttributesStorage()
+ .AddObserver(this);
+
+#if defined(OS_CHROMEOS)
+ registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
+ content::NotificationService::AllSources());
+#endif
+}
+void ProfileInfoHandler::OnJavascriptDisallowed() {
g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.RemoveObserver(this);
@@ -51,8 +58,6 @@ void ProfileInfoHandler::RenderViewReused() {
#if defined(OS_CHROMEOS)
registrar_.RemoveAll();
#endif
-
- observers_registered_ = false;
}
#if defined(OS_CHROMEOS)
@@ -81,18 +86,7 @@ void ProfileInfoHandler::OnProfileAvatarChanged(
}
void ProfileInfoHandler::HandleGetProfileInfo(const base::ListValue* args) {
- if (!observers_registered_) {
- observers_registered_ = true;
-
- g_browser_process->profile_manager()
- ->GetProfileAttributesStorage()
- .AddObserver(this);
-
-#if defined(OS_CHROMEOS)
- registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
- content::NotificationService::AllSources());
-#endif
- }
+ AllowJavascript();
CHECK_EQ(1U, args->GetSize());
const base::Value* callback_id;

Powered by Google App Engine
This is Rietveld 408576698