From af9b6e4d68530fe0fe693d83386ea7e6f487d5ce Mon Sep 17 00:00:00 2001 From: Steffen Imhof Date: Mon, 26 Jul 2010 11:49:09 -0700 Subject: [PATCH] Bug 565163 - e10s: nsHTMLDNSPrefetch needs to be forwarded to chrome. r=dougt --HG-- extra : rebase_source : bb91a8287ad6484846c89f57d916c97f3c05fb70 --- content/html/content/src/Makefile.in | 8 ++++++ .../html/content/src/nsHTMLDNSPrefetch.cpp | 26 +++++++++++++++++++ content/html/content/src/nsHTMLDNSPrefetch.h | 10 +++++++ dom/ipc/TabChild.cpp | 12 +++++++++ netwerk/ipc/NeckoCommon.h | 1 + netwerk/ipc/NeckoParent.cpp | 11 ++++++++ netwerk/ipc/NeckoParent.h | 2 ++ netwerk/ipc/PNecko.ipdl | 2 ++ 8 files changed, 72 insertions(+) diff --git a/content/html/content/src/Makefile.in b/content/html/content/src/Makefile.in index 3a54e1f2d6e..f2d8cb8f259 100644 --- a/content/html/content/src/Makefile.in +++ b/content/html/content/src/Makefile.in @@ -52,6 +52,12 @@ EXPORTS = \ nsClientRect.h \ $(NULL) +ifdef MOZ_IPC +EXPORTS += \ + nsHTMLDNSPrefetch.h \ + $(NULL) +endif + CPPSRCS = \ nsClientRect.cpp \ nsHTMLDNSPrefetch.cpp \ @@ -121,6 +127,8 @@ endif 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 \ diff --git a/content/html/content/src/nsHTMLDNSPrefetch.cpp b/content/html/content/src/nsHTMLDNSPrefetch.cpp index 0a6c141be99..dc7d98eb7c2 100644 --- a/content/html/content/src/nsHTMLDNSPrefetch.cpp +++ b/content/html/content/src/nsHTMLDNSPrefetch.cpp @@ -36,6 +36,12 @@ * * ***** 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" @@ -129,6 +135,19 @@ nsHTMLDNSPrefetch::IsAllowed (nsIDocument *aDocument) 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; @@ -156,6 +175,13 @@ nsHTMLDNSPrefetch::PrefetchHigh(Link *aElement) 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; diff --git a/content/html/content/src/nsHTMLDNSPrefetch.h b/content/html/content/src/nsHTMLDNSPrefetch.h index a6e25d764ec..e2973ae6e5e 100644 --- a/content/html/content/src/nsHTMLDNSPrefetch.h +++ b/content/html/content/src/nsHTMLDNSPrefetch.h @@ -56,6 +56,12 @@ class Link; } // namespace dom } // namespace mozilla +namespace mozilla { +namespace net { +class NeckoParent; +} // namespace net +} // namespace mozilla + class nsHTMLDNSPrefetch { public: @@ -136,6 +142,10 @@ public: nsWeakPtr mElement; } mEntries[sMaxDeferred]; }; + +#ifdef MOZ_IPC + friend class mozilla::net::NeckoParent; +#endif }; #endif diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index ab393094e8e..972a76f5471 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -41,6 +41,7 @@ #include "mozilla/dom/PContentDialogChild.h" #include "nsIWebBrowser.h" +#include "nsIWebBrowserSetup.h" #include "nsEmbedCID.h" #include "nsComponentManagerUtils.h" #include "nsIBaseWindow.h" @@ -453,6 +454,17 @@ TabChild::RecvCreateWidget(const MagicWindowHandle& parentWidget) 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 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(); } diff --git a/netwerk/ipc/NeckoCommon.h b/netwerk/ipc/NeckoCommon.h index 9b7420fc14e..7070454c57b 100644 --- a/netwerk/ipc/NeckoCommon.h +++ b/netwerk/ipc/NeckoCommon.h @@ -42,6 +42,7 @@ #define mozilla_net_NeckoCommon_h #include "nsXULAppAPI.h" +#include "prenv.h" #if defined(DEBUG) || defined(ENABLE_TESTS) # define NECKO_ERRORS_ARE_FATAL_DEFAULT true diff --git a/netwerk/ipc/NeckoParent.cpp b/netwerk/ipc/NeckoParent.cpp index 9731a80b7c4..c896653c142 100644 --- a/netwerk/ipc/NeckoParent.cpp +++ b/netwerk/ipc/NeckoParent.cpp @@ -43,6 +43,8 @@ #include "mozilla/net/HttpChannelParent.h" #include "mozilla/net/CookieServiceParent.h" +#include "nsHTMLDNSPrefetch.h" + namespace mozilla { namespace net { @@ -84,5 +86,14 @@ NeckoParent::DeallocPCookieService(PCookieServiceParent* cs) return true; } +bool +NeckoParent::RecvHTMLDNSPrefetch(const nsString& hostname, + const PRUint16& flags) +{ + nsAutoString h(hostname); + nsHTMLDNSPrefetch::Prefetch(h, flags); + return true; +} + }} // mozilla::net diff --git a/netwerk/ipc/NeckoParent.h b/netwerk/ipc/NeckoParent.h index 1817b9fe992..55438f7b20a 100644 --- a/netwerk/ipc/NeckoParent.h +++ b/netwerk/ipc/NeckoParent.h @@ -60,6 +60,8 @@ protected: virtual bool DeallocPHttpChannel(PHttpChannelParent*); virtual PCookieServiceParent* AllocPCookieService(); virtual bool DeallocPCookieService(PCookieServiceParent*); + virtual bool RecvHTMLDNSPrefetch(const nsString& hostname, + const PRUint16& flags); }; } // namespace net diff --git a/netwerk/ipc/PNecko.ipdl b/netwerk/ipc/PNecko.ipdl index 813c336f768..e68f38f4db6 100644 --- a/netwerk/ipc/PNecko.ipdl +++ b/netwerk/ipc/PNecko.ipdl @@ -59,6 +59,8 @@ parent: PHttpChannel(nullable PBrowser iframeEmbedding); PCookieService(); + + HTMLDNSPrefetch(nsString hostname, PRUint16 flags); };