Index: chrome/browser/resources/pdf/pdf.js |
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js |
index b2969e4ce52f7064cf47f6bbe914cfc72ab6a877..05eca0b494456cd3d2acaec566154fd56acdd20f 100644 |
--- a/chrome/browser/resources/pdf/pdf.js |
+++ b/chrome/browser/resources/pdf/pdf.js |
@@ -153,6 +153,8 @@ function PDFViewer(streamDetails) { |
// Parse open pdf parameters. |
this.paramsParser_ = new OpenPDFParamsParser(); |
+ this.navigator_ = new Navigator(this.streamDetails_.originalUrl, |
+ this.viewport_, this.paramsParser_); |
} |
PDFViewer.prototype = { |
@@ -362,68 +364,6 @@ PDFViewer.prototype = { |
/** |
* @private |
- * Helper function to navigate to given URL. This might involve navigating |
- * within the PDF page or opening a new url (in the same tab or a new tab). |
- * @param {string} url The URL to navigate to. |
- * @param {boolean} newTab Whether to perform the navigation in a new tab or |
- * in the current tab. |
- */ |
- navigate_: function(url, newTab) { |
- if (url.length == 0) |
- return; |
- var originalUrl = this.streamDetails_.originalUrl; |
- // If |urlFragment| starts with '#', then it's for the same URL with a |
- // different URL fragment. |
- if (url.charAt(0) == '#') { |
- // if '#' is already present in |originalUrl| then remove old fragment |
- // and add new url fragment. |
- var hashIndex = originalUrl.search('#'); |
- if (hashIndex != -1) |
- url = originalUrl.substring(0, hashIndex) + url; |
- else |
- url = originalUrl + url; |
- } |
- |
- // If there's no scheme, add http. |
- if (url.indexOf('://') == -1 && url.indexOf('mailto:') == -1) |
- url = 'http://' + url; |
- |
- // Make sure url starts with a valid scheme. |
- if (url.indexOf('http://') != 0 && |
- url.indexOf('https://') != 0 && |
- url.indexOf('ftp://') != 0 && |
- url.indexOf('file://') != 0 && |
- url.indexOf('mailto:') != 0) { |
- return; |
- } |
- // Make sure url is not only a scheme. |
- if (url == 'http://' || |
- url == 'https://' || |
- url == 'ftp://' || |
- url == 'file://' || |
- url == 'mailto:') { |
- return; |
- } |
- |
- if (newTab) { |
- // Prefer the tabs API because it guarantees we can just open a new tab. |
- // window.open doesn't have this guarantee. |
- if (chrome.tabs) |
- chrome.tabs.create({ url: url }); |
- else |
- window.open(url); |
- } else { |
- var pageNumber = |
- this.paramsParser_.getViewportFromUrlParams(url).page; |
- if (pageNumber != undefined) |
- this.viewport_.goToPage(pageNumber); |
- else |
- window.location.href = url; |
- } |
- }, |
- |
- /** |
- * @private |
* An event handler for handling message events received from the plugin. |
* @param {MessageObject} message a message event. |
*/ |
@@ -471,7 +411,7 @@ PDFViewer.prototype = { |
if (this.isPrintPreview_) |
this.navigate_(message.data.url, true); |
else |
- this.navigate_(message.data.url, message.data.newTab); |
+ this.navigator_.navigate(message.data.url, message.data.newTab); |
break; |
case 'setNamedDestinations': |
this.paramsParser_.namedDestinations = message.data.namedDestinations; |