2012-07-20 15:41:30 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "Activity.h"
|
|
|
|
#include "nsDOMClassInfo.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIDOMActivityOptions.h"
|
2012-11-15 19:05:32 +00:00
|
|
|
#include "nsEventStateManager.h"
|
2012-07-20 15:41:30 +00:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2012-11-05 15:20:03 +00:00
|
|
|
#ifdef MOZ_SYS_MSG
|
2012-07-20 15:41:30 +00:00
|
|
|
DOMCI_DATA(MozActivity, Activity)
|
2012-11-05 15:20:03 +00:00
|
|
|
#endif
|
2012-07-20 15:41:30 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Activity)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozActivity)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
|
2012-11-05 15:20:03 +00:00
|
|
|
#ifdef MOZ_SYS_MSG
|
2012-07-20 15:41:30 +00:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozActivity)
|
2012-11-05 15:20:03 +00:00
|
|
|
#endif
|
2012-07-20 15:41:30 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMRequest)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(Activity, DOMRequest)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(Activity, DOMRequest)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Activity)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Activity,
|
|
|
|
DOMRequest)
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mProxy)
|
2012-07-20 15:41:30 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Activity,
|
|
|
|
DOMRequest)
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mProxy)
|
2012-07-20 15:41:30 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Activity, DOMRequest)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Activity::Initialize(nsISupports* aOwner,
|
|
|
|
JSContext* aContext,
|
|
|
|
JSObject* aObject,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aArgc,
|
2012-07-20 15:41:30 +00:00
|
|
|
JS::Value* aArgv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aOwner);
|
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
Init(window);
|
|
|
|
|
2012-11-15 19:05:32 +00:00
|
|
|
if (!nsEventStateManager::IsHandlingUserInput()) {
|
|
|
|
nsCOMPtr<nsIDOMRequestService> rs =
|
|
|
|
do_GetService("@mozilla.org/dom/dom-request-service;1");
|
|
|
|
rs->FireErrorAsync(static_cast<DOMRequest*>(this),
|
|
|
|
NS_LITERAL_STRING("NotUserInput"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-20 15:41:30 +00:00
|
|
|
// We expect a single argument, which is a nsIDOMMozActivityOptions.
|
|
|
|
if (aArgc != 1 || !aArgv[0].isObject()) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2012-07-21 13:59:48 +00:00
|
|
|
|
2012-07-20 15:41:30 +00:00
|
|
|
nsCOMPtr<nsISupports> tmp;
|
|
|
|
nsContentUtils::XPConnect()->WrapJS(aContext, aArgv[0].toObjectOrNull(),
|
|
|
|
NS_GET_IID(nsIDOMMozActivityOptions),
|
|
|
|
getter_AddRefs(tmp));
|
|
|
|
nsCOMPtr<nsIDOMMozActivityOptions> options = do_QueryInterface(tmp);
|
|
|
|
if (!options) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instantiate a JS proxy that will do the child <-> parent communication
|
|
|
|
// with the JS implementation of the backend.
|
|
|
|
nsresult rv;
|
|
|
|
mProxy = do_CreateInstance("@mozilla.org/dom/activities/proxy;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-25 04:07:58 +00:00
|
|
|
mProxy->StartActivity(this, options, window);
|
2012-07-20 15:41:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-21 13:59:48 +00:00
|
|
|
Activity::~Activity()
|
|
|
|
{
|
2012-07-20 15:41:30 +00:00
|
|
|
if (mProxy) {
|
|
|
|
mProxy->Cleanup();
|
|
|
|
}
|
|
|
|
}
|
2012-07-21 13:59:48 +00:00
|
|
|
|
|
|
|
Activity::Activity()
|
|
|
|
: DOMRequest()
|
|
|
|
{
|
|
|
|
// Unfortunately we must explicitly declare the default constructor in order
|
|
|
|
// to prevent an implicitly deleted constructor in DOMRequest compile error
|
|
|
|
// in GCC 4.6.
|
|
|
|
}
|
|
|
|
|