Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Word's images pasting to Safari #4339

Merged
merged 24 commits into from
Nov 23, 2020
Merged

Conversation

Comandeer
Copy link
Member

What is the purpose of this pull request?

New feature

Does your PR contain necessary tests?

All patches that change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

Did you follow the CKEditor 4 code style guide?

Your code should follow the guidelines from the CKEditor 4 code style guide which helps keep the entire codebase consistent.

  • PR is consistent with the code style guide

What is the proposed changelog entry for this pull request?

* [#1134](https://github.com/ckeditor/ckeditor4/issues/1134): [Safari] Fixed: [Paste from Word](https://ckeditor.com/cke4/addon/pastefromword) does not embed images.

What changes did you make?

I've basically taken the contents from @msamsel's #1976 and integrated it with our CKEDITOR.plugins.pastetools.filters.image filter.

Which issues does your PR resolve?

Closes #1134.

@jacekbogdanski jacekbogdanski self-assigned this Oct 25, 2020
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works pretty nice! I see that this code had already some partial review in original PR, so there is not much left. For now, I've tested it with jpg, png, and gif. Please, see the review comments.

I also see that you marked this PR as a feature, although the original issue has been reported as a bug. I suppose that we could change it to feature as image support for OS X Word edition.

plugins/pastetools/filter/image.js Outdated Show resolved Hide resolved
Comment on lines 216 to 247
var blobUrls = removeDuplicates( CKEDITOR.tools.array.filter( imgTags, function( imgTag ) {
return imgTag.match( /^blob:/i );
} ) ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we could extract removeDuplicates function to array tools as something like CKEDITOR.tools.array.unique?

return imgTag.match( /^blob:/i );
} ) ),
promises = CKEDITOR.tools.array.map( blobUrls, function( blobUrl ) {
return convertBlobUrlToBase64( blobUrl );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convertToBlobUrlToBase64 could be probably used as higher-order function?

fileType = 'image/png';
break;
case '47494638':
fileType = 'image/gif';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was unexpected to me to find out that actually gif images are supported by PFW. They seem to work on Chrome and Firefox, but not in Safari:
image

I've used this GIF:
test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I didn't know that Word supports GIFs 😅 I was pretty sure they are converted to PNGs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually they are converted to PNG… So it works because most browsers support APNG.

Safari in such a case use GIF format. It's strange that it isn't rendered correctly as we have GIF recognition 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding GIF mime type to array of supported image formats seems to do the trick.

header += bytesHeader[ i ].toString( 16 );
}

switch ( header ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's some dark magic 😄 I'm not sure if it should be named header, probably File signature is more accurate here. It would be good to have real, existing images with these signatures, to confirm that the feature covers all expected image types. These can be checked e.g. here: https://www.filesignatures.net/index.php?search=FFD8FFE0&mode=SIG although I suppose it may be hard to get all spf, jfif etc extension examples and I'm not sure if Word is not converting them also into a more unified format.

@@ -128,12 +136,16 @@
* @param {String} url The URL from which the data is loaded.
* @param {Function} [callback] A callback function to be called on
* data load. If not provided, the data will be loaded
* synchronously.
* @returns {String} The loaded data. For asynchronous requests, an
* synchronously. Please notice that only text data might be loaded synchrnously.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* synchronously. Please notice that only text data might be loaded synchrnously.
* synchronously. Please notice that only text data might be loaded synchronously.

},

// (#1134)
'test load async arraybuffer': function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are also missing text and xml types. I guess they are probably tested already as we are using them indirectly in ajax logic, but it would be good to check if API works correctly.


function simulatePasteBlob( editor, assertion, options ) {
// jscs:disable maximumLineLength
var imgBase64 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia219thzg25abkRE/BpDc3pqvphHvRFys2weqvp+krbWKIX7nhDbzLOItiM8358pTwdirqpPFnMF2xLc1WvLyOwTAibpbmvHHcvttU57y5+XqNZrLe3lE/Pq8eUj2fXKfOe3pfOjzhJYtB/yll5SDFcSDiH+hRkH25+L+sdxKEAMZahrlSX8ukqMOWy/jXW2m6M9LDBc31B9LFuv6gVKg/0Szi3KAr1kGq1GMjU/aLbnq6/lRxc4XfJ98hTargX++DbMJBSiYMIe9Ck1YAxFkKEAG3xbYaKmDDgYyFK0UGYpfoWYXG+fAPPI6tJnNwb7ClP7IyF+D+bjOtCpkhz6CFrIa/I6sFtNl8auFXGMTP34sNwI/JhkgEtmDz14ySfaRcTIBInmKPE32kxyyE2Tv+thKbEVePDfW/byMM1Kmm0XdObS7oGD/MypMXFPXrCwOtoYjyyn7BV29/MZfsVzpLDdRtuIZnbpXzvlf+ev8MvYr/Gq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958i26aXiHpU3PAkm3wnnS0SaTLfqlXSPv7MmTtnoGy6/3b1GvdMw8BCz9GwOIY2Pllt7nOWoYiCdASRIq/W3ptoLDO3krYjaMA9kHpkv3jym70Q1lKMGpLnWBuVwmXIclC+2nM7AjWEiddx4ongC7DeL5+CDD7Gqif+ryUqQhwApiKoMLlOQEU7kBT1ecEMBVBhctzAijcgaaqzwlgKoIKl+cEULgDTVWfE8BUBBUuzwmgcAeaqj4ngKkIKlyeE0DhDjRVfU4AUxFUuDwngMIdaKr6nACmIqhweU4AhTvQVPX/B7+LJxLB2zHEAAAAAElFTkSuQmCC',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would be possible to use real images instead with more test cases?

Comment on lines 3 to 5
if ( !CKEDITOR.env.safari ) {
bender.ignore();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it makes sense to keep this test also for different browsers to make sure we didn't introduce regression?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other browsers are covered by unit tests for Paste Tools, Paste from Word and Paste from Libre Office, so I don't think it would be necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to perform manual tests for images during the testing phase to make sure that we didn't introduce any regression. Enabling these tests on browsers which should support images significantly improves odds that we will actually test it, as generic tests may not have enough test samples.

Please, also ignore this test on mobile.

Comment on lines +3 to +5
@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, basicstyles, pastefromword, elementspath, image, format, sourcearea

1. Open [attached Word document](_assets/Image_safari.docx).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a more complicated document with more image sources, especially gif and different flavors of jpg.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I produce different flavors of JPG? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we probably don't need to test different flavors of JPG, as all of its signatures starts with the same sequence: FF D8 FF. Checking if the image file starts with it should be enough for our case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I produce different flavors of JPG?

By using some conversion tool. But indeed making signature-less strict should work. I've checked File Signature Database and it doesn't seem that a less specific signature will catch any other filetype 🤞🏻

@jacekbogdanski
Copy link
Member

I also see that there are some jsduck errors
image

Please, update docs to match the correct types.

@Comandeer
Copy link
Member Author

Please, update docs to match the correct types.

Hmm, that can be a little problematic, as Uint8Array is correct… Seems like jsduck is old enough to not recognize Typed Arrays 🤔

@github-actions
Copy link

github-actions bot commented Nov 3, 2020

It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days.

@github-actions github-actions bot added the stale The issue / PR will be closed within the next 7 days of inactivity. label Nov 3, 2020
@Comandeer Comandeer self-assigned this Nov 3, 2020
@Comandeer
Copy link
Member Author

Comandeer commented Nov 8, 2020

Ok,

  • support for GIFs added by adding them to the array of supported image types,
  • tests with real images added,
  • I've also added throwing error when the image in blob is in unsupported format (reused the error introduced in Improve importing images from Microsoft Word #4291,
  • added CKEDITOR.tools.array.unique(),
  • some refactoring.

@github-actions github-actions bot removed the stale The issue / PR will be closed within the next 7 days of inactivity. label Nov 9, 2020
@jacekbogdanski jacekbogdanski self-assigned this Nov 9, 2020
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that can be a little problematic, as Uint8Array is correct… Seems like jsduck is old enough to not recognize Typed Arrays 🤔

I see that Blob is correctly recognized, so it's indeed weird that jsduck is not able to read this type. Maybe there is some workaround for custom type? If not, I suppose we will have to rename it into Object to avoid building warnings? Although, it's pity going some weird workarounds because the tooling doesn't work correctly.

Currently, ajax methods are a bit mixed up. Previously, we had:

  • load - loading with text response
  • loadXml - loading with xml response

now we have:

  • load - by default text, but also supports xml and arraybuffer
  • loadXml - still supporting only xml

Maybe, we should add explicit loadBinaryData/loadData? It probably doesn't really make sense deprecating loadXml as explicitness of this method is actually nice. Most readable seems to have load (without default type), loadText, loadXml, loadBinaryData but it's a bit too late for that.

* arrayWithoutDuplicates = CKEDITOR.tools.array.unique( array );
* console.log( arrayWithoutDuplicates ); // [ 1, 2, 3 ]
* ```
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing @since tag and @member CKEDITOR.tools.array.

@@ -11,7 +11,9 @@
'use strict';

/**
* Filter handling pasting images from RTF content.
* Filter handling pasting images. In Safari images are extracted
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any strict check if it's actually Safari? I suppose it should rather tell that in case of missing RTF it will be using this method?


## Unexpected

* Iage is not rendered correctly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Comment on lines 3 to 5
if ( !CKEDITOR.env.safari ) {
bender.ignore();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to perform manual tests for images during the testing phase to make sure that we didn't introduce any regression. Enabling these tests on browsers which should support images significantly improves odds that we will actually test it, as generic tests may not have enough test samples.

Please, also ignore this test on mobile.

Comment on lines +3 to +5
@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, basicstyles, pastefromword, elementspath, image, format, sourcearea

1. Open [attached Word document](_assets/Image_safari.docx).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I produce different flavors of JPG?

By using some conversion tool. But indeed making signature-less strict should work. I've checked File Signature Database and it doesn't seem that a less specific signature will catch any other filetype 🤞🏻

function convertBlobUrlToBase64( blobUrlSrc ) {
return new CKEDITOR.tools.promise( function( resolve ) {
CKEDITOR.ajax.load( blobUrlSrc, function( arrayBuffer ) {
var data = new Uint8Array( arrayBuffer ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about old IE support here (IE8-9) as Uint8Array is not supported there. However, nothing breaks - seems like we are not supporting image pasting there at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in old IEs this code is just ignored.

@@ -0,0 +1,16 @@
@bender-tags: feature, 4.16.0, 1134, 2800, pastefromword
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, pastefromword, image, pagebreak, autogrow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add sourcearea test steps similar to pasteimagessafari manual test to make sure that the image is transformed to base64.

@@ -179,6 +164,111 @@
}
];

/**
* Array of all recognizable image file signatrues with their respective types.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Array of all recognizable image file signatrues with their respective types.
* Recognizable image file signatures with their respective types.

Comment on lines 36 to 48
var image = options && options.image || SAMPLE_PNG,
imageDataUrl = options && options.imageDataUrl || SAMPLE_PNG,
url = getObjectUrl( image, options && options.imageType ),
template = options && options.template || '<p{%CLASS%}>Hello<img style="height:200px; width:200px" src="{%URL%}" />world.</p>',
input = template.replace( /{%URL%}/g, url ).replace( /{%CLASS%}/g, ' class="MsoNormal"' ),
expected = template.replace( /{%URL%}/g, imageDataUrl ).replace( /{%CLASS%}/g, '' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is a bit unreadable with all default option values. Maybe we could simplify it with some merging logic?

CKEDITOR.tools.object.merge( defaultOptions, options || {} );

return new CKEDITOR.tools.promise( function( resolve ) {
CKEDITOR.ajax.load( blobUrlSrc, function( arrayBuffer ) {
var data = new Uint8Array( arrayBuffer ),
imageType = getImageTypeFromSignature( data.subarray( 0, 4 ) ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we pass here the whole arrayBuffer? It seems like taking the first 4 characters is already done in getImageTypeFromSignature function? In that case, this should be probably renamed again to just getImageType.

@jacekbogdanski
Copy link
Member

Could you also rebase PR onto the latest major? Seems like there are some conficts.

@Comandeer
Copy link
Member Author

Ok, I've addressed issues found during the review.

Maybe, we should add explicit loadBinaryData/loadData? It probably doesn't really make sense deprecating loadXml as explicitness of this method is actually nice. Most readable seems to have load (without default type), loadText, loadXml, loadBinaryData but it's a bit too late for that.

TBH I don't find it's too late. We can always have additional methods and load with a default response type.

I'll raise an issue for it.

Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration PFW Image with Safari
2 participants