1 // Copyright (c) 2011 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/options/options_managed_banner_handler.h" 6 7 #include "base/string_util.h" 8 #include "base/values.h" 9 #include "chrome/browser/profiles/profile.h" 10 #include "content/browser/webui/web_ui.h" 11 12 OptionsManagedBannerHandler::OptionsManagedBannerHandler( 13 WebUI* web_ui, const string16& page_name, OptionsPage page) 14 : policy::ManagedPrefsBannerBase(web_ui->GetProfile()->GetPrefs(), page), 15 web_ui_(web_ui), page_name_(page_name), page_(page) { 16 // Initialize the visibility state of the banner. 17 SetupBannerVisibility(); 18 } 19 20 OptionsManagedBannerHandler::~OptionsManagedBannerHandler() {} 21 22 void OptionsManagedBannerHandler::OnUpdateVisibility() { 23 // A preference that may be managed has changed. Update our visibility 24 // state. 25 SetupBannerVisibility(); 26 } 27 28 void OptionsManagedBannerHandler::SetupBannerVisibility() { 29 // Construct the banner visibility script name. 30 std::string script = "options." + UTF16ToASCII(page_name_) + 31 ".getInstance().setManagedBannerVisibility"; 32 33 // Get the visiblity value from the base class. 34 FundamentalValue visibility(DetermineVisibility()); 35 36 // Set the managed state in the javascript handler. 37 web_ui_->CallJavascriptFunction(script, visibility); 38 } 39