| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/md_bookmarks/bookmarks_message_handler.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/pref_names.h" |
| 11 #include "components/prefs/pref_change_registrar.h" |
| 12 #include "components/prefs/pref_service.h" |
| 13 |
| 14 BookmarksMessageHandler::BookmarksMessageHandler() {} |
| 15 |
| 16 BookmarksMessageHandler::~BookmarksMessageHandler() {} |
| 17 |
| 18 void BookmarksMessageHandler::RegisterMessages() { |
| 19 web_ui()->RegisterMessageCallback( |
| 20 "getIncognitoAvailability", |
| 21 base::Bind(&BookmarksMessageHandler::HandleGetIncognitoAvailability, |
| 22 base::Unretained(this))); |
| 23 } |
| 24 |
| 25 void BookmarksMessageHandler::OnJavascriptAllowed() { |
| 26 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 27 pref_change_registrar_.Init(prefs); |
| 28 pref_change_registrar_.Add( |
| 29 prefs::kIncognitoModeAvailability, |
| 30 base::Bind(&BookmarksMessageHandler::UpdateIncognitoAvailability, |
| 31 base::Unretained(this))); |
| 32 } |
| 33 |
| 34 void BookmarksMessageHandler::OnJavascriptDisallowed() { |
| 35 pref_change_registrar_.RemoveAll(); |
| 36 } |
| 37 |
| 38 void BookmarksMessageHandler::UpdateIncognitoAvailability() { |
| 39 FireWebUIListener("incognito-availability-changed", |
| 40 base::Value(GetIncognitoAvailability())); |
| 41 } |
| 42 |
| 43 int BookmarksMessageHandler::GetIncognitoAvailability() { |
| 44 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 45 return prefs->GetInteger(prefs::kIncognitoModeAvailability); |
| 46 } |
| 47 |
| 48 void BookmarksMessageHandler::HandleGetIncognitoAvailability( |
| 49 const base::ListValue* args) { |
| 50 CHECK_EQ(1U, args->GetSize()); |
| 51 const base::Value* callback_id; |
| 52 CHECK(args->Get(0, &callback_id)); |
| 53 |
| 54 AllowJavascript(); |
| 55 |
| 56 ResolveJavascriptCallback(*callback_id, |
| 57 base::Value(GetIncognitoAvailability())); |
| 58 } |
| OLD | NEW |