diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-01-31 16:33:43 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-02-06 16:33:22 +0000 |
commit | da51f56cc21233c2d30f0fe0d171727c3102b2e0 (patch) | |
tree | 4e579ab70ce4b19bee7984237f3ce05a96d59d83 /chromium/chrome/browser/resources/pdf | |
parent | c8c2d1901aec01e934adf561a9fdf0cc776cdef8 (diff) |
BASELINE: Update Chromium to 65.0.3525.40
Also imports missing submodules
Change-Id: I36901b7c6a325cda3d2c10cedb2186c25af3b79b
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/chrome/browser/resources/pdf')
12 files changed, 369 insertions, 27 deletions
diff --git a/chromium/chrome/browser/resources/pdf/compiled_resources2.gyp b/chromium/chrome/browser/resources/pdf/compiled_resources2.gyp index 655323d32f2..eae4c571a9e 100644 --- a/chromium/chrome/browser/resources/pdf/compiled_resources2.gyp +++ b/chromium/chrome/browser/resources/pdf/compiled_resources2.gyp @@ -18,6 +18,10 @@ 'includes': ['../../../../third_party/closure_compiler/compile_js2.gypi'], }, { + 'target_name': 'coords_transformer', + 'includes': ['../../../../third_party/closure_compiler/compile_js2.gypi'], + }, + { 'target_name': 'gesture_detector', 'includes': ['../../../../third_party/closure_compiler/compile_js2.gypi'], }, diff --git a/chromium/chrome/browser/resources/pdf/coords_transformer.js b/chromium/chrome/browser/resources/pdf/coords_transformer.js new file mode 100644 index 00000000000..43a073f736d --- /dev/null +++ b/chromium/chrome/browser/resources/pdf/coords_transformer.js @@ -0,0 +1,72 @@ +// Copyright 2018 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. + +/** + * @typedef {{ + * callback: function(Object, Object):void, + * params: Object + * }} + */ +let TransformPagePointRequest; + +/** + * @typedef {{ + * type: string, + * id: number, + * page: number, + * x: number, + * y: number + * }} + */ +let TransformPagePointMessage; + +(function() { + +'use strict'; + +/** + * Transforms page to screen coordinates using messages to the plugin. + */ +window.PDFCoordsTransformer = class { + constructor(postMessageCallback) { + /** @private {!Map<number,!TransformPagePointRequest>} */ + this.outstandingTransformPagePointRequests_ = new Map(); + + /** @private {function(TransformPagePointMessage):void} */ + this.postMessageCallback_ = postMessageCallback; + + /** @private {number} */ + this.nextId_ = 0; + } + + /** + * Send a 'transformPagePoint' message to the plugin. + * @param {function(Object, Object):void} callback Function to call when the + * response is received. + * @param {Object} params User parameters to be used in |callback|. + * @param {number} page 0-based page number of the page where the point is. + * @param {number} x x coordinate of the point. + * @param {number} y y coordinate of the point. + */ + request(callback, params, page, x, y) { + this.outstandingTransformPagePointRequests_.set( + this.nextId_, {callback: callback, params: params}); + this.postMessageCallback_( + {type: 'transformPagePoint', id: this.nextId_, page: page, x: x, y: y}); + this.nextId_++; + } + + /** + * Call when 'transformPagePointReply' is received from the plugin. + * @param {Object} message The message received from the plugin. + */ + onReplyReceived(message) { + const outstandingRequest = + this.outstandingTransformPagePointRequests_.get(message.data.id); + this.outstandingTransformPagePointRequests_.delete(message.data.id); + outstandingRequest.callback(message.data, outstandingRequest.params); + } +}; + +}()); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/viewer-bookmark.js b/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/viewer-bookmark.js index de21ff24b32..a78e9d2f383 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/viewer-bookmark.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark/viewer-bookmark.js @@ -66,11 +66,15 @@ Polymer({ onClick: function() { if (this.bookmark.hasOwnProperty('page')) { if (this.bookmark.hasOwnProperty('y')) { - this.fire( - 'change-page-and-y', - {page: this.bookmark.page, y: this.bookmark.y}); + this.fire('change-page-and-xy', { + page: this.bookmark.page, + x: 0, + y: this.bookmark.y, + origin: 'bookmark' + }); } else { - this.fire('change-page', {page: this.bookmark.page}); + this.fire( + 'change-page', {page: this.bookmark.page, origin: 'bookmark'}); } } else if (this.bookmark.hasOwnProperty('uri')) { this.fire('navigate', {uri: this.bookmark.uri, newtab: true}); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector/viewer-page-selector.js b/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector/viewer-page-selector.js index 198b551805a..a0b018805e1 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector/viewer-page-selector.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector/viewer-page-selector.js @@ -25,7 +25,7 @@ Polymer({ var page = parseInt(this.$.input.value, 10); if (!isNaN(page) && page <= this.docLength && page > 0) - this.fire('change-page', {page: page - 1}); + this.fire('change-page', {page: page - 1, origin: 'pageselector'}); else this.$.input.value = this.pageNo; this.$.input.blur(); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.html b/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.html index 1a99c68e78a..1d5c1ad9bb5 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.html +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.html @@ -147,6 +147,7 @@ </paper-icon-button> <viewer-toolbar-dropdown id="bookmarks" + metrics-id="bookmarks" hidden$="[[!bookmarks.length]]" open-icon="pdf:bookmark" closed-icon="pdf:bookmark-border" diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar-dropdown/viewer-toolbar-dropdown.js b/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar-dropdown/viewer-toolbar-dropdown.js index f1751dd3306..33987f3eb94 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar-dropdown/viewer-toolbar-dropdown.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar-dropdown/viewer-toolbar-dropdown.js @@ -27,6 +27,9 @@ Polymer({ /** Icon to display when the dropdown is open. */ openIcon: String, + /** Unique id to identify this dropdown for metrics purposes. */ + metricsId: String, + /** True if the dropdown is currently open. */ dropdownOpen: {type: Boolean, reflectToAttribute: true, value: false}, @@ -66,6 +69,7 @@ Polymer({ this.$.dropdown.style.display = 'block'; if (!this.maxHeightValid_) this.updateMaxHeight(); + this.fire('dropdown-opened', this.metricsId); } this.cancelAnimation_(); this.playAnimation_(this.dropdownOpen); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-toolbar.js b/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-toolbar.js index 565cc488334..2854e8b8f40 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-toolbar.js +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar/viewer-zoom-toolbar.js @@ -38,7 +38,8 @@ Polymer({ this.fireFitToChangedEvent_( this.$['fit-button'].activeIndex == FIT_TO_WIDTH_BUTTON_STATE ? FittingType.FIT_TO_WIDTH : - FittingType.FIT_TO_PAGE); + FittingType.FIT_TO_PAGE, + true); }, /** @@ -60,7 +61,7 @@ Polymer({ * @param {FittingType} fittingType Page fitting type to force. */ forceFit: function(fittingType) { - this.fireFitToChangedEvent_(fittingType); + this.fireFitToChangedEvent_(fittingType, false); // Set the button state since there was no mouse click. var nextButtonState = @@ -73,9 +74,13 @@ Polymer({ * @private * Fire a 'fit-to-changed' {CustomEvent} with the given FittingType as detail. * @param {FittingType} fittingType to include as payload. + * @param {boolean} userInitiated whether the event was initiated by a user + * action. */ - fireFitToChangedEvent_: function(fittingType) { - this.fire('fit-to-changed', fittingType); + fireFitToChangedEvent_: function(fittingType, userInitiated) { + this.fire( + 'fit-to-changed', + {fittingType: fittingType, userInitiated: userInitiated}); }, /** diff --git a/chromium/chrome/browser/resources/pdf/index.html b/chromium/chrome/browser/resources/pdf/index.html index 96a13be132e..69c1c39c8c4 100644 --- a/chromium/chrome/browser/resources/pdf/index.html +++ b/chromium/chrome/browser/resources/pdf/index.html @@ -39,6 +39,8 @@ <script src="pdf_scripting_api.js"></script> <script src="chrome://resources/js/util.js"></script> <script src="browser_api.js"></script> +<script src="coords_transformer.js"></script> +<script src="metrics.js"></script> <script src="pdf.js"></script> <script src="main.js"></script> </html> diff --git a/chromium/chrome/browser/resources/pdf/manifest.json b/chromium/chrome/browser/resources/pdf/manifest.json index 33a1e96fc7a..3b45a058c94 100644 --- a/chromium/chrome/browser/resources/pdf/manifest.json +++ b/chromium/chrome/browser/resources/pdf/manifest.json @@ -9,6 +9,7 @@ "incognito": "split", "permissions": [ "<all_urls>", + "metricsPrivate", "resourcesPrivate" ], "mime_types": [ diff --git a/chromium/chrome/browser/resources/pdf/metrics.js b/chromium/chrome/browser/resources/pdf/metrics.js new file mode 100644 index 00000000000..61091cd4dc1 --- /dev/null +++ b/chromium/chrome/browser/resources/pdf/metrics.js @@ -0,0 +1,206 @@ +// Copyright 2017 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() { + +'use strict'; + +// Keep in sync with enums.xml. +// Do not change the numeric values or reuse them since these numbers are +// persisted to logs. +const UserAction = { + DOCUMENT_OPENED: 0, // Baseline to use as denominator for all formulas. + ROTATE_FIRST: 1, + ROTATE: 2, + FIT_TO_WIDTH_FIRST: 3, + FIT_TO_WIDTH: 4, + FIT_TO_PAGE_FIRST: 5, + FIT_TO_PAGE: 6, + OPEN_BOOKMARKS_PANEL_FIRST: 7, + OPEN_BOOKMARKS_PANEL: 8, + FOLLOW_BOOKMARK_FIRST: 9, + FOLLOW_BOOKMARK: 10, + PAGE_SELECTOR_NAVIGATE_FIRST: 11, + PAGE_SELECTOR_NAVIGATE: 12, + NUMBER_OF_ACTIONS: 13 +}; + +/** + * Handles events specific to the PDF viewer and logs the corresponding metrics. + * + * @interface + */ +window.PDFMetrics = class { + constructor() {} + + /** + * Call when the document is first loaded. This event serves as denominator to + * determine percentages of documents in which an action was taken as well as + * average number of each action per document. + */ + onDocumentOpened() {} + + /** + * Call when the document is rotated clockwise or counter-clockwise. + */ + onRotation() {} + + /** + * Call when the zoom mode is changed to fit a FittingType. + * @param {FittingType} fittingType the new FittingType. + */ + onFitTo(fittingType) {} + + /** + * Call when the bookmarks panel is opened. + */ + onOpenBookmarksPanel() {} + + /** + * Call when a bookmark is followed. + */ + onFollowBookmark() {} + + /** + * Call when the page selection is used to navigate to another page. + */ + onPageSelectorNavigation() {} +}; + +/** + * Dummy implementation of PDFMetrics. + * This is used in print preview mode to avoid bundling the actions in the PDF + * viewer and the print preview in the same histogram. Also, metricsPrivate is + * not available in print preview. + * @implements {PDFMetrics} + */ +window.PDFMetricsDummy = class { + constructor() {} + + /** @override */ + onDocumentOpened() {} + + /** @override */ + onRotation() {} + + /** @override */ + onFitTo(fittingType) {} + + /** @override */ + onOpenBookmarksPanel() {} + + /** @override */ + onFollowBookmark() {} + + /** @override */ + onPageSelectorNavigation() {} +}; + +/** + * Implementation of PDFMetrics that logs the corresponding metrics to UMA + * through chrome.metricsPrivate. + * @implements {PDFMetrics} + */ +window.PDFMetricsImpl = class { + constructor() { + /** + * @private {Set} + */ + this.firstEventLogged_ = new Set(); + + /** + * @private {Object} + */ + this.actionsMetric_ = { + 'metricName': 'PDF.Actions', + 'type': chrome.metricsPrivate.MetricTypeType.HISTOGRAM_LOG, + 'min': 1, + 'max': UserAction.NUMBER_OF_ACTIONS, + 'buckets': UserAction.NUMBER_OF_ACTIONS + 1 + }; + } + + /** @override */ + onDocumentOpened() { + this.logOnlyFirstTime_(UserAction.DOCUMENT_OPENED); + } + + /** @override */ + onRotation() { + this.logFirstAndTotal_(UserAction.ROTATE_FIRST, UserAction.ROTATE); + } + + /** @override */ + onFitTo(fittingType) { + if (fittingType == FittingType.FIT_TO_PAGE) { + this.logFirstAndTotal_( + UserAction.FIT_TO_PAGE_FIRST, UserAction.FIT_TO_PAGE); + } else if (fittingType == FittingType.FIT_TO_WIDTH) { + this.logFirstAndTotal_( + UserAction.FIT_TO_WIDTH_FIRST, UserAction.FIT_TO_WIDTH); + } + // There is no user action to do a fit-to-height, this only happens with + // the open param "view=FitV". + } + + /** @override */ + onOpenBookmarksPanel() { + this.logFirstAndTotal_( + UserAction.OPEN_BOOKMARKS_PANEL_FIRST, UserAction.OPEN_BOOKMARKS_PANEL); + } + + /** @override */ + onFollowBookmark() { + this.logFirstAndTotal_( + UserAction.FOLLOW_BOOKMARK_FIRST, UserAction.FOLLOW_BOOKMARK); + } + + /** @override */ + onPageSelectorNavigation() { + this.logFirstAndTotal_( + UserAction.PAGE_SELECTOR_NAVIGATE_FIRST, + UserAction.PAGE_SELECTOR_NAVIGATE); + } + + /** + * @private + * Logs the "first" event code if it hasn't been logged by this instance yet + * and also log the "total" event code. This distinction allows analyzing + * both: + * - in what percentage of documents each action was taken; + * - how many times, on average, each action is taken on a document; + * @param {number} firstEventCode event code for the "first" metric. + * @return {number} totalEventCode event code for the "total" metric. + */ + logFirstAndTotal_(firstEventCode, totalEventCode) { + this.log_(totalEventCode); + this.logOnlyFirstTime_(firstEventCode); + } + + /** + * @private + * Logs the given event code to chrome.metricsPrivate. + * @param {number} eventCode event code to log. + */ + log_(eventCode) { + chrome.metricsPrivate.recordValue(this.actionsMetric_, eventCode); + } + + /** + * @private + * Logs the given event code. Subsequent calls of this method with the same + * event code have no effect on the this PDFMetrics instance. + * @param {number} eventCode event code to log. + */ + logOnlyFirstTime_(eventCode) { + if (!this.firstEventLogged_.has(eventCode)) { + this.log_(eventCode); + this.firstEventLogged_.add(eventCode); + } + } +}; + +window.PDFMetrics.UserAction = UserAction; + +}()); diff --git a/chromium/chrome/browser/resources/pdf/pdf.js b/chromium/chrome/browser/resources/pdf/pdf.js index dcbf3d3a35e..4a8cb93199e 100644 --- a/chromium/chrome/browser/resources/pdf/pdf.js +++ b/chromium/chrome/browser/resources/pdf/pdf.js @@ -105,6 +105,13 @@ function PDFViewer(browserApi) { this.isPrintPreviewLoaded_ = false; this.isUserInitiatedEvent_ = true; + /** + * @type {PDFMetrics} + */ + this.metrics = + (chrome.metricsPrivate ? new PDFMetricsImpl() : new PDFMetricsDummy()); + this.metrics.onDocumentOpened(); + // Parse open pdf parameters. this.paramsParser_ = new OpenPDFParamsParser(this.getNamedDestination_.bind(this)); @@ -217,12 +224,23 @@ function PDFViewer(browserApi) { this.toolbar_.docTitle = getFilenameFromURL(this.originalUrl_); } + this.coordsTransformer_ = + new PDFCoordsTransformer(this.plugin_.postMessage.bind(this.plugin_)); + document.body.addEventListener('change-page', e => { this.viewport_.goToPage(e.detail.page); + if (e.detail.origin == 'bookmark') + this.metrics.onFollowBookmark(); + else if (e.detail.origin == 'pageselector') + this.metrics.onPageSelectorNavigation(); }); - document.body.addEventListener('change-page-and-y', e => { - this.viewport_.goToPageAndY(e.detail.page, e.detail.y); + document.body.addEventListener('change-page-and-xy', e => { + // The coordinates received in |e| are in page coordinates and need to be + // transformed to screen coordinates. + this.coordsTransformer_.request( + this.goToPageAndXY_.bind(this, e.detail.origin, e.detail.page), {}, + e.detail.page, e.detail.x, e.detail.y); }); document.body.addEventListener('navigate', e => { @@ -232,6 +250,11 @@ function PDFViewer(browserApi) { this.navigator_.navigate(e.detail.uri, disposition); }); + document.body.addEventListener('dropdown-opened', e => { + if (e.detail == 'bookmarks') + this.metrics.onOpenBookmarksPanel(); + }); + this.toolbarManager_ = new ToolbarManager(window, this.toolbar_, this.zoomToolbar_); @@ -427,6 +450,7 @@ PDFViewer.prototype = { * Rotate the plugin clockwise. */ rotateClockwise_: function() { + this.metrics.onRotation(); this.plugin_.postMessage({type: 'rotateClockwise'}); }, @@ -435,6 +459,7 @@ PDFViewer.prototype = { * Rotate the plugin counter-clockwise. */ rotateCounterClockwise_: function() { + this.metrics.onRotation(); this.plugin_.postMessage({type: 'rotateCounterclockwise'}); }, @@ -444,15 +469,18 @@ PDFViewer.prototype = { * @param {CustomEvent} e Event received with the new FittingType as detail. */ fitToChanged_: function(e) { - if (e.detail == FittingType.FIT_TO_PAGE) { + if (e.detail.fittingType == FittingType.FIT_TO_PAGE) { this.viewport_.fitToPage(); this.toolbarManager_.forceHideTopToolbar(); - } else if (e.detail == FittingType.FIT_TO_WIDTH) { + } else if (e.detail.fittingType == FittingType.FIT_TO_WIDTH) { this.viewport_.fitToWidth(); - } else if (e.detail == FittingType.FIT_TO_HEIGHT) { + } else if (e.detail.fittingType == FittingType.FIT_TO_HEIGHT) { this.viewport_.fitToHeight(); this.toolbarManager_.forceHideTopToolbar(); } + + if (e.detail.userInitiated) + this.metrics.onFitTo(e.detail.fittingType); }, /** @@ -503,20 +531,16 @@ PDFViewer.prototype = { * @param {Object} params The open params passed in the URL. */ handleURLParams_: function(params) { - if (params.page != undefined) - this.viewport_.goToPage(params.page); + if (params.zoom) + this.viewport_.setZoom(params.zoom); if (params.position) { - // Make sure we don't cancel effect of page parameter. - this.viewport_.position = { - x: this.viewport_.position.x + params.position.x, - y: this.viewport_.position.y + params.position.y - }; + this.viewport_.goToPageAndXY( + params.page ? params.page : 0, params.position.x, params.position.y); + } else if (params.page) { + this.viewport_.goToPage(params.page); } - if (params.zoom) - this.viewport_.setZoom(params.zoom); - if (params.view) { this.isUserInitiatedEvent_ = false; this.zoomToolbar_.forceFit(params.view); @@ -535,6 +559,21 @@ PDFViewer.prototype = { /** * @private + * Moves the viewport to a point in a page. Called back after a + * 'transformPagePointReply' is returned from the plugin. + * @param {string} origin Identifier for the caller for logging purposes. + * @param {number} page The index of the page to go to. zero-based. + * @param {Object} message Message received from the plugin containing the + * x and y to navigate to in screen coordinates. + */ + goToPageAndXY_: function(origin, page, message) { + this.viewport_.goToPageAndXY(page, message.x, message.y); + if (origin == 'bookmark') + this.metrics.onFollowBookmark(); + }, + + /** + * @private * Update the loading progress of the document in response to a progress * message being received from the plugin. * @param {number} progress the progress as a percentage. @@ -696,6 +735,9 @@ PDFViewer.prototype = { case 'formFocusChange': this.isFormFieldFocused_ = message.data.focused; break; + case 'transformPagePointReply': + this.coordsTransformer_.onReplyReceived(message); + break; } }, diff --git a/chromium/chrome/browser/resources/pdf/viewport.js b/chromium/chrome/browser/resources/pdf/viewport.js index 53e1b17ea60..709b646ff6d 100644 --- a/chromium/chrome/browser/resources/pdf/viewport.js +++ b/chromium/chrome/browser/resources/pdf/viewport.js @@ -798,15 +798,16 @@ Viewport.prototype = { * @param {number} page the index of the page to go to. zero-based. */ goToPage: function(page) { - this.goToPageAndY(page, 0); + this.goToPageAndXY(page, 0, 0); }, /** * Go to the given y position in the given page index. * @param {number} page the index of the page to go to. zero-based. + * @param {number} x the x position in the page to go to. * @param {number} y the y position in the page to go to. */ - goToPageAndY: function(page, y) { + goToPageAndXY: function(page, x, y) { this.mightZoom_(() => { if (this.pageDimensions_.length === 0) return; @@ -822,7 +823,7 @@ Viewport.prototype = { if (!this.isPagedMode()) toolbarOffset = this.topToolbarHeight_; this.position = { - x: dimensions.x * this.zoom, + x: (dimensions.x + x) * this.zoom, y: (dimensions.y + y) * this.zoom - toolbarOffset }; this.updateViewport_(); |