OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 * @return {number} Width of a scrollbar in pixels | 8 * @return {number} Width of a scrollbar in pixels |
9 */ | 9 */ |
10 function getScrollbarWidth() { | 10 function getScrollbarWidth() { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 zoomChangeInfo.newZoomFactor); | 129 zoomChangeInfo.newZoomFactor); |
130 // We should not change zoom level when we are responsible for initiating | 130 // We should not change zoom level when we are responsible for initiating |
131 // the zoom. onZoomChange() is called before setZoomComplete() callback | 131 // the zoom. onZoomChange() is called before setZoomComplete() callback |
132 // when we initiate the zoom. | 132 // when we initiate the zoom. |
133 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) | 133 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) |
134 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); | 134 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); |
135 }.bind(this)); | 135 }.bind(this)); |
136 } | 136 } |
137 | 137 |
138 // Parse open pdf parameters. | 138 // Parse open pdf parameters. |
139 var paramsParser = new OpenPDFParamsParser(this.streamDetails_.originalUrl); | 139 this.paramsParser = new OpenPDFParamsParser(this.streamDetails_.originalUrl); |
140 this.urlParams_ = paramsParser.urlParams; | |
141 } | 140 } |
142 | 141 |
143 PDFViewer.prototype = { | 142 PDFViewer.prototype = { |
144 /** | 143 /** |
145 * @private | 144 * @private |
146 * Handle key events. These may come from the user directly or via the | 145 * Handle key events. These may come from the user directly or via the |
147 * scripting API. | 146 * scripting API. |
148 * @param {KeyboardEvent} e the event to handle. | 147 * @param {KeyboardEvent} e the event to handle. |
149 */ | 148 */ |
150 handleKeyEvent_: function(e) { | 149 handleKeyEvent_: function(e) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 }); | 276 }); |
278 }, | 277 }, |
279 | 278 |
280 /** | 279 /** |
281 * @private | 280 * @private |
282 * Handle open pdf parameters. This function updates the viewport as per | 281 * Handle open pdf parameters. This function updates the viewport as per |
283 * the parameters mentioned in the url while opening pdf. The order is | 282 * the parameters mentioned in the url while opening pdf. The order is |
284 * important as later actions can override the effects of previous actions. | 283 * important as later actions can override the effects of previous actions. |
285 */ | 284 */ |
286 handleURLParams_: function() { | 285 handleURLParams_: function() { |
287 if (this.urlParams_.page) | 286 if (this.paramsParser.namedDest) { |
288 this.viewport_.goToPage(this.urlParams_.page); | 287 this.viewport_.goToPage( |
289 if (this.urlParams_.position) { | 288 this.paramsParser.namedDestinations[this.paramsParser.namedDest]); |
289 } | |
290 if (this.paramsParser.urlParams.page) | |
291 this.viewport_.goToPage(this.paramsParser.urlParams.page); | |
292 if (this.paramsParser.urlParams.position) { | |
290 // Make sure we don't cancel effect of page parameter. | 293 // Make sure we don't cancel effect of page parameter. |
291 this.viewport_.position = { | 294 this.viewport_.position = { |
292 x: this.viewport_.position.x + this.urlParams_.position.x, | 295 x: this.viewport_.position.x + this.paramsParser.urlParams.position.x, |
293 y: this.viewport_.position.y + this.urlParams_.position.y | 296 y: this.viewport_.position.y + this.paramsParser.urlParams.position.y |
294 }; | 297 }; |
295 } | 298 } |
296 if (this.urlParams_.zoom) | 299 if (this.paramsParser.urlParams.zoom) |
297 this.viewport_.setZoom(this.urlParams_.zoom); | 300 this.viewport_.setZoom(this.paramsParser.urlParams.zoom); |
298 }, | 301 }, |
299 | 302 |
300 /** | 303 /** |
301 * @private | 304 * @private |
302 * Update the loading progress of the document in response to a progress | 305 * Update the loading progress of the document in response to a progress |
303 * message being received from the plugin. | 306 * message being received from the plugin. |
304 * @param {number} progress the progress as a percentage. | 307 * @param {number} progress the progress as a percentage. |
305 */ | 308 */ |
306 updateProgress_: function(progress) { | 309 updateProgress_: function(progress) { |
307 this.progressBar_.progress = progress; | 310 this.progressBar_.progress = progress; |
(...skipping 26 matching lines...) Expand all Loading... | |
334 */ | 337 */ |
335 onPasswordSubmitted_: function(event) { | 338 onPasswordSubmitted_: function(event) { |
336 this.plugin_.postMessage({ | 339 this.plugin_.postMessage({ |
337 type: 'getPasswordComplete', | 340 type: 'getPasswordComplete', |
338 password: event.detail.password | 341 password: event.detail.password |
339 }); | 342 }); |
340 }, | 343 }, |
341 | 344 |
342 /** | 345 /** |
343 * @private | 346 * @private |
347 * Helper function to process url from message and to navigate with in the | |
raymes
2015/01/13 01:59:31
nit: "with in" -> "within"
Deepak
2015/01/13 08:29:07
Done.
| |
348 * PDF page or opening new url in the same tab. | |
349 * @param {Object} message data that have the url and newTab info. | |
350 */ | |
351 navigate_: function(navigateData) { | |
352 var inputURL = navigateData.url; | |
353 // If there's no scheme, add http. | |
354 if (inputURL.indexOf('://') == -1 && inputURL.indexOf('mailto:') == -1) { | |
355 inputURL = 'http://' + inputURL; | |
356 } | |
357 // Make sure |url_copy| starts with a valid scheme. | |
358 if (inputURL.indexOf('http://') != 0 && | |
359 inputURL.indexOf('https://') != 0 && | |
360 inputURL.indexOf('ftp://') != 0 && | |
361 inputURL.indexOf('file://') != 0 && | |
362 inputURL.indexOf('mailto:') != 0) { | |
363 return; | |
364 } | |
365 // Make sure |url_copy| is not only a scheme. | |
366 if (inputURL == 'http://' || | |
367 inputURL == 'https://' || | |
368 inputURL == 'ftp://' || | |
369 inputURL == 'file://' || | |
370 inputURL == 'mailto:') { | |
371 return; | |
372 } | |
373 | |
374 if (navigateData.newTab) { | |
375 chrome.tabs.create({ url: inputURL }); | |
376 } else { | |
377 var hashIndex = inputURL.search('#'); | |
378 if (hashIndex != -1) { | |
379 var urlStr = inputURL.substring(hashIndex + 1); | |
380 if (this.paramsParser.namedDestinations[urlStr] != undefined) | |
raymes
2015/01/13 01:59:31
Rather than just getting the named destination out
Deepak
2015/01/13 08:29:07
Done.
| |
381 this.viewport_.goToPage(this.paramsParser.namedDestinations[urlStr]); | |
382 } else { | |
383 window.location.href = inputURL; | |
384 } | |
385 } | |
raymes
2015/01/13 01:59:31
I think the logic in this function needs some work
Deepak
2015/01/13 08:29:07
I have added a new function on lines of getInitalP
| |
386 }, | |
387 | |
388 /** | |
389 * @private | |
344 * An event handler for handling message events received from the plugin. | 390 * An event handler for handling message events received from the plugin. |
345 * @param {MessageObject} message a message event. | 391 * @param {MessageObject} message a message event. |
346 */ | 392 */ |
347 handlePluginMessage_: function(message) { | 393 handlePluginMessage_: function(message) { |
348 switch (message.data.type.toString()) { | 394 switch (message.data.type.toString()) { |
349 case 'documentDimensions': | 395 case 'documentDimensions': |
350 this.documentDimensions_ = message.data; | 396 this.documentDimensions_ = message.data; |
351 this.viewport_.setDocumentDimensions(this.documentDimensions_); | 397 this.viewport_.setDocumentDimensions(this.documentDimensions_); |
352 // If we received the document dimensions, the password was good so we | 398 // If we received the document dimensions, the password was good so we |
353 // can dismiss the password screen. | 399 // can dismiss the password screen. |
(...skipping 22 matching lines...) Expand all Loading... | |
376 else | 422 else |
377 this.passwordScreen_.deny(); | 423 this.passwordScreen_.deny(); |
378 break; | 424 break; |
379 case 'goToPage': | 425 case 'goToPage': |
380 this.viewport_.goToPage(message.data.page); | 426 this.viewport_.goToPage(message.data.page); |
381 break; | 427 break; |
382 case 'loadProgress': | 428 case 'loadProgress': |
383 this.updateProgress_(message.data.progress); | 429 this.updateProgress_(message.data.progress); |
384 break; | 430 break; |
385 case 'navigate': | 431 case 'navigate': |
386 if (message.data.newTab) | 432 this.navigate_(message.data); |
raymes
2015/01/13 01:59:31
can we pull out the url and newTab properties and
Deepak
2015/01/13 08:29:07
Done.
| |
387 window.open(message.data.url); | 433 break; |
388 else | 434 case 'setNamedDestinations': |
389 window.location.href = message.data.url; | 435 this.paramsParser.namedDestinations = message.data.namedDestinations; |
390 break; | 436 break; |
391 case 'setScrollPosition': | 437 case 'setScrollPosition': |
392 var position = this.viewport_.position; | 438 var position = this.viewport_.position; |
393 if (message.data.x != undefined) | 439 if (message.data.x != undefined) |
394 position.x = message.data.x; | 440 position.x = message.data.x; |
395 if (message.data.y != undefined) | 441 if (message.data.y != undefined) |
396 position.y = message.data.y; | 442 position.y = message.data.y; |
397 this.viewport_.position = position; | 443 this.viewport_.position = position; |
398 break; | 444 break; |
399 case 'setTranslatedStrings': | 445 case 'setTranslatedStrings': |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 this.streamDetails_.tabId != -1); | 647 this.streamDetails_.tabId != -1); |
602 }, | 648 }, |
603 | 649 |
604 /** | 650 /** |
605 * @type {Viewport} the viewport of the PDF viewer. | 651 * @type {Viewport} the viewport of the PDF viewer. |
606 */ | 652 */ |
607 get viewport() { | 653 get viewport() { |
608 return this.viewport_; | 654 return this.viewport_; |
609 } | 655 } |
610 }; | 656 }; |
OLD | NEW |