1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/activities/src/Activity.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "Activity.h" 1.9 + 1.10 +#include "nsContentUtils.h" 1.11 +#include "nsDOMClassInfo.h" 1.12 +#include "nsIConsoleService.h" 1.13 +#include "nsIDocShell.h" 1.14 +#include "nsIDocument.h" 1.15 + 1.16 +using namespace mozilla::dom; 1.17 + 1.18 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Activity) 1.19 +NS_INTERFACE_MAP_END_INHERITING(DOMRequest) 1.20 + 1.21 +NS_IMPL_ADDREF_INHERITED(Activity, DOMRequest) 1.22 +NS_IMPL_RELEASE_INHERITED(Activity, DOMRequest) 1.23 + 1.24 +NS_IMPL_CYCLE_COLLECTION_INHERITED(Activity, DOMRequest, 1.25 + mProxy) 1.26 + 1.27 +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Activity, DOMRequest) 1.28 +NS_IMPL_CYCLE_COLLECTION_TRACE_END 1.29 + 1.30 +/* virtual */ JSObject* 1.31 +Activity::WrapObject(JSContext* aCx) 1.32 +{ 1.33 + return MozActivityBinding::Wrap(aCx, this); 1.34 +} 1.35 + 1.36 +nsresult 1.37 +Activity::Initialize(nsPIDOMWindow* aWindow, 1.38 + JSContext* aCx, 1.39 + const ActivityOptions& aOptions) 1.40 +{ 1.41 + MOZ_ASSERT(aWindow); 1.42 + 1.43 + nsCOMPtr<nsIDocument> document = aWindow->GetExtantDoc(); 1.44 + 1.45 + bool isActive; 1.46 + aWindow->GetDocShell()->GetIsActive(&isActive); 1.47 + 1.48 + if (!isActive && 1.49 + !nsContentUtils::IsChromeDoc(document)) { 1.50 + nsCOMPtr<nsIDOMRequestService> rs = 1.51 + do_GetService("@mozilla.org/dom/dom-request-service;1"); 1.52 + rs->FireErrorAsync(static_cast<DOMRequest*>(this), 1.53 + NS_LITERAL_STRING("NotUserInput")); 1.54 + 1.55 + nsCOMPtr<nsIConsoleService> console( 1.56 + do_GetService("@mozilla.org/consoleservice;1")); 1.57 + NS_ENSURE_TRUE(console, NS_OK); 1.58 + 1.59 + nsString message = 1.60 + NS_LITERAL_STRING("Can only start activity from user input or chrome code"); 1.61 + console->LogStringMessage(message.get()); 1.62 + 1.63 + return NS_OK; 1.64 + } 1.65 + 1.66 + // Instantiate a JS proxy that will do the child <-> parent communication 1.67 + // with the JS implementation of the backend. 1.68 + nsresult rv; 1.69 + mProxy = do_CreateInstance("@mozilla.org/dom/activities/proxy;1", &rv); 1.70 + NS_ENSURE_SUCCESS(rv, rv); 1.71 + 1.72 + JS::Rooted<JS::Value> optionsValue(aCx); 1.73 + if (!aOptions.ToObject(aCx, &optionsValue)) { 1.74 + return NS_ERROR_FAILURE; 1.75 + } 1.76 + 1.77 + mProxy->StartActivity(static_cast<nsIDOMDOMRequest*>(this), optionsValue, aWindow); 1.78 + return NS_OK; 1.79 +} 1.80 + 1.81 +Activity::~Activity() 1.82 +{ 1.83 + if (mProxy) { 1.84 + mProxy->Cleanup(); 1.85 + } 1.86 +} 1.87 + 1.88 +Activity::Activity(nsPIDOMWindow* aWindow) 1.89 + : DOMRequest(aWindow) 1.90 +{ 1.91 + MOZ_ASSERT(IsDOMBinding()); 1.92 +} 1.93 +