Chromium Code Reviews| Index: chrome/browser/resources/pdf/navigation_pdf.js |
| diff --git a/chrome/browser/resources/pdf/navigation_pdf.js b/chrome/browser/resources/pdf/navigation_pdf.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..88fda98406554b33d93e8f5a7fcf0cb635ba0832 |
| --- /dev/null |
| +++ b/chrome/browser/resources/pdf/navigation_pdf.js |
| @@ -0,0 +1,73 @@ |
| +// 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 NavigationPDF. This parses url and based on the nameddest PDF |
| + * file will scroll to specified page or open the url in the same tab or new |
| + * 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.
|
| + */ |
| +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.
|
| +} |
| + |
| +NavigationPDF.prototype = { |
| + /** |
| + * @private |
| + * 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.
|
| + * within the PDF page or opening a new url (in the same tab or a new tab). |
| + * @param {string} url The URL to navigate to. |
| + * @param {boolean} newTab Whether to perform the navigation in a new tab or |
| + * in the current tab. |
| + * @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.
|
| + */ |
| + 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.
|
| + if (url.length == 0) |
| + return; |
| + // If |urlFragment| starts with '#', then it's for the same URL with a |
| + // different URL fragment. |
| + if (url.charAt(0) == '#') { |
| + // if '#' is already present in |originalUrl| then remove old fragment |
| + // and add new url fragment. |
| + var hashIndex = originalUrl.search('#'); |
| + if (hashIndex != -1) |
| + url = originalUrl.substring(0, hashIndex) + url; |
| + else |
| + url = originalUrl + url; |
| + } |
| + |
| + var inputURL = url; |
| + // If there's no scheme, add http. |
| + if (inputURL.indexOf('://') == -1 && inputURL.indexOf('mailto:') == -1) |
| + inputURL = 'http://' + inputURL; |
| + |
| + // Make sure inputURL starts with a valid scheme. |
| + if (inputURL.indexOf('http://') != 0 && |
| + inputURL.indexOf('https://') != 0 && |
| + inputURL.indexOf('ftp://') != 0 && |
| + inputURL.indexOf('file://') != 0 && |
| + inputURL.indexOf('mailto:') != 0) { |
| + return; |
| + } |
| + // Make sure inputURL is not only a scheme. |
| + if (inputURL == 'http://' || |
| + inputURL == 'https://' || |
| + inputURL == 'ftp://' || |
| + inputURL == 'file://' || |
| + inputURL == 'mailto:') { |
| + return; |
| + } |
| + |
| + if (newTab) { |
| + chrome.tabs.create({ url: inputURL }); |
| + } else { |
| + var pageNumber = |
| + 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
|
| + if (pageNumber != undefined) |
| + 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.
|
| + else |
| + window.location.href = inputURL; |
| + } |
| + } |
| +}; |