Bug 565163 - e10s: nsHTMLDNSPrefetch needs to be forwarded to chrome. r=dougt
authorSteffen Imhof <steffen.imhof@googlemail.com>
Mon, 26 Jul 2010 11:49:09 -0700
changeset 48229 0fc77dad4ec79f8edaf829a9e5ef4cbfe121db07
parent 48228 90ade0c197edbe5da9a17cb819e47b7d6f9cbee3
child 48230 03646477831113602d42d09fdf39d6f2d65a52d0
push idunknown
push userunknown
push dateunknown
reviewersdougt
bugs565163
milestone2.0b3pre
Bug 565163 - e10s: nsHTMLDNSPrefetch needs to be forwarded to chrome. r=dougt
content/html/content/src/Makefile.in
content/html/content/src/nsHTMLDNSPrefetch.cpp
content/html/content/src/nsHTMLDNSPrefetch.h
dom/ipc/TabChild.cpp
netwerk/ipc/NeckoCommon.h
netwerk/ipc/NeckoParent.cpp
netwerk/ipc/NeckoParent.h
netwerk/ipc/PNecko.ipdl
--- a/content/html/content/src/Makefile.in
+++ b/content/html/content/src/Makefile.in
@@ -47,16 +47,22 @@ LIBRARY_NAME	= gkconhtmlcon_s
 LIBXUL_LIBRARY	= 1
 
 
 EXPORTS		= \
 		nsImageMapUtils.h \
 		nsClientRect.h \
 		$(NULL)
 
+ifdef MOZ_IPC
+EXPORTS        += \
+                nsHTMLDNSPrefetch.h \
+                $(NULL)
+endif
+
 CPPSRCS		= \
 		nsClientRect.cpp \
 		nsHTMLDNSPrefetch.cpp \
 		nsGenericHTMLElement.cpp \
 		nsFormSubmission.cpp \
 		nsImageMapUtils.cpp \
 		nsTextEditorState.cpp \
 		nsHTMLElement.cpp \
@@ -116,16 +122,18 @@ CPPSRCS		+= \
 		nsHTMLVideoElement.cpp \
 		$(NULL)
 endif
 
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
+include $(topsrcdir)/config/config.mk
+include $(topsrcdir)/ipc/chromium/chromium-config.mk
 
 INCLUDES	+= \
 		-I$(srcdir)/../../../base/src \
 		-I$(srcdir)/../../../events/src \
 		-I$(srcdir)/../../../xbl/src \
 		-I$(srcdir)/../../../../layout/forms \
 		-I$(srcdir)/../../../../layout/style \
 		-I$(srcdir)/../../../../layout/tables \
--- a/content/html/content/src/nsHTMLDNSPrefetch.cpp
+++ b/content/html/content/src/nsHTMLDNSPrefetch.cpp
@@ -31,16 +31,22 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#ifdef MOZ_IPC
+#include "base/basictypes.h"
+#include "mozilla/net/NeckoCommon.h"
+#include "mozilla/net/NeckoChild.h"
+#endif
+
 #include "nsHTMLDNSPrefetch.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 
 #include "nsNetUtil.h"
 
 #include "nsIDNSListener.h"
 #include "nsIWebProgressListener.h"
@@ -124,16 +130,29 @@ nsHTMLDNSPrefetch::IsAllowed (nsIDocumen
 {
   // There is no need to do prefetch on non UI scenarios such as XMLHttpRequest.
   return aDocument->IsDNSPrefetchAllowed() && aDocument->GetWindow();
 }
 
 nsresult
 nsHTMLDNSPrefetch::Prefetch(Link *aElement, PRUint16 flags)
 {
+#ifdef MOZ_IPC
+  if (mozilla::net::IsNeckoChild()) {
+    // Instead of transporting the Link object to the other process
+    // we are using the hostname based function here, too. Compared to the 
+    // IPC the performance hit should be negligible.
+    nsAutoString hostname;
+    nsresult rv = aElement->GetHostname(hostname);
+    NS_ENSURE_SUCCESS(rv,rv);
+
+    return Prefetch(hostname, flags);
+  }
+#endif
+
   if (!(sInitialized && sPrefetches && sDNSService && sDNSListener))
     return NS_ERROR_NOT_AVAILABLE;
 
   return sPrefetches->Add(flags, aElement);
 }
 
 nsresult
 nsHTMLDNSPrefetch::PrefetchLow(Link *aElement)
@@ -151,16 +170,23 @@ nsresult
 nsHTMLDNSPrefetch::PrefetchHigh(Link *aElement)
 {
   return Prefetch(aElement, 0);
 }
 
 nsresult
 nsHTMLDNSPrefetch::Prefetch(nsAString &hostname, PRUint16 flags)
 {
+#ifdef MOZ_IPC
+  if (mozilla::net::IsNeckoChild()) {
+    mozilla::net::gNeckoChild->SendHTMLDNSPrefetch(nsAutoString(hostname), flags);
+    return NS_OK;
+  }
+#endif
+
   if (!(sInitialized && sDNSService && sPrefetches && sDNSListener))
     return NS_ERROR_NOT_AVAILABLE;
 
   nsCOMPtr<nsICancelable> tmpOutstanding;
   return sDNSService->AsyncResolve(NS_ConvertUTF16toUTF8(hostname), flags | nsIDNSService::RESOLVE_SPECULATE,
                                    sDNSListener, nsnull, getter_AddRefs(tmpOutstanding));
 }
 
--- a/content/html/content/src/nsHTMLDNSPrefetch.h
+++ b/content/html/content/src/nsHTMLDNSPrefetch.h
@@ -51,16 +51,22 @@
 class nsIDocument;
 class nsITimer;
 namespace mozilla {
 namespace dom {
 class Link;
 } // namespace dom
 } // namespace mozilla
 
+namespace mozilla {
+namespace net {
+class NeckoParent;
+} // namespace net
+} // namespace mozilla
+
 class nsHTMLDNSPrefetch 
 {
 public:
   // The required aDocument parameter is the context requesting the prefetch - under
   // certain circumstances (e.g. headers, or security context) associated with
   // the context the prefetch will not be performed. 
   static PRBool   IsAllowed(nsIDocument *aDocument);
  
@@ -131,11 +137,15 @@ public:
     static const int          sMaxDeferredMask = (sMaxDeferred - 1);
     
     struct deferred_entry
     {
       PRUint16                         mFlags;
       nsWeakPtr                        mElement;
     } mEntries[sMaxDeferred];
   };
+
+#ifdef MOZ_IPC
+  friend class mozilla::net::NeckoParent;
+#endif
 };
 
 #endif 
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -36,16 +36,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "TabChild.h"
 #include "mozilla/dom/PContentChild.h"
 #include "mozilla/dom/PContentDialogChild.h"
 
 #include "nsIWebBrowser.h"
