Bug 1108887 - Backout part 2 of bug 949435 (SVG iframe). r=bzbarsky
authorRobert Longson <longsonr@gmail.com>
Wed, 11 Feb 2015 11:20:50 +0000
changeset 255780 cf841de97d18924c8ad9c212322b925eec9ec569
parent 255779 ef7af73497dee750ba2dbcae970ad77e021d02e6
child 255781 11e7ca322c9d8e8ae1b7cf1b9b95d382eec364db
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1108887, 949435
milestone38.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 1108887 - Backout part 2 of bug 949435 (SVG iframe). r=bzbarsky
dom/base/moz.build
dom/base/nsElementFrameLoaderOwner.cpp
dom/base/nsElementFrameLoaderOwner.h
dom/html/nsGenericHTMLFrameElement.cpp
dom/html/nsGenericHTMLFrameElement.h
--- a/dom/base/moz.build
+++ b/dom/base/moz.build
@@ -66,17 +66,16 @@ EXPORTS += [
     'nsDocumentWarningList.h',
     'nsDOMAttributeMap.h',
     'nsDOMCID.h',
     'nsDOMClassInfoClasses.h',
     'nsDOMClassInfoID.h',
     'nsDOMJSUtils.h',
     'nsDOMNavigationTiming.h',
     'nsDOMString.h',
-    'nsElementFrameLoaderOwner.h',
     'nsFocusManager.h',
     'nsFrameMessageManager.h',
     'nsGenericDOMDataNode.h',
     'nsGkAtomList.h',
     'nsGkAtoms.h',
     'nsHostObjectProtocolHandler.h',
     'nsIAttribute.h',
     'nsIContent.h',
@@ -255,17 +254,16 @@ UNIFIED_SOURCES += [
     'nsDOMFileReader.cpp',
     'nsDOMMutationObserver.cpp',
     'nsDOMNavigationTiming.cpp',
     'nsDOMScriptObjectFactory.cpp',
     'nsDOMSerializer.cpp',
     'nsDOMSettableTokenList.cpp',
     'nsDOMTokenList.cpp',
     'nsDOMWindowList.cpp',
-    'nsElementFrameLoaderOwner.cpp',
     'nsFocusManager.cpp',
     'nsFormData.cpp',
     'nsFrameLoader.cpp',
     'nsGenConImageContent.cpp',
     'nsGenericDOMDataNode.cpp',
     'nsGkAtoms.cpp',
     'nsGlobalWindowCommands.cpp',
     'nsHistory.cpp',
deleted file mode 100644
--- a/dom/base/nsElementFrameLoaderOwner.cpp
+++ /dev/null
@@ -1,172 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
-
-/* 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 "nsElementFrameLoaderOwner.h"
-
-#include "nsIDOMDocument.h"
-#include "nsIInterfaceRequestorUtils.h"
-#include "nsContentUtils.h"
-#include "mozilla/Preferences.h"
-#include "mozilla/ErrorResult.h"
-#include "nsIAppsService.h"
-#include "nsServiceManagerUtils.h"
-#include "mozIApplication.h"
-#include "nsIPermissionManager.h"
-#include "GeckoProfiler.h"
-#include "nsIDocument.h"
-#include "nsPIDOMWindow.h"
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-nsElementFrameLoaderOwner::~nsElementFrameLoaderOwner()
-{
-  if (mFrameLoader) {
-    mFrameLoader->Destroy();
-  }
-}
-
-nsresult
-nsElementFrameLoaderOwner::GetContentDocument(nsIDOMDocument** aContentDocument)
-{
-  NS_PRECONDITION(aContentDocument, "Null out param");
-  nsCOMPtr<nsIDOMDocument> document = do_QueryInterface(GetContentDocument());
-  document.forget(aContentDocument);
-  return NS_OK;
-}
-
-nsIDocument*
-nsElementFrameLoaderOwner::GetContentDocument()
-{
-  nsCOMPtr<nsPIDOMWindow> win = GetContentWindow();
-  if (!win) {
-    return nullptr;
-  }
-
-  nsIDocument *doc = win->GetDoc();
-
-  // Return null for cross-origin contentDocument.
-  if (!nsContentUtils::SubjectPrincipal()->
-        SubsumesConsideringDomain(doc->NodePrincipal())) {
-    return nullptr;
-  }
-  return doc;
-}
-
-nsresult
-nsElementFrameLoaderOwner::GetContentWindow(nsIDOMWindow** aContentWindow)
-{
-  NS_PRECONDITION(aContentWindow, "Null out param");
-  nsCOMPtr<nsPIDOMWindow> window = GetContentWindow();
-  window.forget(aContentWindow);
-  return NS_OK;
-}
-
-already_AddRefed<nsPIDOMWindow>
-nsElementFrameLoaderOwner::GetContentWindow()
-{
-  EnsureFrameLoader();
-
-  if (!mFrameLoader) {
-    return nullptr;
-  }
-
-  bool depthTooGreat = false;
-  mFrameLoader->GetDepthTooGreat(&depthTooGreat);
-  if (depthTooGreat) {
-    // Claim to have no contentWindow
-    return nullptr;
-  }
-
-  nsCOMPtr<nsIDocShell> doc_shell;
-  mFrameLoader->GetDocShell(getter_AddRefs(doc_shell));
-
-  nsCOMPtr<nsPIDOMWindow> win = do_GetInterface(doc_shell);
-
-  if (!win) {
-    return nullptr;
-  }
-
-  NS_ASSERTION(win->IsOuterWindow(),
-               "Uh, this window should always be an outer window!");
-
-  return win.forget();
-}
-
-void
-nsElementFrameLoaderOwner::EnsureFrameLoader()
-{
-  Element* thisElement = ThisFrameElement();
-  if (!thisElement->IsInDoc() ||
-      mFrameLoader ||
-      mFrameLoaderCreationDisallowed) {
-    // If frame loader is there, we just keep it around, cached
-    return;
-  }
-
-  // Strangely enough, this method doesn't actually ensure that the
-  // frameloader exists.  It's more of a best-effort kind of thing.
-  mFrameLoader = nsFrameLoader::Create(thisElement, mNetworkCreated);
-  if (mIsPrerendered) {
-    mFrameLoader->SetIsPrerendered();
-  }
-}
-
-NS_IMETHODIMP
-nsElementFrameLoaderOwner::GetFrameLoader(nsIFrameLoader **aFrameLoader)
-{
-  NS_IF_ADDREF(*aFrameLoader = mFrameLoader);
-  return NS_OK;
-}
-
-NS_IMETHODIMP_(already_AddRefed<nsFrameLoader>)
-nsElementFrameLoaderOwner::GetFrameLoader()
-{
-  nsRefPtr<nsFrameLoader> loader = mFrameLoader;
-  return loader.forget();
-}
-
-NS_IMETHODIMP
-nsElementFrameLoaderOwner::SwapFrameLoaders(nsIFrameLoaderOwner* aOtherOwner)
-{
-  // We don't support this yet
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsElementFrameLoaderOwner::SetIsPrerendered()
-{
-  MOZ_ASSERT(!mFrameLoader, "Please call SetIsPrerendered before frameLoader is created");
-  mIsPrerendered = true;
-  return NS_OK;
-}
-
-nsresult
-nsElementFrameLoaderOwner::LoadSrc()
-{
-  EnsureFrameLoader();
-
-  if (!mFrameLoader) {
-    return NS_OK;
-  }
-
-  nsresult rv = mFrameLoader->LoadFrame();
-#ifdef DEBUG
-  if (NS_FAILED(rv)) {
-    NS_WARNING("failed to load URL");
-  }
-#endif
-
-  return rv;
-}
-
-void
-nsElementFrameLoaderOwner::SwapFrameLoaders(nsXULElement& aOtherOwner,
-                                            ErrorResult& aError)
-{
-  aError.Throw(NS_ERROR_NOT_IMPLEMENTED);
-}
deleted file mode 100644
--- a/dom/base/nsElementFrameLoaderOwner.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
-
-/* 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/. */
-
-#ifndef nsElementFrameLoaderOwner_h
-#define nsElementFrameLoaderOwner_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/dom/Element.h"
-#include "nsIFrameLoader.h"
-#include "nsIDOMEventListener.h"
-#include "mozilla/dom/FromParser.h"
-#include "mozilla/ErrorResult.h"
-
-#include "nsFrameLoader.h"
-
-namespace mozilla {
-namespace dom {
-class Element;
-} // namespace dom
-} // namespace mozilla
-
-class nsXULElement;
-
-/**
- * A helper class for frame elements
- */
-class nsElementFrameLoaderOwner : public nsIFrameLoaderOwner
-{
-public:
-  explicit nsElementFrameLoaderOwner(mozilla::dom::FromParser aFromParser)
-    : mNetworkCreated(aFromParser == mozilla::dom::FROM_PARSER_NETWORK)
-    , mIsPrerendered(false)
-    , mBrowserFrameListenersRegistered(false)
-    , mFrameLoaderCreationDisallowed(false)
-  {
-  }
-
-  virtual ~nsElementFrameLoaderOwner();
-
-  NS_DECL_NSIFRAMELOADEROWNER
-
-  // nsIContent
-  void SwapFrameLoaders(nsXULElement& aOtherOwner, mozilla::ErrorResult& aError);
-
-protected:
-  // This doesn't really ensure a frame loader in all cases, only when
-  // it makes sense.
-  void EnsureFrameLoader();
-  nsresult LoadSrc();
-  nsIDocument* GetContentDocument();
-  nsresult GetContentDocument(nsIDOMDocument** aContentDocument);
-  already_AddRefed<nsPIDOMWindow> GetContentWindow();
-  nsresult GetContentWindow(nsIDOMWindow** aContentWindow);
-
-  /**
-   * Get element for this frame. Avoids diamond inheritance problem.
-   * @return Element for this node
-   */
-  virtual mozilla::dom::Element* ThisFrameElement() = 0;
-
-  nsRefPtr<nsFrameLoader> mFrameLoader;
-
-  /**
-   * True when the element is created by the parser using the
-   * NS_FROM_PARSER_NETWORK flag.
-   * If the element is modified, it may lose the flag.
-   */
-  bool mNetworkCreated;
-
-  bool mIsPrerendered;
-  bool mBrowserFrameListenersRegistered;
-  bool mFrameLoaderCreationDisallowed;
-};
-
-#endif // nsElementFrameLoaderOwner_h
--- a/dom/html/nsGenericHTMLFrameElement.cpp
+++ b/dom/html/nsGenericHTMLFrameElement.cpp
@@ -37,28 +37,118 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBrowserElementAPI)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_ADDREF_INHERITED(nsGenericHTMLFrameElement, nsGenericHTMLElement)
 NS_IMPL_RELEASE_INHERITED(nsGenericHTMLFrameElement, nsGenericHTMLElement)
 
 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsGenericHTMLFrameElement)
   NS_INTERFACE_TABLE_INHERITED(nsGenericHTMLFrameElement,
+                               nsIFrameLoaderOwner,
                                nsIDOMMozBrowserFrame,
-                               nsIMozBrowserFrame,
-                               nsIFrameLoaderOwner)
+                               nsIMozBrowserFrame)
 NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
 NS_IMPL_BOOL_ATTR(nsGenericHTMLFrameElement, Mozbrowser, mozbrowser)
 
 int32_t
 nsGenericHTMLFrameElement::TabIndexDefault()
 {
   return 0;
 }
 
