| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/settings/on_startup_handler.h" | 5 #include "chrome/browser/ui/webui/settings/on_startup_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/extensions/settings_api_helpers.h" | 10 #include "chrome/browser/extensions/settings_api_helpers.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/webui/settings_utils.h" |
| 12 #include "content/public/browser/web_ui.h" | 13 #include "content/public/browser/web_ui.h" |
| 13 #include "extensions/browser/extension_system.h" | 14 #include "extensions/browser/extension_system.h" |
| 14 #include "extensions/browser/management_policy.h" | 15 #include "extensions/browser/management_policy.h" |
| 15 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
| 16 | 17 |
| 17 namespace settings { | 18 namespace settings { |
| 18 | 19 |
| 19 OnStartupHandler::OnStartupHandler() {} | 20 OnStartupHandler::OnStartupHandler() {} |
| 20 OnStartupHandler::~OnStartupHandler() {} | 21 OnStartupHandler::~OnStartupHandler() {} |
| 21 | 22 |
| 22 void OnStartupHandler::RegisterMessages() { | 23 void OnStartupHandler::RegisterMessages() { |
| 23 web_ui()->RegisterMessageCallback( | 24 web_ui()->RegisterMessageCallback( |
| 24 "getNtpExtension", base::Bind(&OnStartupHandler::HandleGetNtpExtension, | 25 "getNtpExtension", base::Bind(&OnStartupHandler::HandleGetNtpExtension, |
| 25 base::Unretained(this))); | 26 base::Unretained(this))); |
| 27 web_ui()->RegisterMessageCallback( |
| 28 "validateStartupPage", |
| 29 base::Bind(&OnStartupHandler::HandleValidateStartupPage, |
| 30 base::Unretained(this))); |
| 26 } | 31 } |
| 27 | 32 |
| 28 void OnStartupHandler::HandleGetNtpExtension(const base::ListValue* args) { | 33 void OnStartupHandler::HandleGetNtpExtension(const base::ListValue* args) { |
| 29 const base::Value* callback_id; | 34 const base::Value* callback_id; |
| 30 CHECK(args->Get(0, &callback_id)); | 35 CHECK(args->Get(0, &callback_id)); |
| 31 | 36 |
| 32 AllowJavascript(); | 37 AllowJavascript(); |
| 33 | 38 |
| 34 Profile* profile = Profile::FromWebUI(web_ui()); | 39 Profile* profile = Profile::FromWebUI(web_ui()); |
| 35 const extensions::Extension* ntp_extension = | 40 const extensions::Extension* ntp_extension = |
| 36 extensions::GetExtensionOverridingNewTabPage(profile); | 41 extensions::GetExtensionOverridingNewTabPage(profile); |
| 37 | 42 |
| 38 if (!ntp_extension) { | 43 if (!ntp_extension) { |
| 39 ResolveJavascriptCallback(*callback_id, *base::Value::CreateNullValue()); | 44 ResolveJavascriptCallback(*callback_id, *base::Value::CreateNullValue()); |
| 40 return; | 45 return; |
| 41 } | 46 } |
| 42 | 47 |
| 43 base::DictionaryValue dict; | 48 base::DictionaryValue dict; |
| 44 dict.SetString("id", ntp_extension->id()); | 49 dict.SetString("id", ntp_extension->id()); |
| 45 dict.SetString("name", ntp_extension->name()); | 50 dict.SetString("name", ntp_extension->name()); |
| 46 dict.SetBoolean("canBeDisabled", | 51 dict.SetBoolean("canBeDisabled", |
| 47 !extensions::ExtensionSystem::Get(profile) | 52 !extensions::ExtensionSystem::Get(profile) |
| 48 ->management_policy() | 53 ->management_policy() |
| 49 ->MustRemainEnabled(ntp_extension, nullptr)); | 54 ->MustRemainEnabled(ntp_extension, nullptr)); |
| 50 ResolveJavascriptCallback(*callback_id, dict); | 55 ResolveJavascriptCallback(*callback_id, dict); |
| 51 } | 56 } |
| 52 | 57 |
| 58 void OnStartupHandler::HandleValidateStartupPage(const base::ListValue* args) { |
| 59 AllowJavascript(); |
| 60 |
| 61 CHECK_EQ(args->GetSize(), 2U); |
| 62 |
| 63 const base::Value* callback_id; |
| 64 CHECK(args->Get(0, &callback_id)); |
| 65 |
| 66 std::string url_string; |
| 67 CHECK(args->GetString(1, &url_string)); |
| 68 |
| 69 bool valid = settings_utils::FixupAndValidateStartupPage(url_string, nullptr); |
| 70 ResolveJavascriptCallback(*callback_id, base::Value(valid)); |
| 71 } |
| 72 |
| 53 } // namespace settings | 73 } // namespace settings |
| OLD | NEW |