[Clipboard] checking if implementation allows reading/writing a given type to the OS clipboard

Hi,
I have an open issue noted in the spec - seems no implementor has worked  
on this yet so I'm throwing it out here to see what you all think.

Given that
a) We can't give a random script access to every format on the clipboard  
for security/privacy reasons (per earlier feedback from Chrome/WebKit devs  
and common sense)
b) Certain clipboard formats have meta data or special formatting  
requirements that mean the implementation needs to do a bit of processing  
on reading/writing (thinking of Windows' CF_HTML)
c) Text may apparently be placed on the clipboard in different encodings,  
an implementation may have to do conversions
d) Clipboard contents can also be file references, in which case we'll  
make the *file* and not the actual clipboard data available

- it's obvious that the implementation needs to do a bit of work to  
"support" reading/writing given types of data from/to the native clipboard.

Hence, there should be a way a script can check if a clipboard format is  
registered and whether the implementation allows writing this format to  
the clipboard.

My idea (at the moment) is to define a method on an interface (not on  
instances, on the interface object itself) like this:

ClipboardEvent.isTypeSupported('mime/type')

or, perhaps:

DataTransfer.isTypeSupported('mime/type')??

(but it's more clipboard-specific and maybe it's confusing to mix it with  
the DnD stuff?)

An application can then for example do something like

if( ClipboardEvent.isTypeSupported( 'vnd.supersoft/fancyformat' ) ){
 // prepare fancyformat content and place on clipboard
}else{
 // fall back to for example put xml-data-as-plain-text or  
json-data-as-plain-text
}

I'm suggesting to define this method on the interface object because it  
helps web applications do feature detection early.  It could of course be  
defined on instances

addEventListener('copy', function(e){
 if( e.isTypeSupported( 'vnd.supersoft/fancyformat' ) ){
  // prepare fancyformat content and place on clipboard
 }else{
  // fall back to for example put xml-data-as-plain-text or  
json-data-as-plain-text
 }
})

but then a feature/compatibility test would have to be deferred until a  
point where the user potentially has done a lot of work in the web  
application.

Thoughts?

-- 
Hallvord R. M. Steen
Core tester, Opera Software

Received on Friday, 17 February 2012 13:24:04 UTC