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

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

Issue 870453002: Make the scripting OOP PDF API easier to use (take 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | pdf/out_of_process_instance.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
},
/**
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | pdf/out_of_process_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698