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

Unified Diff: chrome/browser/resources/pdf/open_pdf_params_parser.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 | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/pdf/open_pdf_params_parser.js
diff --git a/chrome/browser/resources/pdf/open_pdf_params_parser.js b/chrome/browser/resources/pdf/open_pdf_params_parser.js
new file mode 100644
index 0000000000000000000000000000000000000000..7f55db0434d065c42e41d5ae4f0dccd11e76a862
--- /dev/null
+++ b/chrome/browser/resources/pdf/open_pdf_params_parser.js
@@ -0,0 +1,48 @@
+// Copyright 2014 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.
+
+'use strict';
+
+/**
+ * Creates a new OpenPDFParamsParser. This parses the open pdf parameters
+ * passed in the url to set initial viewport settings for opening the pdf.
+ * @param {string} url to be parsed.
+ */
+function OpenPDFParamsParser(url) {
+ this.url_ = url;
+ this.urlParams = {};
+ this.parseOpenPDFParams_();
+}
+
+OpenPDFParamsParser.prototype = {
+ /**
+ * @private
+ * Parse open PDF parameters. These parameters are mentioned in the url
+ * and specify actions to be performed when opening pdf files.
+ * See http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/
+ * pdfs/pdf_open_parameters.pdf for details.
+ */
+ parseOpenPDFParams_: function() {
+ var originalUrl = this.url_;
+ 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];
+ }
+
+ 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.urlParams['page'] = pageNumber - 1;
+ }
+ }
+};
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698