1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 * A map of view ID (which identifies a particular PDF viewer instance) to
11 * @type {Object.<string, Object>}
16 * A map of view ID (which identifies a particular PDF viewer instance) to
17 * initialization function for that view.
18 * @type {Object.<string, Function>}
20 var pluginInitFunctions
= {};
23 * If we have received a stream object and an initialization function for a
24 * particular PDF viewer instance we know that the extension has loaded in
25 * and we can pass it the stream. We can then delete the corresponding map
27 * @param {string} viewId The ID of the view to initialize with a stream.
29 function flush(viewId
) {
30 if (viewId
in streams
&& viewId
in pluginInitFunctions
) {
31 pluginInitFunctions
[viewId
](streams
[viewId
]);
32 delete streams
[viewId
];
33 delete pluginInitFunctions
[viewId
];
38 * This is called when loading a document with the PDF mime type and passes a
39 * stream that points to the PDF file. This may be run before or after we
40 * receive a message from the PDF viewer with its initialization function.
42 chrome
.streamsPrivate
.onExecuteMimeTypeHandler
.addListener(
43 function(streamDetails
) {
44 // Store the stream until we are contacted by the PDF viewer that owns the
46 streams
[streamDetails
.viewId
] = streamDetails
;
47 flush(streamDetails
.viewId
);
52 * This is called when we receive a message from the PDF viewer indicating
53 * it has loaded and is ready to receive a stream of the data.
55 chrome
.runtime
.onMessage
.addListener(
56 function(request
, sender
, responseFunction
) {
57 // Store the initialization function until we receive the stream which
58 // corresponds to the PDF viewer.
59 pluginInitFunctions
[request
.viewId
] = responseFunction
;
60 flush(request
.viewId
);