Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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/chromeos/device_log_ui.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/bind_helpers.h" | |
| 11 #include "base/values.h" | |
| 12 #include "chrome/common/url_constants.h" | |
| 13 #include "chrome/grit/generated_resources.h" | |
| 14 #include "chromeos/device_event_log.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 | |
| 21 namespace chromeos { | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 class DeviceLogMessageHandler : public content::WebUIMessageHandler { | |
| 26 public: | |
| 27 DeviceLogMessageHandler() {} | |
| 28 ~DeviceLogMessageHandler() override {} | |
| 29 | |
| 30 // WebUIMessageHandler implementation. | |
| 31 virtual void RegisterMessages() override { | |
|
michaelpg
2014/12/11 01:41:45
c++11 style: don't use virtual with override
stevenjb
2014/12/11 19:57:52
Done.
| |
| 32 web_ui()->RegisterMessageCallback( | |
| 33 "DeviceLog.getLog", | |
| 34 base::Bind(&DeviceLogMessageHandler::GetLog, | |
| 35 base::Unretained(this))); | |
| 36 } | |
| 37 | |
| 38 private: | |
| 39 void GetLog(const base::ListValue* value) const { | |
| 40 base::StringValue data(chromeos::device_event_log::GetAsString( | |
| 41 chromeos::device_event_log::NEWEST_FIRST, "json", "", | |
| 42 chromeos::device_event_log::LOG_LEVEL_DEBUG, 0)); | |
| 43 web_ui()->CallJavascriptFunction("DeviceLogUI.getLogCallback", data); | |
| 44 } | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(DeviceLogMessageHandler); | |
| 47 }; | |
| 48 | |
| 49 } // namespace | |
| 50 | |
| 51 DeviceLogUI::DeviceLogUI(content::WebUI* web_ui) | |
| 52 : content::WebUIController(web_ui) { | |
| 53 web_ui->AddMessageHandler(new DeviceLogMessageHandler()); | |
| 54 | |
| 55 content::WebUIDataSource* html = | |
| 56 content::WebUIDataSource::Create(chrome::kChromeUIDeviceLogHost); | |
| 57 | |
| 58 html->AddLocalizedString("titleText", IDS_DEVICE_LOG_TITLE); | |
| 59 html->AddLocalizedString("autoRefreshText", IDS_DEVICE_AUTO_REFRESH); | |
| 60 html->AddLocalizedString("logRefreshText", IDS_DEVICE_LOG_REFRESH); | |
| 61 | |
| 62 html->AddLocalizedString("logLevelShowText", IDS_DEVICE_LOG_LEVEL_SHOW); | |
| 63 html->AddLocalizedString("logLevelErrorText", IDS_DEVICE_LOG_LEVEL_ERROR); | |
| 64 html->AddLocalizedString("logLevelUserText", IDS_DEVICE_LOG_LEVEL_USER); | |
| 65 html->AddLocalizedString("logLevelEventText", IDS_DEVICE_LOG_LEVEL_EVENT); | |
| 66 html->AddLocalizedString("logLevelDebugText", IDS_DEVICE_LOG_LEVEL_DEBUG); | |
| 67 html->AddLocalizedString("logLevelFileinfoText", IDS_DEVICE_LOG_FILEINFO); | |
| 68 html->AddLocalizedString("logLevelTimeDetailText", | |
| 69 IDS_DEVICE_LOG_TIME_DETAIL); | |
| 70 | |
| 71 html->AddLocalizedString("logTypeLoginText", IDS_DEVICE_LOG_TYPE_LOGIN); | |
| 72 html->AddLocalizedString("logTypeNetworkText", IDS_DEVICE_LOG_TYPE_NETWORK); | |
| 73 html->AddLocalizedString("logTypePowerText", IDS_DEVICE_LOG_TYPE_POWER); | |
| 74 | |
| 75 html->AddLocalizedString("logEntryFormat", IDS_DEVICE_LOG_ENTRY); | |
| 76 html->SetJsonPath("strings.js"); | |
| 77 html->AddResourcePath("device_log_ui.css", IDR_DEVICE_LOG_UI_CSS); | |
| 78 html->AddResourcePath("device_log_ui.js", IDR_DEVICE_LOG_UI_JS); | |
| 79 html->SetDefaultResource(IDR_DEVICE_LOG_UI_HTML); | |
| 80 | |
| 81 content::WebUIDataSource::Add( | |
| 82 web_ui->GetWebContents()->GetBrowserContext(), html); | |
| 83 } | |
| 84 | |
| 85 DeviceLogUI::~DeviceLogUI() { | |
| 86 } | |
| 87 | |
| 88 } // namespace chromeos | |
| OLD | NEW |