Bug 813828 - Allow chrome code to launch Web Activities [r=mounir]
authorFabrice Desré <fabrice@mozilla.com>
Wed, 21 Nov 2012 15:36:49 -0800
changeset 113954 7ae5ff606cf2d57a6b758e88500749beaa425532
parent 113953 d00a4624190f4b04985e89eb3c79bbab292faad3
child 113955 5593cd83590e87069b4650421c7b3e309529f703
push id18468
push userfdesre@mozilla.com
push dateWed, 21 Nov 2012 23:36:57 +0000
treeherdermozilla-inbound@7ae5ff606cf2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir
bugs813828
milestone20.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 813828 - Allow chrome code to launch Web Activities [r=mounir]
dom/activities/src/Activity.cpp
--- a/dom/activities/src/Activity.cpp
+++ b/dom/activities/src/Activity.cpp
@@ -2,16 +2,17 @@
  * 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 "Activity.h"
 #include "nsDOMClassInfo.h"
 #include "nsContentUtils.h"
 #include "nsIDOMActivityOptions.h"
 #include "nsEventStateManager.h"
+#include "nsIConsoleService.h"
 
 using namespace mozilla::dom;
 
 #ifdef MOZ_SYS_MSG
 DOMCI_DATA(MozActivity, Activity)
 #endif
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Activity)
@@ -47,21 +48,33 @@ Activity::Initialize(nsISupports* aOwner
                      uint32_t aArgc,
                      JS::Value* aArgv)
 {
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aOwner);
   NS_ENSURE_TRUE(window, NS_ERROR_UNEXPECTED);
 
   Init(window);
 
-  if (!nsEventStateManager::IsHandlingUserInput()) {
+  nsCOMPtr<nsIDocument> document = do_QueryInterface(window->GetExtantDocument());
+
+  if (!nsEventStateManager::IsHandlingUserInput() &&
+      !nsContentUtils::IsChromeDoc(document)) {
     nsCOMPtr<nsIDOMRequestService> rs =
       do_GetService("@mozilla.org/dom/dom-request-service;1");
     rs->FireErrorAsync(static_cast<DOMRequest*>(this),
                        NS_LITERAL_STRING("NotUserInput"));
+
+    nsCOMPtr<nsIConsoleService> console(
+      do_GetService("@mozilla.org/consoleservice;1"));
+    NS_ENSURE_TRUE(console, NS_OK);
+
+    nsString message =
+      NS_LITERAL_STRING("Can start activity from non user input or chrome code");
+    console->LogStringMessage(message.get());
+
     return NS_OK;
   }
 
   // We expect a single argument, which is a nsIDOMMozActivityOptions.
   if (aArgc != 1 || !aArgv[0].isObject()) {
     return NS_ERROR_INVALID_ARG;
   }