2009-07-01 00:39:22 +04:00
|
|
|
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */
|
2009-08-18 23:05:15 +04:00
|
|
|
/* vim: set sw=4 ts=8 et tw=80 : */
|
2009-09-10 02:00:14 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Content App.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* 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 ***** */
|
2009-07-01 00:39:22 +04:00
|
|
|
|
|
|
|
#include "TabChild.h"
|
2010-11-24 16:58:21 +03:00
|
|
|
#include "mozilla/IntentionalCrash.h"
|
2010-07-19 22:33:33 +04:00
|
|
|
#include "mozilla/dom/PContentChild.h"
|
2010-05-17 15:25:22 +04:00
|
|
|
#include "mozilla/dom/PContentDialogChild.h"
|
2010-08-21 03:24:41 +04:00
|
|
|
#include "mozilla/layers/PLayersChild.h"
|
2010-08-21 03:24:41 +04:00
|
|
|
#include "mozilla/layout/RenderFrameChild.h"
|
2010-10-20 21:12:32 +04:00
|
|
|
#include "mozilla/docshell/OfflineCacheUpdateChild.h"
|
2009-07-01 00:39:22 +04:00
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
#include "BasicLayers.h"
|
2009-07-01 00:39:22 +04:00
|
|
|
#include "nsIWebBrowser.h"
|
2010-07-26 22:49:09 +04:00
|
|
|
#include "nsIWebBrowserSetup.h"
|
2009-07-01 00:39:22 +04:00
|
|
|
#include "nsEmbedCID.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
2009-10-29 20:58:31 +03:00
|
|
|
#include "nsIDOMWindow.h"
|
2010-08-13 12:06:40 +04:00
|
|
|
#include "nsIWebProgress.h"
|
|
|
|
#include "nsIDocShell.h"
|
2009-07-01 00:39:22 +04:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2009-10-29 20:58:31 +03:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "mozilla/ipc/DocumentRendererChild.h"
|
2009-11-05 21:14:22 +03:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDOMWindowUtils.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
2010-03-26 21:39:39 +03:00
|
|
|
#include "nsIURI.h"
|
2009-11-05 21:14:22 +03:00
|
|
|
#include "nsIWebBrowserFocus.h"
|
2009-11-17 17:22:23 +03:00
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
2010-02-20 20:05:20 +03:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIJSRuntimeService.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIDOMClassInfo.h"
|
|
|
|
#include "nsIXPCSecurityManager.h"
|
|
|
|
#include "nsIJSContextStack.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsScriptLoader.h"
|
|
|
|
#include "nsPIWindowRoot.h"
|
|
|
|
#include "nsIScriptContext.h"
|
2010-05-17 15:25:22 +04:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2010-03-24 13:47:18 +03:00
|
|
|
#include "nsPresContext.h"
|
2009-11-06 23:43:39 +03:00
|
|
|
#include "nsIDocument.h"
|
2010-08-12 20:47:22 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2009-11-06 23:43:39 +03:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
2010-03-26 21:39:39 +03:00
|
|
|
#include "nsWeakReference.h"
|
2010-08-13 12:06:40 +04:00
|
|
|
#include "nsISecureBrowserUI.h"
|
|
|
|
#include "nsISSLStatusProvider.h"
|
|
|
|
#include "nsSerializationHelper.h"
|
2010-08-17 12:07:42 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIView.h"
|
2011-06-24 06:18:01 +04:00
|
|
|
#include "nsEventListenerManager.h"
|
2010-09-10 09:00:08 +04:00
|
|
|
#include "PCOMContentPermissionRequestChild.h"
|
2011-01-15 01:03:21 +03:00
|
|
|
#include "xpcpublic.h"
|
2009-07-07 20:26:49 +04:00
|
|
|
|
2009-08-12 20:18:08 +04:00
|
|
|
using namespace mozilla::dom;
|
2010-10-27 02:20:53 +04:00
|
|
|
using namespace mozilla::ipc;
|
2010-08-21 03:24:41 +04:00
|
|
|
using namespace mozilla::layers;
|
2010-08-21 03:24:41 +04:00
|
|
|
using namespace mozilla::layout;
|
2010-10-20 21:12:32 +04:00
|
|
|
using namespace mozilla::docshell;
|
2009-07-01 00:39:22 +04:00
|
|
|
|
2009-11-17 17:22:23 +03:00
|
|
|
NS_IMPL_ISUPPORTS1(ContentListener, nsIDOMEventListener)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ContentListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
RemoteDOMEvent remoteEvent;
|
|
|
|
remoteEvent.mEvent = do_QueryInterface(aEvent);
|
|
|
|
NS_ENSURE_STATE(remoteEvent.mEvent);
|
2010-07-19 22:33:33 +04:00
|
|
|
mTabChild->SendEvent(remoteEvent);
|
2009-11-17 17:22:23 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-17 15:25:22 +04:00
|
|
|
class ContentDialogChild : public PContentDialogChild
|
|
|
|
{
|
|
|
|
public:
|
2010-11-09 05:49:00 +03:00
|
|
|
virtual bool Recv__delete__(const InfallibleTArray<int>& aIntParams,
|
|
|
|
const InfallibleTArray<nsString>& aStringParams);
|
2010-05-17 15:25:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-07-19 22:33:33 +04:00
|
|
|
TabChild::TabChild(PRUint32 aChromeFlags)
|
2010-08-21 03:24:41 +04:00
|
|
|
: mRemoteFrame(nsnull)
|
|
|
|
, mTabChildGlobal(nsnull)
|
2010-07-19 22:33:33 +04:00
|
|
|
, mChromeFlags(aChromeFlags)
|
2009-07-01 00:39:22 +04:00
|
|
|
{
|
2010-05-17 15:21:55 +04:00
|
|
|
printf("creating %d!\n", NS_IsMainThread());
|
2009-11-05 21:14:22 +03:00
|
|
|
}
|
2009-07-01 00:39:22 +04:00
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
nsresult
|
|
|
|
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);
|
|
|
|
mWebNav = do_QueryInterface(webBrowser);
|
|
|
|
NS_ASSERTION(mWebNav, "nsWebBrowser doesn't implement nsIWebNavigation?");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellItem(do_QueryInterface(mWebNav));
|
|
|
|
docShellItem->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-17 15:25:22 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(TabChild)
|
2011-06-16 22:21:08 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
|
2010-05-17 15:25:22 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome2)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow2)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWindowProvider)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITabChild)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDialogCreator)
|
2010-09-18 06:11:05 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsSupportsWeakReference)
|
2010-05-17 15:25:22 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(TabChild)
|
|
|
|
NS_IMPL_RELEASE(TabChild)
|
2009-11-05 21:14:22 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::SetStatus(PRUint32 aStatusType, const PRUnichar* aStatus)
|
|
|
|
{
|
2011-01-04 19:40:54 +03:00
|
|
|
// FIXME/bug 617804: should the platform support this?
|
|
|
|
return NS_OK;
|
2009-11-05 21:14:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::GetWebBrowser(nsIWebBrowser** aWebBrowser)
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::GetWebBrowser not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::SetWebBrowser(nsIWebBrowser* aWebBrowser)
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::SetWebBrowser not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::GetChromeFlags(PRUint32* aChromeFlags)
|
|
|
|
{
|
2010-07-19 22:33:33 +04:00
|
|
|
*aChromeFlags = mChromeFlags;
|
|
|
|
return NS_OK;
|
2009-11-05 21:14:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::SetChromeFlags(PRUint32 aChromeFlags)
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("trying to SetChromeFlags from content process?");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::DestroyBrowserWindow()
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::SetWebBrowser not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::SizeBrowserTo not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::ShowAsModal()
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::ShowAsModal not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::IsWindowModal(PRBool* aRetVal)
|
|
|
|
{
|
|
|
|
*aRetVal = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::ExitModalEventLoop(nsresult aStatus)
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::ExitModalEventLoop not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2009-07-01 00:39:22 +04:00
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::SetStatusWithContext(PRUint32 aStatusType,
|
|
|
|
const nsAString& aStatusText,
|
|
|
|
nsISupports* aStatusContext)
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::SetStatusWithContext not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::SetDimensions(PRUint32 aFlags, PRInt32 aX, PRInt32 aY,
|
|
|
|
PRInt32 aCx, PRInt32 aCy)
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::SetDimensions not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::GetDimensions(PRUint32 aFlags, PRInt32* aX,
|
|
|
|
PRInt32* aY, PRInt32* aCx, PRInt32* aCy)
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::GetDimensions not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::SetFocus()
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::SetFocus not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::GetVisibility(PRBool* aVisibility)
|
|
|
|
{
|
|
|
|
*aVisibility = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::SetVisibility(PRBool aVisibility)
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::SetVisibility not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::GetTitle(PRUnichar** aTitle)
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::GetTitle not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::SetTitle(const PRUnichar* aTitle)
|
|
|
|
{
|
2011-01-04 19:40:54 +03:00
|
|
|
// FIXME/bug 617804: should the platform support this?
|
|
|
|
return NS_OK;
|
2009-11-05 21:14:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::GetSiteWindow(void** aSiteWindow)
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::GetSiteWindow not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::Blur()
|
|
|
|
{
|
2010-11-03 16:00:49 +03:00
|
|
|
NS_NOTREACHED("TabChild::Blur not supported in TabChild");
|
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::FocusNextElement()
|
|
|
|
{
|
2010-07-19 22:33:33 +04:00
|
|
|
SendMoveFocus(PR_TRUE);
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::FocusPrevElement()
|
|
|
|
{
|
2010-07-19 22:33:33 +04:00
|
|
|
SendMoveFocus(PR_FALSE);
|
2009-11-05 21:14:22 +03:00
|
|
|
return NS_OK;
|
2009-10-28 23:41:46 +03:00
|
|
|
}
|
2009-07-01 00:39:22 +04:00
|
|
|
|
2010-01-01 04:34:06 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::GetInterface(const nsIID & aIID, void **aSink)
|
|
|
|
{
|
|
|
|
// XXXbz should we restrict the set of interfaces we hand out here?
|
|
|
|
// See bug 537429
|
|
|
|
return QueryInterface(aIID, aSink);
|
|
|
|
}
|
|
|
|
|
2010-01-01 04:35:55 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::ProvideWindow(nsIDOMWindow* aParent, PRUint32 aChromeFlags,
|
2010-07-05 17:11:08 +04:00
|
|
|
PRBool aCalledFromJS,
|
2010-01-01 04:35:55 +03:00
|
|
|
PRBool aPositionSpecified, PRBool aSizeSpecified,
|
|
|
|
nsIURI* aURI, const nsAString& aName,
|
|
|
|
const nsACString& aFeatures, PRBool* aWindowIsNew,
|
|
|
|
nsIDOMWindow** aReturn)
|
|
|
|
{
|
|
|
|
*aReturn = nsnull;
|
|
|
|
|
2010-07-19 22:33:33 +04:00
|
|
|
PBrowserChild* newChild;
|
|
|
|
if (!CallCreateWindow(&newChild)) {
|
2010-01-01 04:35:55 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2011-04-14 21:55:42 +04:00
|
|
|
*aWindowIsNew = PR_TRUE;
|
2010-01-01 04:35:55 +03:00
|
|
|
nsCOMPtr<nsIDOMWindow> win =
|
|
|
|
do_GetInterface(static_cast<TabChild*>(newChild)->mWebNav);
|
|
|
|
win.forget(aReturn);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-17 15:25:22 +04:00
|
|
|
static nsInterfaceHashtable<nsVoidPtrHashKey, nsIDialogParamBlock> gActiveDialogs;
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChild::OpenDialog(PRUint32 aType, const nsACString& aName,
|
|
|
|
const nsACString& aFeatures,
|
|
|
|
nsIDialogParamBlock* aArguments,
|
|
|
|
nsIDOMElement* aFrameElement)
|
|
|
|
{
|
|
|
|
if (!gActiveDialogs.IsInitialized()) {
|
|
|
|
NS_ENSURE_STATE(gActiveDialogs.Init());
|
|
|
|
}
|
2010-11-09 05:49:00 +03:00
|
|
|
InfallibleTArray<PRInt32> intParams;
|
|
|
|
InfallibleTArray<nsString> stringParams;
|
2010-05-17 15:25:22 +04:00
|
|
|
ParamsToArrays(aArguments, intParams, stringParams);
|
|
|
|
PContentDialogChild* dialog =
|
|
|
|
SendPContentDialogConstructor(aType, nsCString(aName),
|
|
|
|
nsCString(aFeatures), intParams, stringParams);
|
|
|
|
NS_ENSURE_STATE(gActiveDialogs.Put(dialog, aArguments));
|
|
|
|
nsIThread *thread = NS_GetCurrentThread();
|
|
|
|
while (gActiveDialogs.GetWeak(dialog)) {
|
|
|
|
if (!NS_ProcessNextEvent(thread)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-11-09 05:49:00 +03:00
|
|
|
ContentDialogChild::Recv__delete__(const InfallibleTArray<int>& aIntParams,
|
|
|
|
const InfallibleTArray<nsString>& aStringParams)
|
2010-05-17 15:25:22 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDialogParamBlock> params;
|
|
|
|
if (gActiveDialogs.Get(this, getter_AddRefs(params))) {
|
|
|
|
TabChild::ArraysToParams(aIntParams, aStringParams, params);
|
|
|
|
gActiveDialogs.Remove(this);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TabChild::ParamsToArrays(nsIDialogParamBlock* aParams,
|
2010-11-09 05:49:00 +03:00
|
|
|
InfallibleTArray<int>& aIntParams,
|
|
|
|
InfallibleTArray<nsString>& aStringParams)
|
2010-05-17 15:25:22 +04:00
|
|
|
{
|
|
|
|
if (aParams) {
|
|
|
|
for (PRInt32 i = 0; i < 8; ++i) {
|
|
|
|
PRInt32 val = 0;
|
|
|
|
aParams->GetInt(i, &val);
|
|
|
|
aIntParams.AppendElement(val);
|
|
|
|
}
|
|
|
|
PRInt32 j = 0;
|
2010-11-03 16:02:33 +03:00
|
|
|
nsXPIDLString strVal;
|
|
|
|
while (NS_SUCCEEDED(aParams->GetString(j, getter_Copies(strVal)))) {
|
2010-05-17 15:25:22 +04:00
|
|
|
aStringParams.AppendElement(strVal);
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-09 05:49:00 +03:00
|
|
|
TabChild::ArraysToParams(const InfallibleTArray<int>& aIntParams,
|
|
|
|
const InfallibleTArray<nsString>& aStringParams,
|
2010-05-17 15:25:22 +04:00
|
|
|
nsIDialogParamBlock* aParams)
|
|
|
|
{
|
|
|
|
if (aParams) {
|
|
|
|
for (PRInt32 i = 0; PRUint32(i) < aIntParams.Length(); ++i) {
|
|
|
|
aParams->SetInt(i, aIntParams[i]);
|
|
|
|
}
|
|
|
|
for (PRInt32 j = 0; PRUint32(j) < aStringParams.Length(); ++j) {
|
|
|
|
aParams->SetString(j, aStringParams[j].get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-21 03:24:40 +04:00
|
|
|
void
|
|
|
|
TabChild::DestroyWindow()
|
2009-10-28 23:41:46 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(mWebNav);
|
|
|
|
if (baseWindow)
|
|
|
|
baseWindow->Destroy();
|
2009-07-07 20:26:49 +04:00
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
// NB: the order of mWidget->Destroy() and mRemoteFrame->Destroy()
|
|
|
|
// is important: we want to kill off remote layers before their
|
|
|
|
// frames
|
|
|
|
if (mWidget) {
|
2010-08-21 03:24:41 +04:00
|
|
|
mWidget->Destroy();
|
2010-03-01 22:05:48 +03:00
|
|
|
}
|
2009-07-07 20:26:49 +04:00
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
if (mRemoteFrame) {
|
|
|
|
mRemoteFrame->Destroy();
|
|
|
|
mRemoteFrame = nsnull;
|
2010-07-26 22:49:09 +04:00
|
|
|
}
|
2009-08-12 20:18:08 +04:00
|
|
|
}
|
2009-07-14 11:33:50 +04:00
|
|
|
|
2010-07-22 03:23:03 +04:00
|
|
|
void
|
|
|
|
TabChild::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
// The messageManager relays messages via the TabChild which
|
|
|
|
// no longer exists.
|
|
|
|
static_cast<nsFrameMessageManager*>
|
|
|
|
(mTabChildGlobal->mMessageManager.get())->Disconnect();
|
|
|
|
mTabChildGlobal->mMessageManager = nsnull;
|
|
|
|
}
|
|
|
|
|
2009-08-12 20:18:08 +04:00
|
|
|
TabChild::~TabChild()
|
|
|
|
{
|
2009-11-05 21:14:22 +03:00
|
|
|
nsCOMPtr<nsIWebBrowser> webBrowser = do_QueryInterface(mWebNav);
|
|
|
|
if (webBrowser) {
|
|
|
|
webBrowser->SetContainerWindow(nsnull);
|
|
|
|
}
|
2010-02-20 20:05:20 +03:00
|
|
|
if (mCx) {
|
2010-08-18 14:02:49 +04:00
|
|
|
DestroyCx();
|
2010-02-20 20:05:20 +03:00
|
|
|
}
|
2010-08-23 12:44:43 +04:00
|
|
|
|
2011-06-24 06:18:01 +04:00
|
|
|
nsEventListenerManager* elm = mTabChildGlobal->GetListenerManager(PR_FALSE);
|
2010-08-23 12:44:43 +04:00
|
|
|
if (elm) {
|
|
|
|
elm->Disconnect();
|
|
|
|
}
|
2010-05-12 13:52:15 +04:00
|
|
|
mTabChildGlobal->mTabChild = nsnull;
|
2009-07-01 00:39:22 +04:00
|
|
|
}
|
|
|
|
|
2009-09-18 03:09:20 +04:00
|
|
|
bool
|
2010-07-19 22:33:33 +04:00
|
|
|
TabChild::RecvLoadURL(const nsCString& uri)
|
2009-07-01 00:39:22 +04:00
|
|
|
{
|
2009-07-30 01:12:15 +04:00
|
|
|
printf("loading %s, %d\n", uri.get(), NS_IsMainThread());
|
2009-07-01 00:39:22 +04:00
|
|
|
|
2009-10-28 05:01:38 +03:00
|
|
|
nsresult rv = mWebNav->LoadURI(NS_ConvertUTF8toUTF16(uri).get(),
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE,
|
|
|
|
NULL, NULL, NULL);
|
2009-10-28 23:41:46 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("mWebNav->LoadURI failed. Eating exception, what else can I do?");
|
|
|
|
}
|
2009-11-06 23:43:39 +03:00
|
|
|
|
2010-08-21 03:24:40 +04:00
|
|
|
return NS_SUCCEEDED(rv);
|
2009-07-01 00:39:22 +04:00
|
|
|
}
|
|
|
|
|
2009-09-18 03:09:20 +04:00
|
|
|
bool
|
2010-08-21 03:24:40 +04:00
|
|
|
TabChild::RecvShow(const nsIntSize& size)
|
2009-07-01 00:39:22 +04:00
|
|
|
{
|
2010-08-21 03:24:40 +04:00
|
|
|
printf("[TabChild] SHOW (w,h)= (%d, %d)\n", size.width, size.height);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(mWebNav);
|
|
|
|
if (!baseWindow) {
|
|
|
|
NS_ERROR("mWebNav doesn't QI to nsIBaseWindow");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
if (!InitWidget(size)) {
|
2010-08-21 03:24:40 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
baseWindow->InitWindow(0, mWidget,
|
|
|
|
0, 0, size.width, size.height);
|
2010-08-21 03:24:40 +04:00
|
|
|
baseWindow->Create();
|
|
|
|
baseWindow->SetVisibility(PR_TRUE);
|
|
|
|
|
|
|
|
// 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();
|
2009-07-01 00:39:22 +04:00
|
|
|
}
|
|
|
|
|
2009-09-18 03:09:20 +04:00
|
|
|
bool
|
2010-08-21 03:24:40 +04:00
|
|
|
TabChild::RecvMove(const nsIntSize& size)
|
2009-07-01 00:39:22 +04:00
|
|
|
{
|
2010-08-21 03:24:40 +04:00
|
|
|
printf("[TabChild] RESIZE to (w,h)= (%ud, %ud)\n", size.width, size.height);
|
2009-07-01 00:39:22 +04:00
|
|
|
|
2010-08-21 03:24:40 +04:00
|
|
|
mWidget->Resize(0, 0, size.width, size.height,
|
|
|
|
PR_TRUE);
|
2009-07-01 00:39:22 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(mWebNav);
|
2010-08-21 03:24:40 +04:00
|
|
|
baseWin->SetPositionAndSize(0, 0, size.width, size.height,
|
|
|
|
PR_TRUE);
|
2009-09-18 03:09:20 +04:00
|
|
|
return true;
|
2009-07-01 00:39:22 +04:00
|
|
|
}
|
2009-10-29 20:58:31 +03:00
|
|
|
|
2009-11-05 21:14:22 +03:00
|
|
|
bool
|
2010-07-19 22:33:33 +04:00
|
|
|
TabChild::RecvActivate()
|
2009-11-05 21:14:22 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebBrowserFocus> browser = do_QueryInterface(mWebNav);
|
|
|
|
browser->Activate();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-18 04:08:32 +04:00
|
|
|
bool TabChild::RecvDeactivate()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebBrowserFocus> browser = do_QueryInterface(mWebNav);
|
|
|
|
browser->Deactivate();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-11-05 21:21:09 +03:00
|
|
|
bool
|
2010-07-19 22:33:33 +04:00
|
|
|
TabChild::RecvMouseEvent(const nsString& aType,
|
|
|
|
const float& aX,
|
|
|
|
const float& aY,
|
|
|
|
const PRInt32& aButton,
|
|
|
|
const PRInt32& aClickCount,
|
|
|
|
const PRInt32& aModifiers,
|
|
|
|
const bool& aIgnoreRootScrollFrame)
|
2009-11-05 21:21:09 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mWebNav);
|
|
|
|
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(window);
|
|
|
|
NS_ENSURE_TRUE(utils, true);
|
|
|
|
utils->SendMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers,
|
|
|
|
aIgnoreRootScrollFrame);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-19 09:52:18 +03:00
|
|
|
bool
|
2010-07-19 22:33:33 +04:00
|
|
|
TabChild::RecvKeyEvent(const nsString& aType,
|
|
|
|
const PRInt32& aKeyCode,
|
|
|
|
const PRInt32& aCharCode,
|
|
|
|
const PRInt32& aModifiers,
|
|
|
|
const bool& aPreventDefault)
|
2010-03-19 09:52:18 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mWebNav);
|
|
|
|
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(window);
|
|
|
|
NS_ENSURE_TRUE(utils, true);
|
|
|
|
PRBool ignored = PR_FALSE;
|
|
|
|
utils->SendKeyEvent(aType, aKeyCode, aCharCode,
|
|
|
|
aModifiers, aPreventDefault, &ignored);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-17 12:07:42 +04:00
|
|
|
bool
|
|
|
|
TabChild::RecvCompositionEvent(const nsCompositionEvent& event)
|
|
|
|
{
|
|
|
|
nsCompositionEvent localEvent(event);
|
|
|
|
DispatchWidgetEvent(localEvent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TabChild::RecvTextEvent(const nsTextEvent& event)
|
|
|
|
{
|
|
|
|
nsTextEvent localEvent(event);
|
|
|
|
DispatchWidgetEvent(localEvent);
|
|
|
|
IPC::ParamTraits<nsTextEvent>::Free(event);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TabChild::RecvSelectionEvent(const nsSelectionEvent& event)
|
|
|
|
{
|
|
|
|
nsSelectionEvent localEvent(event);
|
|
|
|
DispatchWidgetEvent(localEvent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TabChild::DispatchWidgetEvent(nsGUIEvent& event)
|
|
|
|
{
|
2010-09-24 07:28:15 +04:00
|
|
|
if (!mWidget)
|
|
|
|
return false;
|
2010-08-17 12:07:42 +04:00
|
|
|
|
|
|
|
nsEventStatus status;
|
2010-09-24 07:28:15 +04:00
|
|
|
event.widget = mWidget;
|
|
|
|
NS_ENSURE_SUCCESS(mWidget->DispatchEvent(&event, status), false);
|
2010-08-17 12:07:42 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-27 02:20:53 +04:00
|
|
|
PDocumentRendererChild*
|
|
|
|
TabChild::AllocPDocumentRenderer(const nsRect& documentRect,
|
2010-10-27 02:20:53 +04:00
|
|
|
const gfxMatrix& transform,
|
2010-08-17 12:07:42 +04:00
|
|
|
const nsString& bgcolor,
|
2010-10-27 02:20:53 +04:00
|
|
|
const PRUint32& renderFlags,
|
2010-10-27 02:20:53 +04:00
|
|
|
const bool& flushLayout,
|
|
|
|
const nsIntSize& renderSize)
|
2009-10-29 20:58:31 +03:00
|
|
|
{
|
2010-10-27 02:20:53 +04:00
|
|
|
return new DocumentRendererChild();
|
2009-10-29 20:58:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-12-03 11:16:14 +03:00
|
|
|
TabChild::DeallocPDocumentRenderer(PDocumentRendererChild* actor)
|
2009-10-29 20:58:31 +03:00
|
|
|
{
|
2009-12-03 11:16:14 +03:00
|
|
|
delete actor;
|
2009-10-29 20:58:31 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-10-27 02:20:53 +04:00
|
|
|
TabChild::RecvPDocumentRendererConstructor(PDocumentRendererChild* actor,
|
|
|
|
const nsRect& documentRect,
|
2010-10-27 02:20:53 +04:00
|
|
|
const gfxMatrix& transform,
|
2010-10-27 02:20:53 +04:00
|
|
|
const nsString& bgcolor,
|
|
|
|
const PRUint32& renderFlags,
|
2010-10-27 02:20:53 +04:00
|
|
|
const bool& flushLayout,
|
|
|
|
const nsIntSize& renderSize)
|
2010-10-27 02:20:53 +04:00
|
|
|
{
|
|
|
|
DocumentRendererChild *render = static_cast<DocumentRendererChild *>(actor);
|
2009-10-29 20:58:31 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWebBrowser> browser = do_QueryInterface(mWebNav);
|
|
|
|
if (!browser)
|
|
|
|
return true; // silently ignore
|
|
|
|
nsCOMPtr<nsIDOMWindow> window;
|
|
|
|
if (NS_FAILED(browser->GetContentDOMWindow(getter_AddRefs(window))) ||
|
|
|
|
!window)
|
|
|
|
{
|
|
|
|
return true; // silently ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString data;
|
2010-10-27 02:20:53 +04:00
|
|
|
bool ret = render->RenderDocument(window,
|
2010-10-27 02:20:53 +04:00
|
|
|
documentRect, transform,
|
|
|
|
bgcolor,
|
2010-10-27 02:20:53 +04:00
|
|
|
renderFlags, flushLayout,
|
2010-10-27 02:20:53 +04:00
|
|
|
renderSize, data);
|
2009-10-29 20:58:31 +03:00
|
|
|
if (!ret)
|
|
|
|
return true; // silently ignore
|
|
|
|
|
2010-10-27 02:20:53 +04:00
|
|
|
return PDocumentRendererChild::Send__delete__(actor, renderSize, data);
|
2009-10-29 20:58:31 +03:00
|
|
|
}
|
2009-11-17 17:22:23 +03:00
|
|
|
|
2010-05-17 15:25:22 +04:00
|
|
|
PContentDialogChild*
|
|
|
|
TabChild::AllocPContentDialog(const PRUint32&,
|
|
|
|
const nsCString&,
|
|
|
|
const nsCString&,
|
2010-11-09 05:49:00 +03:00
|
|
|
const InfallibleTArray<int>&,
|
|
|
|
const InfallibleTArray<nsString>&)
|
2010-05-17 15:25:22 +04:00
|
|
|
{
|
|
|
|
return new ContentDialogChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TabChild::DeallocPContentDialog(PContentDialogChild* aDialog)
|
|
|
|
{
|
|
|
|
delete aDialog;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:00:08 +04:00
|
|
|
PContentPermissionRequestChild*
|
|
|
|
TabChild::AllocPContentPermissionRequest(const nsCString& aType, const IPC::URI&)
|
2010-05-13 21:44:51 +04:00
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("unused");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-09-10 09:00:08 +04:00
|
|
|
TabChild::DeallocPContentPermissionRequest(PContentPermissionRequestChild* actor)
|
2010-05-13 21:44:51 +04:00
|
|
|
{
|
2010-09-10 09:00:08 +04:00
|
|
|
static_cast<PCOMContentPermissionRequestChild*>(actor)->IPDLRelease();
|
|
|
|
return true;
|
2010-05-13 21:44:51 +04:00
|
|
|
}
|
|
|
|
|
2009-11-17 17:22:23 +03:00
|
|
|
bool
|
2010-07-19 22:33:33 +04:00
|
|
|
TabChild::RecvActivateFrameEvent(const nsString& aType, const bool& capture)
|
2009-11-17 17:22:23 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mWebNav);
|
|
|
|
NS_ENSURE_TRUE(window, true);
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> chromeHandler =
|
|
|
|
do_QueryInterface(window->GetChromeEventHandler());
|
|
|
|
NS_ENSURE_TRUE(chromeHandler, true);
|
|
|
|
nsRefPtr<ContentListener> listener = new ContentListener(this);
|
|
|
|
NS_ENSURE_TRUE(listener, true);
|
|
|
|
chromeHandler->AddEventListener(aType, listener, capture);
|
|
|
|
return true;
|
|
|
|
}
|
2010-02-20 20:05:20 +03:00
|
|
|
|
2010-10-20 21:12:32 +04:00
|
|
|
POfflineCacheUpdateChild*
|
|
|
|
TabChild::AllocPOfflineCacheUpdate(const URI& manifestURI,
|
|
|
|
const URI& documentURI,
|
|
|
|
const nsCString& clientID,
|
|
|
|
const bool& stickDocument)
|
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("unused");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TabChild::DeallocPOfflineCacheUpdate(POfflineCacheUpdateChild* actor)
|
|
|
|
{
|
|
|
|
OfflineCacheUpdateChild* offlineCacheUpdate = static_cast<OfflineCacheUpdateChild*>(actor);
|
|
|
|
delete offlineCacheUpdate;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-20 20:05:20 +03:00
|
|
|
bool
|
2010-07-19 22:33:33 +04:00
|
|
|
TabChild::RecvLoadRemoteScript(const nsString& aURL)
|
2010-02-20 20:05:20 +03:00
|
|
|
{
|
2010-08-24 21:01:28 +04:00
|
|
|
if (!mCx && !InitTabChildGlobal())
|
|
|
|
return false;
|
|
|
|
|
2010-08-18 14:02:49 +04:00
|
|
|
LoadFrameScriptInternal(aURL);
|
2010-02-20 20:05:20 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-07-19 22:33:33 +04:00
|
|
|
TabChild::RecvAsyncMessage(const nsString& aMessage,
|
|
|
|
const nsString& aJSON)
|
2010-02-20 20:05:20 +03:00
|
|
|
{
|
|
|
|
if (mTabChildGlobal) {
|
2011-06-16 22:21:08 +04:00
|
|
|
nsFrameScriptCx cx(static_cast<nsIWebBrowserChrome*>(this), this);
|
|
|
|
nsRefPtr<nsFrameMessageManager> mm =
|
|
|
|
static_cast<nsFrameMessageManager*>(mTabChildGlobal->mMessageManager.get());
|
2011-06-24 06:18:00 +04:00
|
|
|
mm->ReceiveMessage(static_cast<nsIDOMEventTarget*>(mTabChildGlobal),
|
2011-06-16 22:21:08 +04:00
|
|
|
aMessage, PR_FALSE, aJSON, nsnull, nsnull);
|
2010-02-20 20:05:20 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-12 20:47:22 +04:00
|
|
|
class UnloadScriptEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UnloadScriptEvent(TabChild* aTabChild, TabChildGlobal* aTabChildGlobal)
|
|
|
|
: mTabChild(aTabChild), mTabChildGlobal(aTabChildGlobal)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
NS_NewDOMEvent(getter_AddRefs(event), nsnull, nsnull);
|
|
|
|
if (event) {
|
|
|
|
event->InitEvent(NS_LITERAL_STRING("unload"), PR_FALSE, PR_FALSE);
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(event));
|
|
|
|
privateEvent->SetTrusted(PR_TRUE);
|
|
|
|
|
|
|
|
PRBool dummy;
|
|
|
|
mTabChildGlobal->DispatchEvent(event, &dummy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<TabChild> mTabChild;
|
|
|
|
TabChildGlobal* mTabChildGlobal;
|
|
|
|
};
|
|
|
|
|
2010-08-06 02:11:23 +04:00
|
|
|
bool
|
|
|
|
TabChild::RecvDestroy()
|
|
|
|
{
|
2010-08-12 20:47:22 +04:00
|
|
|
// Let the frame scripts know the child is being closed
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new UnloadScriptEvent(this, mTabChildGlobal)
|
|
|
|
);
|
2010-08-06 02:11:23 +04:00
|
|
|
|
2010-08-12 20:47:22 +04:00
|
|
|
// XXX what other code in ~TabChild() should we be running here?
|
2010-08-21 03:24:40 +04:00
|
|
|
DestroyWindow();
|
2010-08-06 02:11:23 +04:00
|
|
|
|
2010-08-12 20:47:22 +04:00
|
|
|
return Send__delete__(this);
|
2010-08-06 02:11:23 +04:00
|
|
|
}
|
2010-02-20 20:05:20 +03:00
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
PRenderFrameChild*
|
|
|
|
TabChild::AllocPRenderFrame()
|
|
|
|
{
|
|
|
|
return new RenderFrameChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TabChild::DeallocPRenderFrame(PRenderFrameChild* aFrame)
|
|
|
|
{
|
|
|
|
delete aFrame;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-20 20:05:20 +03:00
|
|
|
bool
|
|
|
|
TabChild::InitTabChildGlobal()
|
|
|
|
{
|
2010-08-24 21:01:28 +04:00
|
|
|
if (mCx && mTabChildGlobal)
|
|
|
|
return true;
|
|
|
|
|
2010-02-20 20:05:20 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mWebNav);
|
|
|
|
NS_ENSURE_TRUE(window, false);
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> chromeHandler =
|
|
|
|
do_QueryInterface(window->GetChromeEventHandler());
|
|
|
|
NS_ENSURE_TRUE(chromeHandler, false);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIJSRuntimeService> runtimeSvc =
|
|
|
|
do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
|
|
|
|
NS_ENSURE_TRUE(runtimeSvc, false);
|
|
|
|
|
|
|
|
JSRuntime* rt = nsnull;
|
|
|
|
runtimeSvc->GetRuntime(&rt);
|
|
|
|
NS_ENSURE_TRUE(rt, false);
|
|
|
|
|
|
|
|
JSContext* cx = JS_NewContext(rt, 8192);
|
|
|
|
NS_ENSURE_TRUE(cx, false);
|
|
|
|
|
|
|
|
mCx = cx;
|
|
|
|
|
|
|
|
nsContentUtils::XPConnect()->SetSecurityManagerForJSContext(cx, nsContentUtils::GetSecurityManager(), 0);
|
|
|
|
nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal));
|
|
|
|
|
2010-11-15 10:08:36 +03:00
|
|
|
JS_SetNativeStackQuota(cx, 128 * sizeof(size_t) * 1024);
|
2010-02-20 20:05:20 +03:00
|
|
|
|
2011-06-21 20:53:19 +04:00
|
|
|
JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_JIT | JSOPTION_PRIVATE_IS_NSISUPPORTS);
|
2010-02-24 13:04:06 +03:00
|
|
|
JS_SetVersion(cx, JSVERSION_LATEST);
|
2011-03-18 07:08:18 +03:00
|
|
|
JS_SetErrorReporter(cx, ContentScriptErrorReporter);
|
2011-01-15 01:03:21 +03:00
|
|
|
|
|
|
|
xpc_LocalizeContext(cx);
|
|
|
|
|
2010-02-20 20:05:20 +03:00
|
|
|
JSAutoRequest ar(cx);
|
|
|
|
nsIXPConnect* xpc = nsContentUtils::XPConnect();
|
|
|
|
const PRUint32 flags = nsIXPConnect::INIT_JS_STANDARD_CLASSES |
|
|
|
|
/*nsIXPConnect::OMIT_COMPONENTS_OBJECT ? |*/
|
|
|
|
nsIXPConnect::FLAG_SYSTEM_GLOBAL_OBJECT;
|
|
|
|
|
|
|
|
nsRefPtr<TabChildGlobal> scope = new TabChildGlobal(this);
|
|
|
|
NS_ENSURE_TRUE(scope, false);
|
|
|
|
|
|
|
|
mTabChildGlobal = scope;
|
|
|
|
|
|
|
|
nsISupports* scopeSupports =
|
2011-06-24 06:18:00 +04:00
|
|
|
NS_ISUPPORTS_CAST(nsIDOMEventTarget*, scope);
|
2010-02-20 20:05:20 +03:00
|
|
|
JS_SetContextPrivate(cx, scopeSupports);
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
xpc->InitClassesWithNewWrappedGlobal(cx, scopeSupports,
|
2010-07-20 00:36:49 +04:00
|
|
|
NS_GET_IID(nsISupports),
|
2010-10-27 10:57:31 +04:00
|
|
|
scope->GetPrincipal(), nsnull,
|
2010-08-18 14:02:49 +04:00
|
|
|
flags, getter_AddRefs(mGlobal));
|
2010-02-20 20:05:20 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(chromeHandler);
|
|
|
|
NS_ENSURE_TRUE(root, false);
|
|
|
|
root->SetParentTarget(scope);
|
|
|
|
|
|
|
|
JSObject* global = nsnull;
|
2010-08-18 14:02:49 +04:00
|
|
|
rv = mGlobal->GetJSObject(&global);
|
2010-02-20 20:05:20 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
JS_SetGlobalObject(cx, global);
|
2010-08-18 14:02:49 +04:00
|
|
|
DidCreateCx();
|
2010-02-20 20:05:20 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
bool
|
|
|
|
TabChild::InitWidget(const nsIntSize& size)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!mWidget && !mRemoteFrame, "CreateWidget twice?");
|
|
|
|
|
2010-09-24 07:28:15 +04:00
|
|
|
mWidget = nsIWidget::CreatePuppetWidget(this);
|
2010-08-21 03:24:41 +04:00
|
|
|
if (!mWidget) {
|
|
|
|
NS_ERROR("couldn't create fake widget");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mWidget->Create(
|
|
|
|
nsnull, 0, // no parents
|
|
|
|
nsIntRect(nsIntPoint(0, 0), size),
|
|
|
|
nsnull, // HandleWidgetEvent
|
2011-04-17 05:22:44 +04:00
|
|
|
nsnull // nsDeviceContext
|
2010-08-21 03:24:41 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
RenderFrameChild* remoteFrame =
|
|
|
|
static_cast<RenderFrameChild*>(SendPRenderFrameConstructor());
|
|
|
|
if (!remoteFrame) {
|
|
|
|
NS_WARNING("failed to construct RenderFrame");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(0 == remoteFrame->ManagedPLayersChild().Length(),
|
|
|
|
"shouldn't have a shadow manager yet");
|
|
|
|
PLayersChild* shadowManager = remoteFrame->SendPLayersConstructor();
|
|
|
|
if (!shadowManager) {
|
|
|
|
NS_WARNING("failed to construct LayersChild");
|
|
|
|
// This results in |remoteFrame| being deleted.
|
|
|
|
PRenderFrameChild::Send__delete__(remoteFrame);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerManager* lm = mWidget->GetLayerManager();
|
|
|
|
NS_ABORT_IF_FALSE(LayerManager::LAYERS_BASIC == lm->GetBackendType(),
|
|
|
|
"content processes should only be using BasicLayers");
|
|
|
|
|
|
|
|
BasicShadowLayerManager* bslm = static_cast<BasicShadowLayerManager*>(lm);
|
|
|
|
NS_ABORT_IF_FALSE(!bslm->HasShadowManager(),
|
|
|
|
"PuppetWidget shouldn't have shadow manager yet");
|
|
|
|
bslm->SetShadowManager(shadowManager);
|
|
|
|
|
|
|
|
mRemoteFrame = remoteFrame;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-19 22:33:33 +04:00
|
|
|
static bool
|
|
|
|
SendSyncMessageToParent(void* aCallbackData,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const nsAString& aJSON,
|
2010-11-09 05:49:00 +03:00
|
|
|
InfallibleTArray<nsString>* aJSONRetVal)
|
2010-02-20 20:05:20 +03:00
|
|
|
{
|
|
|
|
return static_cast<TabChild*>(aCallbackData)->
|
2010-07-19 22:33:33 +04:00
|
|
|
SendSyncMessage(nsString(aMessage), nsString(aJSON),
|
|
|
|
aJSONRetVal);
|
2010-02-20 20:05:20 +03:00
|
|
|
}
|
|
|
|
|
2010-07-19 22:33:33 +04:00
|
|
|
static bool
|
|
|
|
SendAsyncMessageToParent(void* aCallbackData,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const nsAString& aJSON)
|
2010-02-20 20:05:20 +03:00
|
|
|
{
|
|
|
|
return static_cast<TabChild*>(aCallbackData)->
|
2010-07-19 22:33:33 +04:00
|
|
|
SendAsyncMessage(nsString(aMessage), nsString(aJSON));
|
2010-02-20 20:05:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
TabChildGlobal::TabChildGlobal(TabChild* aTabChild)
|
|
|
|
: mTabChild(aTabChild)
|
|
|
|
{
|
|
|
|
mMessageManager = new nsFrameMessageManager(PR_FALSE,
|
|
|
|
SendSyncMessageToParent,
|
|
|
|
SendAsyncMessageToParent,
|
|
|
|
nsnull,
|
|
|
|
mTabChild,
|
|
|
|
nsnull,
|
|
|
|
aTabChild->GetJSContext());
|
|
|
|
}
|
|
|
|
|
2010-08-11 17:59:00 +04:00
|
|
|
TabChildGlobal::~TabChildGlobal()
|
|
|
|
{
|
|
|
|
if (mListenerManager) {
|
|
|
|
mListenerManager->Disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-20 20:05:20 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(TabChildGlobal)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TabChildGlobal,
|
|
|
|
nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mMessageManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(TabChildGlobal,
|
|
|
|
nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mMessageManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TabChildGlobal)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFrameMessageManager)
|
2010-08-31 22:58:35 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISyncMessageSender)
|
2010-02-20 20:05:20 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentFrameMessageManager)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptContextPrincipal)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ContentFrameMessageManager)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(TabChildGlobal, nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TabChildGlobal, nsDOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChildGlobal::GetContent(nsIDOMWindow** aContent)
|
|
|
|
{
|
|
|
|
*aContent = nsnull;
|
2010-07-22 03:23:03 +04:00
|
|
|
if (!mTabChild)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2010-02-20 20:05:20 +03:00
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_GetInterface(mTabChild->WebNavigation());
|
|
|
|
window.swap(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-24 16:58:21 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChildGlobal::PrivateNoteIntentionalCrash()
|
|
|
|
{
|
|
|
|
mozilla::NoteIntentionalCrash("tab");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-03 23:30:25 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TabChildGlobal::GetDocShell(nsIDocShell** aDocShell)
|
|
|
|
{
|
|
|
|
*aDocShell = nsnull;
|
2010-05-12 13:52:15 +04:00
|
|
|
if (!mTabChild)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2010-03-03 23:30:25 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(mTabChild->WebNavigation());
|
|
|
|
docShell.swap(*aDocShell);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-02-20 20:05:20 +03:00
|
|
|
JSContext*
|
|
|
|
TabChildGlobal::GetJSContextForEventHandlers()
|
|
|
|
{
|
2010-05-12 13:52:15 +04:00
|
|
|
if (!mTabChild)
|
|
|
|
return nsnull;
|
2010-02-20 20:05:20 +03:00
|
|
|
return mTabChild->GetJSContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal*
|
|
|
|
TabChildGlobal::GetPrincipal()
|
|
|
|
{
|
2010-05-12 13:52:15 +04:00
|
|
|
if (!mTabChild)
|
|
|
|
return nsnull;
|
2010-02-20 20:05:20 +03:00
|
|
|
return mTabChild->GetPrincipal();
|
|
|
|
}
|
2010-08-18 07:19:24 +04:00
|
|
|
|