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

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

Issue 843463002: Add print and getSelectedText functions to the OOP PDF scripting API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@postMessage-api
Patch Set: Created 5 years, 11 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
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | chrome/test/data/pdf/basic_plugin_test.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {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
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;
42 } 48 }
43 }.bind(this), false); 49 }.bind(this), false);
44 } 50 }
45 51
46 PDFScriptingAPI.prototype = { 52 PDFScriptingAPI.prototype = {
47 /** 53 /**
48 * @private 54 * @private
49 * Send a message to the extension. If messages try to get sent before there 55 * Send a message to the extension. If messages try to get sent before there
50 * is a plugin element set, then we queue them up and send them later (this 56 * is a plugin element set, then we queue them up and send them later (this
51 * can happen in print preview). 57 * can happen in print preview).
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 */ 128 */
123 loadPreviewPage: function(url, index) { 129 loadPreviewPage: function(url, index) {
124 this.sendMessage_({ 130 this.sendMessage_({
125 type: 'loadPreviewPage', 131 type: 'loadPreviewPage',
126 url: url, 132 url: url,
127 index: index 133 index: index
128 }); 134 });
129 }, 135 },
130 136
131 /** 137 /**
132 * Get accessibility JSON for the document. 138 * Get accessibility JSON for the document. May only be called after document
139 * load.
133 * @param {Function} callback a callback to be called with the accessibility 140 * @param {Function} callback a callback to be called with the accessibility
134 * json that has been retrieved. 141 * json that has been retrieved.
135 * @param {number} [page] the 0-indexed page number to get accessibility data 142 * @param {number} [page] the 0-indexed page number to get accessibility data
136 * for. If this is not provided, data about the entire document is 143 * for. If this is not provided, data about the entire document is
137 * returned. 144 * returned.
138 * @return {boolean} true if the function is successful, false if there is an 145 * @return {boolean} true if the function is successful, false if there is an
139 * outstanding request for accessibility data that has not been answered. 146 * outstanding request for accessibility data that has not been answered.
140 */ 147 */
141 getAccessibilityJSON: function(callback, page) { 148 getAccessibilityJSON: function(callback, page) {
142 if (this.accessibilityCallback_) 149 if (this.accessibilityCallback_)
143 return false; 150 return false;
144 this.accessibilityCallback_ = callback; 151 this.accessibilityCallback_ = callback;
145 var message = { 152 var message = {
146 type: 'getAccessibilityJSON', 153 type: 'getAccessibilityJSON',
147 }; 154 };
148 if (page || page == 0) 155 if (page || page == 0)
149 message.page = page; 156 message.page = page;
150 this.sendMessage_(message); 157 this.sendMessage_(message);
151 return true; 158 return true;
152 }, 159 },
153 160
154 /** 161 /**
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 /**
155 * Send a key event to the extension. 198 * Send a key event to the extension.
156 * @param {number} keyCode the key code to send to the extension. 199 * @param {number} keyCode the key code to send to the extension.
157 */ 200 */
158 sendKeyEvent: function(keyCode) { 201 sendKeyEvent: function(keyCode) {
159 this.sendMessage_({ 202 this.sendMessage_({
160 type: 'sendKeyEvent', 203 type: 'sendKeyEvent',
161 keyCode: keyCode 204 keyCode: keyCode
162 }); 205 });
163 }, 206 },
164 }; 207 };
(...skipping 17 matching lines...) Expand all
182 }; 225 };
183 // Add the functions to the iframe so that they can be called directly. 226 // Add the functions to the iframe so that they can be called directly.
184 iframe.setViewportChangedCallback = 227 iframe.setViewportChangedCallback =
185 client.setViewportChangedCallback.bind(client); 228 client.setViewportChangedCallback.bind(client);
186 iframe.setLoadCallback = client.setLoadCallback.bind(client); 229 iframe.setLoadCallback = client.setLoadCallback.bind(client);
187 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); 230 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client);
188 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); 231 iframe.loadPreviewPage = client.loadPreviewPage.bind(client);
189 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); 232 iframe.sendKeyEvent = client.sendKeyEvent.bind(client);
190 return iframe; 233 return iframe;
191 } 234 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | chrome/test/data/pdf/basic_plugin_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698