Index: chrome/browser/resources/pdf/pdf_scripting_api.js |
diff --git a/chrome/browser/resources/pdf/pdf_scripting_api.js b/chrome/browser/resources/pdf/pdf_scripting_api.js |
index e8dd4bca03a412020645901432979cf911758427..26d6b01f6fc0d7a19a61c5d1c8f464a579758611 100644 |
--- a/chrome/browser/resources/pdf/pdf_scripting_api.js |
+++ b/chrome/browser/resources/pdf/pdf_scripting_api.js |
@@ -9,7 +9,6 @@ |
* @param {Object} plugin the plugin element containing the pdf viewer. |
*/ |
function PDFScriptingAPI(window, plugin) { |
- this.loaded_ = false; |
this.pendingScriptingMessages_ = []; |
this.setPlugin(plugin); |
@@ -29,9 +28,10 @@ function PDFScriptingAPI(window, plugin) { |
event.data.viewportHeight); |
break; |
case 'documentLoaded': |
- this.loaded_ = true; |
- if (this.loadCallback_) |
+ if (this.loadCallback_) { |
this.loadCallback_(); |
+ this.loadCallback_ = null; |
+ } |
break; |
case 'getAccessibilityJSONReply': |
if (this.accessibilityCallback_) { |
@@ -72,14 +72,8 @@ PDFScriptingAPI.prototype = { |
setPlugin: function(plugin) { |
this.plugin_ = plugin; |
- // Send an initialization message to the plugin indicating the window to |
- // respond to. |
if (this.plugin_) { |
- this.sendMessage_({ |
- type: 'setParentWindow' |
- }); |
- |
- // Now we can flush pending messages |
+ // Flush pending messages. |
while (this.pendingScriptingMessages_.length > 0) |
this.sendMessage_(this.pendingScriptingMessages_.shift()); |
} |
@@ -97,11 +91,17 @@ PDFScriptingAPI.prototype = { |
* Sets the callback which will be run when the PDF document has finished |
* loading. If the document is already loaded, it will be run immediately. |
* @param {Function} callback the callback to be called. |
+ * @return {boolean} false if there is a callback already set and true |
+ * otherwise. |
*/ |
setLoadCallback: function(callback) { |
+ if (this.loadCallback_) |
+ return false; |
this.loadCallback_ = callback; |
- if (this.loaded_ && callback) |
- callback(); |
+ this.sendMessage_({ |
+ type: 'isDocumentLoaded' |
+ }); |
+ return true; |
}, |
/** |