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

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

Issue 595153003: Compile print_preview, part 5: reduce down to 104 errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@I_print_preview_4
Patch Set: fix a comment Created 6 years, 2 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 /** 5 /**
6 * Create a new PDFScriptingAPI. This provides a scripting interface to 6 * Create a new PDFScriptingAPI. This provides a scripting interface to
7 * the PDF viewer so that it can be customized by things like print preview. 7 * the PDF viewer so that it can be customized by things like print preview.
8 * @param {Window} window the window of the page containing the pdf viewer. 8 * @param {Window} window the window of the page containing the pdf viewer.
9 * @param {string} extensionUrl the url of the PDF extension. 9 * @param {string} extensionUrl the url of the PDF extension.
10 * @constructor
10 */ 11 */
11 function PDFScriptingAPI(window, extensionUrl) { 12 function PDFScriptingAPI(window, extensionUrl) {
12 this.extensionUrl_ = extensionUrl; 13 this.extensionUrl_ = extensionUrl;
13 this.messageQueue_ = []; 14 this.messageQueue_ = [];
14 window.addEventListener('message', function(event) { 15 window.addEventListener('message', function(event) {
15 if (event.origin != this.extensionUrl_) { 16 if (event.origin != this.extensionUrl_) {
16 console.error('Received message that was not from the extension: ' + 17 console.error('Received message that was not from the extension: ' +
17 event); 18 event);
18 return; 19 return;
19 } 20 }
20 switch (event.data.type) { 21 switch (event.data.type) {
21 case 'readyToReceive': 22 case 'readyToReceive':
22 this.setDestinationWindow(event.source); 23 this.setDestinationWindow(event.source);
23 break; 24 break;
24 case 'viewport': 25 case 'viewport':
26 event.data = /**
27 * @type {{pageX: number,
28 * pageY: number,
29 * pageWidth: number,
30 * viewportWidth: number,
31 * viewportHeight: number}}
32 */(event.data);
25 if (this.viewportChangedCallback_) 33 if (this.viewportChangedCallback_)
26 this.viewportChangedCallback_(event.data.pageX, 34 this.viewportChangedCallback_(event.data.pageX,
27 event.data.pageY, 35 event.data.pageY,
28 event.data.pageWidth, 36 event.data.pageWidth,
29 event.data.viewportWidth, 37 event.data.viewportWidth,
30 event.data.viewportHeight); 38 event.data.viewportHeight);
31 break; 39 break;
32 case 'documentLoaded': 40 case 'documentLoaded':
33 if (this.loadCallback_) 41 if (this.loadCallback_)
34 this.loadCallback_(); 42 this.loadCallback_();
35 break; 43 break;
36 case 'getAccessibilityJSONReply': 44 case 'getAccessibilityJSONReply':
37 if (this.accessibilityCallback_) { 45 if (this.accessibilityCallback_) {
46 event.data = /** @type {{json: string}} */(event.data);
38 this.accessibilityCallback_(event.data.json); 47 this.accessibilityCallback_(event.data.json);
39 this.accessibilityCallback_ = null; 48 this.accessibilityCallback_ = null;
40 } 49 }
41 break; 50 break;
42 } 51 }
43 }.bind(this), false); 52 }.bind(this), false);
44 } 53 }
45 54
46 PDFScriptingAPI.prototype = { 55 PDFScriptingAPI.prototype = {
47 /** 56 /**
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 /** 168 /**
160 * Creates a PDF viewer with a scripting interface. This is basically 1) an 169 * Creates a PDF viewer with a scripting interface. This is basically 1) an
161 * iframe which is navigated to the PDF viewer extension and 2) a scripting 170 * iframe which is navigated to the PDF viewer extension and 2) a scripting
162 * interface which provides access to various features of the viewer for use 171 * interface which provides access to various features of the viewer for use
163 * by print preview and accessbility. 172 * by print preview and accessbility.
164 * @param {string} src the source URL of the PDF to load initially. 173 * @param {string} src the source URL of the PDF to load initially.
165 * @return {HTMLIFrameElement} the iframe element containing the PDF viewer. 174 * @return {HTMLIFrameElement} the iframe element containing the PDF viewer.
166 */ 175 */
167 function PDFCreateOutOfProcessPlugin(src) { 176 function PDFCreateOutOfProcessPlugin(src) {
168 var EXTENSION_URL = 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai'; 177 var EXTENSION_URL = 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai';
169 var iframe = window.document.createElement('iframe'); 178 var iframe = assertInstanceof(window.document.createElement('iframe'),
179 HTMLIFrameElement);
170 iframe.setAttribute('src', EXTENSION_URL + '/index.html?' + src); 180 iframe.setAttribute('src', EXTENSION_URL + '/index.html?' + src);
171 var client = new PDFScriptingAPI(window, EXTENSION_URL); 181 var client = new PDFScriptingAPI(window, EXTENSION_URL);
172 182
173 // Add the functions to the iframe so that they can be called directly. 183 // Add the functions to the iframe so that they can be called directly.
174 iframe.setViewportChangedCallback = 184 iframe.setViewportChangedCallback =
175 client.setViewportChangedCallback.bind(client); 185 client.setViewportChangedCallback.bind(client);
176 iframe.setLoadCallback = client.setLoadCallback.bind(client); 186 iframe.setLoadCallback = client.setLoadCallback.bind(client);
177 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); 187 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client);
178 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); 188 iframe.loadPreviewPage = client.loadPreviewPage.bind(client);
179 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); 189 iframe.sendKeyEvent = client.sendKeyEvent.bind(client);
180 return iframe; 190 return iframe;
181 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698