forked from mirrors/gecko-dev
		
	 9c2e7458ba
			
		
	
	
		9c2e7458ba
		
	
	
	
	
		
			
			Most usage is a straight replacement but gtk needs extra changes as it transfers plain text in UTF8 natively and needs to be converted into UTF16, and Windows uses single-byte characters for RTF and CF_HTML formats so we preserve this. Differential Revision: https://phabricator.services.mozilla.com/D158587
		
			
				
	
	
		
			55 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /* Any copyright is dedicated to the Public Domain.
 | |
|    http://creativecommons.org/publicdomain/zero/1.0/ */
 | |
| 
 | |
| /**
 | |
|  * @param {string} text
 | |
|  */
 | |
| function setClipboardText(text) {
 | |
|   const ClipboardHelper = Cc[
 | |
|     "@mozilla.org/widget/clipboardhelper;1"
 | |
|   ].getService(Ci.nsIClipboardHelper);
 | |
|   ClipboardHelper.copyString(text);
 | |
| }
 | |
| 
 | |
| /**
 | |
|  * @returns {string}
 | |
|  */
 | |
| function getTextFromClipboard() {
 | |
|   const transferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(
 | |
|     Ci.nsITransferable
 | |
|   );
 | |
|   transferable.init(window.docShell.QueryInterface(Ci.nsILoadContext));
 | |
|   transferable.addDataFlavor("text/plain");
 | |
|   Services.clipboard.getData(transferable, Services.clipboard.kGlobalClipboard);
 | |
| 
 | |
|   const results = {};
 | |
|   transferable.getTransferData("text/plain", results);
 | |
|   return results.value.QueryInterface(Ci.nsISupportsString)?.data ?? "";
 | |
| }
 | |
| 
 | |
| /**
 | |
|  * Returns events specifically for text recognition.
 | |
|  */
 | |
| function getTelemetryScalars() {
 | |
|   const snapshot = Services.telemetry.getSnapshotForKeyedScalars(
 | |
|     "main",
 | |
|     true /* clear events */
 | |
|   );
 | |
| 
 | |
|   if (!snapshot.parent) {
 | |
|     return {};
 | |
|   }
 | |
| 
 | |
|   return snapshot.parent;
 | |
| }
 | |
| 
 | |
| function clearTelemetry() {
 | |
|   Services.telemetry.clearScalars();
 | |
|   Services.telemetry
 | |
|     .getHistogramById("TEXT_RECOGNITION_API_PERFORMANCE")
 | |
|     .clear();
 | |
|   Services.telemetry
 | |
|     .getHistogramById("TEXT_RECOGNITION_INTERACTION_TIMING")
 | |
|     .clear();
 | |
|   Services.telemetry.getHistogramById("TEXT_RECOGNITION_TEXT_LENGTH").clear();
 | |
| }
 |