changeset 10691:9f43fb83e989

8187928: [WebView] Images copied from clipboard not written in source file format Reviewed-by: arajkumar, ghb, mbilla Contributed-by: rajath.kamath@oracle.com
author mbilla
date Mon, 06 Nov 2017 19:10:19 +0530
parents 614193e9cc65
children ecf62449ebb8
files modules/javafx.web/src/main/java/com/sun/javafx/webkit/PasteboardImpl.java modules/javafx.web/src/main/java/com/sun/javafx/webkit/UIClientImpl.java modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCImageDecoderImpl.java modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCImage.java
diffstat 4 files changed, 23 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/PasteboardImpl.java	Mon Nov 06 10:55:16 2017 +0530
+++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/PasteboardImpl.java	Mon Nov 06 19:10:19 2017 +0530
@@ -73,11 +73,12 @@
         if (fxImage != null) {
             ClipboardContent content = new ClipboardContent();
             content.putImage(fxImage);
+            String fileExtension = wcImage.getFrame().getFileExtension();
             try {
-                File imageDump = File.createTempFile("jfx", ".png");
+                File imageDump = File.createTempFile("jfx", "." + fileExtension);
                 imageDump.deleteOnExit();
                 ImageIO.write(UIClientImpl.toBufferedImage(fxImage),
-                    "png",
+                    fileExtension,
                     imageDump);
                 content.putFiles(Arrays.asList(imageDump));
             } catch (IOException | SecurityException e) {
--- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/UIClientImpl.java	Mon Nov 06 10:55:16 2017 +0530
+++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/UIClientImpl.java	Mon Nov 06 19:10:19 2017 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -349,9 +349,10 @@
             if (isImageSource) {
                 Object platformImage = image.getWidth() > 0 && image.getHeight() > 0 ?
                         image.getPlatformImage() : null;
+                String fileExtension = image.getFileExtension();
                 if (platformImage != null) {
                     try {
-                        File temp = File.createTempFile("jfx", ".png");
+                        File temp = File.createTempFile("jfx", "." + fileExtension);
                         temp.deleteOnExit();
                         ImageIO.write(
                             toBufferedImage(Toolkit.getImageAccessor().fromPlatformImage(
@@ -359,7 +360,7 @@
                                     platformImage
                                 )
                             )),
-                            "png",
+                            fileExtension,
                             temp);
                         content.put(DataFormat.FILES, Arrays.asList(temp));
                     } catch (IOException | SecurityException e) {
--- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCImageDecoderImpl.java	Mon Nov 06 10:55:16 2017 +0530
+++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCImageDecoderImpl.java	Mon Nov 06 19:10:19 2017 +0530
@@ -59,6 +59,7 @@
     private PrismImage[] images;
     private volatile byte[] data;
     private volatile int dataSize = 0;
+    private String fileNameExtension;
 
     static {
         log = Logger.getLogger(WCImageDecoderImpl.class.getName());
@@ -82,8 +83,7 @@
     }
 
     @Override protected String getFilenameExtension() {
-        /// retrieve image format from reader
-        return ".img";
+        return "." + fileNameExtension;
     }
 
     private boolean imageSizeAvilable() {
@@ -210,6 +210,7 @@
             if (imageHeight < metadata.imageHeight) {
                 imageHeight = metadata.imageHeight;
             }
+            fileNameExtension = l.getFormatDescription().getExtensions().get(0);
         }
     };
 
@@ -226,8 +227,9 @@
     private static final class Frame extends WCImageFrame {
         private WCImage image;
 
-        private Frame(WCImage image) {
+        private Frame(WCImage image, String extension) {
             this.image = image;
+            this.image.setFileExtension(extension);
         }
 
         @Override public WCImage getFrame() {
@@ -275,7 +277,7 @@
                         hashCode(), idx, type));
             }
             PrismImage img = getPrismImage(idx, frame);
-            return new Frame(img);
+            return new Frame(img, fileNameExtension);
         }
         if (log.isLoggable(Level.FINE)) {
             log.fine(String.format("%X FAILED getFrame(%d)", hashCode(), idx));
--- a/modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCImage.java	Mon Nov 06 10:55:16 2017 +0530
+++ b/modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCImage.java	Mon Nov 06 19:10:19 2017 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,11 +29,20 @@
 
 public abstract class WCImage extends Ref {
     private WCRenderQueue rq;
+    private String fileExtension;
 
     public abstract int getWidth();
 
     public abstract int getHeight();
 
+    public String getFileExtension() {
+        return fileExtension;
+    }
+
+    public void setFileExtension(String fileExtension) {
+        this.fileExtension = fileExtension;
+    }
+
     public Object getPlatformImage() {return null;}
 
     protected abstract String toDataURL(String mimeType);