Bug 947132 - [RTSP] Replace system message by activity for rtsp loading. r=fabrice, a=1.3+
authorEthan Tseng <ettseng@mozilla.com>
Sat, 07 Dec 2013 15:24:02 +0800
changeset 175208 9f562482c0c42be613b2624bfd4bdfec3620fd97
parent 175207 fa19b7565b4806b694939f70c88126672f086cb1
child 175209 a343a740c4b6d4597e63969f78da8f667ee6b5e9
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice, 1
bugs947132
milestone28.0a2
Bug 947132 - [RTSP] Replace system message by activity for rtsp loading. r=fabrice, a=1.3+
dom/messages/SystemMessagePermissionsChecker.jsm
uriloader/exthandler/nsExternalHelperAppService.cpp
--- a/dom/messages/SystemMessagePermissionsChecker.jsm
+++ b/dom/messages/SystemMessagePermissionsChecker.jsm
@@ -105,17 +105,16 @@ this.SystemMessagePermissionsTable = {
     "nfc-manager": []
   },
   "nfc-manager-tech-lost": {
     "nfc-manager": []
   },
   "nfc-powerlevel-change": {
     "settings": ["read", "write"]
   },
-  "rtsp-open-video": {},
 };
 
 this.SystemMessagePermissionsChecker = {
   /**
    * Return all the needed permission names for the given system message.
    * @param string aSysMsgName
    *        The system messsage name.
    * @returns object
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -116,17 +116,18 @@
 #include "mozilla/Preferences.h"
 #include "mozilla/ipc/URIUtils.h"
 
 #ifdef MOZ_WIDGET_GONK
 #include "nsDeviceStorage.h"
 #endif
 
 #ifdef NECKO_PROTOCOL_rtsp
-#include "nsISystemMessagesInternal.h"
+#include "nsIScriptSecurityManager.h"
+#include "nsIMessageManager.h"
 #endif
 
 using namespace mozilla;
 using namespace mozilla::ipc;
 
 // Buffer file writes in 32kb chunks
 #define BUFFERED_OUTPUT_SIZE (1024 * 32)
 
@@ -600,70 +601,69 @@ public:
     JS_ClearPendingException(mCx);
   }
 private:
   JSContext *mCx;
 };
 } // anonymous namespace
 
 /**
- * This function broadcasts a system message in order to launch video app for
- * rtsp scheme. This is Gonk-specific behavior.
+ * This function sends a message. This 'content-handler' message is handled in
+ * b2g/chrome/content/shell.js where it starts an activity request that will
+ * open the video app.
  */
 void nsExternalHelperAppService::LaunchVideoAppForRtsp(nsIURI* aURI)
 {
-  NS_NAMED_LITERAL_STRING(msgType, "rtsp-open-video");
+  bool rv;
 
-  // Make the url is rtsp.
-  bool isRTSP = false;
-  aURI->SchemeIs("rtsp", &isRTSP);
-  NS_ASSERTION(isRTSP, "Not rtsp protocol! Something goes wrong here");
+  // Get a system principal.
+  nsCOMPtr<nsIScriptSecurityManager> securityManager =
+    do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
+  NS_ENSURE_TRUE_VOID(securityManager);
 
-  // Construct jsval for system message.
+  nsCOMPtr<nsIPrincipal> principal;
+  securityManager->GetSystemPrincipal(getter_AddRefs(principal));
+  NS_ENSURE_TRUE_VOID(principal);
+
+  // Construct the message in jsVal format.
   AutoSafeJSContext cx;
   AutoClearPendingException helper(cx);
   JS::Rooted<JSObject*> msgObj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr));
   NS_ENSURE_TRUE_VOID(msgObj);
   JS::Rooted<JS::Value> jsVal(cx);
-  bool rv;
-
-  // Set the "url" and "title" properties of the message.
-  // In the case of RTSP streaming, the title is the same as the url.
-  {
-    nsAutoCString spec;
-    aURI->GetAsciiSpec(spec);
-    JSString *urlStr = JS_NewStringCopyN(cx, spec.get(), spec.Length());
-    NS_ENSURE_TRUE_VOID(urlStr);
-    jsVal.setString(urlStr);
-
-    rv = JS_SetProperty(cx, msgObj, "url", jsVal);
-    NS_ENSURE_TRUE_VOID(rv);
-
-    rv = JS_SetProperty(cx, msgObj, "title", jsVal);
-    NS_ENSURE_TRUE_VOID(rv);
-  }
 
   // Set the "type" property of the message. This is a fake MIME type.
   {
     NS_NAMED_LITERAL_CSTRING(mimeType, "video/rtsp");
     JSString *typeStr = JS_NewStringCopyN(cx, mimeType.get(), mimeType.Length());
     NS_ENSURE_TRUE_VOID(typeStr);
     jsVal.setString(typeStr);
+    rv = JS_SetProperty(cx, msgObj, "type", jsVal);
+    NS_ENSURE_TRUE_VOID(rv);
   }
-  rv = JS_SetProperty(cx, msgObj, "type", jsVal);
-  NS_ENSURE_TRUE_VOID(rv);
+  // Set the "url" and "title" properties of the message.
+  // They are the same in the case of RTSP streaming.
+  {
+    nsAutoCString spec;
+    aURI->GetSpec(spec);
+    JSString *urlStr = JS_NewStringCopyN(cx, spec.get(), spec.Length());
+    NS_ENSURE_TRUE_VOID(urlStr);
+    jsVal.setString(urlStr);
+    rv = JS_SetProperty(cx, msgObj, "url", jsVal);
+    NS_ENSURE_TRUE_VOID(rv);
+    rv = JS_SetProperty(cx, msgObj, "title", jsVal);
+  }
+  jsVal.setObject(*msgObj);
 
-  // Broadcast system message.
-  nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
-    do_GetService("@mozilla.org/system-message-internal;1");
-  NS_ENSURE_TRUE_VOID(systemMessenger);
-  jsVal.setObject(*msgObj);
-  systemMessenger->BroadcastMessage(msgType, jsVal, JS::UndefinedValue());
-
-  return;
+  // Send the message.
+  nsCOMPtr<nsIMessageSender> cpmm =
+    do_GetService("@mozilla.org/childprocessmessagemanager;1");
+  NS_ENSURE_TRUE_VOID(cpmm);
+  cpmm->SendAsyncMessage(NS_LITERAL_STRING("content-handler"),
+    jsVal, JSVAL_NULL, principal, cx, 2);
 }
 #endif
 
 NS_IMETHODIMP nsExternalHelperAppService::DoContent(const nsACString& aMimeContentType,
                                                     nsIRequest *aRequest,
                                                     nsIInterfaceRequestor *aWindowContext,
                                                     bool aForceSave,
                                                     nsIStreamListener ** aStreamListener)