Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / resources / pdf / main.js
blobe6938bc55cd0ec6b73298108c0c5a72da84b22c0
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.
5 'use strict';
7 /**
8 * Global PDFViewer object, accessible for testing.
9 * @type Object
11 var viewer;
14 (function() {
15 /**
16 * Stores any pending messages received which should be passed to the
17 * PDFViewer when it is created.
18 * @type Array
20 var pendingMessages = [];
22 /**
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);
30 /**
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());
42 /**
43 * Entrypoint for starting the PDF viewer. This function obtains the browser
44 * API for the PDF and constructs a PDFViewer object with it.
46 function main() {
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);
54 main();
55 })();