Commit 73181742 authored by Orin Jaworski's avatar Orin Jaworski Committed by Commit Bot

[omnibox] Add version details and other context to batch exports

This CL expands the schema of chrome://omnibox batch exports to
include information about version and running context. To do this
without much duplication of code, VersionUI was refactored slightly.

Bug: 964528
Change-Id: I7de7484d18497a8c5a9d6a165e0922991bf663bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1713238Reviewed-by: default avatarmanuk hovanesian <manukh@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: Orin Jaworski <orinj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681046}
parent aa0104a6
......@@ -16,6 +16,7 @@ js_library("omnibox") {
":omnibox_input",
":omnibox_output",
"//chrome/browser/ui/webui/omnibox:mojo_bindings_js_library_for_compile",
"//ui/webui/resources/js:load_time_data",
]
}
......
......@@ -8,12 +8,14 @@
<link rel="stylesheet" href="omnibox.css">
<script src="chrome://resources/js/cr.js"></script>
<script src="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js"></script>
<script src="chrome://resources/js/load_time_data.js"></script>
<script src="chrome://resources/js/util.js"></script>
<script src="chrome/browser/ui/webui/omnibox/omnibox.mojom-lite.js"></script>
<script src="omnibox_element.js"></script>
<script src="omnibox_input.js"></script>
<script src="omnibox_output.js"></script>
<script src="omnibox.js"></script>
<script src="strings.js"></script>
</head>
<body>
......
......@@ -213,8 +213,9 @@ class ExportDelegate {
* This is the worker function that transforms query inputs to accumulate
* batch exports, then finally initiates a download for the complete set.
* @param {!Array<!QueryInputs>} batchQueryInputs
* @param {string} batchName
*/
async processBatch(batchQueryInputs) {
async processBatch(batchQueryInputs, batchName) {
const batchExports = [];
for (const queryInputs of batchQueryInputs) {
const omniboxResponse = await browserProxy
......@@ -233,8 +234,21 @@ class ExportDelegate {
};
batchExports.push(exportData);
}
const fileName = `omnibox_batch_${ExportDelegate.getTimeStamp()}.json`;
const batchData = { appVersion: navigator.appVersion, batchExports };
const now = new Date();
const fileName = `omnibox_batch_${ExportDelegate.getTimeStamp(now)}.json`;
// If this data format changes, please roll schemaVersion.
const batchData = {
schemaKind: 'Omnibox Batch Export',
schemaVersion: 2,
dateCreated: now.toISOString(),
author: '',
description: '',
authorTool: 'chrome://omnibox',
batchName,
versionDetails: window.loadTimeData.data_,
appVersion: navigator.appVersion,
batchExports
};
ExportDelegate.download_(batchData, fileName);
}
......@@ -244,11 +258,14 @@ class ExportDelegate {
* @param {!BatchSpecifier} processBatchData
*/
processBatchData(processBatchData) {
if (processBatchData.batchMode && processBatchData.batchQueryInputs) {
this.processBatch(processBatchData.batchQueryInputs);
if (processBatchData.batchMode && processBatchData.batchQueryInputs &&
processBatchData.batchName) {
this.processBatch(
processBatchData.batchQueryInputs, processBatchData.batchName);
} else {
const expected = {
batchMode: "combined",
batchName: "name for this batch of queries",
batchQueryInputs: [
{
inputText: "example input text",
......@@ -305,9 +322,15 @@ class ExportDelegate {
a.click();
}
/** @return {string} A sortable timestamp string for use in filenames. */
static getTimeStamp() {
const iso = new Date().toISOString();
/**
* @param {Date=} date
* @return {string} A sortable timestamp string for use in filenames.
*/
static getTimeStamp(date) {
if (!date) {
date = new Date();
}
const iso = date.toISOString();
return iso.replace(/:/g, '').split('.')[0];
}
}
......
......@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/omnibox/omnibox_page_handler.h"
#include "chrome/browser/ui/webui/version_ui.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/browser_resources.h"
#include "content/public/browser/web_ui.h"
......@@ -19,6 +20,11 @@ OmniboxUI::OmniboxUI(content::WebUI* web_ui) : ui::MojoWebUIController(web_ui) {
// Set up the chrome://omnibox/ source.
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIOmniboxHost);
// Expose version information to client because it is useful in output.
VersionUI::AddVersionDetailStrings(source);
source->SetJsonPath("strings.js");
source->AddResourcePath("omnibox.css", IDR_OMNIBOX_CSS);
source->AddResourcePath("omnibox_input.css", IDR_OMNIBOX_INPUT_CSS);
source->AddResourcePath("output_results_group.css",
......
......@@ -55,8 +55,7 @@ namespace {
WebUIDataSource* CreateVersionUIDataSource() {
WebUIDataSource* html_source =
WebUIDataSource::Create(chrome::kChromeUIVersionHost);
// Localized strings.
// These localized strings are used to label version details.
static constexpr LocalizedString kStrings[] = {
{version_ui::kTitle, IDS_VERSION_UI_TITLE},
{version_ui::kApplicationLabel, IDS_PRODUCT_NAME},
......@@ -82,6 +81,42 @@ WebUIDataSource* CreateVersionUIDataSource() {
};
AddLocalizedStringsBulk(html_source, kStrings, base::size(kStrings));
VersionUI::AddVersionDetailStrings(html_source);
html_source->SetJsonPath("strings.js");
html_source->AddResourcePath(version_ui::kVersionJS, IDR_VERSION_UI_JS);
html_source->AddResourcePath(version_ui::kAboutVersionCSS,
IDR_VERSION_UI_CSS);
html_source->SetDefaultResource(IDR_VERSION_UI_HTML);
return html_source;
}
} // namespace
VersionUI::VersionUI(content::WebUI* web_ui)
: content::WebUIController(web_ui) {
Profile* profile = Profile::FromWebUI(web_ui);
#if defined(OS_CHROMEOS)
web_ui->AddMessageHandler(std::make_unique<VersionHandlerChromeOS>());
#elif defined(OS_WIN)
web_ui->AddMessageHandler(std::make_unique<VersionHandlerWindows>());
#else
web_ui->AddMessageHandler(std::make_unique<VersionHandler>());
#endif
#if !defined(OS_ANDROID)
// Set up the chrome://theme/ source.
content::URLDataSource::Add(profile, std::make_unique<ThemeSource>(profile));
#endif
WebUIDataSource::Add(profile, CreateVersionUIDataSource());
}
VersionUI::~VersionUI() {}
// static
void VersionUI::AddVersionDetailStrings(content::WebUIDataSource* html_source) {
html_source->AddLocalizedString(version_ui::kOfficial,
version_info::IsOfficialBuild()
? IDS_VERSION_UI_OFFICIAL
......@@ -150,35 +185,4 @@ WebUIDataSource* CreateVersionUIDataSource() {
#endif // defined(OS_WIN)
html_source->AddString(version_ui::kSanitizer, version_info::GetSanitizerList());
html_source->SetJsonPath("strings.js");
html_source->AddResourcePath(version_ui::kVersionJS, IDR_VERSION_UI_JS);
html_source->AddResourcePath(version_ui::kAboutVersionCSS,
IDR_VERSION_UI_CSS);
html_source->SetDefaultResource(IDR_VERSION_UI_HTML);
return html_source;
}
} // namespace
VersionUI::VersionUI(content::WebUI* web_ui)
: content::WebUIController(web_ui) {
Profile* profile = Profile::FromWebUI(web_ui);
#if defined(OS_CHROMEOS)
web_ui->AddMessageHandler(std::make_unique<VersionHandlerChromeOS>());
#elif defined(OS_WIN)
web_ui->AddMessageHandler(std::make_unique<VersionHandlerWindows>());
#else
web_ui->AddMessageHandler(std::make_unique<VersionHandler>());
#endif
#if !defined(OS_ANDROID)
// Set up the chrome://theme/ source.
content::URLDataSource::Add(profile, std::make_unique<ThemeSource>(profile));
#endif
WebUIDataSource::Add(profile, CreateVersionUIDataSource());
}
VersionUI::~VersionUI() {}
......@@ -7,6 +7,7 @@
#include "base/macros.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/web_ui_data_source.h"
// The WebUI handler for chrome://version.
class VersionUI : public content::WebUIController {
......@@ -14,6 +15,10 @@ class VersionUI : public content::WebUIController {
explicit VersionUI(content::WebUI* web_ui);
~VersionUI() override;
// Loads a data source with many named details comprising version info.
// The keys are from version_ui_constants.
static void AddVersionDetailStrings(content::WebUIDataSource* html_source);
private:
DISALLOW_COPY_AND_ASSIGN(VersionUI);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment