Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "Activity.h"
7 #include "nsContentUtils.h"
8 #include "nsDOMClassInfo.h"
9 #include "nsIConsoleService.h"
10 #include "nsIDocShell.h"
11 #include "nsIDocument.h"
13 using namespace mozilla::dom;
15 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Activity)
16 NS_INTERFACE_MAP_END_INHERITING(DOMRequest)
18 NS_IMPL_ADDREF_INHERITED(Activity, DOMRequest)
19 NS_IMPL_RELEASE_INHERITED(Activity, DOMRequest)
21 NS_IMPL_CYCLE_COLLECTION_INHERITED(Activity, DOMRequest,
22 mProxy)
24 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Activity, DOMRequest)
25 NS_IMPL_CYCLE_COLLECTION_TRACE_END
27 /* virtual */ JSObject*
28 Activity::WrapObject(JSContext* aCx)
29 {
30 return MozActivityBinding::Wrap(aCx, this);
31 }
33 nsresult
34 Activity::Initialize(nsPIDOMWindow* aWindow,
35 JSContext* aCx,
36 const ActivityOptions& aOptions)
37 {
38 MOZ_ASSERT(aWindow);
40 nsCOMPtr<nsIDocument> document = aWindow->GetExtantDoc();
42 bool isActive;
43 aWindow->GetDocShell()->GetIsActive(&isActive);
45 if (!isActive &&
46 !nsContentUtils::IsChromeDoc(document)) {
47 nsCOMPtr<nsIDOMRequestService> rs =
48 do_GetService("@mozilla.org/dom/dom-request-service;1");
49 rs->FireErrorAsync(static_cast<DOMRequest*>(this),
50 NS_LITERAL_STRING("NotUserInput"));
52 nsCOMPtr<nsIConsoleService> console(
53 do_GetService("@mozilla.org/consoleservice;1"));
54 NS_ENSURE_TRUE(console, NS_OK);
56 nsString message =
57 NS_LITERAL_STRING("Can only start activity from user input or chrome code");
58 console->LogStringMessage(message.get());
60 return NS_OK;
61 }
63 // Instantiate a JS proxy that will do the child <-> parent communication
64 // with the JS implementation of the backend.
65 nsresult rv;
66 mProxy = do_CreateInstance("@mozilla.org/dom/activities/proxy;1", &rv);
67 NS_ENSURE_SUCCESS(rv, rv);
69 JS::Rooted<JS::Value> optionsValue(aCx);
70 if (!aOptions.ToObject(aCx, &optionsValue)) {
71 return NS_ERROR_FAILURE;
72 }
74 mProxy->StartActivity(static_cast<nsIDOMDOMRequest*>(this), optionsValue, aWindow);
75 return NS_OK;
76 }
78 Activity::~Activity()
79 {
80 if (mProxy) {
81 mProxy->Cleanup();
82 }
83 }
85 Activity::Activity(nsPIDOMWindow* aWindow)
86 : DOMRequest(aWindow)
87 {
88 MOZ_ASSERT(IsDOMBinding());
89 }