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 {Function} navigateInCurrentTabCallback The Callback function that | 12 * @param {Function} navigateInCurrentTabCallback The Callback function that |
| 13 * gets called when navigation happens in the current tab. | 13 * gets called when navigation happens in the current tab. |
| 14 * @param {Function} navigateInNewTabCallback The Callback function | 14 * @param {Function} navigateInNewTabCallback The Callback function |
| 15 * that gets called when navigation happens in the new tab. | 15 * that gets called when navigation happens in the new tab. |
| 16 * @param {Function} navigateInNewWindowCallback The Callback function | |
| 17 * that gets called when navigation happens in the new window. | |
| 16 */ | 18 */ |
| 17 function Navigator(originalUrl, | 19 function Navigator(originalUrl, |
| 18 viewport, | 20 viewport, |
| 19 paramsParser, | 21 paramsParser, |
| 20 navigateInCurrentTabCallback, | 22 navigateInCurrentTabCallback, |
| 21 navigateInNewTabCallback) { | 23 navigateInNewTabCallback, |
| 24 navigateInNewWindowCallback) { | |
|
raymes
2016/09/05 04:29:32
Now that we're passing 3 functions in here, we may
jaepark
2016/09/06 02:49:56
Done.
| |
| 22 this.originalUrl_ = originalUrl; | 25 this.originalUrl_ = originalUrl; |
| 23 this.viewport_ = viewport; | 26 this.viewport_ = viewport; |
| 24 this.paramsParser_ = paramsParser; | 27 this.paramsParser_ = paramsParser; |
| 25 this.navigateInCurrentTabCallback_ = navigateInCurrentTabCallback; | 28 this.navigateInCurrentTabCallback_ = navigateInCurrentTabCallback; |
| 26 this.navigateInNewTabCallback_ = navigateInNewTabCallback; | 29 this.navigateInNewTabCallback_ = navigateInNewTabCallback; |
| 30 this.navigateInNewWindowCallback_ = navigateInNewWindowCallback; | |
| 27 } | 31 } |
| 28 | 32 |
| 29 /** | 33 /** |
| 30 * Represents options when navigating to a new url. C++ counterpart of | 34 * Represents options when navigating to a new url. C++ counterpart of |
| 31 * the enum is in ui/base/window_open_disposition.h. This enum represents | 35 * the enum is in ui/base/window_open_disposition.h. This enum represents |
| 32 * the only values that are passed from Plugin. | 36 * the only values that are passed from Plugin. |
| 33 * @enum {number} | 37 * @enum {number} |
| 34 */ | 38 */ |
| 35 Navigator.WindowOpenDisposition = { | 39 Navigator.WindowOpenDisposition = { |
| 36 CURRENT_TAB: 1, | 40 CURRENT_TAB: 1, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 this.paramsParser_.getViewportFromUrlParams( | 81 this.paramsParser_.getViewportFromUrlParams( |
| 78 url, this.onViewportReceived_.bind(this)); | 82 url, this.onViewportReceived_.bind(this)); |
| 79 break; | 83 break; |
| 80 case Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB: | 84 case Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB: |
| 81 this.navigateInNewTabCallback_(url, false); | 85 this.navigateInNewTabCallback_(url, false); |
| 82 break; | 86 break; |
| 83 case Navigator.WindowOpenDisposition.NEW_FOREGROUND_TAB: | 87 case Navigator.WindowOpenDisposition.NEW_FOREGROUND_TAB: |
| 84 this.navigateInNewTabCallback_(url, true); | 88 this.navigateInNewTabCallback_(url, true); |
| 85 break; | 89 break; |
| 86 case Navigator.WindowOpenDisposition.NEW_WINDOW: | 90 case Navigator.WindowOpenDisposition.NEW_WINDOW: |
| 87 // TODO(jaepark): Shift + left clicking a link in PDF should open the | 91 this.navigateInNewWindowCallback_(url); |
| 88 // link in a new window. See http://crbug.com/628057. | |
| 89 this.paramsParser_.getViewportFromUrlParams( | |
| 90 url, this.onViewportReceived_.bind(this)); | |
| 91 break; | 92 break; |
| 92 case Navigator.WindowOpenDisposition.SAVE_TO_DISK: | 93 case Navigator.WindowOpenDisposition.SAVE_TO_DISK: |
| 93 // TODO(jaepark): Alt + left clicking a link in PDF should | 94 // TODO(jaepark): Alt + left clicking a link in PDF should |
| 94 // download the link. | 95 // download the link. |
| 95 this.paramsParser_.getViewportFromUrlParams( | 96 this.paramsParser_.getViewportFromUrlParams( |
| 96 url, this.onViewportReceived_.bind(this)); | 97 url, this.onViewportReceived_.bind(this)); |
| 97 break; | 98 break; |
| 98 default: | 99 default: |
| 99 break; | 100 break; |
| 100 } | 101 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 if (isRelative) { | 203 if (isRelative) { |
| 203 var slashIndex = this.originalUrl_.lastIndexOf('/'); | 204 var slashIndex = this.originalUrl_.lastIndexOf('/'); |
| 204 var path = slashIndex != -1 ? | 205 var path = slashIndex != -1 ? |
| 205 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_; | 206 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_; |
| 206 return path + '/' + url; | 207 return path + '/' + url; |
| 207 } | 208 } |
| 208 | 209 |
| 209 return 'http://' + url; | 210 return 'http://' + url; |
| 210 } | 211 } |
| 211 }; | 212 }; |
| OLD | NEW |