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

Side by Side Diff: chrome/browser/resources/pdf/main.js

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Global PDFViewer object, accessible for testing. 8 * Global PDFViewer object, accessible for testing.
9 * @type Object 9 * @type Object
10 */ 10 */
11 var viewer; 11 var viewer;
12 12
13 13
14 (function() { 14 (function() {
15 /** 15 /**
16 * Stores any pending messages received which should be passed to the 16 * Stores any pending messages received which should be passed to the
17 * PDFViewer when it is created. 17 * PDFViewer when it is created.
18 * @type Array 18 * @type Array
19 */ 19 */
20 var pendingMessages = []; 20 var pendingMessages = [];
21 21
22 /** 22 /**
23 * Handles events that are received prior to the PDFViewer being created. 23 * Handles events that are received prior to the PDFViewer being created.
24 * @param {Object} message A message event received. 24 * @param {Object} message A message event received.
25 */ 25 */
26 function handleScriptingMessage(message) { 26 function handleScriptingMessage(message) {
27 pendingMessages.push(message); 27 pendingMessages.push(message);
28 } 28 }
29 29
30 /** 30 /**
31 * Initialize the global PDFViewer and pass any outstanding messages to it. 31 * Initialize the global PDFViewer and pass any outstanding messages to it.
32 * @param {Object} browserApi An object providing an API to the browser. 32 * @param {Object} browserApi An object providing an API to the browser.
33 */ 33 */
34 function initViewer(browserApi) { 34 function initViewer(browserApi) {
35 // PDFViewer will handle any messages after it is created. 35 // PDFViewer will handle any messages after it is created.
36 window.removeEventListener('message', handleScriptingMessage, false); 36 window.removeEventListener('message', handleScriptingMessage, false);
37 viewer = new PDFViewer(browserApi); 37 viewer = new PDFViewer(browserApi);
38 while (pendingMessages.length > 0) 38 while (pendingMessages.length > 0)
39 viewer.handleScriptingMessage(pendingMessages.shift()); 39 viewer.handleScriptingMessage(pendingMessages.shift());
40 } 40 }
41 41
42 /** 42 /**
43 * Entrypoint for starting the PDF viewer. This function obtains the browser 43 * Entrypoint for starting the PDF viewer. This function obtains the browser
44 * API for the PDF and constructs a PDFViewer object with it. 44 * API for the PDF and constructs a PDFViewer object with it.
45 */ 45 */
46 function main() { 46 function main() {
47 // Set up an event listener to catch scripting messages which are sent prior 47 // Set up an event listener to catch scripting messages which are sent prior
48 // to the PDFViewer being created. 48 // to the PDFViewer being created.
49 window.addEventListener('message', handleScriptingMessage, false); 49 window.addEventListener('message', handleScriptingMessage, false);
50 50
51 createBrowserApi().then(initViewer); 51 createBrowserApi().then(initViewer);
52 } 52 }
53 53
54 main(); 54 main();
55 })(); 55 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698