Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: chrome/browser/resources/pdf/pdf.js

Issue 918953002: Fix for PDFs with lots of named destinations take a long time to load. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | chrome/test/data/pdf/navigator_test.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/pdf/pdf.js
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js
index 309886fde637a343d583d44f3d367064a374c317..5e60f2329f280b51c23c3850e077c9ec86cf5cb5 100644
--- a/chrome/browser/resources/pdf/pdf.js
+++ b/chrome/browser/resources/pdf/pdf.js
@@ -190,10 +190,11 @@ function PDFViewer(streamDetails) {
}
// Parse open pdf parameters.
- this.paramsParser_ = new OpenPDFParamsParser();
+ this.paramsParser_ =
+ new OpenPDFParamsParser(this.getNamedDestination_.bind(this));
this.navigator_ = new Navigator(this.streamDetails_.originalUrl,
- this.viewport_, this.paramsParser_, onNavigateInCurrentTab,
- onNavigateInNewTab);
+ this.viewport_, this.paramsParser_,
+ onNavigateInCurrentTab, onNavigateInNewTab);
this.viewportScroller_ =
new ViewportScroller(this.viewport_, this.plugin_, window);
}
@@ -350,35 +351,54 @@ PDFViewer.prototype = {
* @private
* Notify the plugin to print.
*/
- print_: function() { this.plugin_.postMessage({type: 'print'}); },
+ print_: function() {
+ this.plugin_.postMessage({
+ type: 'print'
+ });
+ },
/**
* @private
* Notify the plugin to save.
*/
- save_: function() { this.plugin_.postMessage({type: 'save'}); },
+ save_: function() {
+ this.plugin_.postMessage({
+ type: 'save'
+ });
+ },
+
+ /**
+ * Fetches the page number corresponding to the given named destination from
+ * the plugin.
+ * @param {string} name The namedDestination to fetch page number from plugin.
+ */
+ getNamedDestination_: function(name) {
+ this.plugin_.postMessage({
+ type: 'getNamedDestination',
+ namedDestination: name
+ });
+ },
/**
* @private
* Handle open pdf parameters. This function updates the viewport as per
* the parameters mentioned in the url while opening pdf. The order is
* important as later actions can override the effects of previous actions.
+ * @param {Object} viewportPosition The initial position of the viewport to be
+ * displayed.
*/
- handleURLParams_: function() {
- var urlParams =
- this.paramsParser_.getViewportFromUrlParams(
- this.streamDetails_.originalUrl);
- if (urlParams.page)
- this.viewport_.goToPage(urlParams.page);
- if (urlParams.position) {
+ handleURLParams_: function(viewportPosition) {
+ if (viewportPosition.page != undefined)
+ this.viewport_.goToPage(viewportPosition.page);
+ if (viewportPosition.position) {
// Make sure we don't cancel effect of page parameter.
this.viewport_.position = {
- x: this.viewport_.position.x + urlParams.position.x,
- y: this.viewport_.position.y + urlParams.position.y
+ x: this.viewport_.position.x + viewportPosition.position.x,
+ y: this.viewport_.position.y + viewportPosition.position.y
};
}
- if (urlParams.zoom)
- this.viewport_.setZoom(urlParams.zoom);
+ if (viewportPosition.zoom)
+ this.viewport_.setZoom(viewportPosition.zoom);
},
/**
@@ -406,7 +426,8 @@ PDFViewer.prototype = {
// Document load complete.
if (this.lastViewportPosition_)
this.viewport_.position = this.lastViewportPosition_;
- this.handleURLParams_();
+ this.paramsParser_.getViewportFromUrlParams(
+ this.streamDetails_.originalUrl, this.handleURLParams_.bind(this));
this.loaded_ = true;
this.sendScriptingMessage_({
type: 'documentLoaded'
@@ -486,9 +507,6 @@ PDFViewer.prototype = {
else
this.navigator_.navigate(message.data.url, message.data.newTab);
break;
- case 'setNamedDestinations':
- this.paramsParser_.namedDestinations = message.data.namedDestinations;
- break;
case 'setScrollPosition':
var position = this.viewport_.position;
if (message.data.x !== undefined)
@@ -519,6 +537,10 @@ PDFViewer.prototype = {
case 'setIsSelecting':
this.viewportScroller_.setEnableScrolling(message.data.isSelecting);
break;
+ case 'getNamedDestinationReply':
+ this.paramsParser_.onNamedDestinationReceived(
+ message.data.pageNumber);
+ break;
}
},
« no previous file with comments | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | chrome/test/data/pdf/navigator_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698