2012-07-20 17:41:30 +02: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 22:38:55 +03:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2012-07-20 17:41:30 +02:00
|
|
|
#include "nsContentUtils.h"
|
2013-03-17 08:55:15 +01:00
|
|
|
#include "nsDOMClassInfo.h"
|
2012-11-21 15:36:49 -08:00
|
|
|
#include "nsIConsoleService.h"
|
2013-03-17 08:55:15 +01:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDocument.h"
|
2012-07-20 17:41:30 +02: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 12:49:00 -04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(Activity, DOMRequest,
|
|
|
|
mProxy)
|
2012-07-20 17:41:30 +02:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Activity, DOMRequest)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2013-03-17 09:51:36 +01:00
|
|
|
/* virtual */ JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 10:13:33 -04:00
|
|
|
Activity::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-03-17 09:51:36 +01:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 10:13:33 -04:00
|
|
|
return MozActivityBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-17 09:51:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-06 21:53:23 -05:00
|
|
|
Activity::Initialize(nsPIDOMWindow* aWindow,
|
2014-03-18 00:38:36 -04:00
|
|
|
JSContext* aCx,
|
|
|
|
const ActivityOptions& aOptions)
|
2012-07-20 17:41:30 +02:00
|
|
|
{
|
2014-01-06 21:53:23 -05:00
|
|
|
MOZ_ASSERT(aWindow);
|
2013-03-17 09:51:36 +01:00
|
|
|
|
2014-01-06 21:53:23 -05:00
|
|
|
nsCOMPtr<nsIDocument> document = aWindow->GetExtantDoc();
|
2012-11-21 15:36:49 -08:00
|
|
|
|
2012-11-27 08:40:18 -08:00
|
|
|
bool isActive;
|
2014-01-06 21:53:23 -05:00
|
|
|
aWindow->GetDocShell()->GetIsActive(&isActive);
|
2012-11-27 08:40:18 -08:00
|
|
|
|
|
|
|
if (!isActive &&
|
2012-11-21 15:36:49 -08: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 15:36:49 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleService> console(
|
|
|
|
do_GetService("@mozilla.org/consoleservice;1"));
|
|
|
|
NS_ENSURE_TRUE(console, NS_OK);
|
|
|
|
|
|
|
|
nsString message =
|
2014-01-06 21:53:23 -05:00
|
|
|
NS_LITERAL_STRING("Can only start activity from user input or chrome code");
|
2012-11-21 15:36:49 -08:00
|
|
|
console->LogStringMessage(message.get());
|
|
|
|
|
2012-11-15 19:05:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-20 17:41:30 +02: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 00:38:36 -04:00
|
|
|
JS::Rooted<JS::Value> optionsValue(aCx);
|
2014-06-11 22:38:55 +03:00
|
|
|
if (!ToJSValue(aCx, aOptions, &optionsValue)) {
|
2014-03-18 00:38:36 -04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProxy->StartActivity(static_cast<nsIDOMDOMRequest*>(this), optionsValue, aWindow);
|
2012-07-20 17:41:30 +02:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-21 09:59:48 -04:00
|
|
|
Activity::~Activity()
|
|
|
|
{
|
2012-07-20 17:41:30 +02:00
|
|
|
if (mProxy) {
|
|
|
|
mProxy->Cleanup();
|
|
|
|
}
|
|
|
|
}
|
2012-07-21 09:59:48 -04:00
|
|
|
|
2014-01-06 21:53:23 -05:00
|
|
|
Activity::Activity(nsPIDOMWindow* aWindow)
|
|
|
|
: DOMRequest(aWindow)
|
2012-07-21 09:59:48 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|