LCOV - code coverage report
Current view: directory - extensions/cookie - nsCookiePromptService.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 37 0 0.0 %
Date: 2012-06-02 Functions: 7 0 0.0 %

       1                 : /* ***** BEGIN LICENSE BLOCK *****
       2                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       3                 :  *
       4                 :  * The contents of this file are subject to the Mozilla Public License Version
       5                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       6                 :  * the License. You may obtain a copy of the License at
       7                 :  * http://www.mozilla.org/MPL/
       8                 :  *
       9                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      10                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      11                 :  * for the specific language governing rights and limitations under the
      12                 :  * License.
      13                 :  *
      14                 :  * The Original Code is cookie manager code.
      15                 :  *
      16                 :  * The Initial Developer of the Original Code is
      17                 :  * Michiel van Leeuwen (mvl@exedo.nl).
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2003
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *
      23                 :  * Alternatively, the contents of this file may be used under the terms of
      24                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      25                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      26                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      27                 :  * of those above. If you wish to allow use of your version of this file only
      28                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      29                 :  * use your version of this file under the terms of the MPL, indicate your
      30                 :  * decision by deleting the provisions above and replace them with the notice
      31                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      32                 :  * the provisions above, a recipient may use your version of this file under
      33                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      34                 :  *
      35                 :  * ***** END LICENSE BLOCK ***** */
      36                 : 
      37                 : 
      38                 : #include "nsCookiePromptService.h"
      39                 : #include "nsICookie.h"
      40                 : #include "nsICookieAcceptDialog.h"
      41                 : #include "nsIDOMWindow.h"
      42                 : #include "nsPIDOMWindow.h"
      43                 : #include "nsIWindowWatcher.h"
      44                 : #include "nsIServiceManager.h"
      45                 : #include "nsString.h"
      46                 : #include "nsIDialogParamBlock.h"
      47                 : #include "nsIMutableArray.h"
      48                 : 
      49                 : /****************************************************************
      50                 :  ************************ nsCookiePromptService *****************
      51                 :  ****************************************************************/
      52                 : 
      53               0 : NS_IMPL_ISUPPORTS1(nsCookiePromptService, nsICookiePromptService)
      54                 : 
      55               0 : nsCookiePromptService::nsCookiePromptService() {
      56               0 : }
      57                 : 
      58               0 : nsCookiePromptService::~nsCookiePromptService() {
      59               0 : }
      60                 : 
      61                 : NS_IMETHODIMP
      62               0 : nsCookiePromptService::CookieDialog(nsIDOMWindow *aParent,
      63                 :                                     nsICookie *aCookie,
      64                 :                                     const nsACString &aHostname,
      65                 :                                     PRInt32 aCookiesFromHost,
      66                 :                                     bool aChangingCookie,
      67                 :                                     bool *aRememberDecision,
      68                 :                                     PRInt32 *aAccept)
      69                 : {
      70                 :   nsresult rv;
      71                 : 
      72               0 :   nsCOMPtr<nsIDialogParamBlock> block = do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID,&rv);
      73               0 :   if (NS_FAILED(rv)) return rv;
      74                 : 
      75               0 :   block->SetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, 1);
      76               0 :   block->SetString(nsICookieAcceptDialog::HOSTNAME, NS_ConvertUTF8toUTF16(aHostname).get());
      77               0 :   block->SetInt(nsICookieAcceptDialog::COOKIESFROMHOST, aCookiesFromHost);
      78               0 :   block->SetInt(nsICookieAcceptDialog::CHANGINGCOOKIE, aChangingCookie ? 1 : 0);
      79                 :   
      80                 :   nsCOMPtr<nsIMutableArray> objects =
      81               0 :     do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
      82               0 :   if (NS_FAILED(rv)) return rv;
      83                 : 
      84               0 :   rv = objects->AppendElement(aCookie, false);
      85               0 :   if (NS_FAILED(rv)) return rv;
      86                 : 
      87               0 :   block->SetObjects(objects);
      88                 : 
      89               0 :   nsCOMPtr<nsIWindowWatcher> wwatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
      90               0 :   if (NS_FAILED(rv)) return rv;
      91                 : 
      92               0 :   nsCOMPtr<nsISupports> arguments = do_QueryInterface(block);
      93               0 :   nsCOMPtr<nsIDOMWindow> dialog;
      94                 : 
      95               0 :   nsCOMPtr<nsIDOMWindow> parent(aParent);
      96               0 :   if (!parent) // if no parent provided, consult the window watcher:
      97               0 :     wwatcher->GetActiveWindow(getter_AddRefs(parent));
      98                 : 
      99               0 :   if (parent) {
     100               0 :     nsCOMPtr<nsPIDOMWindow> privateParent(do_QueryInterface(parent));
     101               0 :     if (privateParent)
     102               0 :       privateParent = privateParent->GetPrivateRoot();
     103               0 :     parent = do_QueryInterface(privateParent);
     104                 :   }
     105                 : 
     106                 :   // The cookie dialog will be modal for the root chrome window rather than the
     107                 :   // tab containing the permission-requesting page.  This removes confusion
     108                 :   // about which monitor is displaying the dialog (see bug 470356), but also
     109                 :   // avoids unwanted tab switches (see bug 405239).
     110               0 :   rv = wwatcher->OpenWindow(parent, "chrome://cookie/content/cookieAcceptDialog.xul", "_blank",
     111                 :                             "centerscreen,chrome,modal,titlebar", arguments,
     112               0 :                             getter_AddRefs(dialog));
     113                 : 
     114               0 :   if (NS_FAILED(rv)) return rv;
     115                 : 
     116                 :   // get back output parameters
     117                 :   PRInt32 tempValue;
     118               0 :   block->GetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, &tempValue);
     119               0 :   *aAccept = tempValue;
     120                 :   
     121                 :   // GetInt returns a PRInt32; we need to sanitize it into bool
     122               0 :   block->GetInt(nsICookieAcceptDialog::REMEMBER_DECISION, &tempValue);
     123               0 :   *aRememberDecision = (tempValue == 1);
     124                 : 
     125               0 :   return rv;
     126                 : }
     127                 : 

Generated by: LCOV version 1.7