| 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 {Object} plugin the plugin element containing the pdf viewer. | 9 * @param {Object} plugin the plugin element containing the pdf viewer. |
| 10 */ | 10 */ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 this.loaded_ = true; | 32 this.loaded_ = true; |
| 33 if (this.loadCallback_) | 33 if (this.loadCallback_) |
| 34 this.loadCallback_(); | 34 this.loadCallback_(); |
| 35 break; | 35 break; |
| 36 case 'getAccessibilityJSONReply': | 36 case 'getAccessibilityJSONReply': |
| 37 if (this.accessibilityCallback_) { | 37 if (this.accessibilityCallback_) { |
| 38 this.accessibilityCallback_(event.data.json); | 38 this.accessibilityCallback_(event.data.json); |
| 39 this.accessibilityCallback_ = null; | 39 this.accessibilityCallback_ = null; |
| 40 } | 40 } |
| 41 break; | 41 break; |
| 42 case 'getSelectedTextReply': | |
| 43 if (this.selectedTextCallback_) { | |
| 44 this.selectedTextCallback_(event.data.selectedText); | |
| 45 this.selectedTextCallback_ = null; | |
| 46 } | |
| 47 break; | |
| 48 } | 42 } |
| 49 }.bind(this), false); | 43 }.bind(this), false); |
| 50 } | 44 } |
| 51 | 45 |
| 52 PDFScriptingAPI.prototype = { | 46 PDFScriptingAPI.prototype = { |
| 53 /** | 47 /** |
| 54 * @private | 48 * @private |
| 55 * Send a message to the extension. If messages try to get sent before there | 49 * Send a message to the extension. If messages try to get sent before there |
| 56 * is a plugin element set, then we queue them up and send them later (this | 50 * is a plugin element set, then we queue them up and send them later (this |
| 57 * can happen in print preview). | 51 * can happen in print preview). |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 */ | 122 */ |
| 129 loadPreviewPage: function(url, index) { | 123 loadPreviewPage: function(url, index) { |
| 130 this.sendMessage_({ | 124 this.sendMessage_({ |
| 131 type: 'loadPreviewPage', | 125 type: 'loadPreviewPage', |
| 132 url: url, | 126 url: url, |
| 133 index: index | 127 index: index |
| 134 }); | 128 }); |
| 135 }, | 129 }, |
| 136 | 130 |
| 137 /** | 131 /** |
| 138 * Get accessibility JSON for the document. May only be called after document | 132 * Get accessibility JSON for the document. |
| 139 * load. | |
| 140 * @param {Function} callback a callback to be called with the accessibility | 133 * @param {Function} callback a callback to be called with the accessibility |
| 141 * json that has been retrieved. | 134 * json that has been retrieved. |
| 142 * @param {number} [page] the 0-indexed page number to get accessibility data | 135 * @param {number} [page] the 0-indexed page number to get accessibility data |
| 143 * for. If this is not provided, data about the entire document is | 136 * for. If this is not provided, data about the entire document is |
| 144 * returned. | 137 * returned. |
| 145 * @return {boolean} true if the function is successful, false if there is an | 138 * @return {boolean} true if the function is successful, false if there is an |
| 146 * outstanding request for accessibility data that has not been answered. | 139 * outstanding request for accessibility data that has not been answered. |
| 147 */ | 140 */ |
| 148 getAccessibilityJSON: function(callback, page) { | 141 getAccessibilityJSON: function(callback, page) { |
| 149 if (this.accessibilityCallback_) | 142 if (this.accessibilityCallback_) |
| 150 return false; | 143 return false; |
| 151 this.accessibilityCallback_ = callback; | 144 this.accessibilityCallback_ = callback; |
| 152 var message = { | 145 var message = { |
| 153 type: 'getAccessibilityJSON', | 146 type: 'getAccessibilityJSON', |
| 154 }; | 147 }; |
| 155 if (page || page == 0) | 148 if (page || page == 0) |
| 156 message.page = page; | 149 message.page = page; |
| 157 this.sendMessage_(message); | 150 this.sendMessage_(message); |
| 158 return true; | 151 return true; |
| 159 }, | 152 }, |
| 160 | 153 |
| 161 /** | 154 /** |
| 162 * Select all the text in the document. May only be called after document | |
| 163 * load. | |
| 164 */ | |
| 165 selectAll: function() { | |
| 166 this.sendMessage_({ | |
| 167 type: 'selectAll' | |
| 168 }); | |
| 169 }, | |
| 170 | |
| 171 /** | |
| 172 * Get the selected text in the document. The callback will be called with the | |
| 173 * text that is selected. May only be called after document load. | |
| 174 * @param {Function} callback a callback to be called with the selected text. | |
| 175 * @return {boolean} true if the function is successful, false if there is an | |
| 176 * outstanding request for selected text that has not been answered. | |
| 177 */ | |
| 178 getSelectedText: function(callback) { | |
| 179 if (this.selectedTextCallback_) | |
| 180 return false; | |
| 181 this.selectedTextCallback_ = callback; | |
| 182 this.sendMessage_({ | |
| 183 type: 'getSelectedText' | |
| 184 }); | |
| 185 return true; | |
| 186 }, | |
| 187 | |
| 188 /** | |
| 189 * Print the document. May only be called after document load. | |
| 190 */ | |
| 191 print: function() { | |
| 192 this.sendMessage_({ | |
| 193 type: 'print' | |
| 194 }); | |
| 195 }, | |
| 196 | |
| 197 /** | |
| 198 * Send a key event to the extension. | 155 * Send a key event to the extension. |
| 199 * @param {number} keyCode the key code to send to the extension. | 156 * @param {number} keyCode the key code to send to the extension. |
| 200 */ | 157 */ |
| 201 sendKeyEvent: function(keyCode) { | 158 sendKeyEvent: function(keyCode) { |
| 202 this.sendMessage_({ | 159 this.sendMessage_({ |
| 203 type: 'sendKeyEvent', | 160 type: 'sendKeyEvent', |
| 204 keyCode: keyCode | 161 keyCode: keyCode |
| 205 }); | 162 }); |
| 206 }, | 163 }, |
| 207 }; | 164 }; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 225 }; | 182 }; |
| 226 // 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. |
| 227 iframe.setViewportChangedCallback = | 184 iframe.setViewportChangedCallback = |
| 228 client.setViewportChangedCallback.bind(client); | 185 client.setViewportChangedCallback.bind(client); |
| 229 iframe.setLoadCallback = client.setLoadCallback.bind(client); | 186 iframe.setLoadCallback = client.setLoadCallback.bind(client); |
| 230 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); | 187 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); |
| 231 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); | 188 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); |
| 232 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); | 189 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); |
| 233 return iframe; | 190 return iframe; |
| 234 } | 191 } |
| OLD | NEW |