| 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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 if (url.charAt(0) == '#') { | 362 if (url.charAt(0) == '#') { |
| 363 // if '#' is already present in |originalUrl| then remove old fragment | 363 // if '#' is already present in |originalUrl| then remove old fragment |
| 364 // and add new url fragment. | 364 // and add new url fragment. |
| 365 var hashIndex = originalUrl.search('#'); | 365 var hashIndex = originalUrl.search('#'); |
| 366 if (hashIndex != -1) | 366 if (hashIndex != -1) |
| 367 url = originalUrl.substring(0, hashIndex) + url; | 367 url = originalUrl.substring(0, hashIndex) + url; |
| 368 else | 368 else |
| 369 url = originalUrl + url; | 369 url = originalUrl + url; |
| 370 } | 370 } |
| 371 | 371 |
| 372 var inputURL = url; | |
| 373 // If there's no scheme, add http. | 372 // If there's no scheme, add http. |
| 374 if (inputURL.indexOf('://') == -1 && inputURL.indexOf('mailto:') == -1) | 373 if (url.indexOf('://') == -1 && url.indexOf('mailto:') == -1) |
| 375 inputURL = 'http://' + inputURL; | 374 url = 'http://' + url; |
| 376 | 375 |
| 377 // Make sure inputURL starts with a valid scheme. | 376 // Make sure url starts with a valid scheme. |
| 378 if (inputURL.indexOf('http://') != 0 && | 377 if (url.indexOf('http://') != 0 && |
| 379 inputURL.indexOf('https://') != 0 && | 378 url.indexOf('https://') != 0 && |
| 380 inputURL.indexOf('ftp://') != 0 && | 379 url.indexOf('ftp://') != 0 && |
| 381 inputURL.indexOf('file://') != 0 && | 380 url.indexOf('file://') != 0 && |
| 382 inputURL.indexOf('mailto:') != 0) { | 381 url.indexOf('mailto:') != 0) { |
| 383 return; | 382 return; |
| 384 } | 383 } |
| 385 // Make sure inputURL is not only a scheme. | 384 // Make sure url is not only a scheme. |
| 386 if (inputURL == 'http://' || | 385 if (url == 'http://' || |
| 387 inputURL == 'https://' || | 386 url == 'https://' || |
| 388 inputURL == 'ftp://' || | 387 url == 'ftp://' || |
| 389 inputURL == 'file://' || | 388 url == 'file://' || |
| 390 inputURL == 'mailto:') { | 389 url == 'mailto:') { |
| 391 return; | 390 return; |
| 392 } | 391 } |
| 393 | 392 |
| 394 if (newTab) { | 393 if (newTab) { |
| 395 chrome.tabs.create({ url: inputURL }); | 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); |
| 396 } else { | 400 } else { |
| 397 var pageNumber = | 401 var pageNumber = |
| 398 this.paramsParser_.getViewportFromUrlParams(inputURL).page; | 402 this.paramsParser_.getViewportFromUrlParams(url).page; |
| 399 if (pageNumber != undefined) | 403 if (pageNumber != undefined) |
| 400 this.viewport_.goToPage(pageNumber); | 404 this.viewport_.goToPage(pageNumber); |
| 401 else | 405 else |
| 402 window.location.href = inputURL; | 406 window.location.href = url; |
| 403 } | 407 } |
| 404 }, | 408 }, |
| 405 | 409 |
| 406 /** | 410 /** |
| 407 * @private | 411 * @private |
| 408 * An event handler for handling message events received from the plugin. | 412 * An event handler for handling message events received from the plugin. |
| 409 * @param {MessageObject} message a message event. | 413 * @param {MessageObject} message a message event. |
| 410 */ | 414 */ |
| 411 handlePluginMessage_: function(message) { | 415 handlePluginMessage_: function(message) { |
| 412 switch (message.data.type.toString()) { | 416 switch (message.data.type.toString()) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 441 case 'getSelectedTextReply': | 445 case 'getSelectedTextReply': |
| 442 this.sendScriptingMessage_(message.data); | 446 this.sendScriptingMessage_(message.data); |
| 443 break; | 447 break; |
| 444 case 'goToPage': | 448 case 'goToPage': |
| 445 this.viewport_.goToPage(message.data.page); | 449 this.viewport_.goToPage(message.data.page); |
| 446 break; | 450 break; |
| 447 case 'loadProgress': | 451 case 'loadProgress': |
| 448 this.updateProgress_(message.data.progress); | 452 this.updateProgress_(message.data.progress); |
| 449 break; | 453 break; |
| 450 case 'navigate': | 454 case 'navigate': |
| 455 // If in print preview, always open a new tab. |
| 451 if (this.isPrintPreview_) | 456 if (this.isPrintPreview_) |
| 452 break; | 457 this.navigate_(message.data.url, true); |
| 453 this.navigate_(message.data.url, message.data.newTab); | 458 else |
| 459 this.navigate_(message.data.url, message.data.newTab); |
| 454 break; | 460 break; |
| 455 case 'setNamedDestinations': | 461 case 'setNamedDestinations': |
| 456 this.paramsParser_.namedDestinations = message.data.namedDestinations; | 462 this.paramsParser_.namedDestinations = message.data.namedDestinations; |
| 457 break; | 463 break; |
| 458 case 'setScrollPosition': | 464 case 'setScrollPosition': |
| 459 var position = this.viewport_.position; | 465 var position = this.viewport_.position; |
| 460 if (message.data.x !== undefined) | 466 if (message.data.x !== undefined) |
| 461 position.x = message.data.x; | 467 position.x = message.data.x; |
| 462 if (message.data.y !== undefined) | 468 if (message.data.y !== undefined) |
| 463 position.y = message.data.y; | 469 position.y = message.data.y; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 this.streamDetails_.tabId != -1); | 684 this.streamDetails_.tabId != -1); |
| 679 }, | 685 }, |
| 680 | 686 |
| 681 /** | 687 /** |
| 682 * @type {Viewport} the viewport of the PDF viewer. | 688 * @type {Viewport} the viewport of the PDF viewer. |
| 683 */ | 689 */ |
| 684 get viewport() { | 690 get viewport() { |
| 685 return this.viewport_; | 691 return this.viewport_; |
| 686 } | 692 } |
| 687 }; | 693 }; |
| OLD | NEW |