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"
|
2013-03-17 07:55:15 +00:00
|
|
|
|
2012-07-20 15:41:30 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-03-17 07:55:15 +00:00
|
|
|
#include "nsDOMClassInfo.h"
|
2012-11-21 23:36:49 +00:00
|
|
|
#include "nsIConsoleService.h"
|
2013-03-17 07:55:15 +00:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDocument.h"
|
2012-07-20 15:41:30 +00:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Activity)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMRequest)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(Activity, DOMRequest)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(Activity, DOMRequest)
|
|
|
|
|
2012-12-02 08:54:37 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED_1(Activity, DOMRequest,
|
|
|
|
mProxy)
|
2012-07-20 15:41:30 +00:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Activity, DOMRequest)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2013-03-17 08:51:36 +00:00
|
|
|
/* virtual */ JSObject*
|
2013-04-25 16:29:54 +00:00
|
|
|
Activity::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
2013-03-17 08:51:36 +00:00
|
|
|
{
|
|
|
|
return MozActivityBinding::Wrap(aCx, aScope, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-07 02:53:23 +00:00
|
|
|
Activity::Initialize(nsPIDOMWindow* aWindow,
|
2014-03-18 04:38:36 +00:00
|
|
|
JSContext* aCx,
|
|
|
|
const ActivityOptions& aOptions)
|
2012-07-20 15:41:30 +00:00
|
|
|
{
|
2014-01-07 02:53:23 +00:00
|
|
|
MOZ_ASSERT(aWindow);
|
2013-03-17 08:51:36 +00:00
|
|
|
|
2014-01-07 02:53:23 +00:00
|
|
|
nsCOMPtr<nsIDocument> document = aWindow->GetExtantDoc();
|
2012-11-21 23:36:49 +00:00
|
|
|
|
2012-11-27 16:40:18 +00:00
|
|
|
bool isActive;
|
2014-01-07 02:53:23 +00:00
|
|
|
aWindow->GetDocShell()->GetIsActive(&isActive);
|
2012-11-27 16:40:18 +00:00
|
|
|
|
|
|
|
if (!isActive &&
|
2012-11-21 23:36:49 +00:00
|
|
|
!nsContentUtils::IsChromeDoc(document)) {
|
2012-11-15 19:05:32 +00:00
|
|
|
nsCOMPtr<nsIDOMRequestService> rs =
|
|
|
|
do_GetService("@mozilla.org/dom/dom-request-service;1");
|
|
|
|
rs->FireErrorAsync(static_cast<DOMRequest*>(this),
|
|
|
|
NS_LITERAL_STRING("NotUserInput"));
|
2012-11-21 23:36:49 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleService> console(
|
|
|
|
do_GetService("@mozilla.org/consoleservice;1"));
|
|
|
|
NS_ENSURE_TRUE(console, NS_OK);
|
|
|
|
|
|
|
|
nsString message =
|
2014-01-07 02:53:23 +00:00
|
|
|
NS_LITERAL_STRING("Can only start activity from user input or chrome code");
|
2012-11-21 23:36:49 +00:00
|
|
|
console->LogStringMessage(message.get());
|
|
|
|
|
2012-11-15 19:05:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-20 15:41:30 +00:00
|
|
|
// 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);
|
|
|
|
|
2014-03-18 04:38:36 +00:00
|
|
|
JS::Rooted<JS::Value> optionsValue(aCx);
|
|
|
|
if (!aOptions.ToObject(aCx, JS::NullPtr(), &optionsValue)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProxy->StartActivity(static_cast<nsIDOMDOMRequest*>(this), optionsValue, aWindow);
|
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
|
|
|
|
2014-01-07 02:53:23 +00:00
|
|
|
Activity::Activity(nsPIDOMWindow* aWindow)
|
|
|
|
: DOMRequest(aWindow)
|
2012-07-21 13:59:48 +00:00
|
|
|
{
|
2013-03-17 08:51:36 +00:00
|
|
|
MOZ_ASSERT(IsDOMBinding());
|
2012-07-21 13:59:48 +00:00
|
|
|
}
|
|
|
|
|