+nsGenericHTMLFrameElement::~nsGenericHTMLFrameElement()
+{
+  if (mFrameLoader) {
+    mFrameLoader->Destroy();
+  }
+}
+
+nsresult
+nsGenericHTMLFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
+{
+  NS_PRECONDITION(aContentDocument, "Null out param");
+  nsCOMPtr<nsIDOMDocument> document = do_QueryInterface(GetContentDocument());
+  document.forget(aContentDocument);
+  return NS_OK;
+}
+
+nsIDocument*
+nsGenericHTMLFrameElement::GetContentDocument()
+{
+  nsCOMPtr<nsPIDOMWindow> win = GetContentWindow();
+  if (!win) {
+    return nullptr;
+  }
+
+  nsIDocument *doc = win->GetDoc();
+
+  // Return null for cross-origin contentDocument.
+  if (!nsContentUtils::SubjectPrincipal()->
+        SubsumesConsideringDomain(doc->NodePrincipal())) {
+    return nullptr;
+  }
+  return doc;
+}
+
+nsresult
+nsGenericHTMLFrameElement::GetContentWindow(nsIDOMWindow** aContentWindow)
+{
+  NS_PRECONDITION(aContentWindow, "Null out param");
+  nsCOMPtr<nsPIDOMWindow> window = GetContentWindow();
+  window.forget(aContentWindow);
+  return NS_OK;
+}
+
+already_AddRefed<nsPIDOMWindow>
+nsGenericHTMLFrameElement::GetContentWindow()
+{
+  EnsureFrameLoader();
+
+  if (!mFrameLoader) {
+    return nullptr;
+  }
+
+  bool depthTooGreat = false;
+  mFrameLoader->GetDepthTooGreat(&depthTooGreat);
+  if (depthTooGreat) {
+    // Claim to have no contentWindow
+    return nullptr;
+  }
+
+  nsCOMPtr<nsIDocShell> doc_shell;
+  mFrameLoader->GetDocShell(getter_AddRefs(doc_shell));
+
+  nsCOMPtr<nsPIDOMWindow> win = do_GetInterface(doc_shell);
+
+  if (!win) {
+    return nullptr;
+  }
+
+  NS_ASSERTION(win->IsOuterWindow(),
+               "Uh, this window should always be an outer window!");
+
+  return win.forget();
+}
+
+void
+nsGenericHTMLFrameElement::EnsureFrameLoader()
+{
+  if (!IsInDoc() || mFrameLoader || mFrameLoaderCreationDisallowed) {
+    // If frame loader is there, we just keep it around, cached
+    return;
+  }
+
+  // Strangely enough, this method doesn't actually ensure that the
+  // frameloader exists.  It's more of a best-effort kind of thing.
+  mFrameLoader = nsFrameLoader::Create(this, mNetworkCreated);
+  if (mIsPrerendered) {
+    mFrameLoader->SetIsPrerendered();
+  }
+}
+
 nsresult
 nsGenericHTMLFrameElement::CreateRemoteFrameLoader(nsITabParent* aTabParent)
 {
   MOZ_ASSERT(!mFrameLoader);
   EnsureFrameLoader();
   NS_ENSURE_STATE(mFrameLoader);
   mFrameLoader->SetRemoteBrowser(aTabParent);
 
@@ -67,16 +157,64 @@ nsGenericHTMLFrameElement::CreateRemoteF
     // for the iframe creation. Therefore the subdoc frame didn't have a
     // frameloader when UpdatePositionAndSize was supposed to be called in
     // ReflowFinished, and we need to do it properly now.
     mFrameLoader->UpdatePositionAndSize(subdocFrame);
   }
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsGenericHTMLFrameElement::GetFrameLoader(nsIFrameLoader **aFrameLoader)
+{
+  NS_IF_ADDREF(*aFrameLoader = mFrameLoader);
+  return NS_OK;
+}
+
+NS_IMETHODIMP_(already_AddRefed<nsFrameLoader>)
+nsGenericHTMLFrameElement::GetFrameLoader()
+{
+  nsRefPtr<nsFrameLoader> loader = mFrameLoader;
+  return loader.forget();
+}
+
+NS_IMETHODIMP
+nsGenericHTMLFrameElement::SwapFrameLoaders(nsIFrameLoaderOwner* aOtherOwner)
+{
+  // We don't support this yet
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+nsGenericHTMLFrameElement::SetIsPrerendered()
+{
+  MOZ_ASSERT(!mFrameLoader, "Please call SetIsPrerendered before frameLoader is created");
+  mIsPrerendered = true;
+  return NS_OK;
+}
+
+nsresult
+nsGenericHTMLFrameElement::LoadSrc()
+{
+  EnsureFrameLoader();
+
+  if (!mFrameLoader) {
+    return NS_OK;
+  }
+
+  nsresult rv = mFrameLoader->LoadFrame();
+#ifdef DEBUG
+  if (NS_FAILED(rv)) {
+    NS_WARNING("failed to load URL");
+  }
+#endif
+
+  return rv;
+}
+
 nsresult
 nsGenericHTMLFrameElement::BindToTree(nsIDocument* aDocument,
                                       nsIContent* aParent,
                                       nsIContent* aBindingParent,
                                       bool aCompileEventHandlers)
 {
   nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
                                                  aBindingParent,
@@ -502,8 +640,16 @@ nsGenericHTMLFrameElement::AllowCreateFr
 
 NS_IMETHODIMP
 nsGenericHTMLFrameElement::InitializeBrowserAPI()
 {
   MOZ_ASSERT(mFrameLoader);
   InitBrowserElementAPI();
   return NS_OK;
 }
+
+void
+nsGenericHTMLFrameElement::SwapFrameLoaders(nsXULElement& aOtherOwner,
+                                            ErrorResult& aError)
+{
+  aError.Throw(NS_ERROR_NOT_IMPLEMENTED);
+}
+
--- a/dom/html/nsGenericHTMLFrameElement.h
+++ b/dom/html/nsGenericHTMLFrameElement.h
@@ -7,44 +7,47 @@
 
 #ifndef nsGenericHTMLFrameElement_h
 #define nsGenericHTMLFrameElement_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/nsBrowserElement.h"
 
-#include "nsElementFrameLoaderOwner.h"
 #include "nsFrameLoader.h"
 #include "nsGenericHTMLElement.h"
 #include "nsIDOMEventListener.h"
 #include "nsIFrameLoader.h"
 #include "nsIMozBrowserFrame.h"
 
 class nsXULElement;
 
 /**
  * A helper class for frame elements
  */
 class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
-                                  public nsElementFrameLoaderOwner,
+                                  public nsIFrameLoaderOwner,
                                   public mozilla::nsBrowserElement,
                                   public nsIMozBrowserFrame
 {
 public:
   nsGenericHTMLFrameElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
                             mozilla::dom::FromParser aFromParser)
     : nsGenericHTMLElement(aNodeInfo)
-    , nsElementFrameLoaderOwner(aFromParser)
     , nsBrowserElement()
+    , mNetworkCreated(aFromParser == mozilla::dom::FROM_PARSER_NETWORK)
+    , mIsPrerendered(false)
+    , mBrowserFrameListenersRegistered(false)
+    , mFrameLoaderCreationDisallowed(false)
   {
   }
 
   NS_DECL_ISUPPORTS_INHERITED
 
+  NS_DECL_NSIFRAMELOADEROWNER
   NS_DECL_NSIDOMMOZBROWSERFRAME
   NS_DECL_NSIMOZBROWSERFRAME
 
   // nsIContent
   virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, int32_t *aTabIndex) MOZ_OVERRIDE;
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                               nsIContent* aBindingParent,
                               bool aCompileEventHandlers) MOZ_OVERRIDE;
