Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode:nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsXULAlerts.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "nsAutoPtr.h" |
michael@0 | 9 | #include "mozilla/LookAndFeel.h" |
michael@0 | 10 | #include "nsIServiceManager.h" |
michael@0 | 11 | #include "nsISupportsArray.h" |
michael@0 | 12 | #include "nsISupportsPrimitives.h" |
michael@0 | 13 | #include "nsPIDOMWindow.h" |
michael@0 | 14 | #include "nsIWindowWatcher.h" |
michael@0 | 15 | |
michael@0 | 16 | using namespace mozilla; |
michael@0 | 17 | |
michael@0 | 18 | #define ALERT_CHROME_URL "chrome://global/content/alerts/alert.xul" |
michael@0 | 19 | |
michael@0 | 20 | NS_IMPL_ISUPPORTS(nsXULAlertObserver, nsIObserver) |
michael@0 | 21 | |
michael@0 | 22 | NS_IMETHODIMP |
michael@0 | 23 | nsXULAlertObserver::Observe(nsISupports* aSubject, const char* aTopic, |
michael@0 | 24 | const char16_t* aData) |
michael@0 | 25 | { |
michael@0 | 26 | if (!strcmp("alertfinished", aTopic)) { |
michael@0 | 27 | nsIDOMWindow* currentAlert = mXULAlerts->mNamedWindows.GetWeak(mAlertName); |
michael@0 | 28 | // The window in mNamedWindows might be a replacement, thus it should only |
michael@0 | 29 | // be removed if it is the same window that is associated with this listener. |
michael@0 | 30 | if (currentAlert == mAlertWindow) { |
michael@0 | 31 | mXULAlerts->mNamedWindows.Remove(mAlertName); |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | nsresult rv = NS_OK; |
michael@0 | 36 | if (mObserver) { |
michael@0 | 37 | rv = mObserver->Observe(aSubject, aTopic, aData); |
michael@0 | 38 | } |
michael@0 | 39 | return rv; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | nsresult |
michael@0 | 43 | nsXULAlerts::ShowAlertNotification(const nsAString& aImageUrl, const nsAString& aAlertTitle, |
michael@0 | 44 | const nsAString& aAlertText, bool aAlertTextClickable, |
michael@0 | 45 | const nsAString& aAlertCookie, nsIObserver* aAlertListener, |
michael@0 | 46 | const nsAString& aAlertName, const nsAString& aBidi, |
michael@0 | 47 | const nsAString& aLang) |
michael@0 | 48 | { |
michael@0 | 49 | nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); |
michael@0 | 50 | |
michael@0 | 51 | nsCOMPtr<nsISupportsArray> argsArray; |
michael@0 | 52 | nsresult rv = NS_NewISupportsArray(getter_AddRefs(argsArray)); |
michael@0 | 53 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 54 | |
michael@0 | 55 | // create scriptable versions of our strings that we can store in our nsISupportsArray.... |
michael@0 | 56 | nsCOMPtr<nsISupportsString> scriptableImageUrl (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); |
michael@0 | 57 | NS_ENSURE_TRUE(scriptableImageUrl, NS_ERROR_FAILURE); |
michael@0 | 58 | |
michael@0 | 59 | scriptableImageUrl->SetData(aImageUrl); |
michael@0 | 60 | rv = argsArray->AppendElement(scriptableImageUrl); |
michael@0 | 61 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 62 | |
michael@0 | 63 | nsCOMPtr<nsISupportsString> scriptableAlertTitle (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); |
michael@0 | 64 | NS_ENSURE_TRUE(scriptableAlertTitle, NS_ERROR_FAILURE); |
michael@0 | 65 | |
michael@0 | 66 | scriptableAlertTitle->SetData(aAlertTitle); |
michael@0 | 67 | rv = argsArray->AppendElement(scriptableAlertTitle); |
michael@0 | 68 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 69 | |
michael@0 | 70 | nsCOMPtr<nsISupportsString> scriptableAlertText (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); |
michael@0 | 71 | NS_ENSURE_TRUE(scriptableAlertText, NS_ERROR_FAILURE); |
michael@0 | 72 | |
michael@0 | 73 | scriptableAlertText->SetData(aAlertText); |
michael@0 | 74 | rv = argsArray->AppendElement(scriptableAlertText); |
michael@0 | 75 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 76 | |
michael@0 | 77 | nsCOMPtr<nsISupportsPRBool> scriptableIsClickable (do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID)); |
michael@0 | 78 | NS_ENSURE_TRUE(scriptableIsClickable, NS_ERROR_FAILURE); |
michael@0 | 79 | |
michael@0 | 80 | scriptableIsClickable->SetData(aAlertTextClickable); |
michael@0 | 81 | rv = argsArray->AppendElement(scriptableIsClickable); |
michael@0 | 82 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 83 | |
michael@0 | 84 | nsCOMPtr<nsISupportsString> scriptableAlertCookie (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); |
michael@0 | 85 | NS_ENSURE_TRUE(scriptableAlertCookie, NS_ERROR_FAILURE); |
michael@0 | 86 | |
michael@0 | 87 | scriptableAlertCookie->SetData(aAlertCookie); |
michael@0 | 88 | rv = argsArray->AppendElement(scriptableAlertCookie); |
michael@0 | 89 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 90 | |
michael@0 | 91 | nsCOMPtr<nsISupportsPRInt32> scriptableOrigin (do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID)); |
michael@0 | 92 | NS_ENSURE_TRUE(scriptableOrigin, NS_ERROR_FAILURE); |
michael@0 | 93 | |
michael@0 | 94 | int32_t origin = |
michael@0 | 95 | LookAndFeel::GetInt(LookAndFeel::eIntID_AlertNotificationOrigin); |
michael@0 | 96 | scriptableOrigin->SetData(origin); |
michael@0 | 97 | |
michael@0 | 98 | rv = argsArray->AppendElement(scriptableOrigin); |
michael@0 | 99 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 100 | |
michael@0 | 101 | nsCOMPtr<nsISupportsString> scriptableBidi (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); |
michael@0 | 102 | NS_ENSURE_TRUE(scriptableBidi, NS_ERROR_FAILURE); |
michael@0 | 103 | |
michael@0 | 104 | scriptableBidi->SetData(aBidi); |
michael@0 | 105 | rv = argsArray->AppendElement(scriptableBidi); |
michael@0 | 106 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 107 | |
michael@0 | 108 | nsCOMPtr<nsISupportsString> scriptableLang (do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); |
michael@0 | 109 | NS_ENSURE_TRUE(scriptableLang, NS_ERROR_FAILURE); |
michael@0 | 110 | |
michael@0 | 111 | scriptableLang->SetData(aLang); |
michael@0 | 112 | rv = argsArray->AppendElement(scriptableLang); |
michael@0 | 113 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 114 | |
michael@0 | 115 | // Alerts with the same name should replace the old alert in the same position. |
michael@0 | 116 | // Provide the new alert window with a pointer to the replaced window so that |
michael@0 | 117 | // it may take the same position. |
michael@0 | 118 | nsCOMPtr<nsISupportsInterfacePointer> replacedWindow = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv); |
michael@0 | 119 | NS_ENSURE_TRUE(replacedWindow, NS_ERROR_FAILURE); |
michael@0 | 120 | nsIDOMWindow* previousAlert = mNamedWindows.GetWeak(aAlertName); |
michael@0 | 121 | replacedWindow->SetData(previousAlert); |
michael@0 | 122 | replacedWindow->SetDataIID(&NS_GET_IID(nsIDOMWindow)); |
michael@0 | 123 | rv = argsArray->AppendElement(replacedWindow); |
michael@0 | 124 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 125 | |
michael@0 | 126 | // Add an observer (that wraps aAlertListener) to remove the window from |
michael@0 | 127 | // mNamedWindows when it is closed. |
michael@0 | 128 | nsCOMPtr<nsISupportsInterfacePointer> ifptr = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv); |
michael@0 | 129 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 130 | nsRefPtr<nsXULAlertObserver> alertObserver = new nsXULAlertObserver(this, aAlertName, aAlertListener); |
michael@0 | 131 | nsCOMPtr<nsISupports> iSupports(do_QueryInterface(alertObserver)); |
michael@0 | 132 | ifptr->SetData(iSupports); |
michael@0 | 133 | ifptr->SetDataIID(&NS_GET_IID(nsIObserver)); |
michael@0 | 134 | rv = argsArray->AppendElement(ifptr); |
michael@0 | 135 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 136 | |
michael@0 | 137 | nsCOMPtr<nsIDOMWindow> newWindow; |
michael@0 | 138 | rv = wwatch->OpenWindow(0, ALERT_CHROME_URL, "_blank", |
michael@0 | 139 | "chrome,dialog=yes,titlebar=no,popup=yes", argsArray, |
michael@0 | 140 | getter_AddRefs(newWindow)); |
michael@0 | 141 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 142 | |
michael@0 | 143 | mNamedWindows.Put(aAlertName, newWindow); |
michael@0 | 144 | alertObserver->SetAlertWindow(newWindow); |
michael@0 | 145 | |
michael@0 | 146 | return NS_OK; |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | nsresult |
michael@0 | 150 | nsXULAlerts::CloseAlert(const nsAString& aAlertName) |
michael@0 | 151 | { |
michael@0 | 152 | nsIDOMWindow* alert = mNamedWindows.GetWeak(aAlertName); |
michael@0 | 153 | nsCOMPtr<nsPIDOMWindow> domWindow = do_QueryInterface(alert); |
michael@0 | 154 | if (domWindow) { |
michael@0 | 155 | domWindow->DispatchCustomEvent("XULAlertClose"); |
michael@0 | 156 | } |
michael@0 | 157 | return NS_OK; |
michael@0 | 158 | } |
michael@0 | 159 |