Bug 1260931 - Part 6: pass origin attributes to nsIWebBrowser. r=smaug
authorYoshi Huang <allstars.chh@mozilla.com>
Mon, 05 Sep 2016 20:43:51 +0800
changeset 312791 d2a98312df816dbb3e997311f0cdd576791a9edd
parent 312790 0a2c681ec3476cfe958ee0816b6f0f0d20a36ce7
child 312792 7f00c0316a194286cc663f0bdfa1362c270de074
push id30658
push usercbook@mozilla.com
push dateTue, 06 Sep 2016 13:28:59 +0000
treeherdermozilla-central@bec2b7e3c0eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1260931
milestone51.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 1260931 - Part 6: pass origin attributes to nsIWebBrowser. r=smaug
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
embedding/browser/moz.build
embedding/browser/nsIWebBrowser.idl
embedding/browser/nsWebBrowser.cpp
embedding/browser/nsWebBrowser.h
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -504,17 +504,17 @@ TabChild::Create(nsIContentChild* aManag
         RefPtr<TabChild> child = sPreallocatedTab.get();
         sPreallocatedTab = nullptr;
 
         MOZ_ASSERT(!child->mTriedBrowserInit);
 
         child->mManager = aManager;
         child->SetTabId(aTabId);
         child->SetTabContext(aContext);
-        child->NotifyTabContextUpdated();
+        child->NotifyTabContextUpdated(true);
         return child.forget();
     }
 
     RefPtr<TabChild> iframe = new TabChild(aManager, aTabId,
                                              aContext, aChromeFlags);
     return NS_SUCCEEDED(iframe->Init()) ? iframe.forget() : nullptr;
 }
 
@@ -722,16 +722,17 @@ TabChild::Init()
 {
   nsCOMPtr<nsIWebBrowser> webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
   if (!webBrowser) {
     NS_ERROR("Couldn't create a nsWebBrowser?");
     return NS_ERROR_FAILURE;
   }
 
   webBrowser->SetContainerWindow(this);
+  webBrowser->SetOriginAttributes(OriginAttributesRef());
   mWebNav = do_QueryInterface(webBrowser);
   NS_ASSERTION(mWebNav, "nsWebBrowser doesn't implement nsIWebNavigation?");
 
   nsCOMPtr<nsIDocShellTreeItem> docShellItem(do_QueryInterface(WebNavigation()));
   docShellItem->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
 
   nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(WebNavigation());
   if (!baseWindow) {
@@ -750,17 +751,17 @@ TabChild::Init()
     LayoutDeviceIntRect(0, 0, 0, 0),
     nullptr                  // HandleWidgetEvent
   );
 
   baseWindow->InitWindow(0, mPuppetWidget, 0, 0, 0, 0);
   baseWindow->Create();
 
   // Set the tab context attributes then pass to docShell
-  NotifyTabContextUpdated();
+  NotifyTabContextUpdated(false);
 
   // IPC uses a WebBrowser object for which DNS prefetching is turned off
   // by default. But here we really want it, so enable it explicitly
   nsCOMPtr<nsIWebBrowserSetup> webBrowserSetup =
     do_QueryInterface(baseWindow);
   if (webBrowserSetup) {
     webBrowserSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_DNS_PREFETCH,
                                  true);
@@ -820,27 +821,30 @@ TabChild::Init()
         }
       });
   mAPZEventState = new APZEventState(mPuppetWidget, Move(callback));
 
   return NS_OK;
 }
 
 void
