Index: chrome/browser/resources/pdf/pdf.js |
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js |
index 7c3d906bf68dc831ca37c47fc447c616c5c2fa25..8938b1ee73f5fcb0f1f8bb72e7cf8e9f2d040184 100644 |
--- a/chrome/browser/resources/pdf/pdf.js |
+++ b/chrome/browser/resources/pdf/pdf.js |
@@ -265,6 +265,33 @@ PDFViewer.prototype = { |
/** |
* @private |
+ * Handle open PDF parameters. |
raymes
2014/08/18 00:39:34
nit: Maybe we can elaborate on the comment saying
Nikhil
2014/08/18 04:53:32
Done.
|
+ */ |
+ handleOpenPDFParams_: function() { |
+ var originalUrl = this.streamDetails.originalUrl; |
+ var hasParams = originalUrl.search('#'); |
+ if (hasParams == -1) |
+ return; |
+ |
+ var paramTokens = originalUrl.substring(hasParams + 1).split('&'); |
+ var paramsDictionary = {}; |
+ for (var i = 0; i < paramTokens.length; ++i) { |
+ var keyValueSplit = paramTokens[i].split('='); |
+ if (keyValueSplit.length != 2) |
+ continue; |
+ paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; |
+ } |
+ |
+ // Order is important as later actions can override the effects |
+ // of previous actions. |
+ if ('page' in paramsDictionary) { |
+ // value is 1-based. |
+ this.viewport_.goToPage(paramsDictionary['page'] - 1); |
+ } |
+ }, |
+ |
+ /** |
+ * @private |
* Update the loading progress of the document in response to a progress |
* message being received from the plugin. |
* @param {number} progress the progress as a percentage. |
@@ -282,6 +309,7 @@ PDFViewer.prototype = { |
} |
} else if (progress == 100) { |
// Document load complete. |
+ this.handleOpenPDFParams_(); |
Nikhil
2014/08/16 10:24:01
Is there a way to check whether we are in PrintPre
Nikhil
2014/08/17 16:53:45
Maybe I can introduce isPrintPreview() here? Simil
raymes
2014/08/18 00:39:34
I think it should be ok not to do any check here.
Nikhil
2014/08/18 04:53:32
Acknowledged.
|
this.loaded = true; |
var loadEvent = new Event('pdfload'); |
window.dispatchEvent(loadEvent); |