OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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/polymer_flags_ui.h" |
| 6 |
| 7 // todo |
| 8 #include <string> |
| 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" |
| 12 #include "base/values.h" |
| 13 #include "chrome/common/url_constants.h" |
| 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_ui.h" |
| 17 #include "content/public/browser/web_ui_data_source.h" |
| 18 #include "content/public/browser/web_ui_message_handler.h" |
| 19 #include "grit/browser_resources.h" |
| 20 #include "grit/settings_resources.h" |
| 21 #include "grit/settings_resources_map.h" |
| 22 |
| 23 class PolymerFlagsDOMHandler : public content::WebUIMessageHandler { |
| 24 public: |
| 25 PolymerFlagsDOMHandler() {} |
| 26 ~PolymerFlagsDOMHandler() override {} |
| 27 |
| 28 // WebUIMessageHandler: |
| 29 void RegisterMessages() override; |
| 30 |
| 31 void HandleRequestFlags(const base::ListValue* args); |
| 32 |
| 33 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(PolymerFlagsDOMHandler); |
| 35 }; |
| 36 |
| 37 void PolymerFlagsDOMHandler::RegisterMessages() { |
| 38 web_ui()->RegisterMessageCallback("requestFlags", |
| 39 base::Bind(&PolymerFlagsDOMHandler::HandleRequestFlags, |
| 40 base::Unretained(this))); |
| 41 } |
| 42 |
| 43 void PolymerFlagsDOMHandler::HandleRequestFlags(const base::ListValue* args) { |
| 44 base::ListValue flags; |
| 45 base::DictionaryValue* flag1 = new base::DictionaryValue(); |
| 46 flag1->SetString("id", "trick-out-chromium"); |
| 47 flag1->SetString("name", "Trick out Chromium"); |
| 48 flag1->SetString("description", "Changes Chromium in some cool new way."); |
| 49 flag1->SetBoolean("enabled", true); |
| 50 flags.Append(flag1); |
| 51 base::DictionaryValue* flag2 = new base::DictionaryValue(); |
| 52 flag2->SetString("id", "upside-down"); |
| 53 flag2->SetString("name", "Upside down browser"); |
| 54 flag2->SetString( |
| 55 "description", |
| 56 "Shows web pages upside down. " |
| 57 "Experimentally supported for Australian users and Jake Tucker."); |
| 58 flag2->SetBoolean("enabled", false); |
| 59 flags.Append(flag2); |
| 60 base::DictionaryValue* flag3 = new base::DictionaryValue(); |
| 61 flag3->SetString("id", "enable-easter-eggs"); |
| 62 flag3->SetString("name", "Enable easter eggs"); |
| 63 flag3->SetString( |
| 64 "description", |
| 65 "Enables easter eggs in the browser. Careful, eggs may crack, " |
| 66 "leaving system vulnerable to viruses and bacteria."); |
| 67 flag3->SetBoolean("enabled", false); |
| 68 flags.Append(flag3); |
| 69 base::DictionaryValue* flag4 = new base::DictionaryValue(); |
| 70 flag4->SetString("id", "hydra-processes"); |
| 71 flag4->SetString("name", "Enable Hydra processes"); |
| 72 flag4->SetString( |
| 73 "description", |
| 74 "Processes behave like the Hydra. Each time a process is killed, " |
| 75 "two more are spun up to take its place. " |
| 76 "Incompatible with the Heracles extension."); |
| 77 flag4->SetBoolean("enabled", false); |
| 78 flags.Append(flag4); |
| 79 web_ui()->CallJavascriptFunction("PolymerFlags.setFlags", flags); |
| 80 } |
| 81 |
| 82 PolymerFlagsUI::PolymerFlagsUI(content::WebUI* web_ui) |
| 83 : content::WebUIController(web_ui) { |
| 84 web_ui->AddMessageHandler(new PolymerFlagsDOMHandler()); |
| 85 |
| 86 content::WebUIDataSource* source = |
| 87 content::WebUIDataSource::Create(chrome::kChromeUIPolymerFlagsHost); |
| 88 |
| 89 // Localized strings. |
| 90 source->AddLocalizedString("title", IDS_ABOUT_TITLE); |
| 91 source->AddLocalizedString("warningText", IDS_FLAGS_WARNING_TEXT); |
| 92 source->AddLocalizedString("warningLabel", IDS_FLAGS_WARNING_HEADER); |
| 93 source->AddLocalizedString("warningHeader", IDS_FLAGS_LONG_TITLE); |
| 94 source->SetJsonPath("strings.js"); |
| 95 |
| 96 // Add required resources. |
| 97 source->AddResourcePath("polymer_flags.css", IDR_POLYMER_FLAGS_CSS); |
| 98 source->AddResourcePath("polymer_flags.js", IDR_POLYMER_FLAGS_JS); |
| 99 source->AddResourcePath("flag.css", IDR_POLYMER_FLAGS_FLAG_CSS); |
| 100 source->AddResourcePath("flag.html", IDR_POLYMER_FLAGS_FLAG_HTML); |
| 101 source->AddResourcePath("flag.js", IDR_POLYMER_FLAGS_FLAG_JS); |
| 102 source->AddResourcePath("flags_table.css", IDR_POLYMER_FLAGS_TABLE_CSS); |
| 103 source->AddResourcePath("flags_table.html", IDR_POLYMER_FLAGS_TABLE_HTML); |
| 104 source->AddResourcePath("flags_table.js", IDR_POLYMER_FLAGS_TABLE_JS); |
| 105 source->SetDefaultResource(IDR_POLYMER_FLAGS_HTML); |
| 106 |
| 107 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), |
| 108 source); |
| 109 } |
| 110 |
| 111 PolymerFlagsUI::~PolymerFlagsUI() { |
| 112 } |
OLD | NEW |