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 * 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 */ | 10 */ |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 message.page = page; | 142 message.page = page; |
143 this.sendMessage_(message); | 143 this.sendMessage_(message); |
144 return true; | 144 return true; |
145 }, | 145 }, |
146 | 146 |
147 /** | 147 /** |
148 * Send a key event to the extension. | 148 * Send a key event to the extension. |
149 * @param {number} keyCode the key code to send to the extension. | 149 * @param {number} keyCode the key code to send to the extension. |
150 */ | 150 */ |
151 sendKeyEvent: function(keyCode) { | 151 sendKeyEvent: function(keyCode) { |
152 // TODO(raymes): Figure out a way to do this. It's only used to do scrolling | 152 this.sendMessage_({ |
153 // the viewport, so probably just expose viewport controls instead. | 153 type: 'sendKeyEvent', |
| 154 keyCode: keyCode |
| 155 }); |
154 }, | 156 }, |
155 }; | 157 }; |
156 | 158 |
157 /** | 159 /** |
158 * Creates a PDF viewer with a scripting interface. This is basically 1) an | 160 * Creates a PDF viewer with a scripting interface. This is basically 1) an |
159 * iframe which is navigated to the PDF viewer extension and 2) a scripting | 161 * iframe which is navigated to the PDF viewer extension and 2) a scripting |
160 * interface which provides access to various features of the viewer for use | 162 * interface which provides access to various features of the viewer for use |
161 * by print preview and accessbility. | 163 * by print preview and accessbility. |
162 * @param {string} src the source URL of the PDF to load initially. | 164 * @param {string} src the source URL of the PDF to load initially. |
163 * @return {HTMLIFrameElement} the iframe element containing the PDF viewer. | 165 * @return {HTMLIFrameElement} the iframe element containing the PDF viewer. |
164 */ | 166 */ |
165 function PDFCreateOutOfProcessPlugin(src) { | 167 function PDFCreateOutOfProcessPlugin(src) { |
166 var EXTENSION_URL = 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai'; | 168 var EXTENSION_URL = 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai'; |
167 var iframe = window.document.createElement('iframe'); | 169 var iframe = window.document.createElement('iframe'); |
168 iframe.setAttribute('src', EXTENSION_URL + '/index.html?' + src); | 170 iframe.setAttribute('src', EXTENSION_URL + '/index.html?' + src); |
169 var client = new PDFScriptingAPI(window, EXTENSION_URL); | 171 var client = new PDFScriptingAPI(window, EXTENSION_URL); |
170 | 172 |
171 // Add the functions to the iframe so that they can be called directly. | 173 // Add the functions to the iframe so that they can be called directly. |
172 iframe.setViewportChangedCallback = | 174 iframe.setViewportChangedCallback = |
173 client.setViewportChangedCallback.bind(client); | 175 client.setViewportChangedCallback.bind(client); |
174 iframe.setLoadCallback = client.setLoadCallback.bind(client); | 176 iframe.setLoadCallback = client.setLoadCallback.bind(client); |
175 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); | 177 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); |
176 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); | 178 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); |
177 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); | 179 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); |
178 return iframe; | 180 return iframe; |
179 } | 181 } |
OLD | NEW |