Bug 938786 - notify the secure browser UI, if any, first in NotifySubmitObservers; r=bz
authorNathan Froyd <froydnj@mozilla.com>
Thu, 23 Jan 2014 15:06:20 -0500
changeset 181349 bf293cc47a49dfa03184ef51e0572079ff58d19c
parent 181348 bafd28ce2b8799e4965c0c1dc866ee5d90673087
child 181350 ad7fc270445d9949ad64cee1aba7ec1493c2495c
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs938786
milestone29.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 938786 - notify the secure browser UI, if any, first in NotifySubmitObservers; r=bz
content/html/content/src/HTMLFormElement.cpp
security/manager/boot/src/nsSecureBrowserUIImpl.cpp
security/manager/boot/src/nsSecureBrowserUIImpl.h
--- a/content/html/content/src/HTMLFormElement.cpp
+++ b/content/html/content/src/HTMLFormElement.cpp
@@ -12,16 +12,17 @@
 #include "nsIHTMLDocument.h"
 #include "nsEventStateManager.h"
 #include "nsEventStates.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsIDocument.h"
 #include "nsIFormControlFrame.h"
+#include "nsISecureBrowserUI.h"
 #include "nsError.h"
 #include "nsContentUtils.h"
 #include "nsInterfaceHashtable.h"
 #include "nsContentList.h"
 #include "nsCOMArray.h"
 #include "nsAutoPtr.h"
 #include "nsTArray.h"
 #include "nsIMutableArray.h"
