1 // Copyright 2014 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.
8 * Global PDFViewer object, accessible for testing.
16 * Stores any pending messages received which should be passed to the
17 * PDFViewer when it is created.
20 var pendingMessages = [];
23 * Handles events that are received prior to the PDFViewer being created.
24 * @param {Object} message A message event received.
26 function handleScriptingMessage(message) {
27 pendingMessages.push(message);
31 * Initialize the global PDFViewer and pass any outstanding messages to it.
32 * @param {Object} browserApi An object providing an API to the browser.
34 function initViewer(browserApi) {
35 // PDFViewer will handle any messages after it is created.
36 window.removeEventListener('message', handleScriptingMessage, false);
37 viewer = new PDFViewer(browserApi);
38 while (pendingMessages.length > 0)
39 viewer.handleScriptingMessage(pendingMessages.shift());
43 * Entrypoint for starting the PDF viewer. This function obtains the browser
44 * API for the PDF and constructs a PDFViewer object with it.
47 // Set up an event listener to catch scripting messages which are sent prior
48 // to the PDFViewer being created.
49 window.addEventListener('message', handleScriptingMessage, false);
51 createBrowserApi().then(initViewer);