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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 // We should not change zoom level when we are responsible for initiating | 134 // We should not change zoom level when we are responsible for initiating |
135 // the zoom. onZoomChange() is called before setZoomComplete() callback | 135 // the zoom. onZoomChange() is called before setZoomComplete() callback |
136 // when we initiate the zoom. | 136 // when we initiate the zoom. |
137 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) | 137 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) |
138 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); | 138 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); |
139 }.bind(this)); | 139 }.bind(this)); |
140 } | 140 } |
141 | 141 |
142 // Parse open pdf parameters. | 142 // Parse open pdf parameters. |
143 this.paramsParser_ = new OpenPDFParamsParser(); | 143 this.paramsParser_ = new OpenPDFParamsParser(); |
144 this.navigator_ = new Navigator(); | |
144 } | 145 } |
145 | 146 |
146 PDFViewer.prototype = { | 147 PDFViewer.prototype = { |
147 /** | 148 /** |
148 * @private | 149 * @private |
149 * Handle key events. These may come from the user directly or via the | 150 * Handle key events. These may come from the user directly or via the |
150 * scripting API. | 151 * scripting API. |
151 * @param {KeyboardEvent} e the event to handle. | 152 * @param {KeyboardEvent} e the event to handle. |
152 */ | 153 */ |
153 handleKeyEvent_: function(e) { | 154 handleKeyEvent_: function(e) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 */ | 341 */ |
341 onPasswordSubmitted_: function(event) { | 342 onPasswordSubmitted_: function(event) { |
342 this.plugin_.postMessage({ | 343 this.plugin_.postMessage({ |
343 type: 'getPasswordComplete', | 344 type: 'getPasswordComplete', |
344 password: event.detail.password | 345 password: event.detail.password |
345 }); | 346 }); |
346 }, | 347 }, |
347 | 348 |
348 /** | 349 /** |
349 * @private | 350 * @private |
350 * Helper function to navigate to given URL. This might involve navigating | |
351 * within the PDF page or opening a new url (in the same tab or a new tab). | |
352 * @param {string} url The URL to navigate to. | |
353 * @param {boolean} newTab Whether to perform the navigation in a new tab or | |
354 * in the current tab. | |
355 */ | |
356 navigate_: function(url, newTab) { | |
357 if (url.length == 0) | |
358 return; | |
359 var originalUrl = this.streamDetails_.originalUrl; | |
360 // If |urlFragment| starts with '#', then it's for the same URL with a | |
361 // different URL fragment. | |
362 if (url.charAt(0) == '#') { | |
363 // if '#' is already present in |originalUrl| then remove old fragment | |
364 // and add new url fragment. | |
365 var hashIndex = originalUrl.search('#'); | |
366 if (hashIndex != -1) | |
367 url = originalUrl.substring(0, hashIndex) + url; | |
368 else | |
369 url = originalUrl + url; | |
370 } | |
371 | |
372 // If there's no scheme, add http. | |
373 if (url.indexOf('://') == -1 && url.indexOf('mailto:') == -1) | |
374 url = 'http://' + url; | |
375 | |
376 // Make sure url starts with a valid scheme. | |
377 if (url.indexOf('http://') != 0 && | |
378 url.indexOf('https://') != 0 && | |
379 url.indexOf('ftp://') != 0 && | |
380 url.indexOf('file://') != 0 && | |
381 url.indexOf('mailto:') != 0) { | |
382 return; | |
383 } | |
384 // Make sure url is not only a scheme. | |
385 if (url == 'http://' || | |
386 url == 'https://' || | |
387 url == 'ftp://' || | |
388 url == 'file://' || | |
389 url == 'mailto:') { | |
390 return; | |
391 } | |
392 | |
393 if (newTab) { | |
394 // Prefer the tabs API because it guarantees we can just open a new tab. | |
395 // window.open doesn't have this guarantee. | |
396 if (chrome.tabs) | |
397 chrome.tabs.create({ url: url }); | |
398 else | |
399 window.open(url); | |
400 } else { | |
401 var pageNumber = | |
402 this.paramsParser_.getViewportFromUrlParams(url).page; | |
403 if (pageNumber != undefined) | |
404 this.viewport_.goToPage(pageNumber); | |
405 else | |
406 window.location.href = url; | |
407 } | |
408 }, | |
409 | |
410 /** | |
411 * @private | |
412 * An event handler for handling message events received from the plugin. | 351 * An event handler for handling message events received from the plugin. |
413 * @param {MessageObject} message a message event. | 352 * @param {MessageObject} message a message event. |
414 */ | 353 */ |
415 handlePluginMessage_: function(message) { | 354 handlePluginMessage_: function(message) { |
416 switch (message.data.type.toString()) { | 355 switch (message.data.type.toString()) { |
417 case 'documentDimensions': | 356 case 'documentDimensions': |
418 this.documentDimensions_ = message.data; | 357 this.documentDimensions_ = message.data; |
419 this.viewport_.setDocumentDimensions(this.documentDimensions_); | 358 this.viewport_.setDocumentDimensions(this.documentDimensions_); |
420 // If we received the document dimensions, the password was good so we | 359 // If we received the document dimensions, the password was good so we |
421 // can dismiss the password screen. | 360 // can dismiss the password screen. |
(...skipping 24 matching lines...) Expand all Loading... | |
446 this.sendScriptingMessage_(message.data); | 385 this.sendScriptingMessage_(message.data); |
447 break; | 386 break; |
448 case 'goToPage': | 387 case 'goToPage': |
449 this.viewport_.goToPage(message.data.page); | 388 this.viewport_.goToPage(message.data.page); |
450 break; | 389 break; |
451 case 'loadProgress': | 390 case 'loadProgress': |
452 this.updateProgress_(message.data.progress); | 391 this.updateProgress_(message.data.progress); |
453 break; | 392 break; |
454 case 'navigate': | 393 case 'navigate': |
455 // If in print preview, always open a new tab. | 394 // If in print preview, always open a new tab. |
456 if (this.isPrintPreview_) | 395 if (this.isPrintPreview_) { |
457 this.navigate_(message.data.url, true); | 396 this.navigate_(message.data.url, true); |
458 else | 397 } else { |
459 this.navigate_(message.data.url, message.data.newTab); | 398 this.navigator_.navigate(message.data.url, message.data.newTab, |
399 this.streamDetails_.originalUrl, this.viewport_, this.paramsParser_); | |
raymes
2015/01/21 07:03:44
Can you please pass in the original URL, viewport
Deepak
2015/01/21 08:33:41
Done.
| |
400 } | |
460 break; | 401 break; |
461 case 'setNamedDestinations': | 402 case 'setNamedDestinations': |
462 this.paramsParser_.namedDestinations = message.data.namedDestinations; | 403 this.paramsParser_.namedDestinations = message.data.namedDestinations; |
463 break; | 404 break; |
464 case 'setScrollPosition': | 405 case 'setScrollPosition': |
465 var position = this.viewport_.position; | 406 var position = this.viewport_.position; |
466 if (message.data.x !== undefined) | 407 if (message.data.x !== undefined) |
467 position.x = message.data.x; | 408 position.x = message.data.x; |
468 if (message.data.y !== undefined) | 409 if (message.data.y !== undefined) |
469 position.y = message.data.y; | 410 position.y = message.data.y; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 this.streamDetails_.tabId != -1); | 625 this.streamDetails_.tabId != -1); |
685 }, | 626 }, |
686 | 627 |
687 /** | 628 /** |
688 * @type {Viewport} the viewport of the PDF viewer. | 629 * @type {Viewport} the viewport of the PDF viewer. |
689 */ | 630 */ |
690 get viewport() { | 631 get viewport() { |
691 return this.viewport_; | 632 return this.viewport_; |
692 } | 633 } |
693 }; | 634 }; |
OLD | NEW |