Bug 836951 - Add mDocShell to nsSecureBrowserUIImpl. Traverse up to the root doc shell. r=bsmith,smaug a=bbajaj
authorTanvi Vyas <tvyas@mozilla.com>
Fri, 29 Mar 2013 17:59:24 -0700
changeset 128734 3274a156c130027e408de0717bd361740755d0bb
parent 128733 4717c038bc0c1f3436ccc4c8648e7986959a590e
child 128735 3beb53352a9201d916e5e135160e13ffe82c150e
push id3574
push usertvyas@mozilla.com
push dateSat, 30 Mar 2013 01:00:08 +0000
treeherdermozilla-aurora@3274a156c130 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmith, smaug, bbajaj
bugs836951
milestone21.0a2
Bug 836951 - Add mDocShell to nsSecureBrowserUIImpl. Traverse up to the root doc shell. r=bsmith,smaug a=bbajaj
docshell/base/nsDocShell.cpp
dom/ipc/TabParent.cpp
netwerk/base/public/nsISecureBrowserUI.idl
security/manager/boot/src/nsSecureBrowserUIImpl.cpp
security/manager/boot/src/nsSecureBrowserUIImpl.h
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -2436,16 +2436,17 @@ nsDocShell::GetSecurityUI(nsISecureBrows
     NS_IF_ADDREF(*aSecurityUI = mSecurityUI);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::SetSecurityUI(nsISecureBrowserUI *aSecurityUI)
 {
     mSecurityUI = aSecurityUI;
+    mSecurityUI->SetDocShell(this);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetUseErrorPages(bool *aUseErrorPages)
 {
     *aUseErrorPages = mUseErrorPages;
     return NS_OK;
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -25,16 +25,17 @@
 #include "nsContentPermissionHelper.h"
 #include "nsContentUtils.h"
 #include "nsDebug.h"
 #include "nsEventDispatcher.h"
 #include "nsEventStateManager.h"
 #include "nsFocusManager.h"
 #include "nsFrameLoader.h"
 #include "nsIContent.h"
+#include "nsIDocShell.h"
 #include "nsIDOMApplicationRegistry.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIDOMHTMLFrameElement.h"
 #include "nsIDOMWindow.h"
 #include "nsIDialogCreator.h"
 #include "nsIPromptFactory.h"
@@ -495,16 +496,24 @@ TabParent::GetState(uint32_t *aState)
 {
   NS_ENSURE_ARG(aState);
   NS_WARNING("SecurityState not valid here");
   *aState = 0;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+TabParent::SetDocShell(nsIDocShell *aDocShell)
+{
+  NS_ENSURE_ARG(aDocShell);
+  NS_WARNING("No mDocShell member in TabParent so there is no docShell to set");
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 TabParent::GetTooltipText(nsAString & aTooltipText)
 {
   aTooltipText.Truncate();
   return NS_OK;
 }
 
 PDocumentRendererParent*
 TabParent::AllocPDocumentRenderer(const nsRect& documentRect,
--- a/netwerk/base/public/nsISecureBrowserUI.idl
+++ b/netwerk/base/public/nsISecureBrowserUI.idl
@@ -3,21 +3,23 @@
  * 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 "nsISupports.idl"
 
 interface nsIDOMWindow;
 interface nsIDOMElement;
+interface nsIDocShell;
 
-[scriptable, uuid(081e31e0-a144-11d3-8c7c-00609792278c)]
+[scriptable, uuid(e97e5688-add2-4a1d-acae-396d7702e382)]
 interface nsISecureBrowserUI : nsISupports
 {
     void init(in nsIDOMWindow window);
+    void setDocShell(in nsIDocShell docShell);
 
     readonly attribute unsigned long state;
     readonly attribute AString tooltipText;
 };
 
 %{C++
 #define NS_SECURE_BROWSER_UI_CONTRACTID "@mozilla.org/secure_browser_ui;1"
 #define NS_SECURE_BROWSER_UI_CLASSNAME "Mozilla Secure Browser UI Handler"
--- a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp
+++ b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp
@@ -14,16 +14,17 @@
 #include "nsSecureBrowserUIImpl.h"
 #include "nsCOMPtr.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIServiceManager.h"
 #include "nsIObserverService.h"
 #include "nsCURILoader.h"
 #include "nsIDocShell.h"
+#include "nsIDocShellTreeItem.h"
 #include "nsIDocument.h"
 #include "nsIPrincipal.h"
 #include "nsIDOMElement.h"
 #include "nsPIDOMWindow.h"
 #include "nsIContent.h"
 #include "nsIWebProgress.h"
 #include "nsIWebProgressListener.h"
 #include "nsIChannel.h"
@@ -281,22 +282,31 @@ nsSecureBrowserUIImpl::MapInternalToExte
     case lis_no_security:
       *aState = STATE_IS_INSECURE;
       break;
   }
 
   if (ev && (*aState & STATE_IS_SECURE))
     *aState |= nsIWebProgressListener::STATE_IDENTITY_EV_TOPLEVEL;
 
-  nsCOMPtr<nsPIDOMWindow> piwin = do_QueryReferent(mWindow);
-  if (!piwin)
+  nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShell);
+  if (!docShell)
     return NS_OK;
 
-  nsIDocShell* docShell = piwin->GetDocShell();
-  MOZ_ASSERT(docShell);
+  int32_t docShellType;
+  // For content docShell's, the mixed content security state is set on the root docShell.
+  if (NS_SUCCEEDED(docShell->GetItemType(&docShellType)) && docShellType == nsIDocShellTreeItem::typeContent) {
+    nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(docShell));
+    nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
+    docShellTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
+    NS_ASSERTION(sameTypeRoot, "No document shell root tree item from document shell tree item!");
+    docShell = do_QueryInterface(sameTypeRoot);
+    if (!docShell)
+      return NS_OK;
+  }
 
   // Has a Mixed Content Load initiated in nsMixedContentBlocker?
   // If so, the state should be broken; overriding the previous state
   // set by the lock parameter.
   if (docShell->GetHasMixedActiveContentLoaded() &&
       docShell->GetHasMixedDisplayContentLoaded()) {
       *aState = STATE_IS_BROKEN |
                 nsIWebProgressListener::STATE_LOADED_MIXED_ACTIVE_CONTENT |
@@ -315,16 +325,24 @@ nsSecureBrowserUIImpl::MapInternalToExte
 
   if (docShell->GetHasMixedDisplayContentBlocked())
     *aState |= nsIWebProgressListener::STATE_BLOCKED_MIXED_DISPLAY_CONTENT;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsSecureBrowserUIImpl::SetDocShell(nsIDocShell *aDocShell)
+{
+  nsresult rv;
+  mDocShell = do_GetWeakReference(aDocShell, &rv);
+  return rv;
+}
+
+NS_IMETHODIMP
 nsSecureBrowserUIImpl::GetTooltipText(nsAString& aText)
 {
   lockIconState state;
   nsXPIDLString tooltip;
 
   {
     ReentrantMonitorAutoEnter lock(mReentrantMonitor);
     state = mNotifiedSecurityState;
--- a/security/manager/boot/src/nsSecureBrowserUIImpl.h
+++ b/security/manager/boot/src/nsSecureBrowserUIImpl.h
@@ -12,16 +12,17 @@
 #include "nsString.h"
 #include "nsIObserver.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMWindow.h"
 #include "nsIDOMHTMLFormElement.h"
 #include "nsIStringBundle.h"
 #include "nsISecureBrowserUI.h"
 #include "nsIDocShell.h"
+#include "nsIDocShellTreeItem.h"
 #include "nsIWebProgressListener.h"
 #include "nsIFormSubmitObserver.h"
 #include "nsIURI.h"
 #include "nsISecurityEventSink.h"
 #include "nsWeakReference.h"
 #include "nsISSLStatusProvider.h"
 #include "nsIAssociatedContentSecurity.h"
 #include "pldhash.h"
@@ -61,16 +62,17 @@ public:
                     nsIURI *actionURL, bool* cancelSubmit);
   NS_IMETHOD NotifyInvalidSubmit(nsIDOMHTMLFormElement* formNode,
                                  nsIArray* invalidElements) { return NS_OK; }
   
 protected:
   mozilla::ReentrantMonitor mReentrantMonitor;
   
   nsWeakPtr mWindow;
+  nsWeakPtr mDocShell;
   nsCOMPtr<nsINetUtil> mIOService;
   nsCOMPtr<nsIStringBundle> mStringBundle;
   nsCOMPtr<nsIURI> mCurrentURI;
   nsCOMPtr<nsISecurityEventSink> mToplevelEventSink;
   
   enum lockIconState {
     lis_no_security,
     lis_broken_security,