Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: chrome/browser/resources/pdf/navigator.js

Issue 2892623002: Type check PDF plugin JS code, down to 53 errors. (Closed)
Patch Set: Revert compiled_resources2.gyp for now. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/open_pdf_params_parser.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {number} tabId The tab ID of the PDF viewer or -1 if the viewer is 10 * @param {number} tabId The tab ID of the PDF viewer or -1 if the viewer is
11 * not displayed in a tab. 11 * not displayed in a tab.
12 * @constructor
12 */ 13 */
13 function NavigatorDelegate(tabId) { 14 function NavigatorDelegate(tabId) {
14 this.tabId_ = tabId; 15 this.tabId_ = tabId;
15 } 16 }
16 17
17 /** 18 /**
18 * Creates a new Navigator for navigating to links inside or outside the PDF. 19 * Creates a new Navigator for navigating to links inside or outside the PDF.
19 * @param {string} originalUrl The original page URL. 20 * @param {string} originalUrl The original page URL.
20 * @param {Object} viewport The viewport info of the page. 21 * @param {Object} viewport The viewport info of the page.
21 * @param {Object} paramsParser The object for URL parsing. 22 * @param {Object} paramsParser The object for URL parsing.
22 * @param {Object} navigatorDelegate The object with callback functions that 23 * @param {Object} navigatorDelegate The object with callback functions that
23 * get called when navigation happens in the current tab, a new tab, 24 * get called when navigation happens in the current tab, a new tab,
24 * and a new window. 25 * and a new window.
26 * @constructor
25 */ 27 */
26 function Navigator(originalUrl, viewport, paramsParser, navigatorDelegate) { 28 function Navigator(originalUrl, viewport, paramsParser, navigatorDelegate) {
27 this.originalUrl_ = originalUrl; 29 this.originalUrl_ = originalUrl;
28 this.viewport_ = viewport; 30 this.viewport_ = viewport;
29 this.paramsParser_ = paramsParser; 31 this.paramsParser_ = paramsParser;
30 this.navigatorDelegate_ = navigatorDelegate; 32 this.navigatorDelegate_ = navigatorDelegate;
31 } 33 }
32 34
33 NavigatorDelegate.prototype = { 35 NavigatorDelegate.prototype = {
34 /** 36 /**
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 Navigator.WindowOpenDisposition = { 86 Navigator.WindowOpenDisposition = {
85 CURRENT_TAB: 1, 87 CURRENT_TAB: 1,
86 NEW_FOREGROUND_TAB: 3, 88 NEW_FOREGROUND_TAB: 3,
87 NEW_BACKGROUND_TAB: 4, 89 NEW_BACKGROUND_TAB: 4,
88 NEW_WINDOW: 6, 90 NEW_WINDOW: 6,
89 SAVE_TO_DISK: 7 91 SAVE_TO_DISK: 7
90 }; 92 };
91 93
92 Navigator.prototype = { 94 Navigator.prototype = {
93 /** 95 /**
94 * @private
95 * Function to navigate to the given URL. This might involve navigating 96 * Function to navigate to the given URL. This might involve navigating
96 * within the PDF page or opening a new url (in the same tab or a new tab). 97 * within the PDF page or opening a new url (in the same tab or a new tab).
97 * @param {string} url The URL to navigate to. 98 * @param {string} url The URL to navigate to.
98 * @param {number} disposition The window open disposition when 99 * @param {number} disposition The window open disposition when
99 * navigating to the new URL. 100 * navigating to the new URL.
100 */ 101 */
101 navigate: function(url, disposition) { 102 navigate: function(url, disposition) {
102 if (url.length == 0) 103 if (url.length == 0)
103 return; 104 return;
104 105
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 var pageNumber = viewportPosition.page; 167 var pageNumber = viewportPosition.page;
167 if (pageNumber != undefined && originalUrl == newUrl) 168 if (pageNumber != undefined && originalUrl == newUrl)
168 this.viewport_.goToPage(pageNumber); 169 this.viewport_.goToPage(pageNumber);
169 else 170 else
170 this.navigatorDelegate_.navigateInCurrentTab(viewportPosition.url); 171 this.navigatorDelegate_.navigateInCurrentTab(viewportPosition.url);
171 }, 172 },
172 173
173 /** 174 /**
174 * @private 175 * @private
175 * Checks if the URL starts with a scheme and is not just a scheme. 176 * Checks if the URL starts with a scheme and is not just a scheme.
176 * @param {string} The input URL 177 * @param {string} url The input URL
177 * @return {boolean} Whether the url is valid. 178 * @return {boolean} Whether the url is valid.
178 */ 179 */
179 isValidUrl_: function(url) { 180 isValidUrl_: function(url) {
180 // Make sure |url| starts with a valid scheme. 181 // Make sure |url| starts with a valid scheme.
181 if (!url.startsWith('http://') && 182 if (!url.startsWith('http://') &&
182 !url.startsWith('https://') && 183 !url.startsWith('https://') &&
183 !url.startsWith('ftp://') && 184 !url.startsWith('ftp://') &&
184 !url.startsWith('file://') && 185 !url.startsWith('file://') &&
185 !url.startsWith('mailto:')) { 186 !url.startsWith('mailto:')) {
186 return false; 187 return false;
(...skipping 12 matching lines...) Expand all
199 url == 'mailto:') { 200 url == 'mailto:') {
200 return false; 201 return false;
201 } 202 }
202 203
203 return true; 204 return true;
204 }, 205 },
205 206
206 /** 207 /**
207 * @private 208 * @private
208 * Attempt to figure out what a URL is when there is no scheme. 209 * Attempt to figure out what a URL is when there is no scheme.
209 * @param {string} The input URL 210 * @param {string} url The input URL
210 * @return {string} The URL with a scheme or the original URL if it is not 211 * @return {string} The URL with a scheme or the original URL if it is not
211 * possible to determine the scheme. 212 * possible to determine the scheme.
212 */ 213 */
213 guessUrlWithoutScheme_: function(url) { 214 guessUrlWithoutScheme_: function(url) {
214 // If the original URL is mailto:, that does not make sense to start with, 215 // If the original URL is mailto:, that does not make sense to start with,
215 // and neither does adding |url| to it. 216 // and neither does adding |url| to it.
216 // If the original URL is not a valid URL, this cannot make a valid URL. 217 // If the original URL is not a valid URL, this cannot make a valid URL.
217 // In both cases, just bail out. 218 // In both cases, just bail out.
218 if (this.originalUrl_.startsWith('mailto:') || 219 if (this.originalUrl_.startsWith('mailto:') ||
219 !this.isValidUrl_(this.originalUrl_)) { 220 !this.isValidUrl_(this.originalUrl_)) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 if (isRelative) { 254 if (isRelative) {
254 var slashIndex = this.originalUrl_.lastIndexOf('/'); 255 var slashIndex = this.originalUrl_.lastIndexOf('/');
255 var path = slashIndex != -1 ? 256 var path = slashIndex != -1 ?
256 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_; 257 this.originalUrl_.substr(0, slashIndex) : this.originalUrl_;
257 return path + '/' + url; 258 return path + '/' + url;
258 } 259 }
259 260
260 return 'http://' + url; 261 return 'http://' + url;
261 } 262 }
262 }; 263 };
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/open_pdf_params_parser.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698