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"
|
2014-06-11 19:38:55 +00:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
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)
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(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*
|
2014-04-08 22:27:18 +00:00
|
|
|
Activity::WrapObject(JSContext* aCx)
|
2013-03-17 08:51:36 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return MozActivityBinding::Wrap(aCx, this);
|
2013-03-17 08:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-06-11 19:38:55 +00:00
|
|
|
if (!ToJSValue(aCx, aOptions, &optionsValue)) {
|
2014-03-18 04:38:36 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|