Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5267)

Unified Diff: chrome/browser/resources/pdf/pdf.js

Issue 830433002: Navigation to relative fragments does not work correctly for OOP pdf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Indentation fix. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/pdf/pdf.js
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js
index 735c508fdd197c0924cf7b8127f5f9d6c0eb9ee0..f452267764301fb5b3b54812ef53c91a32408dad 100644
--- a/chrome/browser/resources/pdf/pdf.js
+++ b/chrome/browser/resources/pdf/pdf.js
@@ -136,8 +136,7 @@ function PDFViewer(streamDetails) {
}
// Parse open pdf parameters.
- var paramsParser = new OpenPDFParamsParser(this.streamDetails_.originalUrl);
- this.urlParams_ = paramsParser.urlParams;
+ this.paramsParser = new OpenPDFParamsParser();
raymes 2015/01/15 04:51:11 Let's keep this named paramsParser_. An underscore
Deepak 2015/01/15 06:30:05 Done.
}
PDFViewer.prototype = {
@@ -284,17 +283,21 @@ PDFViewer.prototype = {
* important as later actions can override the effects of previous actions.
*/
handleURLParams_: function() {
- if (this.urlParams_.page)
- this.viewport_.goToPage(this.urlParams_.page);
- if (this.urlParams_.position) {
+ var urlParams =
+ this.paramsParser.getURLPDFParams(this.streamDetails_.originalUrl);
+ if (urlParams.page)
+ this.viewport_.goToPage(urlParams.page);
+ if (urlParams.nameddest)
+ this.viewport_.goToPage(urlParams.nameddest);
raymes 2015/01/15 04:51:11 If we merge nameddest and page we can remove this
Deepak 2015/01/15 06:30:05 Done.
+ if (urlParams.position) {
// Make sure we don't cancel effect of page parameter.
this.viewport_.position = {
- x: this.viewport_.position.x + this.urlParams_.position.x,
- y: this.viewport_.position.y + this.urlParams_.position.y
+ x: this.viewport_.position.x + urlParams.position.x,
+ y: this.viewport_.position.y + urlParams.position.y
};
}
- if (this.urlParams_.zoom)
- this.viewport_.setZoom(this.urlParams_.zoom);
+ if (urlParams.zoom)
+ this.viewport_.setZoom(urlParams.zoom);
},
/**
@@ -341,6 +344,66 @@ 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} message data that have the url for navigation.
+ * @param {boolean} message data that have info regarding navigation happen
+ * within the PDF page or in the newTab.
+ */
+ navigate_: function(urlFragment, isNewTab) {
raymes 2015/01/15 04:51:11 I'd like to start reducing this size of this class
Deepak 2015/01/15 06:30:05 I understand, I will do refactoring in a separate
+ var namedFragment;
+ if (urlFragment.length != 0) {
+ // If |urlFragment| starts with '#', then it's for the same URL with a
+ // different URL fragment.
+ if (urlFragment.charAt(0) == '#') {
+ // if '#' is already present in |originalUrl| then remove old fragment
+ // and add new url fragment.
+ namedFragment = urlFragment.substring(1);
+ var originalUrl = this.streamDetails_.originalUrl;
+ var hashIndex = originalUrl.search('#');
+ if (hashIndex != -1)
+ urlFragment = originalUrl.substring(0, hashIndex) + urlFragment;
+ else
+ urlFragment = originalUrl + urlFragment;
+ }
+ }
+ var inputURL = urlFragment;
+ // If there's no scheme, add http.
+ if (inputURL.indexOf('://') == -1 && inputURL.indexOf('mailto:') == -1) {
+ inputURL = 'http://' + inputURL;
+ }
+ // Make sure inputURL starts with a valid scheme.
+ if (inputURL.indexOf('http://') != 0 &&
+ inputURL.indexOf('https://') != 0 &&
+ inputURL.indexOf('ftp://') != 0 &&
+ inputURL.indexOf('file://') != 0 &&
+ inputURL.indexOf('mailto:') != 0) {
+ return;
+ }
+ // Make sure inputURL is not only a scheme.
+ if (inputURL == 'http://' ||
+ inputURL == 'https://' ||
+ inputURL == 'ftp://' ||
+ inputURL == 'file://' ||
+ inputURL == 'mailto:') {
+ return;
+ }
+
+ if (isNewTab) {
+ chrome.tabs.create({ url: inputURL });
raymes 2015/01/15 04:51:11 Cool, thanks for looking into that! Let's leave it
Deepak 2015/01/15 06:30:05 Acknowledged.
+ } else {
+ var pageNumber = -1;
+ if (namedFragment)
+ pageNumber = this.paramsParser.namedDestinations[namedFragment];
+ if (pageNumber >= 0)
+ this.viewport_.goToPage(pageNumber);
+ else
+ window.location.href = inputURL;
+ }
+ },
raymes 2015/01/15 04:51:11 Here is what I was thinking (there are a few chang
Deepak 2015/01/15 06:30:05 Done.
+
+ /**
+ * @private
* An event handler for handling message events received from the plugin.
* @param {MessageObject} message a message event.
*/
@@ -386,10 +449,10 @@ PDFViewer.prototype = {
this.updateProgress_(message.data.progress);
break;
case 'navigate':
- if (message.data.newTab)
- window.open(message.data.url);
- else
- window.location.href = message.data.url;
+ this.navigate_(message.data.url, message.data.newTab);
+ break;
+ case 'setNamedDestinations':
+ this.paramsParser.namedDestinations = message.data.namedDestinations;
break;
case 'setScrollPosition':
var position = this.viewport_.position;

Powered by Google App Engine
This is Rietveld 408576698