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

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

Issue 477933003: OOP PDF - Add OpenPDFParamsParser class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback (update variable name) Created 6 years, 4 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') | no next file » | 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 c5920f877dc10c80a416c95c23b8fb7ab4ebc105..2bb5511402abe108e48da0d5f28c52449bf086c0 100644
--- a/chrome/browser/resources/pdf/pdf.js
+++ b/chrome/browser/resources/pdf/pdf.js
@@ -5,6 +5,7 @@
'use strict';
<include src="../../../../ui/webui/resources/js/util.js">
+<include src="open_pdf_params_parser.js">
<include src="pdf_scripting_api.js">
<include src="viewport.js">
@@ -150,6 +151,10 @@ function PDFViewer() {
this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
}.bind(this));
}
+
+ // Parse open pdf parameters.
+ var paramsParser = new OpenPDFParamsParser(this.streamDetails.originalUrl);
+ this.urlParams_ = paramsParser.urlParams;
}
PDFViewer.prototype = {
@@ -265,37 +270,6 @@ PDFViewer.prototype = {
/**
* @private
- * Handle open PDF parameters. These parameters are mentioned in the URL
- * and specify actions to be performed when opening PDF files.
- * See http://crbug.com/64309 for details.
- */
- handleOpenPDFParams_: function() {
- var originalUrl = this.streamDetails.originalUrl;
- var paramIndex = originalUrl.search('#');
- if (paramIndex == -1)
- return;
-
- var paramTokens = originalUrl.substring(paramIndex + 1).split('&');
- var paramsDictionary = {};
- for (var i = 0; i < paramTokens.length; ++i) {
- var keyValueSplit = paramTokens[i].split('=');
- if (keyValueSplit.length != 2)
- continue;
- paramsDictionary[keyValueSplit[0]] = keyValueSplit[1];
- }
-
- // Order is important as later actions can override the effects
- // of previous actions.
- if ('page' in paramsDictionary) {
- // |pageNumber| is 1-based, but goToPage() take a zero-based page number.
- var pageNumber = parseInt(paramsDictionary['page']);
- if (!isNaN(pageNumber))
- this.viewport_.goToPage(pageNumber - 1);
- }
- },
-
- /**
- * @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.
@@ -313,7 +287,6 @@ PDFViewer.prototype = {
}
} else if (progress == 100) {
// Document load complete.
- this.handleOpenPDFParams_();
this.loaded = true;
var loadEvent = new Event('pdfload');
window.dispatchEvent(loadEvent);
@@ -322,6 +295,11 @@ PDFViewer.prototype = {
});
if (this.lastViewportPosition_)
this.viewport_.position = this.lastViewportPosition_;
+
+ // Handle open pdf params. Order is important as later actions can
+ // override the effects of previous actions.
+ if (this.urlParams_.page)
+ this.viewport_.goToPage(this.urlParams_.page);
}
},
« no previous file with comments | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698