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

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

Issue 855323002: Refactoring of code by moving navigate_() to separate file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 NavigationPDF. This parses url and based on the nameddest PDF
9 * file will scroll to specified page or open the url in the same tab or new
10 * tab based on newTab value.
raymes 2015/01/20 02:58:29 nit: "Creates a new Navigator for navigating to li
Deepak 2015/01/20 07:08:37 Done.
11 */
12 function NavigationPDF() {
raymes 2015/01/20 02:58:29 can we call this "Navigator" and and put it inside
Deepak 2015/01/20 07:08:37 Done.
13 }
14
15 NavigationPDF.prototype = {
16 /**
17 * @private
18 * Function to navigate to given URL. This might involve navigating
raymes 2015/01/20 02:58:29 nit "navigate to the given URL"
Deepak 2015/01/20 07:08:37 Done.
19 * within the PDF page or opening a new url (in the same tab or a new tab).
20 * @param {string} url The URL to navigate to.
21 * @param {boolean} newTab Whether to perform the navigation in a new tab or
22 * in the current tab.
23 * @param {string} originalUrl The opiginal page URL.
raymes 2015/01/20 02:58:29 nit: opiginal->original
Deepak 2015/01/20 07:08:37 Done.
24 */
25 navigate: function(url, newTab, originalUrl) {
raymes 2015/01/20 02:58:29 nit: I just landed https://codereview.chromium.org
Deepak 2015/01/20 07:08:37 Done.
26 if (url.length == 0)
27 return;
28 // If |urlFragment| starts with '#', then it's for the same URL with a
29 // different URL fragment.
30 if (url.charAt(0) == '#') {
31 // if '#' is already present in |originalUrl| then remove old fragment
32 // and add new url fragment.
33 var hashIndex = originalUrl.search('#');
34 if (hashIndex != -1)
35 url = originalUrl.substring(0, hashIndex) + url;
36 else
37 url = originalUrl + url;
38 }
39
40 var inputURL = url;
41 // If there's no scheme, add http.
42 if (inputURL.indexOf('://') == -1 && inputURL.indexOf('mailto:') == -1)
43 inputURL = 'http://' + inputURL;
44
45 // Make sure inputURL starts with a valid scheme.
46 if (inputURL.indexOf('http://') != 0 &&
47 inputURL.indexOf('https://') != 0 &&
48 inputURL.indexOf('ftp://') != 0 &&
49 inputURL.indexOf('file://') != 0 &&
50 inputURL.indexOf('mailto:') != 0) {
51 return;
52 }
53 // Make sure inputURL is not only a scheme.
54 if (inputURL == 'http://' ||
55 inputURL == 'https://' ||
56 inputURL == 'ftp://' ||
57 inputURL == 'file://' ||
58 inputURL == 'mailto:') {
59 return;
60 }
61
62 if (newTab) {
63 chrome.tabs.create({ url: inputURL });
64 } else {
65 var pageNumber =
66 viewer.paramsParser_.getViewportFromUrlParams(inputURL).page;
raymes 2015/01/20 02:58:29 Can we pass in the paramsParser as an argument?
Deepak 2015/01/20 07:08:37 yes, it is better we pass these as argument. As it
67 if (pageNumber != undefined)
68 viewer.viewport_.goToPage(pageNumber);
raymes 2015/01/20 02:58:29 Can we pass in the viewport as an argument?
Deepak 2015/01/20 07:08:37 Same as above.
69 else
70 window.location.href = inputURL;
71 }
72 }
73 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698