Bug 1492036 - Reporting API - part 3 - Deprecate reports, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 14 Nov 2018 20:02:33 +0100
changeset 446482 a86e9cde89bbbbb7b6d755a9daacf2e03dc5947e
parent 446481 a599388cbfe7515ea0b4e616c7bb2e60624c0072
child 446483 c200472121fd75104ec9deb50d03d57655f9e668
push id35042
push useraiakab@mozilla.com
push dateThu, 15 Nov 2018 09:54:38 +0000
treeherdermozilla-central@dca9c72df68b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1492036
milestone65.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 1492036 - Reporting API - part 3 - Deprecate reports, r=smaug
dom/bindings/BindingUtils.cpp
dom/reporting/DeprecationReportBody.cpp
dom/reporting/DeprecationReportBody.h
dom/reporting/ReportingUtils.cpp
dom/reporting/ReportingUtils.h
dom/reporting/moz.build
xpcom/ds/StaticAtoms.py
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -8,16 +8,17 @@
 
 #include <algorithm>
 #include <stdarg.h>
 
 #include "mozilla/Assertions.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/StaticPrefs.h"
 #include "mozilla/Unused.h"
 #include "mozilla/UseCounter.h"
 
 #include "AccessCheck.h"
 #include "js/JSON.h"
 #include "js/StableStringChars.h"
 #include "jsfriendapi.h"
 #include "nsContentCreatorFunctions.h"
@@ -38,23 +39,25 @@
 #include "XrayWrapper.h"
 #include "nsPrintfCString.h"
 #include "mozilla/Sprintf.h"
 #include "nsGlobalWindow.h"
 #include "nsReadableUtils.h"
 
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/CustomElementRegistry.h"
+#include "mozilla/dom/DeprecationReportBody.h"
 #include "mozilla/dom/DOMException.h"
 #include "mozilla/dom/ElementBinding.h"
 #include "mozilla/dom/HTMLObjectElement.h"
 #include "mozilla/dom/HTMLObjectElementBinding.h"
 #include "mozilla/dom/HTMLEmbedElement.h"
 #include "mozilla/dom/HTMLElementBinding.h"
 #include "mozilla/dom/HTMLEmbedElementBinding.h"
+#include "mozilla/dom/ReportingUtils.h"
 #include "mozilla/dom/XULElementBinding.h"
 #include "mozilla/dom/XULFrameElementBinding.h"
 #include "mozilla/dom/XULMenuElementBinding.h"
 #include "mozilla/dom/XULPopupElementBinding.h"
 #include "mozilla/dom/XULTextElementBinding.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/WebIDLGlobalNameHash.h"
 #include "mozilla/dom/WorkerPrivate.h"
@@ -2195,17 +2198,17 @@ GetCachedSlotStorageObjectSlow(JSContext
   if (!xpc::WrapperFactory::IsXrayWrapper(obj)) {
     JSObject* retval = js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false);
     MOZ_ASSERT(IsDOMObject(retval));
     *isXray = false;
     return retval;
   }
 
   *isXray = true;
