Backed out changesets df6e7f025c65, 3e5d45dcd5c6, and e00a383520f6 (bug 952456) for B2G test_browserElement_inproc_CopyPaste.html failures.
authorRyan VanderMeulen <ryanvm@gmail.com>
Tue, 18 Aug 2015 07:54:19 -0400
changeset 258211 3ef1a1856a3f3636d280db9dd09912aab5d4332c
parent 258210 434643c56a2853449c4f530c7a9400afc30adb2e
child 258212 d5cf4e7900df6b2351bf3677b49fb70bedf68b99
push id63843
push userryanvm@gmail.com
push dateTue, 18 Aug 2015 14:58:06 +0000
treeherdermozilla-inbound@d55e24c983aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs952456
milestone43.0a1
backs outdf6e7f025c654258e800ff50acb66d0a4bfc8f8f
3e5d45dcd5c6f088b9be5188736d259c9cca7f4a
e00a383520f6f414ca595d5e3dff8be5da4dfe7f
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changesets df6e7f025c65, 3e5d45dcd5c6, and e00a383520f6 (bug 952456) for B2G test_browserElement_inproc_CopyPaste.html failures. CLOSED TREE
dom/base/test/mochitest.ini
dom/base/test/test_copyimage.html
dom/browser-element/BrowserElementChildPreload.js
widget/gonk/GonkClipboardData.cpp
widget/gonk/GonkClipboardData.h
widget/gonk/moz.build
widget/gonk/nsClipboard.cpp
widget/gonk/nsClipboard.h
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -694,17 +694,17 @@ support-files = referrerHelper.js
 [test_anchor_area_referrer_rel.html]
 [test_iframe_referrer.html]
 [test_iframe_referrer_changing.html]
 [test_iframe_referrer_invalid.html]
 [test_caretPositionFromPoint.html]
 [test_classList.html]
 # This test fails on the Mac for some reason
 [test_copyimage.html]
