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 NavigatorDelegate for calling browser-specific functions to | 8 * Creates a new NavigatorDelegate for calling browser-specific functions to |
9 * do the actual navigating. | 9 * do the actual navigating. |
10 * @param {boolean} isInTab Indicates if the PDF viewer is displayed in a tab. | 10 * @param {boolean} isInTab Indicates if the PDF viewer is displayed in a tab. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 window.location.href = url; | 47 window.location.href = url; |
48 }, | 48 }, |
49 | 49 |
50 /** | 50 /** |
51 * @public | 51 * @public |
52 * Called when navigation should happen in the new tab. | 52 * Called when navigation should happen in the new tab. |
53 * @param {string} url The url to be opened in the new tab. | 53 * @param {string} url The url to be opened in the new tab. |
54 * @param {boolean} active Indicates if the new tab should be the active tab. | 54 * @param {boolean} active Indicates if the new tab should be the active tab. |
55 */ | 55 */ |
56 navigateInNewTab: function(url, active) { | 56 navigateInNewTab: function(url, active) { |
57 if (!this.isSourceFileUrl_ && /^file:/i.test(url)) | |
58 return; | |
59 | |
57 // Prefer the tabs API because it guarantees we can just open a new tab. | 60 // Prefer the tabs API because it guarantees we can just open a new tab. |
58 // window.open doesn't have this guarantee. | 61 // window.open doesn't have this guarantee. |
59 if (chrome.tabs) | 62 if (chrome.tabs) |
60 chrome.tabs.create({url: url, active: active}); | 63 chrome.tabs.create({url: url, active: active}); |
61 else | 64 else |
62 window.open(url); | 65 window.open(url); |
63 }, | 66 }, |
64 | 67 |
65 /** | 68 /** |
66 * @public | 69 * @public |
67 * Called when navigation should happen in the new window. | 70 * Called when navigation should happen in the new window. |
68 * @param {string} url The url to be opened in the new window. | 71 * @param {string} url The url to be opened in the new window. |
69 */ | 72 */ |
70 navigateInNewWindow: function(url) { | 73 navigateInNewWindow: function(url) { |
74 if (!this.isSourceFileUrl_ && /^file:/i.test(url)) | |
Lei Zhang
2016/10/10 21:07:04
Can we write a helper function and call it from mu
raymes
2016/10/11 06:37:42
+1
Could you also please add a test to this to na
robwu
2016/10/12 22:08:01
Done.
| |
75 return; | |
76 | |
71 // Prefer the windows API because it guarantees we can just open a new | 77 // Prefer the windows API because it guarantees we can just open a new |
72 // window. window.open with '_blank' argument doesn't have this guarantee. | 78 // window. window.open with '_blank' argument doesn't have this guarantee. |
73 if (chrome.windows) | 79 if (chrome.windows) |
74 chrome.windows.create({url: url}); | 80 chrome.windows.create({url: url}); |
75 else | 81 else |
76 window.open(url, '_blank'); | 82 window.open(url, '_blank'); |
77 } | 83 } |
78 }; | 84 }; |
79 | 85 |
80 /** | 86 /** |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 if (isRelative) { | 256 if (isRelative) { |
251 var slashIndex = this.originalUrl_.lastIndexOf('/'); | 257 var slashIndex = this.originalUrl_.lastIndexOf('/'); |
252 var path = slashIndex != -1 ? | 258 var path = slashIndex != -1 ? |
253 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_; | 259 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_; |
254 return path + '/' + url; | 260 return path + '/' + url; |
255 } | 261 } |
256 | 262 |
257 return 'http://' + url; | 263 return 'http://' + url; |
258 } | 264 } |
259 }; | 265 }; |
OLD | NEW |