Chromium Code Reviews| 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 {Object} navigateInCurrentTabCallback The Callback function that get | |
|
raymes
2015/01/29 04:27:13
nit: get->gets
nit: {Object}->{Function}
Deepak
2015/01/29 06:05:41
Done.
| |
| 13 * called when navigation happen in the current tab. | |
|
raymes
2015/01/29 04:27:13
nit: happen->happens
Deepak
2015/01/29 06:05:41
Done.
| |
| 14 * @param {Object} navigateInNewTabCallback The Callback function that get | |
|
raymes
2015/01/29 04:27:13
nit: get->gets
nit: {Object}->{Function}
Deepak
2015/01/29 06:05:41
Done.
| |
| 15 * called when navigation happen in the new tab. | |
|
raymes
2015/01/29 04:27:13
nit: happen->happens
Deepak
2015/01/29 06:05:41
Done.
| |
| 12 */ | 16 */ |
| 13 function Navigator(originalUrl, viewport, paramsParser) { | 17 function Navigator(originalUrl, |
| 18 viewport, | |
|
raymes
2015/01/29 04:27:13
nit: indentation - please align with the (
Deepak
2015/01/29 06:05:41
Done.
| |
| 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 29 matching lines...) Expand all Loading... | |
| 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 // Prefer the tabs API because it guarantees we can just open a new tab. |
| 66 // window.open doesn't have this guarantee. | 76 // window.open doesn't have this guarantee. |
|
raymes
2015/01/30 03:45:03
Please keep this comment in the function that we p
| |
| 77 this.navigateInNewTabCallback_(); | |
| 67 if (chrome.tabs) | 78 if (chrome.tabs) |
| 68 chrome.tabs.create({ url: url }); | 79 chrome.tabs.create({ url: url }); |
| 69 else | 80 else |
| 70 window.open(url); | 81 window.open(url); |
|
raymes
2015/01/29 04:27:13
We should remove the above 4 lines (and comment) n
Deepak
2015/01/29 06:05:41
Done.
| |
| 71 } else { | 82 } else { |
| 72 var pageNumber = | 83 var pageNumber = |
| 73 this.paramsParser_.getViewportFromUrlParams(url).page; | 84 this.paramsParser_.getViewportFromUrlParams(url).page; |
| 74 if (pageNumber != undefined) | 85 if (pageNumber != undefined) { |
| 75 this.viewport_.goToPage(pageNumber); | 86 this.viewport_.goToPage(pageNumber); |
| 76 else | 87 } else { |
| 88 this.navigateInCurrentTabCallback_(); | |
| 77 window.location.href = url; | 89 window.location.href = url; |
|
raymes
2015/01/29 04:27:13
The same with this line - it should be passed in a
Deepak
2015/01/29 06:05:41
Done.
| |
| 90 } | |
| 78 } | 91 } |
| 79 } | 92 } |
| 80 }; | 93 }; |
| OLD | NEW |