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

Side by Side Diff: chrome/browser/resources/pdf/pdf_open_params_parser.js

Issue 477933003: OOP PDF - Add OpenPDFParamsParser class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove invalid comment and change method name Created 6 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7 /**
8 * Creates a new OpenPDFParamsParser. This parses the open pdf parameters
9 * passed in the url to set initial viewport settings for opening the pdf.
10 * @param {string} url to be parsed.
11 */
12 function OpenPDFParamsParser(url) {
13 this.url_ = url;
14 this.viewportSettings_ = {};
15 }
16
17 OpenPDFParamsParser.prototype = {
18 /**
19 * @private
20 * Parse open PDF parameters. These parameters are mentioned in the url
21 * and specify actions to be performed when opening pdf files.
22 * See http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/
23 * pdfs/pdf_open_parameters.pdf for details.
24 */
25 parseOpenPDFParams_: function() {
26 var originalUrl = this.url_;
27 var paramIndex = originalUrl.search('#');
28 if (paramIndex == -1)
29 return;
30
31 var paramTokens = originalUrl.substring(paramIndex + 1).split('&');
32 var paramsDictionary = {};
33 for (var i = 0; i < paramTokens.length; ++i) {
34 var keyValueSplit = paramTokens[i].split('=');
35 if (keyValueSplit.length != 2)
36 continue;
37 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1];
38 }
39
40 if ('page' in paramsDictionary) {
41 // |pageNumber| is 1-based, but goToPage() take a zero-based page number.
42 var pageNumber = parseInt(paramsDictionary['page']);
43 if (!isNaN(pageNumber))
44 this.viewportSettings_['page'] = pageNumber - 1;
45 }
46 },
47
48 /**
49 * @type {ViewportSettings} the viewport settings to be used for opening pdf.
50 */
51 get viewportSettings() {
52 this.parseOpenPDFParams_();
raymes 2014/08/27 01:02:24 Why not just do this on construction? Then you wou
Nikhil 2014/08/27 10:16:09 Done.
53 return this.viewportSettings_;
54 }
55 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698