@@ -67,46 +70,52 @@ public:
 
   nsresult CopyInnerTo(mozilla::dom::Element* aDest);
 
   virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsGenericHTMLFrameElement,
                                                      nsGenericHTMLElement)
 
-  static bool BrowserFramesEnabled();
+  void SwapFrameLoaders(nsXULElement& aOtherOwner, mozilla::ErrorResult& aError);
 
-  /**
-   * nsIFrameLoaderOwner defines two GetFrameLoader() overloads. One
-   * is XPCOM style interface, the other one is C++ only.  "using" pulls
-   * them both in, now GetFrameLoader() is ambiguous because
-   * nsBrowserElement also has GetFrameLoader(). Explicit redefine
-   * GetFrameLoader() to choose nsElementFrameLoaderOwner::GetFrameLoader()
-   */
-  using nsElementFrameLoaderOwner::GetFrameLoader;
-  NS_IMETHOD_(already_AddRefed<nsFrameLoader>) GetFrameLoader() MOZ_OVERRIDE
-  {
-    return nsElementFrameLoaderOwner::GetFrameLoader();
-  }
+  static bool BrowserFramesEnabled();
 
   /**
    * Helper method to map a HTML 'scrolling' attribute value to a nsIScrollable
    * enum value.  scrolling="no" (and its synonyms) maps to
    * nsIScrollable::Scrollbar_Never, and anything else (including nullptr) maps
    * to nsIScrollable::Scrollbar_Auto.
    * @param aValue the attribute value to map or nullptr
    * @return nsIScrollable::Scrollbar_Never or nsIScrollable::Scrollbar_Auto
    */
   static int32_t MapScrollingAttribute(const nsAttrValue* aValue);
 
 protected:
