Bug 926289 - Part 3, Carry recording type and request URL in recording-device-events in Camera API. r=mikeh.
authorShih-Chiang Chien <schien@mozilla.com>
Wed, 23 Oct 2013 19:11:18 +0800
changeset 166132 8f125ace663169b472dfb6f64fe3e0cdef963109
parent 166131 ddf19de28a0eafec4b804503828d0dd0b513f583
child 166133 eef27ae8eb3a8e185c89c99a82d36fdd9fc7ee1d
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikeh
bugs926289
milestone27.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 926289 - Part 3, Carry recording type and request URL in recording-device-events in Camera API. r=mikeh.
dom/camera/DOMCameraControl.cpp
dom/camera/DOMCameraControl.h
--- a/dom/camera/DOMCameraControl.cpp
+++ b/dom/camera/DOMCameraControl.cpp
@@ -1,24 +1,27 @@
 /* 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 "base/basictypes.h"
 #include "nsCOMPtr.h"
 #include "nsDOMClassInfo.h"
+#include "nsHashPropertyBag.h"
 #include "jsapi.h"
 #include "nsThread.h"
 #include "DeviceStorage.h"
 #include "mozilla/dom/CameraControlBinding.h"
-#include "mozilla/dom/ContentChild.h"
+#include "mozilla/dom/TabChild.h"
 #include "mozilla/Services.h"
 #include "mozilla/unused.h"
+#include "nsIAppsService.h"
 #include "nsIObserverService.h"
 #include "nsIDOMDeviceStorage.h"
+#include "nsIScriptSecurityManager.h"
 #include "nsXULAppAPI.h"
 #include "DOMCameraManager.h"
 #include "DOMCameraCapabilities.h"
 #include "DOMCameraControl.h"
 #include "CameraCommon.h"
 #include "mozilla/dom/CameraManagerBinding.h"
 #include "mozilla/dom/BindingUtils.h"
 
@@ -273,23 +276,26 @@ nsDOMCameraControl::StartRecording(JSCon
 
   nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   if (!obs) {
     NS_WARNING("Could not get the Observer service for CameraControl::StartRecording.");
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
-  obs->NotifyObservers(nullptr,
+  nsRefPtr<nsHashPropertyBag> props = CreateRecordingDeviceEventsSubject();
+  obs->NotifyObservers(static_cast<nsIPropertyBag2*>(props),
                        "recording-device-events",
                        NS_LITERAL_STRING("starting").get());
   // Forward recording events to parent process.
   // The events are gathered in chrome process and used for recording indicator
   if (XRE_GetProcessType() != GeckoProcessType_Default) {
-    unused << ContentChild::GetSingleton()->SendRecordingDeviceEvents(NS_LITERAL_STRING("starting"));
+    unused << TabChild::GetFrom(mWindow)->SendRecordingDeviceEvents(NS_LITERAL_STRING("starting"),
+                                                                    true /* isAudio */,
+                                                                    true /* isVideo */);
   }
 
   #ifdef MOZ_B2G
   if (!mAudioChannelAgent) {
     mAudioChannelAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1");
     if (mAudioChannelAgent) {
       // Camera app will stop recording when it falls to the background, so no callback is necessary.
       mAudioChannelAgent->Init(AUDIO_CHANNEL_CONTENT, nullptr);
@@ -313,23 +319,26 @@ void
 nsDOMCameraControl::StopRecording(ErrorResult& aRv)
 {
   nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   if (!obs) {
     NS_WARNING("Could not get the Observer service for CameraControl::StopRecording.");
     aRv.Throw(NS_ERROR_FAILURE);
   }
 
-  obs->NotifyObservers(nullptr,
+  nsRefPtr<nsHashPropertyBag> props = CreateRecordingDeviceEventsSubject();
+  obs->NotifyObservers(static_cast<nsIPropertyBag2*>(props) ,
                        "recording-device-events",
                        NS_LITERAL_STRING("shutdown").get());
   // Forward recording events to parent process.
   // The events are gathered in chrome process and used for recording indicator
   if (XRE_GetProcessType() != GeckoProcessType_Default) {
-    unused << ContentChild::GetSingleton()->SendRecordingDeviceEvents(NS_LITERAL_STRING("shutdown"));
+    unused << TabChild::GetFrom(mWindow)->SendRecordingDeviceEvents(NS_LITERAL_STRING("shutdown"),
+                                                                    true /* isAudio */,
+                                                                    true /* isVideo */);
   }
 
   #ifdef MOZ_B2G
   if (mAudioChannelAgent) {
     mAudioChannelAgent->StopPlaying();
     mAudioChannelAgent = nullptr;
   }
   #endif
@@ -519,8 +528,44 @@ nsDOMCameraControl::Shutdown()
   mCameraControl->Shutdown();
 }
 
 nsRefPtr<ICameraControl>
 nsDOMCameraControl::GetNativeCameraControl()
 {
   return mCameraControl;
 }
+
+already_AddRefed<nsHashPropertyBag>
+nsDOMCameraControl::CreateRecordingDeviceEventsSubject()
+{
+  MOZ_ASSERT(mWindow);
+
+  nsRefPtr<nsHashPropertyBag> props = new nsHashPropertyBag();
+  props->SetPropertyAsBool(NS_LITERAL_STRING("isAudio"), true);
+  props->SetPropertyAsBool(NS_LITERAL_STRING("isVideo"), true);
+
+  nsCOMPtr<nsIDocShell> docShell = mWindow->GetDocShell();
+  if (docShell) {
+    bool isApp;
+    DebugOnly<nsresult> rv = docShell->GetIsApp(&isApp);
+    MOZ_ASSERT(NS_SUCCEEDED(rv));
+
+    nsString requestURL;
+    if (isApp) {
+      rv = docShell->GetAppManifestURL(requestURL);
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
+    } else {
+      nsCString pageURL;
+      nsCOMPtr<nsIURI> docURI = mWindow->GetDocumentURI();
+      MOZ_ASSERT(docURI);
+
+      rv = docURI->GetSpec(pageURL);
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
+
+      requestURL = NS_ConvertUTF8toUTF16(pageURL);
+    }
+    props->SetPropertyAsBool(NS_LITERAL_STRING("isApp"), isApp);
+    props->SetPropertyAsAString(NS_LITERAL_STRING("requestURL"), requestURL);
+  }
+
+  return props.forget();
+}
--- a/dom/camera/DOMCameraControl.h
+++ b/dom/camera/DOMCameraControl.h
@@ -10,16 +10,17 @@
 #include "nsCycleCollectionParticipant.h"
 #include "DictionaryHelpers.h"
 #include "ICameraControl.h"
 #include "DOMCameraPreview.h"
 #include "nsIDOMCameraManager.h"
 #include "CameraCommon.h"
 #include "AudioChannelAgent.h"
 #include "nsProxyRelease.h"
+#include "nsHashPropertyBag.h"
 
 class nsDOMDeviceStorage;
 class nsPIDOMWindow;
 
 namespace mozilla {
 namespace dom {
 class CameraPictureOptions;
 template<typename T> class Optional;
@@ -94,16 +95,17 @@ public:
 protected:
   virtual ~nsDOMCameraControl();
 
 private:
   nsDOMCameraControl(const nsDOMCameraControl&) MOZ_DELETE;
   nsDOMCameraControl& operator=(const nsDOMCameraControl&) MOZ_DELETE;
 
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
+  already_AddRefed<nsHashPropertyBag> CreateRecordingDeviceEventsSubject();
 
 protected:
   /* additional members */
   nsRefPtr<ICameraControl>        mCameraControl; // non-DOM camera control
   nsCOMPtr<nsICameraCapabilities> mDOMCapabilities;
   // An agent used to join audio channel service.
   nsCOMPtr<nsIAudioChannelAgent>  mAudioChannelAgent;
   nsCOMPtr<nsPIDOMWindow> mWindow;