-TabChild::NotifyTabContextUpdated()
+TabChild::NotifyTabContextUpdated(bool aIsPreallocated)
 {
   nsCOMPtr<nsIDocShell> docShell = do_GetInterface(WebNavigation());
   MOZ_ASSERT(docShell);
 
   if (!docShell) {
     return;
   }
 
   UpdateFrameType();
-  nsDocShell::Cast(docShell)->SetOriginAttributes(OriginAttributesRef());
+
+  if (aIsPreallocated)  {
+    nsDocShell::Cast(docShell)->SetOriginAttributes(OriginAttributesRef());
+  }
 
   // Set SANDBOXED_AUXILIARY_NAVIGATION flag if this is a receiver page.
   if (!PresentationURL().IsEmpty()) {
     docShell->SetSandboxFlags(SANDBOXED_AUXILIARY_NAVIGATION);
   }
 }
 
 void
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -682,22 +682,23 @@ protected:
 #ifdef MOZ_WIDGET_GONK
   void MaybeRequestPreinitCamera();
 #endif
 
 private:
   void HandleDoubleTap(const CSSPoint& aPoint, const Modifiers& aModifiers,
                        const ScrollableLayerGuid& aGuid);
 
-  // Notify others that our TabContext has been updated.  (At the moment, this
-  // sets the appropriate origin attributes on our docshell.)
+  // Notify others that our TabContext has been updated.
   //
   // You should call this after calling TabContext::SetTabContext().  We also
   // call this during Init().
-  void NotifyTabContextUpdated();
+  //
+  // @param aIsPreallocated  true if this is called for Preallocated Tab.
+  void NotifyTabContextUpdated(bool aIsPreallocated);
 
   // Update the frameType on our docshell.
   void UpdateFrameType();
 
   void ActorDestroy(ActorDestroyReason why) override;
 
   enum FrameScriptLoading { DONT_LOAD_SCRIPTS, DEFAULT_LOAD_SCRIPTS };
 
--- a/embedding/browser/moz.build
+++ b/embedding/browser/moz.build
@@ -43,15 +43,16 @@ UNIFIED_SOURCES += [
     'nsDocShellTreeOwner.cpp',
     'nsEmbedStream.cpp',
     'nsWebBrowser.cpp',
     'nsWebBrowserContentPolicy.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
 LOCAL_INCLUDES += [
+    '/docshell/base',
     '/dom/base',
     '/dom/svg',
     '/layout/style',
 ]
 
 if CONFIG['GNU_CXX']:
     CXXFLAGS += ['-Wno-error=shadow']
--- a/embedding/browser/nsIWebBrowser.idl
+++ b/embedding/browser/nsIWebBrowser.idl
@@ -8,16 +8,24 @@
 
 interface nsIInterfaceRequestor;
 interface nsIWebBrowserChrome;
 interface nsIURIContentListener;
 interface nsIDOMWindow;
 interface mozIDOMWindowProxy;
 interface nsIWeakReference;
 
+%{C++
+namespace mozilla {
+class DocShellOriginAttributes;
+}
+%}
+
+[ref] native const_OriginAttributesRef(const mozilla::DocShellOriginAttributes);
+
 /**
  * The nsIWebBrowser interface is implemented by web browser objects.
  * Embedders use this interface during initialisation to associate
  * the new web browser instance with the embedders chrome and
  * to register any listeners. The interface may also be used at runtime
  * to obtain the content DOM window and from that the rest of the DOM.
  */
 [scriptable, uuid(4052b6da-4faa-4646-b3a1-7e16a01c2dc2)]
@@ -139,9 +147,17 @@ interface nsIWebBrowser : nsISupports
      * enough that we want to avoid certain optimizations like discarding
      * decoded image data and throttling the refresh driver. In Firefox,
      * this corresponds to the visible tab.
      *
      * Defaults to true. For optimal performance, set it to false when
      * appropriate.
      */
     attribute boolean isActive;
+
+    /**
+     * Set Origin Attributes on the nsIWebBrowser.
+     * The Origin Attributes will be passed to the docshell once it has been
+     * created
+     */
+    [noscript, notxpcom, nostdcall, binaryname(SetOriginAttributes)]
+    void binarySetOriginAttributes(in const_OriginAttributesRef aOriginAttrs);
 };
