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} streamDetails The stream object which points to the data
33 * contained in the PDF.
35 function initViewer(streamDetails) {
36 // PDFViewer will handle any messages after it is created.
37 window.removeEventListener('message', handleScriptingMessage, false);
38 viewer = new PDFViewer(streamDetails);
39 while (pendingMessages.length > 0)
40 viewer.handleScriptingMessage(pendingMessages.shift());
43 function generateStreamDetailsAndInitViewer() {
44 var url = window.location.search.substring(1);
49 embedded: window.parent != window,
53 initViewer(streamDetails);
56 chrome.tabs.getCurrent(function(tab) {
57 streamDetails.tabId = tab.id;
58 initViewer(streamDetails);
63 * Entrypoint for starting the PDF viewer. This function obtains the details
64 * of the PDF 'stream' (the data that points to the PDF) and constructs a
65 * PDFViewer object with it.
68 // Set up an event listener to catch scripting messages which are sent prior
69 // to the PDFViewer being created.
70 window.addEventListener('message', handleScriptingMessage, false);
72 if (window.location.search) {
73 generateStreamDetailsAndInitViewer();
77 // If the viewer is started from the browser plugin, getStreamInfo will
78 // return the details of the stream.
79 chrome.mimeHandlerPrivate.getStreamInfo(function(streamDetails) {
80 initViewer(streamDetails);