2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-07-20 19:41:30 +04: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 23:38:55 +04:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2015-06-13 16:16:00 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2012-07-20 19:41:30 +04:00
|
|
|
#include "nsContentUtils.h"
|
2013-03-17 11:55:15 +04:00
|
|
|
#include "nsDOMClassInfo.h"
|
2012-11-22 03:36:49 +04:00
|
|
|
#include "nsIConsoleService.h"
|
2013-03-17 11:55:15 +04:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDocument.h"
|
2012-07-20 19:41:30 +04: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 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(Activity, DOMRequest,
|
|
|
|
mProxy)
|
2012-07-20 19:41:30 +04:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Activity, DOMRequest)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2013-03-17 12:51:36 +04: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 17:13:33 +03:00
|
|
|
Activity::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-03-17 12:51:36 +04: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 17:13:33 +03:00
|
|
|
return MozActivityBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-17 12:51:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-07 06:53:23 +04:00
|
|
|
Activity::Initialize(nsPIDOMWindow* aWindow,
|
2014-03-18 08:38:36 +04:00
|
|
|
JSContext* aCx,
|
|
|
|
const ActivityOptions& aOptions)
|
2012-07-20 19:41:30 +04:00
|
|
|
{
|
2014-01-07 06:53:23 +04:00
|
|
|
MOZ_ASSERT(aWindow);
|
2013-03-17 12:51:36 +04:00
|
|
|
|
2014-01-07 06:53:23 +04:00
|
|
|
nsCOMPtr<nsIDocument> document = aWindow->GetExtantDoc();
|
2012-11-22 03:36:49 +04:00
|
|
|
|
2012-11-27 20:40:18 +04:00
|
|
|
bool isActive;
|
2014-01-07 06:53:23 +04:00
|
|
|
aWindow->GetDocShell()->GetIsActive(&isActive);
|
2012-11-27 20:40:18 +04:00
|
|
|
|
|
|
|
if (!isActive &&
|
2012-11-22 03:36:49 +04:00
|
|
|
!nsContentUtils::IsChromeDoc(document)) {
|
2012-11-15 23:05:32 +04: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-22 03:36:49 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleService> console(
|
|
|
|
do_GetService("@mozilla.org/consoleservice;1"));
|
|
|
|
NS_ENSURE_TRUE(console, NS_OK);
|
|
|
|
|
|
|
|
nsString message =
|
2014-01-07 06:53:23 +04:00
|
|
|
NS_LITERAL_STRING("Can only start activity from user input or chrome code");
|
2012-11-22 03:36:49 +04:00
|
|
|
console->LogStringMessage(message.get());
|
|
|
|
|
2012-11-15 23:05:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-20 19:41:30 +04: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);
|
|
|
|
|
2015-05-20 22:18:09 +03:00
|
|
|
// We're about the pass the dictionary to a JS-implemented component, so
|
|
|
|
// rehydrate it in a system scode so that security wrappers don't get in the
|
|
|
|
// way. See bug 1161748 comment 16.
|
|
|
|
bool ok;
|
2014-03-18 08:38:36 +04:00
|
|
|
JS::Rooted<JS::Value> optionsValue(aCx);
|
2015-05-20 22:18:09 +03:00
|
|
|
{
|
|
|
|
JSAutoCompartment ac(aCx, xpc::PrivilegedJunkScope());
|
|
|
|
ok = ToJSValue(aCx, aOptions, &optionsValue);
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
|
2014-03-18 08:38:36 +04:00
|
|
|
}
|
2015-05-20 22:18:09 +03:00
|
|
|
ok = JS_WrapValue(aCx, &optionsValue);
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
|
2014-03-18 08:38:36 +04:00
|
|
|
|
2015-06-13 16:16:00 +03:00
|
|
|
ContentChild *cpc = ContentChild::GetSingleton();
|
|
|
|
uint64_t childID = cpc ? cpc->GetID() : 0;
|
|
|
|
|
|
|
|
mProxy->StartActivity(static_cast<nsIDOMDOMRequest*>(this), optionsValue,
|
|
|
|
aWindow, childID);
|
2012-07-20 19:41:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-21 17:59:48 +04:00
|
|
|
Activity::~Activity()
|
|
|
|
{
|
2012-07-20 19:41:30 +04:00
|
|
|
if (mProxy) {
|
|
|
|
mProxy->Cleanup();
|
|
|
|
}
|
|
|
|
}
|
2012-07-21 17:59:48 +04:00
|
|
|
|
2014-01-07 06:53:23 +04:00
|
|
|
Activity::Activity(nsPIDOMWindow* aWindow)
|
|
|
|
: DOMRequest(aWindow)
|
2012-07-21 17:59:48 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|