OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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/dom_ui/conflicts_ui.h" |
| 6 |
| 7 #if defined(OS_WIN) |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "app/l10n_util.h" |
| 12 #include "app/resource_bundle.h" |
| 13 #include "base/string_number_conversions.h" |
| 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" |
| 16 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
| 17 #include "chrome/browser/enumerate_modules_model_win.h" |
| 18 #include "chrome/common/jstemplate_builder.h" |
| 19 #include "chrome/common/notification_observer.h" |
| 20 #include "chrome/common/notification_registrar.h" |
| 21 #include "chrome/common/notification_service.h" |
| 22 #include "chrome/common/url_constants.h" |
| 23 #include "grit/browser_resources.h" |
| 24 #include "grit/chromium_strings.h" |
| 25 #include "grit/generated_resources.h" |
| 26 #include "grit/theme_resources.h" |
| 27 |
| 28 namespace { |
| 29 |
| 30 //////////////////////////////////////////////////////////////////////////////// |
| 31 // |
| 32 // ConflictsUIHTMLSource |
| 33 // |
| 34 //////////////////////////////////////////////////////////////////////////////// |
| 35 |
| 36 class ConflictsUIHTMLSource : public ChromeURLDataManager::DataSource { |
| 37 public: |
| 38 ConflictsUIHTMLSource() |
| 39 : DataSource(chrome::kChromeUIConflictsHost, MessageLoop::current()) {} |
| 40 |
| 41 // Called when the network layer has requested a resource underneath |
| 42 // the path we registered. |
| 43 virtual void StartDataRequest(const std::string& path, |
| 44 bool is_off_the_record, |
| 45 int request_id); |
| 46 |
| 47 virtual std::string GetMimeType(const std::string&) const { |
| 48 return "text/html"; |
| 49 } |
| 50 |
| 51 private: |
| 52 DISALLOW_COPY_AND_ASSIGN(ConflictsUIHTMLSource); |
| 53 }; |
| 54 |
| 55 void ConflictsUIHTMLSource::StartDataRequest(const std::string& path, |
| 56 bool is_off_the_record, |
| 57 int request_id) { |
| 58 // Strings used in the JsTemplate file. |
| 59 DictionaryValue localized_strings; |
| 60 localized_strings.SetString("modulesLongTitle", |
| 61 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_PAGE_TITLE_LONG)); |
| 62 localized_strings.SetString("modulesBlurb", |
| 63 l10n_util::GetStringUTF16(IDS_CONFLICTS_EXPLANATION_TEXT)); |
| 64 localized_strings.SetString("moduleSuspectedBad", |
| 65 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_WARNING_SUSPECTED)); |
| 66 localized_strings.SetString("moduleConfirmedBad", |
| 67 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_WARNING_CONFIRMED)); |
| 68 localized_strings.SetString("helpCenterLink", |
| 69 l10n_util::GetStringUTF16(IDS_CONFLICTS_HELP_CENTER_LINK)); |
| 70 localized_strings.SetString("investigatingText", |
| 71 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_INVESTIGATING)); |
| 72 localized_strings.SetString("modulesNoneLoaded", |
| 73 l10n_util::GetStringUTF16(IDS_CONFLICTS_NO_MODULES_LOADED)); |
| 74 localized_strings.SetString("headerSoftware", |
| 75 l10n_util::GetStringUTF16(IDS_CONFLICTS_HEADER_SOFTWARE)); |
| 76 localized_strings.SetString("headerSignedBy", |
| 77 l10n_util::GetStringUTF16(IDS_CONFLICTS_HEADER_SIGNED_BY)); |
| 78 localized_strings.SetString("headerLocation", |
| 79 l10n_util::GetStringUTF16(IDS_CONFLICTS_HEADER_LOCATION)); |
| 80 localized_strings.SetString("headerWarning", |
| 81 l10n_util::GetStringUTF16(IDS_CONFLICTS_HEADER_WARNING)); |
| 82 localized_strings.SetString("headerHelpTip", |
| 83 l10n_util::GetStringUTF16(IDS_CONFLICTS_HEADER_HELP_TIP)); |
| 84 |
| 85 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); |
| 86 |
| 87 static const base::StringPiece flags_html( |
| 88 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 89 IDR_ABOUT_CONFLICTS_HTML)); |
| 90 std::string full_html(flags_html.data(), flags_html.size()); |
| 91 jstemplate_builder::AppendJsonHtml(&localized_strings, &full_html); |
| 92 jstemplate_builder::AppendI18nTemplateSourceHtml(&full_html); |
| 93 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html); |
| 94 jstemplate_builder::AppendJsTemplateSourceHtml(&full_html); |
| 95 |
| 96 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| 97 html_bytes->data.resize(full_html.size()); |
| 98 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); |
| 99 |
| 100 SendResponse(request_id, html_bytes); |
| 101 } |
| 102 |
| 103 //////////////////////////////////////////////////////////////////////////////// |
| 104 // |
| 105 // ConflictsDOMHandler |
| 106 // |
| 107 //////////////////////////////////////////////////////////////////////////////// |
| 108 |
| 109 // The handler for Javascript messages for the about:flags page. |
| 110 class ConflictsDOMHandler : public DOMMessageHandler, |
| 111 public NotificationObserver { |
| 112 public: |
| 113 ConflictsDOMHandler() {} |
| 114 virtual ~ConflictsDOMHandler() {} |
| 115 |
| 116 // DOMMessageHandler implementation. |
| 117 virtual void RegisterMessages(); |
| 118 |
| 119 // Callback for the "requestModuleList" message. |
| 120 void HandleRequestModuleList(const ListValue* args); |
| 121 |
| 122 private: |
| 123 void SendModuleList(); |
| 124 |
| 125 void Observe(NotificationType type, |
| 126 const NotificationSource& source, |
| 127 const NotificationDetails& details); |
| 128 |
| 129 NotificationRegistrar registrar_; |
| 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(ConflictsDOMHandler); |
| 132 }; |
| 133 |
| 134 void ConflictsDOMHandler::RegisterMessages() { |
| 135 dom_ui_->RegisterMessageCallback("requestModuleList", |
| 136 NewCallback(this, &ConflictsDOMHandler::HandleRequestModuleList)); |
| 137 } |
| 138 |
| 139 void ConflictsDOMHandler::HandleRequestModuleList(const ListValue* args) { |
| 140 // This request is handled asynchronously. See Observe for when we reply back. |
| 141 registrar_.Add(this, NotificationType::MODULE_LIST_ENUMERATED, |
| 142 NotificationService::AllSources()); |
| 143 EnumerateModulesModel::GetSingleton()->ScanNow(); |
| 144 } |
| 145 |
| 146 void ConflictsDOMHandler::SendModuleList() { |
| 147 EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetSingleton(); |
| 148 ListValue* list = loaded_modules->GetModuleList(); |
| 149 DictionaryValue results; |
| 150 results.Set("moduleList", list); |
| 151 |
| 152 // Add the section title and the total count for bad modules found. |
| 153 int confirmed_bad = loaded_modules->confirmed_bad_modules_detected(); |
| 154 int suspected_bad = loaded_modules->suspected_bad_modules_detected(); |
| 155 string16 table_title; |
| 156 if (!confirmed_bad && !suspected_bad) { |
| 157 table_title += l10n_util::GetStringFUTF16( |
| 158 IDS_CONFLICTS_CHECK_PAGE_TABLE_TITLE_SUFFIX_ONE, |
| 159 base::IntToString16(list->GetSize())); |
| 160 } else { |
| 161 table_title += l10n_util::GetStringFUTF16( |
| 162 IDS_CONFLICTS_CHECK_PAGE_TABLE_TITLE_SUFFIX_TWO, |
| 163 base::IntToString16(list->GetSize()), |
| 164 base::IntToString16(confirmed_bad), |
| 165 base::IntToString16(suspected_bad)); |
| 166 } |
| 167 results.SetString("modulesTableTitle", table_title); |
| 168 |
| 169 dom_ui_->CallJavascriptFunction(L"returnModuleList", results); |
| 170 } |
| 171 |
| 172 void ConflictsDOMHandler::Observe(NotificationType type, |
| 173 const NotificationSource& source, |
| 174 const NotificationDetails& details) { |
| 175 switch (type.value) { |
| 176 case NotificationType::MODULE_LIST_ENUMERATED: |
| 177 SendModuleList(); |
| 178 registrar_.RemoveAll(); |
| 179 break; |
| 180 default: |
| 181 NOTREACHED(); |
| 182 break; |
| 183 } |
| 184 } |
| 185 |
| 186 } // namespace |
| 187 |
| 188 /////////////////////////////////////////////////////////////////////////////// |
| 189 // |
| 190 // ConflictsUI |
| 191 // |
| 192 /////////////////////////////////////////////////////////////////////////////// |
| 193 |
| 194 ConflictsUI::ConflictsUI(TabContents* contents) : DOMUI(contents) { |
| 195 AddMessageHandler((new ConflictsDOMHandler())->Attach(this)); |
| 196 |
| 197 ConflictsUIHTMLSource* html_source = new ConflictsUIHTMLSource(); |
| 198 |
| 199 // Set up the about:conflicts source. |
| 200 BrowserThread::PostTask( |
| 201 BrowserThread::IO, FROM_HERE, |
| 202 NewRunnableMethod(Singleton<ChromeURLDataManager>::get(), |
| 203 &ChromeURLDataManager::AddDataSource, |
| 204 make_scoped_refptr(html_source))); |
| 205 } |
| 206 |
| 207 // static |
| 208 RefCountedMemory* ConflictsUI::GetFaviconResourceBytes() { |
| 209 return ResourceBundle::GetSharedInstance(). |
| 210 LoadDataResourceBytes(IDR_CONFLICTS); |
| 211 } |
| 212 |
| 213 #endif |
OLD | NEW |