-skip-if = (buildapp == 'b2g' && toolkit != 'gonk') || (toolkit != 'cocoa' && toolkit != 'gonk' && toolkit != 'gtk2' && toolkit != 'gtk3' && toolkit != 'windows') || e10s #b2g-desktop(Bug 931116, b2g desktop specific, initial triage)
+skip-if = (buildapp == 'b2g' && toolkit != 'gonk') || toolkit != 'gtk2' && toolkit != 'gtk3' && toolkit != 'windows' || e10s #b2g-desktop(Bug 931116, b2g desktop specific, initial triage)
 [test_copypaste.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s #bug 904183 # b2g(clipboard undefined) b2g-debug(clipboard undefined) b2g-desktop(clipboard undefined)
 [test_copypaste.xhtml]
 skip-if = buildapp == 'b2g' || toolkit == 'android' #bug 904183 # b2g(bug 904183) b2g-debug(bug 904183) b2g-desktop(bug 904183)
 [test_createHTMLDocument.html]
 [test_declare_stylesheet_obsolete.html]
 [test_document_constructor.html]
 [test_document_importNode_document.html]
--- a/dom/base/test/test_copyimage.html
+++ b/dom/base/test/test_copyimage.html
@@ -1,87 +1,58 @@
 <!DOCTYPE HTML>
 <html>
 <!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=518249
-https://bugzilla.mozilla.org/show_bug.cgi?id=952456
 -->
 <head>
   <title>Test for copy image</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=518249">Mozilla Bug 518249</a>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=952456">Mozilla Bug 952456</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 function testCopyImage () {
-  var Ci = SpecialPowers.Ci;
-  var Cc = SpecialPowers.Cc;
-  var clipboard = SpecialPowers.Services.clipboard;
+  // selection of the node
+  var node = document.getElementById('logo');
+  var webnav = SpecialPowers.wrap(window)
+               .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+               .getInterface(SpecialPowers.Ci.nsIWebNavigation)
 
-  function getClipboardData(mime) {
-    var transferable = Cc['@mozilla.org/widget/transferable;1']
-                       .createInstance(Ci.nsITransferable);
-    var loadingContext = SpecialPowers.wrap(window).QueryInterface(Ci.nsIInterfaceRequestor)
-                                      .getInterface(Ci.nsIWebNavigation)
-                                      .QueryInterface(Ci.nsILoadContext);
-    transferable.init(loadingContext);
-    transferable.addDataFlavor(mime);
-    clipboard.getData(transferable, 1);
-    var data = SpecialPowers.createBlankObject();
-    transferable.getTransferData(mime, data, {});
-    return data;
-  }
+  var docShell = webnav.QueryInterface(SpecialPowers.Ci.nsIDocShell);
 
-  function testClipboardValue(mime, expected) {
-    var data = SpecialPowers.wrap(getClipboardData(mime));
-    var str = data.value == null ? data.value :
-              data.value.QueryInterface(Ci.nsISupportsString).data;
-    is(str, expected, "clipboard has correct [" + mime + "] content")
-  }
-
-  //--------- Prepare data and copy it.
+  docShell.chromeEventHandler.ownerDocument.popupNode = node;
 
-  // Select the node.
-  var node = document.getElementById('logo');
-
-  // Set node and copy image.
-  var webnav = SpecialPowers.wrap(window)
-               .QueryInterface(Ci.nsIInterfaceRequestor)
-               .getInterface(Ci.nsIWebNavigation)
-  var docShell = webnav.QueryInterface(Ci.nsIDocShell);
+  // let's copy the node
   var documentViewer = docShell.contentViewer
-                               .QueryInterface(Ci.nsIContentViewerEdit);
-  documentViewer.setCommandNode(node);
+                               .QueryInterface(SpecialPowers.Ci.nsIContentViewerEdit);
   documentViewer.copyImage(documentViewer.COPY_IMAGE_ALL);
-
-  //--------- Let's check the content of the clipboard now.
-
-  // Does the clipboard contain text/unicode data ?
+  
+  //--------- now check the content of the clipboard
+  var clipboard = SpecialPowers.Cc["@mozilla.org/widget/clipboard;1"]
+                               .getService(SpecialPowers.Ci.nsIClipboard);
+  
+  // does the clipboard contain text/unicode data ?
   ok(clipboard.hasDataMatchingFlavors(["text/unicode"], 1, clipboard.kGlobalClipboard), "clipboard contains unicode text");
-  // Does the clipboard contain text/html data ?
+  // does the clipboard contain text/html data ?
   ok(clipboard.hasDataMatchingFlavors(["text/html"], 1, clipboard.kGlobalClipboard), "clipboard contains html text");
-  // Does the clipboard contain image data ?
+  // does the clipboard contain image data ?
   ok(clipboard.hasDataMatchingFlavors(["image/png"], 1, clipboard.kGlobalClipboard), "clipboard contains image");
 
-  // Is the text/uncodie data correct ?
-  testClipboardValue('text/unicode', 'about:logo');
-  // Is the text/html data correct ?
-  testClipboardValue('text/html', '<img id="logo" src="about:logo">');
-
   SimpleTest.finish();
 }
 
+
 SimpleTest.waitForExplicitFinish();
+
 addLoadEvent(testCopyImage);
 
 </script>
 </pre>
 <div>
   <img id="logo" src="about:logo">
 </div>
 </body>
--- a/dom/browser-element/BrowserElementChildPreload.js
+++ b/dom/browser-element/BrowserElementChildPreload.js
@@ -58,17 +58,16 @@ const OBSERVED_EVENTS = [
   'audio-playback',
   'activity-done',
   'invalid-widget'
 ];
 
 const COMMAND_MAP = {
   'cut': 'cmd_cut',
   'copy': 'cmd_copyAndCollapseToEnd',
-  'copyImage': 'cmd_copyImage',
   'paste': 'cmd_paste',
   'selectall': 'cmd_selectAll'
 };
 
 /**
  * The BrowserElementChild implements one half of <iframe mozbrowser>.
  * (The other half is, unsurprisingly, BrowserElementParent.)
  *
@@ -851,49 +850,37 @@ BrowserElementChild.prototype = {
     }
 
     this._ctxCounter++;
     this._ctxHandlers = {};
 
     var elem = e.target;
     var menuData = {systemTargets: [], contextmenu: null};
     var ctxMenuId = null;
-    var hasImgElement = false;
-
-    // Set the event target as the copy image command needs it to
-    // determine what was context-clicked on.
-    docShell.contentViewer.QueryInterface(Ci.nsIContentViewerEdit).setCommandNode(elem);
 
     while (elem && elem.parentNode) {
       var ctxData = this._getSystemCtxMenuData(elem);
       if (ctxData) {
         menuData.systemTargets.push({
           nodeName: elem.nodeName,
           data: ctxData
         });
       }
 
       if (!ctxMenuId && 'hasAttribute' in elem && elem.hasAttribute('contextmenu')) {
         ctxMenuId = elem.getAttribute('contextmenu');
       }
-
-      // Enable copy image option
-      if (elem.nodeName == 'IMG') {
-        hasImgElement = true;
-      }
-
       elem = elem.parentNode;
     }
 
-    if (ctxMenuId || hasImgElement) {
-      var menu = null;
-      if (ctxMenuId) {
-        menu = e.target.ownerDocument.getElementById(ctxMenuId);
+    if (ctxMenuId) {
+      var menu = e.target.ownerDocument.getElementById(ctxMenuId);
+      if (menu) {
+        menuData.contextmenu = this._buildMenuObj(menu, '');
       }
-      menuData.contextmenu = this._buildMenuObj(menu, '', hasImgElement);
     }
 
     // Pass along the position where the context menu should be located
     menuData.clientX = e.clientX;
     menuData.clientY = e.clientY;
 
     // The value returned by the contextmenu sync call is true if the embedder
     // called preventDefault() on its contextmenu event.
@@ -1216,54 +1203,41 @@ BrowserElementChild.prototype = {
         id: domRequestID,
         successRv: blob
       });
     }, mimeType);
   },
 
   _recvFireCtxCallback: function(data) {
     debug("Received fireCtxCallback message: (" + data.json.menuitem + ")");
-
-    if (data.json.menuitem == 'copy-image') {
-      // Set command
-      data.json.command = 'copyImage';
-      this._recvDoCommand(data);
-    } else if (data.json.menuitem in this._ctxHandlers) {
+    // We silently ignore if the embedder uses an incorrect id in the callback
+    if (data.json.menuitem in this._ctxHandlers) {
       this._ctxHandlers[data.json.menuitem].click();
       this._ctxHandlers = {};
     } else {
-      // We silently ignore if the embedder uses an incorrect id in the callback
       debug("Ignored invalid contextmenu invocation");
     }
   },
 
-  _buildMenuObj: function(menu, idPrefix, hasImgElement) {
+  _buildMenuObj: function(menu, idPrefix) {
     var menuObj = {type: 'menu', items: []};
-    // Customized context menu
-    if (menu) {
-      this._maybeCopyAttribute(menu, menuObj, 'label');
+    this._maybeCopyAttribute(menu, menuObj, 'label');
 
-      for (var i = 0, child; child = menu.children[i++];) {
-        if (child.nodeName === 'MENU') {
-          menuObj.items.push(this._buildMenuObj(child, idPrefix + i + '_', false));
-        } else if (child.nodeName === 'MENUITEM') {
-          var id = this._ctxCounter + '_' + idPrefix + i;
-          var menuitem = {id: id, type: 'menuitem'};
-          this._maybeCopyAttribute(child, menuitem, 'label');
-          this._maybeCopyAttribute(child, menuitem, 'icon');
-          this._ctxHandlers[id] = child;
-          menuObj.items.push(menuitem);
-        }
+    for (var i = 0, child; child = menu.children[i++];) {
+      if (child.nodeName === 'MENU') {
+        menuObj.items.push(this._buildMenuObj(child, idPrefix + i + '_'));
+      } else if (child.nodeName === 'MENUITEM') {
+        var id = this._ctxCounter + '_' + idPrefix + i;
+        var menuitem = {id: id, type: 'menuitem'};
+        this._maybeCopyAttribute(child, menuitem, 'label');
+        this._maybeCopyAttribute(child, menuitem, 'icon');
+        this._ctxHandlers[id] = child;
+        menuObj.items.push(menuitem);
       }
     }
-    // "Copy Image" menu item
-    if (hasImgElement) {
-      menuObj.items.push({id: 'copy-image'});
-    }
-
     return menuObj;
   },
 
   _recvSetVisible: function(data) {
     debug("Received setVisible message: (" + data.json.visible + ")");
     if (this._forcedVisible == data.json.visible) {
       return;
     }
deleted file mode 100644
--- a/widget/gonk/GonkClipboardData.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "GonkClipboardData.h"
-#include "mozilla/gfx/DataSurfaceHelpers.h"
-
-namespace mozilla {
-
-void
-GonkClipboardData::SetText(const nsAutoString &aText)
-{
-  mPlain = aText;
-}
-
-bool
-GonkClipboardData::HasText() const
-{
-  return !mPlain.IsEmpty();
-}
-
-const nsAutoString&
-GonkClipboardData::GetText() const
-{
-  return mPlain;
-}
-
-void
-GonkClipboardData::SetHTML(const nsAutoString &aHTML)
-{
-  mHTML = aHTML;
-}
-
-bool
-GonkClipboardData::HasHTML() const
-{
-  return !mHTML.IsEmpty();
-}
-
-const nsAutoString&
-GonkClipboardData::GetHTML() const
-{
-  return mHTML;
-}
-
-void
-GonkClipboardData::SetImage(gfx::DataSourceSurface* aDataSource)
-{
-  // Clone a new DataSourceSurface and store it.
-  mImage = gfx::CreateDataSourceSurfaceByCloning(aDataSource);
-}
-
-bool
-GonkClipboardData::HasImage() const
-{
-  return static_cast<bool>(mImage);
-}
-
-already_AddRefed<gfx::DataSourceSurface>
-GonkClipboardData::GetImage() const
-{
-  // Return cloned DataSourceSurface.
-  RefPtr<gfx::DataSourceSurface> cloned = gfx::CreateDataSourceSurfaceByCloning(mImage);
-  return cloned.forget();
-}
-
-void
-GonkClipboardData::Clear()
-{
-  mPlain.Truncate(0);
-  mHTML.Truncate(0);
-  mImage = nullptr;
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/widget/gonk/GonkClipboardData.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_GonkClipboardData
-#define mozilla_GonkClipboardData
-
-#include "mozilla/RefPtr.h"
-#include "nsString.h"
-
-namespace mozilla {
-
-namespace gfx {
-class DataSourceSurface;
-}
-
-class GonkClipboardData final
-{
-public:
-  explicit GonkClipboardData() = default;
-  ~GonkClipboardData() = default;
-
-  // For text/plain
-  void SetText(const nsAutoString &aText);
-  bool HasText() const;
-  const nsAutoString& GetText() const;
-
-  // For text/html
-  void SetHTML(const nsAutoString &aHTML);
-  bool HasHTML() const;
-  const nsAutoString& GetHTML() const;
-
-  // For images
-  void SetImage(gfx::DataSourceSurface* aDataSource);
-  bool HasImage() const;
-  already_AddRefed<gfx::DataSourceSurface> GetImage() const;
-
-  // For other APIs
-  void Clear();
-
-private:
-  nsAutoString mPlain;
-  nsAutoString mHTML;
-  RefPtr<gfx::DataSourceSurface> mImage;
-};
-
-} // namespace mozilla
-
-#endif // mozilla_GonkClipboardData
--- a/widget/gonk/moz.build
+++ b/widget/gonk/moz.build
@@ -53,17 +53,16 @@ if CONFIG['ANDROID_VERSION'] >= '17':
 elif CONFIG['ANDROID_VERSION'] == '15':
     SOURCES += [
         'hwchal/HwcICS.cpp',
     ]
 
 SOURCES += [
     'GeckoTouchDispatcher.cpp',
     'GfxInfo.cpp',
-    'GonkClipboardData.cpp',
     'GonkMemoryPressureMonitoring.cpp',
     'GonkPermission.cpp',
     'HwcComposer2D.cpp',
     'HwcUtils.cpp',
     'nsAppShell.cpp',
     'nsClipboard.cpp',
     'nsIdleServiceGonk.cpp',
     'nsLookAndFeel.cpp',
@@ -78,17 +77,16 @@ SOURCES += [
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
     '/dom/system/android',
     '/gfx/skia/skia/include/config',
     '/gfx/skia/skia/include/core',
-    '/image',
     '/widget',
 ]
 
 DEFINES['HAVE_OFF64_T'] = True
 DEFINES['SK_BUILD_FOR_ANDROID_NDK'] = True
 
 if CONFIG['ANDROID_VERSION'] != '15':
     DEFINES['HAVE_POSIX_CLOCKS'] = True
--- a/widget/gonk/nsClipboard.cpp
+++ b/widget/gonk/nsClipboard.cpp
@@ -1,303 +1,134 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/dom/ContentChild.h"
 #include "nsClipboard.h"
-
-#include "gfxDrawable.h"
-#include "gfxUtils.h"
-#include "ImageOps.h"
-#include "imgIContainer.h"
-#include "imgTools.h"
-#include "mozilla/dom/ContentChild.h"
 #include "nsClipboardProxy.h"
 #include "nsISupportsPrimitives.h"
+#include "nsCOMPtr.h"
 #include "nsComponentManagerUtils.h"
-#include "nsCOMPtr.h"
-#include "nsStringStream.h"
 #include "nsXULAppAPI.h"
 
 using namespace mozilla;
 using mozilla::dom::ContentChild;
 
 #define LOG_TAG "Clipboard"
 #define LOGI(args...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, ## args)
 #define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ## args)
 
-
 NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard)
 
 nsClipboard::nsClipboard()
-  : mClipboard(mozilla::MakeUnique<GonkClipboardData>())
 {
 }
 
 NS_IMETHODIMP
 nsClipboard::SetData(nsITransferable *aTransferable,
-                     nsIClipboardOwner *anOwner,
-                     int32_t aWhichClipboard)
+                     nsIClipboardOwner *anOwner, int32_t aWhichClipboard)
 {
   if (aWhichClipboard != kGlobalClipboard) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   if (!XRE_IsParentProcess()) {
     // Re-direct to the clipboard proxy.
     nsRefPtr<nsClipboardProxy> clipboardProxy = new nsClipboardProxy();
     return clipboardProxy->SetData(aTransferable, anOwner, aWhichClipboard);
   }
 
-  // Get the types of supported flavors.
-  nsCOMPtr<nsISupportsArray> flavorList;
-  nsresult rv = aTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavorList));
-
-  if (!flavorList || NS_FAILED(rv)) {
-    return NS_ERROR_FAILURE;
+  nsCOMPtr<nsISupports> tmp;
+  uint32_t len;
+  nsresult rv  = aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(tmp),
+                                                &len);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
   }
-
-  uint32_t flavorCount = 0;
-  flavorList->Count(&flavorCount);
-  bool imageAdded = false;
-  for (uint32_t i = 0; i < flavorCount; ++i) {
-    nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, i);
-
-    if (currentFlavor) {
-      // MIME type
-      nsXPIDLCString flavorStr;
-      currentFlavor->ToString(getter_Copies(flavorStr));
-
-      // Clip is the data which will be sent to the clipboard.
-      nsCOMPtr<nsISupports> clip;
-      uint32_t len;
-
-      if (flavorStr.EqualsLiteral(kUnicodeMime)) {
-        // text/plain
-        rv = aTransferable->GetTransferData(flavorStr, getter_AddRefs(clip), &len);
-        nsCOMPtr<nsISupportsString> wideString = do_QueryInterface(clip);
-        if (!wideString || NS_FAILED(rv)) {
-          continue;
-        }
-
-        nsAutoString utf16string;
-        wideString->GetData(utf16string);
-        mClipboard->SetText(utf16string);
-      } else if (flavorStr.EqualsLiteral(kHTMLMime)) {
-        // text/html
-        rv = aTransferable->GetTransferData(flavorStr, getter_AddRefs(clip), &len);
-        nsCOMPtr<nsISupportsString> wideString = do_QueryInterface(clip);
-        if (!wideString || NS_FAILED(rv)) {
-          continue;
-        }
+  nsCOMPtr<nsISupportsString> supportsString = do_QueryInterface(tmp);
+  // No support for non-text data
+  if (NS_WARN_IF(!supportsString)) {
+    LOGE("No support for non-text data. See bug 952456.");
+    return NS_ERROR_NOT_IMPLEMENTED;
+  }
+  nsAutoString buffer;
+  supportsString->GetData(buffer);
 
-        nsAutoString utf16string;
-        wideString->GetData(utf16string);
-        mClipboard->SetHTML(utf16string);
-      } else if (!imageAdded && // image is added only once to the clipboard.
-                 (flavorStr.EqualsLiteral(kNativeImageMime) ||
-                  flavorStr.EqualsLiteral(kPNGImageMime) ||
-                  flavorStr.EqualsLiteral(kJPEGImageMime) ||
-                  flavorStr.EqualsLiteral(kJPGImageMime) ||
-                  flavorStr.EqualsLiteral(kGIFImageMime))) {
-        // image/[png|jpeg|jpg|gif] or application/x-moz-nativeimage
-
-        // Look through our transfer data for the image.
-        static const char* const imageMimeTypes[] = {
-          kNativeImageMime, kPNGImageMime, kJPEGImageMime, kJPGImageMime, kGIFImageMime };
-
-        nsCOMPtr<nsISupportsInterfacePointer> imgPtr;
-        for (uint32_t i = 0; !imgPtr && i < ArrayLength(imageMimeTypes); ++i) {
-          aTransferable->GetTransferData(imageMimeTypes[i], getter_AddRefs(clip), &len);
-          imgPtr = do_QueryInterface(clip);
-        }
-        if (!imgPtr) {
-          continue;
-        }
-
-        nsCOMPtr<nsISupports> imageData;
-        imgPtr->GetData(getter_AddRefs(imageData));
-        nsCOMPtr<imgIContainer> image(do_QueryInterface(imageData));
-        if (!image) {
-          continue;
-        }
-
-        RefPtr<gfx::SourceSurface> surface =
-          image->GetFrame(imgIContainer::FRAME_CURRENT,
-                          imgIContainer::FLAG_SYNC_DECODE);
-        if (!surface) {
-          continue;
-        }
-
-        RefPtr<gfx::DataSourceSurface> dataSurface;
-        if (surface->GetFormat() == gfx::SurfaceFormat::B8G8R8A8) {
-          dataSurface = surface->GetDataSurface();
-        } else {
-          // Convert format to SurfaceFormat::B8G8R8A8.
-          dataSurface = gfxUtils::CopySurfaceToDataSourceSurfaceWithFormat(surface, gfx::SurfaceFormat::B8G8R8A8);
-        }
-
-        mClipboard->SetImage(dataSurface);
-        imageAdded = true;
-      }
-    }
-  }
-
+  mClipboard = buffer;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsClipboard::GetData(nsITransferable *aTransferable,
-                     int32_t aWhichClipboard)
+nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
 {
   if (aWhichClipboard != kGlobalClipboard) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   if (!XRE_IsParentProcess()) {
     // Re-direct to the clipboard proxy.
     nsRefPtr<nsClipboardProxy> clipboardProxy = new nsClipboardProxy();
     return clipboardProxy->GetData(aTransferable, aWhichClipboard);
   }
 
-  // Get flavor list that includes all acceptable flavors (including
-  // ones obtained through conversion).
-  // Note: We don't need to call nsITransferable::AddDataFlavor here
-  //       because ContentParent already did.
-  nsCOMPtr<nsISupportsArray> flavorList;
-  nsresult rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
+  nsAutoString buffer(mClipboard);
 
-  if (!flavorList || NS_FAILED(rv)) {
-    return NS_ERROR_FAILURE;
+  nsresult rv;
+  nsCOMPtr<nsISupportsString> dataWrapper =
+    do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
   }
 
-  // Walk through flavors and see which flavor matches the one being pasted.
-  uint32_t flavorCount;
-  flavorList->Count(&flavorCount);
-
-  for (uint32_t i = 0; i < flavorCount; ++i) {
-    nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, i);
-
-    if (currentFlavor) {
-      // flavorStr is the mime type.
-      nsXPIDLCString flavorStr;
-      currentFlavor->ToString(getter_Copies(flavorStr));
-
-      // text/plain, text/Unicode
-      if (flavorStr.EqualsLiteral(kUnicodeMime) && mClipboard->HasText()) {
-        nsresult rv;
-        nsCOMPtr<nsISupportsString> dataWrapper = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
-        rv = dataWrapper->SetData(mClipboard->GetText());
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-          continue;
-        }
-
-        nsCOMPtr<nsISupports> genericDataWrapper = do_QueryInterface(dataWrapper);
-        uint32_t len = mClipboard->GetText().Length() * sizeof(PRUnichar);
-        rv = aTransferable->SetTransferData(flavorStr, genericDataWrapper, len);
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-          continue;
-        }
-        break;
-      }
+  rv = dataWrapper->SetData(buffer);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
 
-      // text/html
-      if (flavorStr.EqualsLiteral(kHTMLMime) && mClipboard->HasHTML()) {
-        nsresult rv;
-        nsCOMPtr<nsISupportsString> dataWrapper = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
-        rv = dataWrapper->SetData(mClipboard->GetHTML());
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-          continue;
-        }
-
-        nsCOMPtr<nsISupports> genericDataWrapper = do_QueryInterface(dataWrapper);
-        uint32_t len = mClipboard->GetHTML().Length() * sizeof(PRUnichar);
-        rv = aTransferable->SetTransferData(flavorStr, genericDataWrapper, len);
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-          continue;
-        }
-        break;
-      }
+  // If our data flavor has already been added, this will fail. But we don't care
+  aTransferable->AddDataFlavor(kUnicodeMime);
 
-      // image/[png|jpeg|jpg|gif]
-      if ((flavorStr.EqualsLiteral(kPNGImageMime) ||
-           flavorStr.EqualsLiteral(kJPEGImageMime) ||
-           flavorStr.EqualsLiteral(kJPGImageMime) ||
-           flavorStr.EqualsLiteral(kGIFImageMime)) &&
-          mClipboard->HasImage() ) {
-        // Get image buffer from clipboard.
-        RefPtr<gfx::DataSourceSurface> image = mClipboard->GetImage();
-
-        // Encode according to MIME type.
-        nsRefPtr<gfxDrawable> drawable = new gfxSurfaceDrawable(image, image->GetSize());
-        nsCOMPtr<imgIContainer> imageContainer(image::ImageOps::CreateFromDrawable(drawable));
-        nsCOMPtr<imgITools> imgTool = do_GetService(NS_IMGTOOLS_CID);
-
-        nsCOMPtr<nsIInputStream> byteStream;
-        imgTool->EncodeImage(imageContainer, flavorStr, EmptyString(), getter_AddRefs(byteStream));
-
-        // Set transferable.
-        nsresult rv = aTransferable->SetTransferData(flavorStr,
-                                                     byteStream,
-                                                     sizeof(nsIInputStream*));
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-          continue;
-        }
-        break;
-      }
-    }
+  nsCOMPtr<nsISupports> nsisupportsDataWrapper =
+    do_QueryInterface(dataWrapper);
+  rv = aTransferable->SetTransferData(kUnicodeMime, nsisupportsDataWrapper,
+                                      buffer.Length() * sizeof(PRUnichar));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsClipboard::EmptyClipboard(int32_t aWhichClipboard)
 {
   if (aWhichClipboard != kGlobalClipboard) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
   if (XRE_IsParentProcess()) {
-    mClipboard->Clear();
+    mClipboard.Truncate(0);
   } else {
     ContentChild::GetSingleton()->SendEmptyClipboard(aWhichClipboard);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsClipboard::HasDataMatchingFlavors(const char **aFlavorList,
                                     uint32_t aLength, int32_t aWhichClipboard,
                                     bool *aHasType)
 {
   *aHasType = false;
-
   if (aWhichClipboard != kGlobalClipboard) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
   if (XRE_IsParentProcess()) {
-    for (uint32_t i = 0; i < aLength; ++i) {
-      const char *flavor = aFlavorList[i];
-      if (!flavor) {
-        continue;
-      }
-      if (!strcmp(flavor, kUnicodeMime)) {
-        *aHasType = mClipboard->HasText();
-      } else if (!strcmp(flavor, kHTMLMime)) {
-        *aHasType = mClipboard->HasHTML();
-      } else if (!strcmp(flavor, kJPEGImageMime) ||
-                 !strcmp(flavor, kJPGImageMime) ||
-                 !strcmp(flavor, kPNGImageMime) ||
-                 !strcmp(flavor, kGIFImageMime)) {
-        // We will encode the image into any format you want, so we don't
-        // need to check each specific format
-        *aHasType = mClipboard->HasImage();
-      }
-    }
+    *aHasType = !mClipboard.IsEmpty();
   } else {
     nsRefPtr<nsClipboardProxy> clipboardProxy = new nsClipboardProxy();
     return clipboardProxy->HasDataMatchingFlavors(aFlavorList, aLength, aWhichClipboard, aHasType);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/widget/gonk/nsClipboard.h
+++ b/widget/gonk/nsClipboard.h
@@ -1,27 +1,24 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
+/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsClipbard_h__
 #define nsClipbard_h__
 
-#include "GonkClipboardData.h"
-#include "mozilla/UniquePtr.h"
 #include "nsIClipboard.h"
 
 class nsClipboard final : public nsIClipboard
 {
+  nsAutoString mClipboard;
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSICLIPBOARD
 
   nsClipboard();
 
 protected:
   ~nsClipboard() {}
-
-private:
-  mozilla::UniquePtr<mozilla::GonkClipboardData> mClipboard;
 };
 
 #endif