-  return xpc::EnsureXrayExpandoObject(cx, obj);;
+  return xpc::EnsureXrayExpandoObject(cx, obj);
 }
 
 DEFINE_XRAY_EXPANDO_CLASS(, DefaultXrayExpandoObjectClass, 0);
 
 NativePropertyHooks sEmptyNativePropertyHooks = {
   nullptr,
   nullptr,
   nullptr,
@@ -4098,21 +4101,91 @@ SetDocumentAndPageUseCounter(JSObject* a
   nsGlobalWindowInner* win = xpc::WindowGlobalOrNull(js::UncheckedUnwrap(aObject));
   if (win && win->GetDocument()) {
     win->GetDocument()->SetDocumentAndPageUseCounter(aUseCounter);
   }
 }
 
 namespace {
 
+#define DEPRECATED_OPERATION(_op) #_op,
+static const char* kDeprecatedOperations[] = {
+#include "nsDeprecatedOperationList.h"
+  nullptr
+};
+#undef DEPRECATED_OPERATION
+
+void
+ReportDeprecation(nsPIDOMWindowInner* aWindow, nsIURI* aURI,
+                  nsIDocument::DeprecatedOperations aOperation,
+                  const nsAString& aFileName,
+                  const Nullable<uint32_t>& aLineNumber,
+                  const Nullable<uint32_t>& aColumnNumber)
+{
+  MOZ_ASSERT(aURI);
+
+  nsAutoCString spec;
+  nsresult rv = aURI->GetSpec(spec);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return;
+  }
+
+  nsAutoString type;
+  type.AssignASCII(kDeprecatedOperations[aOperation]);
+
+  nsAutoCString key;
+  key.AssignASCII(kDeprecatedOperations[aOperation]);
+  key.AppendASCII("Warning");
+
+  nsAutoString msg;
+  rv = nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES,
+                                          key.get(), msg);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return;
+  }
+
+  RefPtr<DeprecationReportBody> body =
+    new DeprecationReportBody(aWindow, type, Nullable<Date>(),
+                              msg, aFileName, aLineNumber, aColumnNumber);
+
+  ReportingUtils::Report(aWindow, nsGkAtoms::deprecation,
+                         NS_ConvertUTF8toUTF16(spec), body);
+}
+
+void
+MaybeReportDeprecation(nsPIDOMWindowInner* aWindow,
+                       nsIDocument::DeprecatedOperations aOperation,
+                       const nsAString& aFileName,
+                       const Nullable<uint32_t>& aLineNumber,
+                       const Nullable<uint32_t>& aColumnNumber)
+{
+  MOZ_ASSERT(aWindow);
+
+  if (!StaticPrefs::dom_reporting_enabled()) {
+    return;
+  }
+
+  if (NS_WARN_IF(!aWindow->GetExtantDoc())) {
+    return;
+  }
+
+  nsCOMPtr<nsIURI> uri = aWindow->GetExtantDoc()->GetDocumentURI();
+  if (NS_WARN_IF(!uri)) {
+    return;
+  }
+
+  ReportDeprecation(aWindow, uri, aOperation, aFileName, aLineNumber,
+                    aColumnNumber);
+}
+
 // This runnable is used to write a deprecation message from a worker to the
 // console running on the main-thread.
 class DeprecationWarningRunnable final : public WorkerProxyToMainThreadRunnable
 {
-  nsIDocument::DeprecatedOperations mOperation;
+  const nsIDocument::DeprecatedOperations mOperation;
 
 public:
   explicit DeprecationWarningRunnable(nsIDocument::DeprecatedOperations aOperation)
     : mOperation(aOperation)
   {}
 
 private:
   void
@@ -4156,16 +4229,31 @@ DeprecationWarning(JSContext* aCx, JSObj
 void
 DeprecationWarning(const GlobalObject& aGlobal,
                    nsIDocument::DeprecatedOperations aOperation)
 {
   if (NS_IsMainThread()) {
     nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
     if (window && window->GetExtantDoc()) {
       window->GetExtantDoc()->WarnOnceAbout(aOperation);
+
+      nsAutoCString fileName;
+      Nullable<uint32_t> lineNumber;
+      Nullable<uint32_t> columnNumber;
+      uint32_t line = 0;
+      uint32_t column = 0;
+      if (nsJSUtils::GetCallingLocation(aGlobal.Context(), fileName,
+                                        &line, &column)) {
+        lineNumber.SetValue(line);
+        columnNumber.SetValue(column);
+      }
+
+      MaybeReportDeprecation(window, aOperation,
+                             NS_ConvertUTF8toUTF16(fileName), lineNumber,
+                             columnNumber);
     }
 
     return;
   }
 
   WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aGlobal.Context());
   if (!workerPrivate) {
     return;
--- a/dom/reporting/DeprecationReportBody.cpp
+++ b/dom/reporting/DeprecationReportBody.cpp
@@ -7,21 +7,21 @@
 #include "mozilla/dom/DeprecationReportBody.h"
 #include "mozilla/dom/ReportingBinding.h"
 
 namespace mozilla {
 namespace dom {
 
 DeprecationReportBody::DeprecationReportBody(nsPIDOMWindowInner* aWindow,
                                              const nsAString& aId,
-                                             Nullable<Date> aDate,
+                                             const Nullable<Date>& aDate,
                                              const nsAString& aMessage,
                                              const nsAString& aSourceFile,
-                                             Nullable<uint32_t> aLineNumber,
-                                             Nullable<uint32_t> aColumnNumber)
+                                             const Nullable<uint32_t>& aLineNumber,
+                                             const Nullable<uint32_t>& aColumnNumber)
   : ReportBody(aWindow)
   , mId(aId)
   , mDate(aDate)
   , mMessage(aMessage)
   , mSourceFile(aSourceFile)
   , mLineNumber(aLineNumber)
   , mColumnNumber(aColumnNumber)
 {
--- a/dom/reporting/DeprecationReportBody.h
+++ b/dom/reporting/DeprecationReportBody.h
@@ -13,21 +13,21 @@
 namespace mozilla {
 namespace dom {
 
 class DeprecationReportBody final : public ReportBody
 {
 public:
   DeprecationReportBody(nsPIDOMWindowInner* aWindow,
                         const nsAString& aId,
-                        Nullable<Date> aDate,
+                        const Nullable<Date>& aDate,
                         const nsAString& aMessage,
                         const nsAString& aSourceFile,
-                        Nullable<uint32_t> aLineNumber,
-                        Nullable<uint32_t> aColumnNumber);
+                        const Nullable<uint32_t>& aLineNumber,
+                        const Nullable<uint32_t>& aColumnNumber);
 
   JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   void
   GetId(nsAString& aId) const;
 
   Nullable<Date>
new file mode 100644
--- /dev/null
+++ b/dom/reporting/ReportingUtils.cpp
@@ -0,0 +1,23 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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 "mozilla/dom/ReportingUtils.h"
+#include "mozilla/dom/ReportBody.h"
+
+namespace mozilla {
+namespace dom {
+
+/* static */ void
+ReportingUtils::Report(nsPIDOMWindowInner* aWindow,
+                       nsAtom* aType,
+                       const nsAString& aURL,
+                       ReportBody* aBody)
+{
+  // TODO
+}
+
+} // dom namespace
+} // mozilla namespace
new file mode 100644
--- /dev/null
+++ b/dom/reporting/ReportingUtils.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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/. */
+
+#ifndef mozilla_dom_ReportingUtils_h
+#define mozilla_dom_ReportingUtils_h
+
+#include "nsString.h"
+
+class nsIPDOMWindowInner;
+
+namespace mozilla {
+namespace dom {
+
+class ReportBody;
+
+class ReportingUtils final
+{
+public:
+  static void
+  Report(nsPIDOMWindowInner* aWindow,
+         nsAtom* aType,
+         const nsAString& aURL,
+         ReportBody* aBody);
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_ReportingUtils_h
--- a/dom/reporting/moz.build
+++ b/dom/reporting/moz.build
@@ -4,23 +4,25 @@
 # 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/.
 
 EXPORTS.mozilla.dom = [
     'DeprecationReportBody.h',
     'Report.h',
     'ReportBody.h',
     'ReportingObserver.h',
+    'ReportingUtils.h',
 ]
 
 UNIFIED_SOURCES += [
     'DeprecationReportBody.cpp',
     'Report.cpp',
     'ReportBody.cpp',
     'ReportingObserver.cpp',
+    'ReportingUtils.cpp',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 with Files('**'):
     BUG_COMPONENT = ('DOM', 'Security')
 
 FINAL_LIBRARY = 'xul'
--- a/xpcom/ds/StaticAtoms.py
+++ b/xpcom/ds/StaticAtoms.py
@@ -290,16 +290,17 @@ STATIC_ATOMS = [
     Atom("declare", "declare"),
     Atom("decoderDoctor", "decoder-doctor"),
     Atom("decoding", "decoding"),
     Atom("decrement", "decrement"),
     Atom("_default", "default"),
     Atom("headerDefaultStyle", "default-style"),
     Atom("defer", "defer"),
     Atom("del", "del"),
+    Atom("deprecation", "deprecation"),
     Atom("descendant", "descendant"),
     Atom("descendantOrSelf", "descendant-or-self"),
     Atom("descending", "descending"),
     Atom("description", "description"),
     Atom("destructor", "destructor"),
     Atom("details", "details"),
     Atom("deviceAspectRatio", "device-aspect-ratio"),
     Atom("deviceHeight", "device-height"),