diff --git a/widget/gtk/nsClipboard.cpp b/widget/gtk/nsClipboard.cpp index bd69ae290bf..8c1ded1d533 100644 --- a/widget/gtk/nsClipboard.cpp +++ b/widget/gtk/nsClipboard.cpp @@ -137,14 +137,6 @@ nsClipboard::SetData(nsITransferable *aTransferable, return NS_OK; } - nsresult rv; - if (!mPrivacyHandler) { - rv = NS_NewClipboardPrivacyHandler(getter_AddRefs(mPrivacyHandler)); - NS_ENSURE_SUCCESS(rv, rv); - } - rv = mPrivacyHandler->PrepareDataForClipboard(aTransferable); - NS_ENSURE_SUCCESS(rv, rv); - // Clear out the clipboard in order to set the new data EmptyClipboard(aWhichClipboard); @@ -154,7 +146,8 @@ nsClipboard::SetData(nsITransferable *aTransferable, // Get the types of supported flavors nsCOMPtr flavors; - rv = aTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavors)); + nsresult rv = + aTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavors)); if (!flavors || NS_FAILED(rv)) return NS_ERROR_FAILURE; diff --git a/widget/gtk/nsClipboard.h b/widget/gtk/nsClipboard.h index b233292f690..70c866a013c 100644 --- a/widget/gtk/nsClipboard.h +++ b/widget/gtk/nsClipboard.h @@ -9,8 +9,7 @@ #define __nsClipboard_h_ #include "nsIClipboard.h" -#include "nsClipboardPrivacyHandler.h" -#include "nsAutoPtr.h" +#include "nsIObserver.h" #include class nsClipboard : public nsIClipboard, @@ -53,7 +52,6 @@ private: nsCOMPtr mGlobalOwner; nsCOMPtr mSelectionTransferable; nsCOMPtr mGlobalTransferable; - nsRefPtr mPrivacyHandler; }; diff --git a/widget/qt/nsClipboard.cpp b/widget/qt/nsClipboard.cpp index 95a54259d26..5939a43007b 100644 --- a/widget/qt/nsClipboard.cpp +++ b/widget/qt/nsClipboard.cpp @@ -468,14 +468,6 @@ nsClipboard::SetData(nsITransferable *aTransferable, return NS_OK; } - nsresult rv; - if (!mPrivacyHandler) { - rv = NS_NewClipboardPrivacyHandler(getter_AddRefs(mPrivacyHandler)); - NS_ENSURE_SUCCESS(rv, rv); - } - rv = mPrivacyHandler->PrepareDataForClipboard(aTransferable); - NS_ENSURE_SUCCESS(rv, rv); - EmptyClipboard(aWhichClipboard); QClipboard::Mode mode; diff --git a/widget/qt/nsClipboard.h b/widget/qt/nsClipboard.h index 185d692e4de..8ba60be3037 100644 --- a/widget/qt/nsClipboard.h +++ b/widget/qt/nsClipboard.h @@ -8,8 +8,6 @@ #include "nsIClipboard.h" #include "nsITransferable.h" #include "nsIClipboardOwner.h" -#include "nsClipboardPrivacyHandler.h" -#include "nsAutoPtr.h" #include "nsCOMPtr.h" #include diff --git a/widget/tests/chrome.ini b/widget/tests/chrome.ini index 2461dddc4ef..72002f1a63d 100644 --- a/widget/tests/chrome.ini +++ b/widget/tests/chrome.ini @@ -8,7 +8,6 @@ support-files = window_bug429954.xul [test_bug478536.xul] skip-if = true # Bug 561929 support-files = window_bug478536.xul -[test_bug462106_perwindow.xul] [test_bug517396.xul] [test_bug538242.xul] support-files = window_bug538242.xul diff --git a/widget/tests/test_bug462106_perwindow.xul b/widget/tests/test_bug462106_perwindow.xul deleted file mode 100644 index 07d1c581f45..00000000000 --- a/widget/tests/test_bug462106_perwindow.xul +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - diff --git a/widget/windows/nsClipboard.h b/widget/windows/nsClipboard.h index 112b8550e09..85bc5aa5173 100644 --- a/widget/windows/nsClipboard.h +++ b/widget/windows/nsClipboard.h @@ -7,6 +7,7 @@ #define nsClipboard_h__ #include "nsBaseClipboard.h" +#include "nsIObserver.h" #include "nsIURI.h" #include diff --git a/widget/xpwidgets/moz.build b/widget/xpwidgets/moz.build index a2aee17d3cd..dbf2db645bd 100644 --- a/widget/xpwidgets/moz.build +++ b/widget/xpwidgets/moz.build @@ -22,7 +22,6 @@ UNIFIED_SOURCES += [ 'nsBaseDragService.cpp', 'nsBaseScreen.cpp', 'nsClipboardHelper.cpp', - 'nsClipboardPrivacyHandler.cpp', 'nsClipboardProxy.cpp', 'nsColorPickerProxy.cpp', 'nsContentProcessWidgetFactory.cpp', diff --git a/widget/xpwidgets/nsBaseClipboard.cpp b/widget/xpwidgets/nsBaseClipboard.cpp index 2721029dfd3..fd22dab6589 100644 --- a/widget/xpwidgets/nsBaseClipboard.cpp +++ b/widget/xpwidgets/nsBaseClipboard.cpp @@ -59,12 +59,6 @@ NS_IMETHODIMP nsBaseClipboard::SetData(nsITransferable * aTransferable, nsIClipb if ( mTransferable ) { NS_ADDREF(mTransferable); - if (!mPrivacyHandler) { - rv = NS_NewClipboardPrivacyHandler(getter_AddRefs(mPrivacyHandler)); - NS_ENSURE_SUCCESS(rv, rv); - } - rv = mPrivacyHandler->PrepareDataForClipboard(mTransferable); - NS_ENSURE_SUCCESS(rv, rv); rv = SetNativeClipboardData(aWhichClipboard); } diff --git a/widget/xpwidgets/nsBaseClipboard.h b/widget/xpwidgets/nsBaseClipboard.h index c45f02840d8..8ceafdb1301 100644 --- a/widget/xpwidgets/nsBaseClipboard.h +++ b/widget/xpwidgets/nsBaseClipboard.h @@ -8,8 +8,6 @@ #include "nsIClipboard.h" #include "nsITransferable.h" -#include "nsClipboardPrivacyHandler.h" -#include "nsAutoPtr.h" class nsITransferable; class nsDataObj; @@ -42,7 +40,6 @@ protected: bool mIgnoreEmptyNotification; nsIClipboardOwner * mClipboardOwner; nsITransferable * mTransferable; - nsRefPtr mPrivacyHandler; }; diff --git a/widget/xpwidgets/nsClipboardPrivacyHandler.cpp b/widget/xpwidgets/nsClipboardPrivacyHandler.cpp deleted file mode 100644 index 625b5875684..00000000000 --- a/widget/xpwidgets/nsClipboardPrivacyHandler.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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/ArrayUtils.h" - -#include "nsClipboardPrivacyHandler.h" -#include "nsITransferable.h" -#include "nsISupportsPrimitives.h" -#include "nsIObserverService.h" -#include "nsIClipboard.h" -#include "nsComponentManagerUtils.h" -#include "nsServiceManagerUtils.h" -#include "nsLiteralString.h" -#include "nsNetCID.h" -#include "nsXPCOM.h" -#include "mozilla/Services.h" - -#if defined(XP_WIN) -#include -#endif - -using namespace mozilla; - -#define NS_MOZ_DATA_FROM_PRIVATEBROWSING "application/x-moz-private-browsing" - -NS_IMPL_ISUPPORTS(nsClipboardPrivacyHandler, nsIObserver, nsISupportsWeakReference) - -nsresult -nsClipboardPrivacyHandler::Init() -{ - nsCOMPtr observerService = - mozilla::services::GetObserverService(); - if (!observerService) - return NS_ERROR_FAILURE; - return observerService->AddObserver(this, "last-pb-context-exited", true); -} - -/** - * Prepare the transferable object to be inserted into the clipboard - * - */ -nsresult -nsClipboardPrivacyHandler::PrepareDataForClipboard(nsITransferable * aTransferable) -{ - NS_ASSERTION(aTransferable, "clipboard given a null transferable"); - - bool isPrivateData = false; - aTransferable->GetIsPrivateData(&isPrivateData); - - nsresult rv = NS_OK; - if (isPrivateData) { - nsCOMPtr data = do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID); - if (data) { - rv = data->SetData(true); - NS_ENSURE_SUCCESS(rv, rv); - - // Ignore the error code of AddDataFlavor, since we might have added - // this flavor before. If this call really fails, so will the next - // one (SetTransferData). - aTransferable->AddDataFlavor(NS_MOZ_DATA_FROM_PRIVATEBROWSING); - - rv = aTransferable->SetTransferData(NS_MOZ_DATA_FROM_PRIVATEBROWSING, data, sizeof(bool)); - NS_ENSURE_SUCCESS(rv, rv); - } - } - - return rv; -} - -NS_IMETHODIMP -nsClipboardPrivacyHandler::Observe(nsISupports *aSubject, char const *aTopic, char16_t const *aData) -{ - nsresult rv; - nsCOMPtr clipboard = - do_GetService("@mozilla.org/widget/clipboard;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - const char * flavors[] = { NS_MOZ_DATA_FROM_PRIVATEBROWSING }; - bool haveFlavors; - rv = clipboard->HasDataMatchingFlavors(flavors, - ArrayLength(flavors), - nsIClipboard::kGlobalClipboard, - &haveFlavors); - if (NS_SUCCEEDED(rv) && haveFlavors) { -#if defined(XP_WIN) - // Workaround for bug 518412. On Windows 7 x64, there is a bug - // in handling clipboard data without any formats between - // 32-bit/64-bit boundaries, which could lead Explorer to crash. - // We work around the problem by clearing the clipboard using - // the usual Win32 API. - NS_ENSURE_TRUE(SUCCEEDED(::OleSetClipboard(nullptr)), NS_ERROR_FAILURE); -#else - // Empty the native clipboard by copying an empty transferable - nsCOMPtr nullData = - do_CreateInstance("@mozilla.org/widget/transferable;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - nullData->Init(nullptr); - rv = clipboard->SetData(nullData, nullptr, - nsIClipboard::kGlobalClipboard); - NS_ENSURE_SUCCESS(rv, rv); -#endif - } - - return NS_OK; -} - -nsresult -NS_NewClipboardPrivacyHandler(nsClipboardPrivacyHandler ** aHandler) -{ - NS_PRECONDITION(aHandler != nullptr, "null ptr"); - if (!aHandler) - return NS_ERROR_NULL_POINTER; - - *aHandler = new nsClipboardPrivacyHandler(); - - NS_ADDREF(*aHandler); - nsresult rv = (*aHandler)->Init(); - if (NS_FAILED(rv)) - NS_RELEASE(*aHandler); - - return rv; -} diff --git a/widget/xpwidgets/nsClipboardPrivacyHandler.h b/widget/xpwidgets/nsClipboardPrivacyHandler.h deleted file mode 100644 index ef9b213a0ad..00000000000 --- a/widget/xpwidgets/nsClipboardPrivacyHandler.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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 nsClipboardPrivacyHandler_h__ -#define nsClipboardPrivacyHandler_h__ - -#include "nsIObserver.h" -#include "nsWeakReference.h" -#include "nsCOMPtr.h" -#include "mozilla/Attributes.h" - -class nsITransferable; - -// nsClipboardPrivacyHandler makes sure that clipboard data copied during -// the private browsing mode does not leak after exiting this mode. -// In order to ensure this, callers should store an object of this class -// for their lifetime, and call PrepareDataForClipboard in their -// nsIClipboard::SetData implementation before starting to use the -// nsITransferable object in any way. - -class nsClipboardPrivacyHandler MOZ_FINAL : public nsIObserver, - public nsSupportsWeakReference -{ - ~nsClipboardPrivacyHandler() {} - -public: - - // nsISupports - NS_DECL_ISUPPORTS - - // nsIObserver - NS_DECL_NSIOBSERVER - - nsresult Init(); - nsresult PrepareDataForClipboard(nsITransferable * aTransferable); -}; - -nsresult NS_NewClipboardPrivacyHandler(nsClipboardPrivacyHandler ** aHandler); - -#endif // nsClipboardPrivacyHandler_h__