Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Side by Side Diff: chrome/browser/ui/webui/md_flags_ui.cc

Issue 1223793018: Fake MD Flags sample WebUI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, update to GYP v2 Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/md_flags_ui.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/md_flags_ui.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/values.h"
10 #include "chrome/common/url_constants.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_ui.h"
14 #include "content/public/browser/web_ui_data_source.h"
15 #include "content/public/browser/web_ui_message_handler.h"
16 #include "grit/browser_resources.h"
17 #include "grit/components_strings.h"
18
19 class MdFlagsDOMHandler : public content::WebUIMessageHandler {
20 public:
21 MdFlagsDOMHandler() {}
22 ~MdFlagsDOMHandler() override {}
23
24 // WebUIMessageHandler:
25 void RegisterMessages() override;
26
27 void HandleRequestFlags(const base::ListValue* args);
28
29 private:
30 DISALLOW_COPY_AND_ASSIGN(MdFlagsDOMHandler);
31 };
32
33 void MdFlagsDOMHandler::RegisterMessages() {
34 web_ui()->RegisterMessageCallback("requestFlags",
35 base::Bind(&MdFlagsDOMHandler::HandleRequestFlags,
36 base::Unretained(this)));
37 }
38
39 void MdFlagsDOMHandler::HandleRequestFlags(const base::ListValue* args) {
40 base::ListValue flags;
41 base::DictionaryValue* flag1 = new base::DictionaryValue();
42 flag1->SetString("id", "trick-out-chromium");
43 flag1->SetString("name", "Trick out Chromium");
44 flag1->SetString("description", "Changes Chromium in some cool new way.");
45 flag1->SetBoolean("enabled", true);
46 flags.Append(flag1);
47 base::DictionaryValue* flag2 = new base::DictionaryValue();
48 flag2->SetString("id", "upside-down");
49 flag2->SetString("name", "Upside down browser");
50 flag2->SetString(
51 "description",
52 "Shows web pages upside down. "
53 "Experimentally supported for Australian users and Jake Tucker.");
54 flag2->SetBoolean("enabled", false);
55 flags.Append(flag2);
56 base::DictionaryValue* flag3 = new base::DictionaryValue();
57 flag3->SetString("id", "enable-easter-eggs");
58 flag3->SetString("name", "Enable easter eggs");
59 flag3->SetString(
60 "description",
61 "Enables easter eggs in the browser. Careful, eggs may crack, "
62 "leaving system vulnerable to viruses and bacteria.");
63 flag3->SetBoolean("enabled", false);
64 flags.Append(flag3);
65 base::DictionaryValue* flag4 = new base::DictionaryValue();
66 flag4->SetString("id", "hydra-processes");
67 flag4->SetString("name", "Enable Hydra processes");
68 flag4->SetString(
69 "description",
70 "Processes behave like the Hydra. Each time a process is killed, "
71 "two more are spun up to take its place. "
72 "Incompatible with the Heracles extension.");
73 flag4->SetBoolean("enabled", false);
74 flags.Append(flag4);
75 web_ui()->CallJavascriptFunction("md_flags.setFlags", flags);
76 }
77
78 MdFlagsUI::MdFlagsUI(content::WebUI* web_ui)
79 : content::WebUIController(web_ui) {
80 web_ui->AddMessageHandler(new MdFlagsDOMHandler());
81
82 content::WebUIDataSource* source =
83 content::WebUIDataSource::Create(chrome::kChromeUIMdFlagsHost);
84
85 // Localized strings.
86 source->AddLocalizedString("title", IDS_ABOUT_TITLE);
87 source->AddLocalizedString("warningText", IDS_FLAGS_UI_WARNING_TEXT);
88 source->AddLocalizedString("warningLabel", IDS_FLAGS_UI_WARNING_HEADER);
89 source->AddLocalizedString("warningHeader", IDS_FLAGS_UI_LONG_TITLE);
90 source->SetJsonPath("strings.js");
91
92 // Add required resources.
93 source->AddResourcePath("md_flags.css", IDR_MD_FLAGS_CSS);
94 source->AddResourcePath("md_flags.js", IDR_MD_FLAGS_JS);
95 source->AddResourcePath("flag.css", IDR_MD_FLAGS_FLAG_CSS);
96 source->AddResourcePath("flag.html", IDR_MD_FLAGS_FLAG_HTML);
97 source->AddResourcePath("flag.js", IDR_MD_FLAGS_FLAG_JS);
98 source->AddResourcePath("flags_table.css", IDR_MD_FLAGS_TABLE_CSS);
99 source->AddResourcePath("flags_table.html", IDR_MD_FLAGS_TABLE_HTML);
100 source->AddResourcePath("flags_table.js", IDR_MD_FLAGS_TABLE_JS);
101 source->SetDefaultResource(IDR_MD_FLAGS_HTML);
102
103 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(),
104 source);
105 }
106
107 MdFlagsUI::~MdFlagsUI() {
108 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/md_flags_ui.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698