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.
5 #include "chrome/browser/ui/webui/device_log_ui.h"
10 #include "base/bind_helpers.h"
11 #include "base/values.h"
12 #include "chrome/common/url_constants.h"
13 #include "chrome/grit/chromium_strings.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "components/device_event_log/device_event_log.h"
16 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_ui.h"
18 #include "content/public/browser/web_ui_data_source.h"
19 #include "content/public/browser/web_ui_message_handler.h"
20 #include "grit/browser_resources.h"
26 class DeviceLogMessageHandler
: public content::WebUIMessageHandler
{
28 DeviceLogMessageHandler() {}
29 ~DeviceLogMessageHandler() override
{}
31 // WebUIMessageHandler implementation.
32 void RegisterMessages() override
{
33 web_ui()->RegisterMessageCallback(
35 base::Bind(&DeviceLogMessageHandler::GetLog
, base::Unretained(this)));
39 void GetLog(const base::ListValue
* value
) const {
40 base::StringValue
data(device_event_log::GetAsString(
41 device_event_log::NEWEST_FIRST
, "json", "",
42 device_event_log::LOG_LEVEL_DEBUG
, 0));
43 web_ui()->CallJavascriptFunction("DeviceLogUI.getLogCallback", data
);
46 DISALLOW_COPY_AND_ASSIGN(DeviceLogMessageHandler
);
51 DeviceLogUI::DeviceLogUI(content::WebUI
* web_ui
)
52 : content::WebUIController(web_ui
) {
53 web_ui
->AddMessageHandler(new DeviceLogMessageHandler());
55 content::WebUIDataSource
* html
=
56 content::WebUIDataSource::Create(chrome::kChromeUIDeviceLogHost
);
58 html
->AddLocalizedString("titleText", IDS_DEVICE_LOG_TITLE
);
59 html
->AddLocalizedString("autoRefreshText", IDS_DEVICE_AUTO_REFRESH
);
60 html
->AddLocalizedString("logRefreshText", IDS_DEVICE_LOG_REFRESH
);
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
);
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 html
->AddLocalizedString("logTypeUsbText", IDS_DEVICE_LOG_TYPE_USB
);
75 html
->AddLocalizedString("logTypeHidText", IDS_DEVICE_LOG_TYPE_HID
);
77 html
->AddLocalizedString("logEntryFormat", IDS_DEVICE_LOG_ENTRY
);
78 html
->SetJsonPath("strings.js");
79 html
->AddResourcePath("device_log_ui.css", IDR_DEVICE_LOG_UI_CSS
);
80 html
->AddResourcePath("device_log_ui.js", IDR_DEVICE_LOG_UI_JS
);
81 html
->SetDefaultResource(IDR_DEVICE_LOG_UI_HTML
);
83 content::WebUIDataSource::Add(web_ui
->GetWebContents()->GetBrowserContext(),
87 DeviceLogUI::~DeviceLogUI() {
90 } // namespace chromeos