Bug 1318471. Get rid of IsCallerChrome calls in scriptsettings code. r=bholley
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 18 Nov 2016 16:13:07 -0500
changeset 323492 f958c1dd30d0073fa48ae81ddde53eac379c4e20
parent 323491 26cf229b0fee1e44c2171324e1c5e2b8f349194a
child 323493 f1a8ad430beb91e91cd91f1331710219611ae61a
push id30978
push usercbook@mozilla.com
push dateMon, 21 Nov 2016 14:44:46 +0000
treeherdermozilla-central@0534254e9a40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1318471
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1318471. Get rid of IsCallerChrome calls in scriptsettings code. r=bholley
dom/base/ScriptSettings.cpp
dom/base/nsContentUtils.h
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -540,17 +540,17 @@ WarningOnlyErrorReporter(JSContext* aCx,
   RefPtr<xpc::ErrorReport> xpcReport = new xpc::ErrorReport();
   nsGlobalWindow* win = xpc::CurrentWindowOrNull(aCx);
   if (!win) {
     // We run addons in a separate privileged compartment, but if we're in an
     // addon compartment we should log warnings to the console of the associated
     // DOM Window.
     win = xpc::AddonWindowOrNull(JS::CurrentGlobalOrNull(aCx));
   }
-  xpcReport->Init(aRep, nullptr, nsContentUtils::IsCallerChrome(),
+  xpcReport->Init(aRep, nullptr, nsContentUtils::IsSystemCaller(aCx),
                   win ? win->AsInner()->WindowID() : 0);
   xpcReport->LogToConsole();
 }
 
 void
 AutoJSAPI::ReportException()
 {
   if (!HasException()) {
@@ -580,18 +580,20 @@ AutoJSAPI::ReportException()
 
       RefPtr<nsGlobalWindow> win = xpc::WindowGlobalOrNull(errorGlobal);
       if (!win) {
         // We run addons in a separate privileged compartment, but they still
         // expect to trigger the onerror handler of their associated DOM Window.
         win = xpc::AddonWindowOrNull(errorGlobal);
       }
       nsPIDOMWindowInner* inner = win ? win->AsInner() : nullptr;
+      bool isChrome = nsContentUtils::IsSystemPrincipal(
+        nsContentUtils::ObjectPrincipal(errorGlobal));
       xpcReport->Init(jsReport.report(), jsReport.toStringResult().c_str(),
-                      nsContentUtils::IsCallerChrome(),
+                      isChrome,
                       inner ? inner->WindowID() : 0);
       if (inner && jsReport.report()->errorNumber != JSMSG_OUT_OF_MEMORY) {
         JS::RootingContext* rcx = JS::RootingContext::get(cx());
         DispatchScriptErrorEvent(inner, rcx, xpcReport, exn);
       } else {
         JS::Rooted<JSObject*> stack(cx(),
           xpc::FindExceptionStackForConsoleReport(inner, exn));
         xpcReport->LogToConsoleWithStack(stack);
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -200,17 +200,17 @@ public:
   static bool     IsCallerContentXBL();
 
   // The APIs for checking whether the caller is system (in the sense of system
   // principal) should only be used when the JSContext is known to accurately
   // represent the caller.  In practice, that means you should only use them in
   // two situations at the moment:
   //
   // 1) Functions used in WebIDL Func annotations.
-  // 2) Bindings code.
+  // 2) Bindings code or other code called directly from the JS engine.
   //
   // Use pretty much anywhere else is almost certainly wrong and should be
   // replaced with [NeedsCallerType] annotations in bindings.
 
   // Check whether the caller is system if you know you're on the main thread.
   static bool IsSystemCaller(JSContext* aCx);
 
   // Check whether the caller is system if you might be on a worker thread.