OLD | NEW |
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 * Turn a dictionary received from postMessage into a key event. | 6 * Turn a dictionary received from postMessage into a key event. |
7 * @param {Object} dict A dictionary representing the key event. | 7 * @param {Object} dict A dictionary representing the key event. |
8 * @return {Event} A key event. | 8 * @return {Event} A key event. |
9 */ | 9 */ |
10 function DeserializeKeyEvent(dict) { | 10 function DeserializeKeyEvent(dict) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 * the PDF viewer so that it can be customized by things like print preview. | 49 * the PDF viewer so that it can be customized by things like print preview. |
50 * @param {Window} window the window of the page containing the pdf viewer. | 50 * @param {Window} window the window of the page containing the pdf viewer. |
51 * @param {Object} plugin the plugin element containing the pdf viewer. | 51 * @param {Object} plugin the plugin element containing the pdf viewer. |
52 */ | 52 */ |
53 function PDFScriptingAPI(window, plugin) { | 53 function PDFScriptingAPI(window, plugin) { |
54 this.loadState_ = LoadState.LOADING; | 54 this.loadState_ = LoadState.LOADING; |
55 this.pendingScriptingMessages_ = []; | 55 this.pendingScriptingMessages_ = []; |
56 this.setPlugin(plugin); | 56 this.setPlugin(plugin); |
57 | 57 |
58 window.addEventListener('message', function(event) { | 58 window.addEventListener('message', function(event) { |
59 if (event.origin != 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai') { | 59 if (event.origin != 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai' && |
| 60 event.origin != 'chrome://print') { |
60 console.error('Received message that was not from the extension: ' + | 61 console.error('Received message that was not from the extension: ' + |
61 event); | 62 event); |
62 return; | 63 return; |
63 } | 64 } |
64 switch (event.data.type) { | 65 switch (event.data.type) { |
65 case 'viewport': | 66 case 'viewport': |
66 if (this.viewportChangedCallback_) | 67 if (this.viewportChangedCallback_) |
67 this.viewportChangedCallback_(event.data.pageX, | 68 this.viewportChangedCallback_(event.data.pageX, |
68 event.data.pageY, | 69 event.data.pageY, |
69 event.data.pageWidth, | 70 event.data.pageWidth, |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 * Creates a PDF viewer with a scripting interface. This is basically 1) an | 265 * Creates a PDF viewer with a scripting interface. This is basically 1) an |
265 * iframe which is navigated to the PDF viewer extension and 2) a scripting | 266 * iframe which is navigated to the PDF viewer extension and 2) a scripting |
266 * interface which provides access to various features of the viewer for use | 267 * interface which provides access to various features of the viewer for use |
267 * by print preview and accessibility. | 268 * by print preview and accessibility. |
268 * @param {string} src the source URL of the PDF to load initially. | 269 * @param {string} src the source URL of the PDF to load initially. |
269 * @return {HTMLIFrameElement} the iframe element containing the PDF viewer. | 270 * @return {HTMLIFrameElement} the iframe element containing the PDF viewer. |
270 */ | 271 */ |
271 function PDFCreateOutOfProcessPlugin(src) { | 272 function PDFCreateOutOfProcessPlugin(src) { |
272 var client = new PDFScriptingAPI(window); | 273 var client = new PDFScriptingAPI(window); |
273 var iframe = window.document.createElement('iframe'); | 274 var iframe = window.document.createElement('iframe'); |
| 275 iframe.setAttribute('src', 'pdf_preview.html?' + src); |
274 // Prevent the frame from being tab-focusable. | 276 // Prevent the frame from being tab-focusable. |
275 iframe.setAttribute('tabindex', '-1'); | 277 iframe.setAttribute('tabindex', '-1'); |
276 | 278 |
277 var EXTENSION_URL = | |
278 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html'; | |
279 iframe.setAttribute('src', EXTENSION_URL + '?' + src); | |
280 iframe.onload = function() { | 279 iframe.onload = function() { |
281 client.setPlugin(iframe.contentWindow); | 280 client.setPlugin(iframe.contentWindow); |
282 }; | 281 }; |
283 | 282 |
284 // Add the functions to the iframe so that they can be called directly. | 283 // Add the functions to the iframe so that they can be called directly. |
285 iframe.setViewportChangedCallback = | 284 iframe.setViewportChangedCallback = |
286 client.setViewportChangedCallback.bind(client); | 285 client.setViewportChangedCallback.bind(client); |
287 iframe.setLoadCallback = client.setLoadCallback.bind(client); | 286 iframe.setLoadCallback = client.setLoadCallback.bind(client); |
288 iframe.setKeyEventCallback = client.setKeyEventCallback.bind(client); | 287 iframe.setKeyEventCallback = client.setKeyEventCallback.bind(client); |
289 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); | 288 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); |
290 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); | 289 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); |
291 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); | 290 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); |
292 return iframe; | 291 return iframe; |
293 } | 292 } |
OLD | NEW |