Bug 769589 - Remove deprecated GetOriginatingURI from nsICookiePermission. r=mconnor sr=cbiesinger
authorMounir Lamouri <mounir.lamouri@gmail.com>
Thu, 30 Aug 2012 17:07:03 -0300
changeset 110804 e4c7a8c7fc65920595b3d72fc67c252e8f30a32a
parent 110803 6075cc5dbe31fbe68e26d7bd70fb1487580a5363
child 110805 cd51f6ca80e276f149c64b6dde15101b26946c9a
push id239
push userakeybl@mozilla.com
push dateThu, 03 Jan 2013 21:54:43 +0000
treeherdermozilla-release@3a7b66445659 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconnor, cbiesinger
bugs769589
milestone18.0a1
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
Bug 769589 - Remove deprecated GetOriginatingURI from nsICookiePermission. r=mconnor sr=cbiesinger
extensions/cookie/nsCookiePermission.cpp
netwerk/cookie/nsICookiePermission.idl
--- a/extensions/cookie/nsCookiePermission.cpp
+++ b/extensions/cookie/nsCookiePermission.cpp
@@ -353,114 +353,16 @@ nsCookiePermission::CanSetCookie(nsIURI 
         }
       }
     }
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP 
-nsCookiePermission::GetOriginatingURI(nsIChannel  *aChannel,
-                                      nsIURI     **aURI)
-{
-  /* to find the originating URI, we use the loadgroup of the channel to obtain
-   * the window owning the load, and from there, we find the top same-type
-   * window and its URI. there are several possible cases:
-   *
-   * 1) no channel.
-   *
-   * 2) a channel with the "force allow third party cookies" option set.
-   *    since we may not have a window, we return the channel URI in this case.
-   *
-   * 3) a channel, but no window. this can occur when the consumer kicking
-   *    off the load doesn't provide one to the channel, and should be limited
-   *    to loads of certain types of resources.
-   *
-   * 4) a window equal to the top window of same type, with the channel its
-   *    document channel. this covers the case of a freshly kicked-off load
-   *    (e.g. the user typing something in the location bar, or clicking on a
-   *    bookmark), where the window's URI hasn't yet been set, and will be
-   *    bogus. we return the channel URI in this case.
-   *
-   * 5) Anything else. this covers most cases for an ordinary page load from
-   *    the location bar, and will catch nested frames within a page, image
-   *    loads, etc. we return the URI of the root window's document's principal
-   *    in this case.
-   */
-
-  *aURI = nullptr;
-
-  // case 1)
-  if (!aChannel)
-    return NS_ERROR_NULL_POINTER;
-
-  // case 2)
-  nsCOMPtr<nsIHttpChannelInternal> httpChannelInternal = do_QueryInterface(aChannel);
-  if (httpChannelInternal)
-  {
-    bool doForce = false;
-    if (NS_SUCCEEDED(httpChannelInternal->GetForceAllowThirdPartyCookie(&doForce)) && doForce)
-    {
-      // return the channel's URI (we may not have a window)
-      aChannel->GetURI(aURI);
-      if (!*aURI)
-        return NS_ERROR_NULL_POINTER;
-
-      return NS_OK;
-    }
-  }
-
-  // find the associated window and its top window
-  nsCOMPtr<nsILoadContext> ctx;
-  NS_QueryNotificationCallbacks(aChannel, ctx);
-  nsCOMPtr<nsIDOMWindow> topWin, ourWin;
-  if (ctx) {
-    ctx->GetTopWindow(getter_AddRefs(topWin));
-    ctx->GetAssociatedWindow(getter_AddRefs(ourWin));
-  }
-
-  // case 3)
-  if (!topWin)
-    return NS_ERROR_INVALID_ARG;
-
-  // case 4)
-  if (ourWin == topWin) {
-    // Check whether this is the document channel for this window (representing
-    // a load of a new page).  This is a bit of a nasty hack, but we will
-    // hopefully flag these channels better later.
-    nsLoadFlags flags;
-    aChannel->GetLoadFlags(&flags);
-
-    if (flags & nsIChannel::LOAD_DOCUMENT_URI) {
-      // get the channel URI - the window's will be bogus
-      aChannel->GetURI(aURI);
-      if (!*aURI)
-        return NS_ERROR_NULL_POINTER;
-
-      return NS_OK;
-    }
-  }
-
-  // case 5) - get the originating URI from the top window's principal
-  nsCOMPtr<nsIScriptObjectPrincipal> scriptObjPrin = do_QueryInterface(topWin);
-  NS_ENSURE_TRUE(scriptObjPrin, NS_ERROR_UNEXPECTED);
-
-  nsIPrincipal* prin = scriptObjPrin->GetPrincipal();
-  NS_ENSURE_TRUE(prin, NS_ERROR_UNEXPECTED);
-  
-  prin->GetURI(aURI);
-
-  if (!*aURI)
-    return NS_ERROR_NULL_POINTER;
-
-  // all done!
-  return NS_OK;
-}
-
 NS_IMETHODIMP
 nsCookiePermission::Observe(nsISupports     *aSubject,
                             const char      *aTopic,
                             const PRUnichar *aData)
 {
   nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(aSubject);
   NS_ASSERTION(!nsCRT::strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic),
                "unexpected topic - we only deal with pref changes!");
--- a/netwerk/cookie/nsICookiePermission.idl
+++ b/netwerk/cookie/nsICookiePermission.idl
@@ -8,17 +8,17 @@ interface nsICookie2;
 interface nsIURI;
 interface nsIChannel;
 
 typedef long nsCookieAccess;
 
 /**
  * An interface to test for cookie permissions
  */
-[scriptable, uuid(4b1a775d-f6d3-4389-be2e-9dfbaf2ab47b)]
+[scriptable, uuid(11ddd4ed-8f5b-40b3-b2a0-27c20ea1c88d)]
 interface nsICookiePermission : nsISupports
 {
   /**
    * nsCookieAccess values
    */
   const nsCookieAccess ACCESS_DEFAULT = 0;
   const nsCookieAccess ACCESS_ALLOW   = 1;
   const nsCookieAccess ACCESS_DENY    = 2;
@@ -90,34 +90,16 @@ interface nsICookiePermission : nsISuppo
    *
    * @return true if the cookie can be set.
    */
   boolean canSetCookie(in nsIURI     aURI,
                        in nsIChannel aChannel,
                        in nsICookie2 aCookie,
                        inout boolean aIsSession,
                        inout int64_t aExpiry);
-
-  /**
-   * getOriginatingURI
-   *
-   * determines the originating URI for a load given a channel, for third-party
-   * cookie blocking. this is done by leveraging the loadgroup of the channel to
-   * find the root content docshell, and the URI associated with its principal.
-   * if the root content docshell or its principal's URI cannot be obtained,
-   * this method will throw.
-   *
-   * @param aChannel
-   *        the channel for the load trying to get or set cookies
-   *
-   * @return the originating URI.
-   *
-   * @status DEPRECATED -- use mozIThirdPartyUtil instead.
-   */
-  nsIURI getOriginatingURI(in nsIChannel aChannel);
 };
 
 %{ C++
 /**
  * The nsICookiePermission implementation is an XPCOM service registered
  * under the ContractID:
  */
 #define NS_COOKIEPERMISSION_CONTRACTID "@mozilla.org/cookie/permission;1"