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} navigateInNewBackgroundTabCallback The Callback function | 14 * @param {Function} navigateInNewTabCallback The Callback function |
15 * that gets called when navigation happens in the new background tab. | 15 * that gets called when navigation happens in the new tab. |
16 */ | 16 */ |
17 function Navigator(originalUrl, | 17 function Navigator(originalUrl, |
18 viewport, | 18 viewport, |
19 paramsParser, | 19 paramsParser, |
20 navigateInCurrentTabCallback, | 20 navigateInCurrentTabCallback, |
21 navigateInNewBackgroundTabCallback) { | 21 navigateInNewTabCallback) { |
22 this.originalUrl_ = originalUrl; | 22 this.originalUrl_ = originalUrl; |
23 this.viewport_ = viewport; | 23 this.viewport_ = viewport; |
24 this.paramsParser_ = paramsParser; | 24 this.paramsParser_ = paramsParser; |
25 this.navigateInCurrentTabCallback_ = navigateInCurrentTabCallback; | 25 this.navigateInCurrentTabCallback_ = navigateInCurrentTabCallback; |
26 this.navigateInNewBackgroundTabCallback_ = navigateInNewBackgroundTabCallback; | 26 this.navigateInNewTabCallback_ = navigateInNewTabCallback; |
27 } | 27 } |
28 | 28 |
29 /** | |
30 * 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 | |
32 * the only values that are passed from Plugin. | |
33 * @enum {number} | |
34 */ | |
35 Navigator.WindowOpenDisposition = { | |
36 CURRENT_TAB: 1, | |
37 NEW_FOREGROUND_TAB: 3, | |
38 NEW_BACKGROUND_TAB: 4, | |
39 NEW_WINDOW: 6, | |
40 SAVE_TO_DISK: 7 | |
41 }; | |
42 | |
29 Navigator.prototype = { | 43 Navigator.prototype = { |
30 /** | 44 /** |
31 * @private | 45 * @private |
32 * Function to navigate to the given URL. This might involve navigating | 46 * Function to navigate to the given URL. This might involve navigating |
33 * within the PDF page or opening a new url (in the same tab or a new tab). | 47 * within the PDF page or opening a new url (in the same tab or a new tab). |
34 * @param {string} url The URL to navigate to. | 48 * @param {string} url The URL to navigate to. |
35 * @param {boolean} newTab Whether to perform the navigation in a new tab or | 49 * @param {boolean} newTab Whether to perform the navigation in a new tab or |
36 * in the current tab. | 50 * in the current tab. |
37 */ | 51 */ |
38 navigate: function(url, newTab) { | 52 navigate: function(url, disposition) { |
39 if (url.length == 0) | 53 if (url.length == 0) |
40 return; | 54 return; |
41 | 55 |
42 // If |urlFragment| starts with '#', then it's for the same URL with a | 56 // If |urlFragment| starts with '#', then it's for the same URL with a |
43 // different URL fragment. | 57 // different URL fragment. |
44 if (url.charAt(0) == '#') { | 58 if (url.charAt(0) == '#') { |
45 // if '#' is already present in |originalUrl| then remove old fragment | 59 // if '#' is already present in |originalUrl| then remove old fragment |
46 // and add new url fragment. | 60 // and add new url fragment. |
47 var hashIndex = this.originalUrl_.search('#'); | 61 var hashIndex = this.originalUrl_.search('#'); |
48 if (hashIndex != -1) | 62 if (hashIndex != -1) |
49 url = this.originalUrl_.substring(0, hashIndex) + url; | 63 url = this.originalUrl_.substring(0, hashIndex) + url; |
50 else | 64 else |
51 url = this.originalUrl_ + url; | 65 url = this.originalUrl_ + url; |
52 } | 66 } |
53 | 67 |
54 // If there's no scheme, then take a guess at the scheme. | 68 // If there's no scheme, then take a guess at the scheme. |
55 if (url.indexOf('://') == -1 && url.indexOf('mailto:') == -1) | 69 if (url.indexOf('://') == -1 && url.indexOf('mailto:') == -1) |
56 url = this.guessUrlWithoutScheme_(url); | 70 url = this.guessUrlWithoutScheme_(url); |
57 | 71 |
58 if (!this.isValidUrl_(url)) | 72 if (!this.isValidUrl_(url)) |
59 return; | 73 return; |
60 | 74 |
61 if (newTab) { | 75 switch (disposition) { |
62 this.navigateInNewBackgroundTabCallback_(url); | 76 case Navigator.WindowOpenDisposition.CURRENT_TAB: |
63 } else { | 77 // TODO (jaepark): It should navigate in a new window when |
Lei Zhang
2016/07/23 00:39:38
It's weird that the first two cases fall through t
jaepark
2016/07/23 03:52:30
Done. I've changed it not to fall through in each
| |
64 this.paramsParser_.getViewportFromUrlParams( | 78 // shift + left clicking link in PDFs. See http://crbug.com/628057. |
65 url, this.onViewportReceived_.bind(this)); | 79 case Navigator.WindowOpenDisposition.NEW_WINDOW: |
80 // TODO (jaepark) : Alt + left clicking link in PDFs should | |
81 // donwload the link. | |
82 case Navigator.WindowOpenDisposition.SAVE_TO_DISK: | |
83 this.paramsParser_.getViewportFromUrlParams( | |
84 url, this.onViewportReceived_.bind(this)); | |
85 break; | |
86 case Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB: | |
87 this.navigateInNewTabCallback_(url, false); | |
88 break; | |
89 case Navigator.WindowOpenDisposition.NEW_FOREGROUND_TAB: | |
90 this.navigateInNewTabCallback_(url, true); | |
91 break; | |
92 default: | |
93 break; | |
66 } | 94 } |
67 }, | 95 }, |
68 | 96 |
69 /** | 97 /** |
70 * @private | 98 * @private |
71 * Called when the viewport position is received. | 99 * Called when the viewport position is received. |
72 * @param {Object} viewportPosition Dictionary containing the viewport | 100 * @param {Object} viewportPosition Dictionary containing the viewport |
73 * position. | 101 * position. |
74 */ | 102 */ |
75 onViewportReceived_: function(viewportPosition) { | 103 onViewportReceived_: function(viewportPosition) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 if (isRelative) { | 196 if (isRelative) { |
169 var slashIndex = this.originalUrl_.lastIndexOf('/'); | 197 var slashIndex = this.originalUrl_.lastIndexOf('/'); |
170 var path = slashIndex != -1 ? | 198 var path = slashIndex != -1 ? |
171 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_; | 199 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_; |
172 return path + '/' + url; | 200 return path + '/' + url; |
173 } | 201 } |
174 | 202 |
175 return 'http://' + url; | 203 return 'http://' + url; |
176 } | 204 } |
177 }; | 205 }; |
OLD | NEW |