Index: chrome/browser/ui/webui/md_flags_ui.cc |
diff --git a/chrome/browser/ui/webui/md_flags_ui.cc b/chrome/browser/ui/webui/md_flags_ui.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cdcb462bd31948fac4d990c0869767c5da2f91dc |
--- /dev/null |
+++ b/chrome/browser/ui/webui/md_flags_ui.cc |
@@ -0,0 +1,108 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/md_flags_ui.h" |
+ |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
+#include "base/values.h" |
+#include "chrome/common/url_constants.h" |
+#include "chrome/grit/generated_resources.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/browser/web_ui.h" |
+#include "content/public/browser/web_ui_data_source.h" |
+#include "content/public/browser/web_ui_message_handler.h" |
+#include "grit/browser_resources.h" |
+#include "grit/components_strings.h" |
+ |
+class MdFlagsDOMHandler : public content::WebUIMessageHandler { |
+ public: |
+ MdFlagsDOMHandler() {} |
+ ~MdFlagsDOMHandler() override {} |
+ |
+ // WebUIMessageHandler: |
+ void RegisterMessages() override; |
+ |
+ void HandleRequestFlags(const base::ListValue* args); |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(MdFlagsDOMHandler); |
+}; |
+ |
+void MdFlagsDOMHandler::RegisterMessages() { |
+ web_ui()->RegisterMessageCallback("requestFlags", |
+ base::Bind(&MdFlagsDOMHandler::HandleRequestFlags, |
+ base::Unretained(this))); |
+} |
+ |
+void MdFlagsDOMHandler::HandleRequestFlags(const base::ListValue* args) { |
+ base::ListValue flags; |
+ base::DictionaryValue* flag1 = new base::DictionaryValue(); |
+ flag1->SetString("id", "trick-out-chromium"); |
+ flag1->SetString("name", "Trick out Chromium"); |
+ flag1->SetString("description", "Changes Chromium in some cool new way."); |
+ flag1->SetBoolean("enabled", true); |
+ flags.Append(flag1); |
+ base::DictionaryValue* flag2 = new base::DictionaryValue(); |
+ flag2->SetString("id", "upside-down"); |
+ flag2->SetString("name", "Upside down browser"); |
+ flag2->SetString( |
+ "description", |
+ "Shows web pages upside down. " |
+ "Experimentally supported for Australian users and Jake Tucker."); |
+ flag2->SetBoolean("enabled", false); |
+ flags.Append(flag2); |
+ base::DictionaryValue* flag3 = new base::DictionaryValue(); |
+ flag3->SetString("id", "enable-easter-eggs"); |
+ flag3->SetString("name", "Enable easter eggs"); |
+ flag3->SetString( |
+ "description", |
+ "Enables easter eggs in the browser. Careful, eggs may crack, " |
+ "leaving system vulnerable to viruses and bacteria."); |
+ flag3->SetBoolean("enabled", false); |
+ flags.Append(flag3); |
+ base::DictionaryValue* flag4 = new base::DictionaryValue(); |
+ flag4->SetString("id", "hydra-processes"); |
+ flag4->SetString("name", "Enable Hydra processes"); |
+ flag4->SetString( |
+ "description", |
+ "Processes behave like the Hydra. Each time a process is killed, " |
+ "two more are spun up to take its place. " |
+ "Incompatible with the Heracles extension."); |
+ flag4->SetBoolean("enabled", false); |
+ flags.Append(flag4); |
+ web_ui()->CallJavascriptFunction("md_flags.setFlags", flags); |
+} |
+ |
+MdFlagsUI::MdFlagsUI(content::WebUI* web_ui) |
+ : content::WebUIController(web_ui) { |
+ web_ui->AddMessageHandler(new MdFlagsDOMHandler()); |
+ |
+ content::WebUIDataSource* source = |
+ content::WebUIDataSource::Create(chrome::kChromeUIMdFlagsHost); |
+ |
+ // Localized strings. |
+ source->AddLocalizedString("title", IDS_ABOUT_TITLE); |
+ source->AddLocalizedString("warningText", IDS_FLAGS_UI_WARNING_TEXT); |
+ source->AddLocalizedString("warningLabel", IDS_FLAGS_UI_WARNING_HEADER); |
+ source->AddLocalizedString("warningHeader", IDS_FLAGS_UI_LONG_TITLE); |
+ source->SetJsonPath("strings.js"); |
+ |
+ // Add required resources. |
+ source->AddResourcePath("md_flags.css", IDR_MD_FLAGS_CSS); |
+ source->AddResourcePath("md_flags.js", IDR_MD_FLAGS_JS); |
+ source->AddResourcePath("flag.css", IDR_MD_FLAGS_FLAG_CSS); |
+ source->AddResourcePath("flag.html", IDR_MD_FLAGS_FLAG_HTML); |
+ source->AddResourcePath("flag.js", IDR_MD_FLAGS_FLAG_JS); |
+ source->AddResourcePath("flags_table.css", IDR_MD_FLAGS_TABLE_CSS); |
+ source->AddResourcePath("flags_table.html", IDR_MD_FLAGS_TABLE_HTML); |
+ source->AddResourcePath("flags_table.js", IDR_MD_FLAGS_TABLE_JS); |
+ source->SetDefaultResource(IDR_MD_FLAGS_HTML); |
+ |
+ content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), |
+ source); |
+} |
+ |
+MdFlagsUI::~MdFlagsUI() { |
+} |