Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / conflicts_ui.cc
blobe101888d87cd232748182aa63e934b199e5e7149
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/webui/conflicts_ui.h"
7 #if defined(OS_WIN)
9 #include <string>
11 #include "base/bind.h"
12 #include "base/bind_helpers.h"
13 #include "base/memory/ref_counted_memory.h"
14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h"
17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/enumerate_modules_model_win.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/url_constants.h"
21 #include "chrome/grit/chromium_strings.h"
22 #include "chrome/grit/generated_resources.h"
23 #include "content/public/browser/notification_observer.h"
24 #include "content/public/browser/notification_registrar.h"
25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/user_metrics.h"
27 #include "content/public/browser/web_contents.h"
28 #include "content/public/browser/web_ui.h"
29 #include "content/public/browser/web_ui_data_source.h"
30 #include "content/public/browser/web_ui_message_handler.h"
31 #include "grit/browser_resources.h"
32 #include "grit/components_strings.h"
33 #include "grit/theme_resources.h"
34 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/layout.h"
36 #include "ui/base/resource/resource_bundle.h"
38 using base::UserMetricsAction;
39 using content::WebContents;
40 using content::WebUIMessageHandler;
42 namespace {
44 content::WebUIDataSource* CreateConflictsUIHTMLSource() {
45 content::WebUIDataSource* source =
46 content::WebUIDataSource::Create(chrome::kChromeUIConflictsHost);
48 source->AddLocalizedString("loadingMessage", IDS_CONFLICTS_LOADING_MESSAGE);
49 source->AddLocalizedString("modulesLongTitle",
50 IDS_CONFLICTS_CHECK_PAGE_TITLE_LONG);
51 source->AddLocalizedString("modulesBlurb", IDS_CONFLICTS_EXPLANATION_TEXT);
52 source->AddLocalizedString("moduleSuspectedBad",
53 IDS_CONFLICTS_CHECK_WARNING_SUSPECTED);
54 source->AddLocalizedString("moduleConfirmedBad",
55 IDS_CONFLICTS_CHECK_WARNING_CONFIRMED);
56 source->AddLocalizedString("helpCenterLink", IDS_LEARN_MORE);
57 source->AddLocalizedString("investigatingText",
58 IDS_CONFLICTS_CHECK_INVESTIGATING);
59 source->AddLocalizedString("modulesNoneLoaded",
60 IDS_CONFLICTS_NO_MODULES_LOADED);
61 source->AddLocalizedString("headerSoftware", IDS_CONFLICTS_HEADER_SOFTWARE);
62 source->AddLocalizedString("headerSignedBy", IDS_CONFLICTS_HEADER_SIGNED_BY);
63 source->AddLocalizedString("headerLocation", IDS_CONFLICTS_HEADER_LOCATION);
64 source->AddLocalizedString("headerVersion", IDS_CONFLICTS_HEADER_VERSION);
65 source->AddLocalizedString("headerHelpTip", IDS_CONFLICTS_HEADER_HELP_TIP);
66 source->SetJsonPath("strings.js");
67 source->AddResourcePath("conflicts.js", IDR_ABOUT_CONFLICTS_JS);
68 source->SetDefaultResource(IDR_ABOUT_CONFLICTS_HTML);
69 return source;
72 ////////////////////////////////////////////////////////////////////////////////
74 // ConflictsDOMHandler
76 ////////////////////////////////////////////////////////////////////////////////
78 // The handler for JavaScript messages for the about:flags page.
79 class ConflictsDOMHandler : public WebUIMessageHandler,
80 public content::NotificationObserver {
81 public:
82 ConflictsDOMHandler() {}
83 ~ConflictsDOMHandler() override {}
85 // WebUIMessageHandler implementation.
86 void RegisterMessages() override;
88 // Callback for the "requestModuleList" message.
89 void HandleRequestModuleList(const base::ListValue* args);
91 private:
92 void SendModuleList();
94 void Observe(int type,
95 const content::NotificationSource& source,
96 const content::NotificationDetails& details) override;
98 content::NotificationRegistrar registrar_;
100 DISALLOW_COPY_AND_ASSIGN(ConflictsDOMHandler);
103 void ConflictsDOMHandler::RegisterMessages() {
104 web_ui()->RegisterMessageCallback("requestModuleList",
105 base::Bind(&ConflictsDOMHandler::HandleRequestModuleList,
106 base::Unretained(this)));
109 void ConflictsDOMHandler::HandleRequestModuleList(const base::ListValue* args) {
110 // This request is handled asynchronously. See Observe for when we reply back.
111 registrar_.Add(this, chrome::NOTIFICATION_MODULE_LIST_ENUMERATED,
112 content::NotificationService::AllSources());
113 EnumerateModulesModel::GetInstance()->ScanNow();
116 void ConflictsDOMHandler::SendModuleList() {
117 EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetInstance();
118 base::ListValue* list = loaded_modules->GetModuleList();
119 base::DictionaryValue results;
120 results.Set("moduleList", list);
122 // Add the section title and the total count for bad modules found.
123 int confirmed_bad = loaded_modules->confirmed_bad_modules_detected();
124 int suspected_bad = loaded_modules->suspected_bad_modules_detected();
125 base::string16 table_title;
126 if (!confirmed_bad && !suspected_bad) {
127 table_title += l10n_util::GetStringFUTF16(
128 IDS_CONFLICTS_CHECK_PAGE_TABLE_TITLE_SUFFIX_ONE,
129 base::IntToString16(list->GetSize()));
130 } else {
131 table_title += l10n_util::GetStringFUTF16(
132 IDS_CONFLICTS_CHECK_PAGE_TABLE_TITLE_SUFFIX_TWO,
133 base::IntToString16(list->GetSize()),
134 base::IntToString16(confirmed_bad),
135 base::IntToString16(suspected_bad));
137 results.SetString("modulesTableTitle", table_title);
139 web_ui()->CallJavascriptFunction("returnModuleList", results);
142 void ConflictsDOMHandler::Observe(int type,
143 const content::NotificationSource& source,
144 const content::NotificationDetails& details) {
145 switch (type) {
146 case chrome::NOTIFICATION_MODULE_LIST_ENUMERATED:
147 SendModuleList();
148 registrar_.RemoveAll();
149 break;
150 default:
151 NOTREACHED();
152 break;
156 } // namespace
158 ///////////////////////////////////////////////////////////////////////////////
160 // ConflictsUI
162 ///////////////////////////////////////////////////////////////////////////////
164 ConflictsUI::ConflictsUI(content::WebUI* web_ui) : WebUIController(web_ui) {
165 content::RecordAction(UserMetricsAction("ViewAboutConflicts"));
166 web_ui->AddMessageHandler(new ConflictsDOMHandler());
168 // Set up the about:conflicts source.
169 Profile* profile = Profile::FromWebUI(web_ui);
170 content::WebUIDataSource::Add(profile, CreateConflictsUIHTMLSource());
173 // static
174 base::RefCountedMemory* ConflictsUI::GetFaviconResourceBytes(
175 ui::ScaleFactor scale_factor) {
176 return static_cast<base::RefCountedMemory*>(
177 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
178 IDR_CONFLICT_FAVICON, scale_factor));
181 #endif