Bug 1356826: Part 4 - Add Cu.isInAutomation and Cu.crashIfNotInAutomation helpers. r=bholley
MozReview-Commit-ID: ADqVqF2XraG
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -524,16 +524,22 @@ interface nsIXPCComponents_Utils : nsISu
attribute boolean werror;
[implicit_jscontext]
attribute boolean strict_mode;
[implicit_jscontext]
attribute boolean ion;
+ // Returns true if we're running in automation and certain security
+ // restrictions can be eased.
+ readonly attribute boolean isInAutomation;
+
+ void crashIfNotInAutomation();
+
[implicit_jscontext]
void setGCZeal(in long zeal);
[implicit_jscontext]
void nukeSandbox(in jsval obj);
/*
* API to dynamically block script for a given global. This takes effect
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -2911,28 +2911,28 @@ nsXPCComponents_Utils::SetWantXrays(Hand
js::AllCompartments());
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::ForcePermissiveCOWs(JSContext* cx)
{
- CrashIfNotInAutomation();
+ xpc::CrashIfNotInAutomation();
CompartmentPrivate::Get(CurrentGlobalOrNull(cx))->forcePermissiveCOWs = true;
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::ForcePrivilegedComponentsForScope(HandleValue vscope,
JSContext* cx)
{
if (!vscope.isObject())
return NS_ERROR_INVALID_ARG;
- CrashIfNotInAutomation();
+ xpc::CrashIfNotInAutomation();
JSObject* scopeObj = js::UncheckedUnwrap(&vscope.toObject());
XPCWrappedNativeScope* scope = ObjectScope(scopeObj);
scope->ForcePrivilegedComponents();
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::GetComponentsForScope(HandleValue vscope, JSContext* cx,
@@ -3008,16 +3008,32 @@ nsXPCComponents_Utils::SetGCZeal(int32_t
{
#ifdef JS_GC_ZEAL
JS_SetGCZeal(cx, uint8_t(aValue), JS_DEFAULT_ZEAL_FREQ);
#endif
return NS_OK;
}
NS_IMETHODIMP
+nsXPCComponents_Utils::GetIsInAutomation(bool* aResult)
+{
+ NS_ENSURE_ARG_POINTER(aResult);
+
+ *aResult = xpc::IsInAutomation();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXPCComponents_Utils::CrashIfNotInAutomation()
+{
+ xpc::CrashIfNotInAutomation();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
nsXPCComponents_Utils::NukeSandbox(HandleValue obj, JSContext* cx)
{
PROFILER_LABEL_FUNC(js::ProfileEntry::Category::JS);
NS_ENSURE_TRUE(obj.isObject(), NS_ERROR_INVALID_ARG);
JSObject* wrapper = &obj.toObject();
NS_ENSURE_TRUE(IsWrapper(wrapper), NS_ERROR_INVALID_ARG);
RootedObject sb(cx, UncheckedUnwrap(wrapper));
NS_ENSURE_TRUE(IsSandbox(sb), NS_ERROR_INVALID_ARG);