+#include "nsIWebBrowserSetup.h"
 #include "nsEmbedCID.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIBaseWindow.h"
 #include "nsIDOMWindow.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsThreadUtils.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "mozilla/ipc/DocumentRendererChild.h"
@@ -448,16 +449,27 @@ TabChild::RecvCreateWidget(const MagicWi
 #endif
 
 #if !defined(XP_MACOSX)
     baseWindow->InitWindow(win, 0, 0, 0, 0, 0);
     baseWindow->Create();
     baseWindow->SetVisibility(PR_TRUE);
 #endif
 
+    // 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,
+                                   PR_TRUE);
+    } else {
+        NS_WARNING("baseWindow doesn't QI to nsIWebBrowserSetup, skipping "
+                   "DNS prefetching enable step.");
+    }
+
     return InitTabChildGlobal();
 }
 
 bool
 TabChild::DestroyWidget()
 {
     nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(mWebNav);
     if (baseWindow)
--- a/netwerk/ipc/NeckoCommon.h
+++ b/netwerk/ipc/NeckoCommon.h
@@ -37,16 +37,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef mozilla_net_NeckoCommon_h
 #define mozilla_net_NeckoCommon_h
 
 #include "nsXULAppAPI.h"
+#include "prenv.h"
 
 #if defined(DEBUG) || defined(ENABLE_TESTS)
 # define NECKO_ERRORS_ARE_FATAL_DEFAULT true
 #else
 # define NECKO_ERRORS_ARE_FATAL_DEFAULT false
 #endif 
 
 // TODO: Eventually remove NECKO_MAYBE_ABORT and DROP_DEAD (bug 575494).
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -38,16 +38,18 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsHttp.h"
 #include "mozilla/net/NeckoParent.h"
 #include "mozilla/net/HttpChannelParent.h"
 #include "mozilla/net/CookieServiceParent.h"
 
+#include "nsHTMLDNSPrefetch.h"
+
 namespace mozilla {
 namespace net {
 
 // C++ file contents
 NeckoParent::NeckoParent()
 {
 }
 
@@ -79,10 +81,19 @@ NeckoParent::AllocPCookieService()
 
 bool 
 NeckoParent::DeallocPCookieService(PCookieServiceParent* cs)
 {
   delete cs;
   return true;
 }
 
+bool
+NeckoParent::RecvHTMLDNSPrefetch(const nsString& hostname,
+                                 const PRUint16& flags)
+{
+  nsAutoString h(hostname);
+  nsHTMLDNSPrefetch::Prefetch(h, flags);
+  return true;
+}
+
 }} // mozilla::net
 
--- a/netwerk/ipc/NeckoParent.h
+++ b/netwerk/ipc/NeckoParent.h
@@ -55,14 +55,16 @@ public:
   NeckoParent();
   virtual ~NeckoParent();
 
 protected:
   virtual PHttpChannelParent* AllocPHttpChannel(PBrowserParent* iframeEmbedding);
   virtual bool DeallocPHttpChannel(PHttpChannelParent*);
   virtual PCookieServiceParent* AllocPCookieService();
   virtual bool DeallocPCookieService(PCookieServiceParent*);
+  virtual bool RecvHTMLDNSPrefetch(const nsString& hostname,
+                                   const PRUint16& flags);
 };
 
 } // namespace net
 } // namespace mozilla
 
 #endif // mozilla_net_NeckoParent_h
--- a/netwerk/ipc/PNecko.ipdl
+++ b/netwerk/ipc/PNecko.ipdl
@@ -54,13 +54,15 @@ sync protocol PNecko
   manages PHttpChannel;
   manages PCookieService;
 
 parent:
   __delete__();
 
   PHttpChannel(nullable PBrowser iframeEmbedding);
   PCookieService();
+
+  HTMLDNSPrefetch(nsString hostname, PRUint16 flags);
 };
 
 
 } // namespace net
 } // namespace mozilla