-  virtual ~nsGenericHTMLFrameElement() {}
+  virtual ~nsGenericHTMLFrameElement();
+
+  // This doesn't really ensure a frame loader in all cases, only when
+  // it makes sense.
+  void EnsureFrameLoader();
+  nsresult LoadSrc();
+  nsIDocument* GetContentDocument();
+  nsresult GetContentDocument(nsIDOMDocument** aContentDocument);
+  already_AddRefed<nsPIDOMWindow> GetContentWindow();
+  nsresult GetContentWindow(nsIDOMWindow** aContentWindow);
 
-  virtual mozilla::dom::Element* ThisFrameElement() MOZ_OVERRIDE
-  {
-    return this;
-  }
+  nsRefPtr<nsFrameLoader> mFrameLoader;
+
+  /**
+   * True when the element is created by the parser using the
+   * NS_FROM_PARSER_NETWORK flag.
+   * If the element is modified, it may lose the flag.
+   */
+  bool mNetworkCreated;
+
+  bool mIsPrerendered;
+  bool mBrowserFrameListenersRegistered;
+  bool mFrameLoaderCreationDisallowed;
 
 private:
   void GetManifestURLByType(nsIAtom *aAppType, nsAString& aOut);
 };
 
 #endif // nsGenericHTMLFrameElement_h