Bug 586115 - Cache LoadFrameScript Calls - e10s, r=jst, fb=azakai, a=b-f
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 18 Aug 2010 13:02:49 +0300
changeset 50801 f4c97baa0e519df38797c34f5628934c6cabbf65
parent 50800 095418dfa2e6c05ceeedf09adf617248fee03c25
child 50802 d736c1a4ad2f43cf10087f1c46756ba5509205e3
push id15161
push useropettay@mozilla.com
push dateWed, 18 Aug 2010 10:03:22 +0000
treeherdermozilla-central@f4c97baa0e51 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst, b-f
bugs586115
milestone2.0b5pre
first release with
nightly linux32
f4c97baa0e51 / 4.0b5pre / 20100818031811 / files
nightly mac
f4c97baa0e51 / 4.0b5pre / 20100818031745 / files
nightly linux64
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly mac
Bug 586115 - Cache LoadFrameScript Calls - e10s, r=jst, fb=azakai, a=b-f
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -116,18 +116,17 @@ class ContentDialogChild : public PConte
 {
 public:
   virtual bool Recv__delete__(const nsTArray<int>& aIntParams,
                               const nsTArray<nsString>& aStringParams);
 };
 
 
 TabChild::TabChild(PRUint32 aChromeFlags)
-  : mCx(nsnull)
-  , mTabChildGlobal(nsnull)
+  : mTabChildGlobal(nsnull)
   , mChromeFlags(aChromeFlags)
 {
     printf("creating %d!\n", NS_IsMainThread());
 }
 
 nsresult
 TabChild::Init()
 {
@@ -503,22 +502,17 @@ TabChild::~TabChild()
     nsCOMPtr<nsIWeakReference> weak =
       do_GetWeakReference(static_cast<nsSupportsWeakReference*>(this));
     webBrowser->RemoveWebBrowserListener(weak, NS_GET_IID(nsIWebProgressListener));
 
     if (webBrowser) {
       webBrowser->SetContainerWindow(nsnull);
     }
     if (mCx) {
-      nsIXPConnect* xpc = nsContentUtils::XPConnect();
-      if (xpc) {
-         xpc->ReleaseJSContext(mCx, PR_FALSE);
-      } else {
-        JS_DestroyContext(mCx);
-      }
+      DestroyCx();
     }
     mTabChildGlobal->mTabChild = nsnull;
 }
 
 NS_IMETHODIMP
 TabChild::OnStateChange(nsIWebProgress *aWebProgress,
                         nsIRequest *aRequest,
                         PRUint32 aStateFlags,
@@ -1004,65 +998,17 @@ TabChild::RecvActivateFrameEvent(const n
   NS_ENSURE_TRUE(listener, true);
   chromeHandler->AddEventListener(aType, listener, capture);
   return true;
 }
 
 bool
 TabChild::RecvLoadRemoteScript(const nsString& aURL)
 {
-  nsCString url = NS_ConvertUTF16toUTF8(aURL);
-  nsCOMPtr<nsIURI> uri;
-  nsresult rv = NS_NewURI(getter_AddRefs(uri), url);
-  NS_ENSURE_SUCCESS(rv, true);
-  NS_NewChannel(getter_AddRefs(mChannel), uri);
-  NS_ENSURE_TRUE(mChannel, true);
-
-  nsCOMPtr<nsIInputStream> input;
-  mChannel->Open(getter_AddRefs(input));
-  nsString dataString;
-  if (input) {
-    const PRUint32 bufferSize = 256;
-    char buffer[bufferSize];
-    nsCString data;
-    PRUint32 avail = 0;
-    input->Available(&avail);
-    PRUint32 read = 0;
-    if (avail) {
-      while (NS_SUCCEEDED(input->Read(buffer, bufferSize, &read)) && read) {
-        data.Append(buffer, read);
-        read = 0;
-      }
-    }
-    nsScriptLoader::ConvertToUTF16(mChannel, (PRUint8*)data.get(), data.Length(),
-                                   EmptyString(), nsnull, dataString);
-  }
-
-  if (!dataString.IsEmpty()) {
-    JSAutoRequest ar(mCx);
-    nsCOMPtr<nsPIDOMWindow> w = do_GetInterface(mWebNav);
-    jsval retval;
-    JSObject* global = nsnull;
-    rv = mRootGlobal->GetJSObject(&global);
-    NS_ENSURE_SUCCESS(rv, false);
-    JSPrincipals* jsprin = nsnull;
-    mPrincipal->GetJSPrincipals(mCx, &jsprin);
-
-    nsContentUtils::XPConnect()->FlagSystemFilenamePrefix(url.get(), PR_TRUE);
-
-    nsContentUtils::ThreadJSContextStack()->Push(mCx);
-    JSBool ret = JS_EvaluateUCScriptForPrincipals(mCx, global, jsprin,
-                                                  (jschar*)dataString.get(),
-                                                  dataString.Length(),
-                                                  url.get(), 1, &retval);
-    JSPRINCIPALS_DROP(mCx, jsprin);
-    JSContext *unused;
-    nsContentUtils::ThreadJSContextStack()->Pop(&unused);
-    NS_ENSURE_TRUE(ret, true); // This gives us a useful warning!
-  }
+  LoadFrameScriptInternal(aURL);
   return true;
 }
 
 bool
 TabChild::RecvAsyncMessage(const nsString& aMessage,
                            const nsString& aJSON)
 {
   if (mTabChildGlobal) {
@@ -1175,29 +1121,29 @@ TabChild::InitTabChildGlobal()
   nsISupports* scopeSupports =
     NS_ISUPPORTS_CAST(nsPIDOMEventTarget*, scope);
   JS_SetContextPrivate(cx, scopeSupports);
 
   nsresult rv =
     xpc->InitClassesWithNewWrappedGlobal(cx, scopeSupports,
                                          NS_GET_IID(nsISupports),
                                          scope->GetPrincipal(), EmptyCString(),
-                                         flags, getter_AddRefs(mRootGlobal));
+                                         flags, getter_AddRefs(mGlobal));
   NS_ENSURE_SUCCESS(rv, false);
 
   nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(chromeHandler);
   NS_ENSURE_TRUE(root, false);
   root->SetParentTarget(scope);
   
   JSObject* global = nsnull;
-  rv = mRootGlobal->GetJSObject(&global);
+  rv = mGlobal->GetJSObject(&global);
   NS_ENSURE_SUCCESS(rv, false);
 
   JS_SetGlobalObject(cx, global);
-
+  DidCreateCx();
   return true;
 }
 
 static bool
 SendSyncMessageToParent(void* aCallbackData,
                         const nsAString& aMessage,
                         const nsAString& aJSON,
                         nsTArray<nsString>* aJSONRetVal)
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -139,16 +139,17 @@ public:
   ContentListener(TabChild* aTabChild) : mTabChild(aTabChild) {}
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMEVENTLISTENER
 protected:
   TabChild* mTabChild;
 };
 
 class TabChild : public PBrowserChild,
+                 public nsFrameScriptExecutor,
                  public nsIWebProgressListener2,
                  public nsIWebBrowserChrome2,
                  public nsIEmbeddingSiteWindow2,
                  public nsIWebBrowserChromeFocus,
                  public nsIInterfaceRequestor,
                  public nsIWindowProvider,
                  public nsSupportsWeakReference,
                  public nsIDialogCreator,
@@ -298,21 +299,17 @@ protected:
     bool DispatchWidgetEvent(nsGUIEvent& event);
 
 private:
     void ActorDestroy(ActorDestroyReason why);
 
     bool InitTabChildGlobal();
 
     nsCOMPtr<nsIWebNavigation> mWebNav;
-    nsCOMPtr<nsIXPConnectJSObjectHolder> mRootGlobal;
-    JSContext* mCx;
-    nsCOMPtr<nsIChannel> mChannel;
     TabChildGlobal* mTabChildGlobal;
-    nsCOMPtr<nsIPrincipal> mPrincipal;
     PRUint32 mChromeFlags;
 
     DISALLOW_EVIL_CONSTRUCTORS(TabChild);
 };
 
 inline TabChild*
 GetTabChildFrom(nsIDocShell* aDocShell)
 {