OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/settings/on_startup_handler.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" |
| 10 #include "chrome/browser/extensions/settings_api_helpers.h" |
| 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "content/public/browser/web_ui.h" |
| 13 #include "extensions/browser/extension_system.h" |
| 14 #include "extensions/browser/management_policy.h" |
| 15 #include "extensions/common/extension.h" |
| 16 |
| 17 namespace settings { |
| 18 |
| 19 OnStartupHandler::OnStartupHandler() {} |
| 20 OnStartupHandler::~OnStartupHandler() {} |
| 21 |
| 22 void OnStartupHandler::RegisterMessages() { |
| 23 web_ui()->RegisterMessageCallback( |
| 24 "getNtpExtension", base::Bind(&OnStartupHandler::HandleGetNtpExtension, |
| 25 base::Unretained(this))); |
| 26 } |
| 27 |
| 28 void OnStartupHandler::HandleGetNtpExtension(const base::ListValue* args) { |
| 29 const base::Value* callback_id; |
| 30 CHECK(args->Get(0, &callback_id)); |
| 31 |
| 32 AllowJavascript(); |
| 33 |
| 34 Profile* profile = Profile::FromWebUI(web_ui()); |
| 35 const extensions::Extension* ntp_extension = |
| 36 extensions::GetExtensionOverridingNewTabPage(profile); |
| 37 |
| 38 if (!ntp_extension) { |
| 39 ResolveJavascriptCallback(*callback_id, *base::Value::CreateNullValue()); |
| 40 return; |
| 41 } |
| 42 |
| 43 base::DictionaryValue dict; |
| 44 dict.SetString("id", ntp_extension->id()); |
| 45 dict.SetString("name", ntp_extension->name()); |
| 46 dict.SetBoolean("canBeDisabled", |
| 47 !extensions::ExtensionSystem::Get(profile) |
| 48 ->management_policy() |
| 49 ->MustRemainEnabled(ntp_extension, nullptr)); |
| 50 ResolveJavascriptCallback(*callback_id, dict); |
| 51 } |
| 52 |
| 53 } // namespace settings |
OLD | NEW |