Commit e7d5f39f authored by Nikita Podguzov's avatar Nikita Podguzov Committed by Commit Bot

Printing API: Add example extension for chrome.printingMetrics API

This extension demonstrates how chrome.printingMetrics API can be used
to fetch print job metadata.
This extension will be used for external documentation as well.

Bug: 992889
Change-Id: I7b874e8961b02ebc8332ef804d9496e6fed35d56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1852252
Commit-Queue: Nikita Podguzov <nikitapodguzov@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707754}
parent 691fb5d5
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.printingMetrics.onPrintJobFinished.addListener(function(printJob) {
chrome.storage.local.get('printJobs', function(result) {
let printJobs = result.printJobs || 0;
printJobs++;
chrome.browserAction.setBadgeText({text: printJobs.toString()});
chrome.storage.local.set({printJobs: printJobs});
});
});
{
"name": "Print Job History",
"version": "1.0",
"description": "Reads your print history and displays the recent print jobs.",
"permissions": [
"printingMetrics",
"storage"
],
"browser_action": {
"default_popup": "printJobs.html",
"default_icon": "print.png"
},
"background": {
"scripts": [
"background.js"
],
"persistent": false
},
"manifest_version": 2
}
/**
* Copyright 2019 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
table, th, td, tr {
border: 1px solid black;
}
table {
width: 100%;
border-collapse: collapse;
}
div {
overflow: auto;
}
<!--
* Copyright 2019 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Recent print jobs</title>
<link href="printJobs.css" rel="stylesheet" type="text/css">
<script src="printJobs.js"></script>
</head>
<body>
<h2>Recent print jobs:</h2>
<div id="printJobs">
<table id="printJobsTable">
<thead>
<tr>
<th rowspan="2">Title</th>
<th rowspan="2">Status</th>
<th rowspan="2">Time</th>
<th rowspan="2">Number of pages</th>
<th colspan="3">Printer</th>
<th colspan="5">Settings</th>
</tr>
<tr>
<th>Name</th>
<th>URI</th>
<th>Source</th>
<th>Color</th>
<th>Duplex</th>
<th>Paper width</th>
<th>Paper height</th>
<th>Copies</th>
</tr>
</thead>
</table>
</div>
</body>
</html>
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function showPrintJobTable() {
chrome.printingMetrics.getPrintJobs(function(printJobs) {
const tbody = document.createElement('tbody');
for (let i = 0; i < printJobs.length; ++i) {
const columnValues = [
printJobs[i].title, printJobs[i].status,
new Date(printJobs[i].completionTime), printJobs[i].numberOfPages,
printJobs[i].printer.name, printJobs[i].printer.uri,
printJobs[i].printer.source, printJobs[i].settings.color,
printJobs[i].settings.duplex, printJobs[i].settings.mediaSize.width,
printJobs[i].settings.mediaSize.height, printJobs[i].settings.copies
];
let tr = document.createElement('tr');
for (columnValue of columnValues) {
const td = document.createElement('td');
td.appendChild(document.createTextNode(columnValue));
td.setAttribute('align', 'center');
tr.appendChild(td);
}
tbody.appendChild(tr);
}
const table = document.getElementById('printJobsTable');
table.appendChild(tbody);
});
}
document.addEventListener('DOMContentLoaded', function() {
showPrintJobTable();
});
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