--- a/embedding/browser/nsWebBrowser.cpp
+++ b/embedding/browser/nsWebBrowser.cpp
@@ -34,16 +34,17 @@
 #include "nsIURI.h"
 #include "nsIWebBrowserPersist.h"
 #include "nsCWebBrowserPersist.h"
 #include "nsIServiceManager.h"
 #include "nsFocusManager.h"
 #include "Layers.h"
 #include "gfxContext.h"
 #include "nsILoadContext.h"
+#include "nsDocShell.h"
 
 // for painting the background window
 #include "mozilla/LookAndFeel.h"
 
 // Printing Includes
 #ifdef NS_PRINTING
 #include "nsIWebBrowserPrint.h"
 #include "nsIContentViewer.h"
@@ -383,16 +384,22 @@ nsWebBrowser::SetIsActive(bool aIsActive
 
   // If we have a docshell, pass on the request
   if (mDocShell) {
     return mDocShell->SetIsActive(aIsActive);
   }
   return NS_OK;
 }
 
+void
+nsWebBrowser::SetOriginAttributes(const DocShellOriginAttributes& aAttrs)
+{
+  mOriginAttributes = aAttrs;
+}
+
 //*****************************************************************************
 // nsWebBrowser::nsIDocShellTreeItem
 //*****************************************************************************
 
 NS_IMETHODIMP
 nsWebBrowser::GetName(nsAString& aName)
 {
   if (mDocShell) {
@@ -1188,16 +1195,17 @@ nsWebBrowser::Create()
     rv = mInternalWidget->Create(nullptr, mParentNativeWindow, bounds,
                                  &widgetInit);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsCOMPtr<nsIDocShell> docShell(
     do_CreateInstance("@mozilla.org/docshell;1", &rv));
   NS_ENSURE_SUCCESS(rv, rv);
+  nsDocShell::Cast(docShell)->SetOriginAttributes(mOriginAttributes);
   rv = SetDocShell(docShell);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // get the system default window background colour
   LookAndFeel::GetColor(LookAndFeel::eColorID_WindowBackground,
                         &mBackgroundColor);
 
   // the docshell has been set so we now have our listener registrars.
--- a/embedding/browser/nsWebBrowser.h
+++ b/embedding/browser/nsWebBrowser.h
@@ -33,16 +33,17 @@
 #include "nsIWebBrowserPersist.h"
 #include "nsIWebBrowserFocus.h"
 #include "nsIWebBrowserStream.h"
 #include "nsIWindowWatcher.h"
 #include "nsIPrintSettings.h"
 #include "nsEmbedStream.h"
 #include "nsIWidgetListener.h"
 
+#include "mozilla/BasePrincipal.h"
 #include "nsTArray.h"
 #include "nsWeakPtr.h"
 
 class nsWebBrowserInitInfo
 {
 public:
   // nsIBaseWindow Stuff
   int32_t x;
@@ -127,16 +128,17 @@ protected:
 protected:
   RefPtr<nsDocShellTreeOwner> mDocShellTreeOwner;
   nsCOMPtr<nsIDocShell> mDocShell;
   nsCOMPtr<nsIInterfaceRequestor> mDocShellAsReq;
   nsCOMPtr<nsIBaseWindow> mDocShellAsWin;
   nsCOMPtr<nsIWebNavigation> mDocShellAsNav;
   nsCOMPtr<nsIScrollable> mDocShellAsScrollable;
   nsCOMPtr<nsITextScroll> mDocShellAsTextScroll;
+  mozilla::DocShellOriginAttributes mOriginAttributes;
 
   nsCOMPtr<nsIWidget> mInternalWidget;
   nsCOMPtr<nsIWindowWatcher> mWWatch;
   nsAutoPtr<nsWebBrowserInitInfo> mInitInfo;
   uint32_t mContentType;
   bool mActivating;
   bool mShouldEnableHistory;
   bool mIsActive;