extensions/cookie/nsCookiePromptService.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsCookiePromptService.h"
     7 #include "nsICookie.h"
     8 #include "nsICookieAcceptDialog.h"
     9 #include "nsIDOMWindow.h"
    10 #include "nsPIDOMWindow.h"
    11 #include "nsIWindowWatcher.h"
    12 #include "nsIServiceManager.h"
    13 #include "nsString.h"
    14 #include "nsIDialogParamBlock.h"
    15 #include "nsIMutableArray.h"
    17 /****************************************************************
    18  ************************ nsCookiePromptService *****************
    19  ****************************************************************/
    21 NS_IMPL_ISUPPORTS(nsCookiePromptService, nsICookiePromptService)
    23 nsCookiePromptService::nsCookiePromptService() {
    24 }
    26 nsCookiePromptService::~nsCookiePromptService() {
    27 }
    29 NS_IMETHODIMP
    30 nsCookiePromptService::CookieDialog(nsIDOMWindow *aParent,
    31                                     nsICookie *aCookie,
    32                                     const nsACString &aHostname,
    33                                     int32_t aCookiesFromHost,
    34                                     bool aChangingCookie,
    35                                     bool *aRememberDecision,
    36                                     int32_t *aAccept)
    37 {
    38   nsresult rv;
    40   nsCOMPtr<nsIDialogParamBlock> block = do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID,&rv);
    41   if (NS_FAILED(rv)) return rv;
    43   block->SetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, 1);
    44   block->SetString(nsICookieAcceptDialog::HOSTNAME, NS_ConvertUTF8toUTF16(aHostname).get());
    45   block->SetInt(nsICookieAcceptDialog::COOKIESFROMHOST, aCookiesFromHost);
    46   block->SetInt(nsICookieAcceptDialog::CHANGINGCOOKIE, aChangingCookie ? 1 : 0);
    48   nsCOMPtr<nsIMutableArray> objects =
    49     do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
    50   if (NS_FAILED(rv)) return rv;
    52   rv = objects->AppendElement(aCookie, false);
    53   if (NS_FAILED(rv)) return rv;
    55   block->SetObjects(objects);
    57   nsCOMPtr<nsIWindowWatcher> wwatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
    58   if (NS_FAILED(rv)) return rv;
    60   nsCOMPtr<nsISupports> arguments = do_QueryInterface(block);
    61   nsCOMPtr<nsIDOMWindow> dialog;
    63   nsCOMPtr<nsIDOMWindow> parent(aParent);
    64   if (!parent) // if no parent provided, consult the window watcher:
    65     wwatcher->GetActiveWindow(getter_AddRefs(parent));
    67   if (parent) {
    68     nsCOMPtr<nsPIDOMWindow> privateParent(do_QueryInterface(parent));
    69     if (privateParent)
    70       privateParent = privateParent->GetPrivateRoot();
    71     parent = do_QueryInterface(privateParent);
    72   }
    74   // The cookie dialog will be modal for the root chrome window rather than the
    75   // tab containing the permission-requesting page.  This removes confusion
    76   // about which monitor is displaying the dialog (see bug 470356), but also
    77   // avoids unwanted tab switches (see bug 405239).
    78   rv = wwatcher->OpenWindow(parent, "chrome://cookie/content/cookieAcceptDialog.xul", "_blank",
    79                             "centerscreen,chrome,modal,titlebar", arguments,
    80                             getter_AddRefs(dialog));
    82   if (NS_FAILED(rv)) return rv;
    84   // get back output parameters
    85   int32_t tempValue;
    86   block->GetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, &tempValue);
    87   *aAccept = tempValue;
    89   // GetInt returns a int32_t; we need to sanitize it into bool
    90   block->GetInt(nsICookieAcceptDialog::REMEMBER_DECISION, &tempValue);
    91   *aRememberDecision = (tempValue == 1);
    93   return rv;
    94 }

mercurial