@@ -858,16 +859,41 @@ HTMLFormElement::NotifySubmitObservers(n
   // category observers
   if (!gFirstFormSubmitted) {
     gFirstFormSubmitted = true;
     NS_CreateServicesFromCategory(NS_FIRST_FORMSUBMIT_CATEGORY,
                                   nullptr,
                                   NS_FIRST_FORMSUBMIT_CATEGORY);
   }
 
+  // XXXbz what do the submit observers actually want?  The window
+  // of the document this is shown in?  Or something else?
+  // sXBL/XBL2 issue
+  nsCOMPtr<nsPIDOMWindow> window = OwnerDoc()->GetWindow();
+
+  // Notify the secure browser UI, if any, that the form is being submitted.
+  nsCOMPtr<nsIDocShell> docshell = OwnerDoc()->GetDocShell();
+  if (docshell && !aEarlyNotify) {
+    nsCOMPtr<nsISecureBrowserUI> secureUI;
+    docshell->GetSecurityUI(getter_AddRefs(secureUI));
+    nsCOMPtr<nsIFormSubmitObserver> formSubmitObserver =
+      do_QueryInterface(secureUI);
+    if (formSubmitObserver) {
+      nsresult rv = formSubmitObserver->Notify(this,
+                                               window,
+                                               aActionURL,
+                                               aCancelSubmit);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      if (*aCancelSubmit) {
+        return NS_OK;
+      }
+    }
+  }
+
   // Notify observers that the form is being submitted.
   nsCOMPtr<nsIObserverService> service =
     mozilla::services::GetObserverService();
   if (!service)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsISimpleEnumerator> theEnum;
   nsresult rv = service->EnumerateObservers(aEarlyNotify ?
@@ -875,21 +901,16 @@ HTMLFormElement::NotifySubmitObservers(n
                                             NS_FORMSUBMIT_SUBJECT,
                                             getter_AddRefs(theEnum));
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (theEnum) {
     nsCOMPtr<nsISupports> inst;
     *aCancelSubmit = false;
 
-    // XXXbz what do the submit observers actually want?  The window
-    // of the document this is shown in?  Or something else?
-    // sXBL/XBL2 issue
-    nsCOMPtr<nsPIDOMWindow> window = OwnerDoc()->GetWindow();
-
     bool loop = true;
     while (NS_SUCCEEDED(theEnum->HasMoreElements(&loop)) && loop) {
       theEnum->GetNext(getter_AddRefs(inst));
 
       nsCOMPtr<nsIFormSubmitObserver> formSubmitObserver(
                       do_QueryInterface(inst));
       if (formSubmitObserver) {
         rv = formSubmitObserver->Notify(this,
--- a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp
+++ b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp
@@ -11,17 +11,16 @@
 #include "prlog.h"
 
 #include "nsISecureBrowserUI.h"
 #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"
@@ -145,21 +144,20 @@ nsSecureBrowserUIImpl::nsSecureBrowserUI
 nsSecureBrowserUIImpl::~nsSecureBrowserUIImpl()
 {
   if (mTransferringRequests.ops) {
     PL_DHashTableFinish(&mTransferringRequests);
     mTransferringRequests.ops = nullptr;
   }
 }
 
-NS_IMPL_ISUPPORTS6(nsSecureBrowserUIImpl,
+NS_IMPL_ISUPPORTS5(nsSecureBrowserUIImpl,
                    nsISecureBrowserUI,
                    nsIWebProgressListener,
                    nsIFormSubmitObserver,
-                   nsIObserver,
                    nsISupportsWeakReference,
                    nsISSLStatusProvider)
 
 NS_IMETHODIMP
 nsSecureBrowserUIImpl::Init(nsIDOMWindow *aWindow)
 {
 
 #ifdef PR_LOGGING
@@ -184,22 +182,16 @@ nsSecureBrowserUIImpl::Init(nsIDOMWindow
   if (pwin->IsInnerWindow()) {
     pwin = pwin->GetOuterWindow();
   }
 
   nsresult rv;
   mWindow = do_GetWeakReference(pwin, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // hook up to the form post notifications:
-  nsCOMPtr<nsIObserverService> svc(do_GetService("@mozilla.org/observer-service;1", &rv));
-  if (NS_SUCCEEDED(rv)) {
-    rv = svc->AddObserver(this, NS_FORMSUBMIT_SUBJECT, true);
-  }
-  
   nsCOMPtr<nsPIDOMWindow> piwindow(do_QueryInterface(aWindow));
   if (!piwindow) return NS_ERROR_FAILURE;
 
   nsIDocShell *docShell = piwindow->GetDocShell();
 
   // The Docshell will own the SecureBrowserUI object
   if (!docShell)
     return NS_ERROR_FAILURE;
@@ -318,24 +310,16 @@ nsSecureBrowserUIImpl::MapInternalToExte
 NS_IMETHODIMP
 nsSecureBrowserUIImpl::SetDocShell(nsIDocShell *aDocShell)
 {
   nsresult rv;
   mDocShell = do_GetWeakReference(aDocShell, &rv);
   return rv;
 }
 
-NS_IMETHODIMP
-nsSecureBrowserUIImpl::Observe(nsISupports*, const char*,
-                               const char16_t*)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-
 static nsresult IsChildOfDomWindow(nsIDOMWindow *parent, nsIDOMWindow *child,
                                    bool* value)
 {
   *value = false;
   
   if (parent == child) {
     *value = true;
     return NS_OK;
--- a/security/manager/boot/src/nsSecureBrowserUIImpl.h
+++ b/security/manager/boot/src/nsSecureBrowserUIImpl.h
@@ -7,17 +7,16 @@
 #define nsSecureBrowserUIImpl_h_
 
 #ifdef DEBUG
 #include "mozilla/Atomics.h"
 #endif
 #include "mozilla/ReentrantMonitor.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
-#include "nsIObserver.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMWindow.h"
 #include "nsIDOMHTMLFormElement.h"
 #include "nsISecureBrowserUI.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIWebProgressListener.h"
 #include "nsIFormSubmitObserver.h"
@@ -37,31 +36,28 @@ class nsIInterfaceRequestor;
 
 #define NS_SECURE_BROWSER_UI_CID \
 { 0xcc75499a, 0x1dd1, 0x11b2, {0x8a, 0x82, 0xca, 0x41, 0x0a, 0xc9, 0x07, 0xb8}}
 
 
 class nsSecureBrowserUIImpl : public nsISecureBrowserUI,
                               public nsIWebProgressListener,
                               public nsIFormSubmitObserver,
-                              public nsIObserver,
                               public nsSupportsWeakReference,
                               public nsISSLStatusProvider
 {
 public:
   
   nsSecureBrowserUIImpl();
   virtual ~nsSecureBrowserUIImpl();
   
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIWEBPROGRESSLISTENER
   NS_DECL_NSISECUREBROWSERUI
   
-  // nsIObserver
-  NS_DECL_NSIOBSERVER
   NS_DECL_NSISSLSTATUSPROVIDER
 
   NS_IMETHOD Notify(nsIDOMHTMLFormElement* formNode, nsIDOMWindow* window,
                     nsIURI *actionURL, bool* cancelSubmit);
   NS_IMETHOD NotifyInvalidSubmit(nsIDOMHTMLFormElement* formNode,
                                  nsIArray* invalidElements) { return NS_OK; }
   
 protected: