| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Creates a new Navigator for navigating to links inside or outside the PDF. | 8 * Creates a new Navigator for navigating to links inside or outside the PDF. |
| 9 * @param {string} originalUrl The original page URL. | 9 * @param {string} originalUrl The original page URL. |
| 10 * @param {Object} viewport The viewport info of the page. | 10 * @param {Object} viewport The viewport info of the page. |
| 11 * @param {Object} paramsParser The object for URL parsing. | 11 * @param {Object} paramsParser The object for URL parsing. |
| 12 * @param {Function} navigateInCurrentTabCallback The Callback function that |
| 13 * gets called when navigation happens in the current tab. |
| 14 * @param {Function} navigateInNewTabCallback The Callback function that gets |
| 15 * called when navigation happens in the new tab. |
| 12 */ | 16 */ |
| 13 function Navigator(originalUrl, viewport, paramsParser) { | 17 function Navigator(originalUrl, |
| 18 viewport, |
| 19 paramsParser, |
| 20 navigateInCurrentTabCallback, |
| 21 navigateInNewTabCallback) { |
| 14 this.originalUrl_ = originalUrl; | 22 this.originalUrl_ = originalUrl; |
| 15 this.viewport_ = viewport; | 23 this.viewport_ = viewport; |
| 16 this.paramsParser_ = paramsParser; | 24 this.paramsParser_ = paramsParser; |
| 25 this.navigateInCurrentTabCallback_ = navigateInCurrentTabCallback; |
| 26 this.navigateInNewTabCallback_ = navigateInNewTabCallback; |
| 17 } | 27 } |
| 18 | 28 |
| 19 Navigator.prototype = { | 29 Navigator.prototype = { |
| 20 /** | 30 /** |
| 21 * @private | 31 * @private |
| 22 * Function to navigate to the given URL. This might involve navigating | 32 * Function to navigate to the given URL. This might involve navigating |
| 23 * within the PDF page or opening a new url (in the same tab or a new tab). | 33 * within the PDF page or opening a new url (in the same tab or a new tab). |
| 24 * @param {string} url The URL to navigate to. | 34 * @param {string} url The URL to navigate to. |
| 25 * @param {boolean} newTab Whether to perform the navigation in a new tab or | 35 * @param {boolean} newTab Whether to perform the navigation in a new tab or |
| 26 * in the current tab. | 36 * in the current tab. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 55 // Make sure inputURL is not only a scheme. | 65 // Make sure inputURL is not only a scheme. |
| 56 if (url == 'http://' || | 66 if (url == 'http://' || |
| 57 url == 'https://' || | 67 url == 'https://' || |
| 58 url == 'ftp://' || | 68 url == 'ftp://' || |
| 59 url == 'file://' || | 69 url == 'file://' || |
| 60 url == 'mailto:') { | 70 url == 'mailto:') { |
| 61 return; | 71 return; |
| 62 } | 72 } |
| 63 | 73 |
| 64 if (newTab) { | 74 if (newTab) { |
| 65 // Prefer the tabs API because it guarantees we can just open a new tab. | 75 this.navigateInNewTabCallback_(url); |
| 66 // window.open doesn't have this guarantee. | |
| 67 if (chrome.tabs) | |
| 68 chrome.tabs.create({ url: url }); | |
| 69 else | |
| 70 window.open(url); | |
| 71 } else { | 76 } else { |
| 72 var pageNumber = | 77 var pageNumber = |
| 73 this.paramsParser_.getViewportFromUrlParams(url).page; | 78 this.paramsParser_.getViewportFromUrlParams(url).page; |
| 74 if (pageNumber != undefined) | 79 if (pageNumber != undefined) |
| 75 this.viewport_.goToPage(pageNumber); | 80 this.viewport_.goToPage(pageNumber); |
| 76 else | 81 else |
| 77 window.location.href = url; | 82 this.navigateInCurrentTabCallback_(url); |
| 78 } | 83 } |
| 79 } | 84 } |
| 80 }; | 85 }; |
| OLD | NEW |