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.navigatePDF_ = new NavigationPDF(); | |
raymes
2015/01/20 02:58:29
this.navigator_ = new Navigator(this.viewport_, th
Deepak
2015/01/20 07:08:37
we should not pass these here as information in th
| |
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 var inputURL = url; | |
373 // If there's no scheme, add http. | |
374 if (inputURL.indexOf('://') == -1 && inputURL.indexOf('mailto:') == -1) | |
375 inputURL = 'http://' + inputURL; | |
376 | |
377 // Make sure inputURL starts with a valid scheme. | |
378 if (inputURL.indexOf('http://') != 0 && | |
379 inputURL.indexOf('https://') != 0 && | |
380 inputURL.indexOf('ftp://') != 0 && | |
381 inputURL.indexOf('file://') != 0 && | |
382 inputURL.indexOf('mailto:') != 0) { | |
383 return; | |
384 } | |
385 // Make sure inputURL is not only a scheme. | |
386 if (inputURL == 'http://' || | |
387 inputURL == 'https://' || | |
388 inputURL == 'ftp://' || | |
389 inputURL == 'file://' || | |
390 inputURL == 'mailto:') { | |
391 return; | |
392 } | |
393 | |
394 if (newTab) { | |
395 chrome.tabs.create({ url: inputURL }); | |
396 } else { | |
397 var pageNumber = | |
398 this.paramsParser_.getViewportFromUrlParams(inputURL).page; | |
399 if (pageNumber != undefined) | |
400 this.viewport_.goToPage(pageNumber); | |
401 else | |
402 window.location.href = inputURL; | |
403 } | |
404 }, | |
405 | |
406 /** | |
407 * @private | |
408 * An event handler for handling message events received from the plugin. | 351 * An event handler for handling message events received from the plugin. |
409 * @param {MessageObject} message a message event. | 352 * @param {MessageObject} message a message event. |
410 */ | 353 */ |
411 handlePluginMessage_: function(message) { | 354 handlePluginMessage_: function(message) { |
412 switch (message.data.type.toString()) { | 355 switch (message.data.type.toString()) { |
413 case 'documentDimensions': | 356 case 'documentDimensions': |
414 this.documentDimensions_ = message.data; | 357 this.documentDimensions_ = message.data; |
415 this.viewport_.setDocumentDimensions(this.documentDimensions_); | 358 this.viewport_.setDocumentDimensions(this.documentDimensions_); |
416 // 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 |
417 // can dismiss the password screen. | 360 // can dismiss the password screen. |
(...skipping 25 matching lines...) Expand all Loading... | |
443 break; | 386 break; |
444 case 'goToPage': | 387 case 'goToPage': |
445 this.viewport_.goToPage(message.data.page); | 388 this.viewport_.goToPage(message.data.page); |
446 break; | 389 break; |
447 case 'loadProgress': | 390 case 'loadProgress': |
448 this.updateProgress_(message.data.progress); | 391 this.updateProgress_(message.data.progress); |
449 break; | 392 break; |
450 case 'navigate': | 393 case 'navigate': |
451 if (this.isPrintPreview_) | 394 if (this.isPrintPreview_) |
452 break; | 395 break; |
453 this.navigate_(message.data.url, message.data.newTab); | 396 this.navigatePDF_.navigate(message.data.url, message.data.newTab, |
397 this.streamDetails_.originalUrl); | |
454 break; | 398 break; |
455 case 'setNamedDestinations': | 399 case 'setNamedDestinations': |
456 this.paramsParser_.namedDestinations = message.data.namedDestinations; | 400 this.paramsParser_.namedDestinations = message.data.namedDestinations; |
457 break; | 401 break; |
458 case 'setScrollPosition': | 402 case 'setScrollPosition': |
459 var position = this.viewport_.position; | 403 var position = this.viewport_.position; |
460 if (message.data.x !== undefined) | 404 if (message.data.x !== undefined) |
461 position.x = message.data.x; | 405 position.x = message.data.x; |
462 if (message.data.y !== undefined) | 406 if (message.data.y !== undefined) |
463 position.y = message.data.y; | 407 position.y = message.data.y; |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 }, | 630 }, |
687 | 631 |
688 /** | 632 /** |
689 * Each bookmark is an Object containing a: | 633 * Each bookmark is an Object containing a: |
690 * - title | 634 * - title |
691 * - page (optional) | 635 * - page (optional) |
692 * - array of children (themselves bookmarks) | 636 * - array of children (themselves bookmarks) |
693 * @type {Array} the top-level bookmarks of the PDF. | 637 * @type {Array} the top-level bookmarks of the PDF. |
694 */ | 638 */ |
695 get bookmarks() { | 639 get bookmarks() { |
696 return this.bookmarks_; | 640 return this.bookmarks_; |
raymes
2015/01/21 07:03:44
Please keep this. It is used in tests
| |
697 } | 641 } |
698 }; | 642 }; |
OLD | NEW |