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