Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "Activity.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "nsContentUtils.h" |
michael@0 | 8 | #include "nsDOMClassInfo.h" |
michael@0 | 9 | #include "nsIConsoleService.h" |
michael@0 | 10 | #include "nsIDocShell.h" |
michael@0 | 11 | #include "nsIDocument.h" |
michael@0 | 12 | |
michael@0 | 13 | using namespace mozilla::dom; |
michael@0 | 14 | |
michael@0 | 15 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Activity) |
michael@0 | 16 | NS_INTERFACE_MAP_END_INHERITING(DOMRequest) |
michael@0 | 17 | |
michael@0 | 18 | NS_IMPL_ADDREF_INHERITED(Activity, DOMRequest) |
michael@0 | 19 | NS_IMPL_RELEASE_INHERITED(Activity, DOMRequest) |
michael@0 | 20 | |
michael@0 | 21 | NS_IMPL_CYCLE_COLLECTION_INHERITED(Activity, DOMRequest, |
michael@0 | 22 | mProxy) |
michael@0 | 23 | |
michael@0 | 24 | NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Activity, DOMRequest) |
michael@0 | 25 | NS_IMPL_CYCLE_COLLECTION_TRACE_END |
michael@0 | 26 | |
michael@0 | 27 | /* virtual */ JSObject* |
michael@0 | 28 | Activity::WrapObject(JSContext* aCx) |
michael@0 | 29 | { |
michael@0 | 30 | return MozActivityBinding::Wrap(aCx, this); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | nsresult |
michael@0 | 34 | Activity::Initialize(nsPIDOMWindow* aWindow, |
michael@0 | 35 | JSContext* aCx, |
michael@0 | 36 | const ActivityOptions& aOptions) |
michael@0 | 37 | { |
michael@0 | 38 | MOZ_ASSERT(aWindow); |
michael@0 | 39 | |
michael@0 | 40 | nsCOMPtr<nsIDocument> document = aWindow->GetExtantDoc(); |
michael@0 | 41 | |
michael@0 | 42 | bool isActive; |
michael@0 | 43 | aWindow->GetDocShell()->GetIsActive(&isActive); |
michael@0 | 44 | |
michael@0 | 45 | if (!isActive && |
michael@0 | 46 | !nsContentUtils::IsChromeDoc(document)) { |
michael@0 | 47 | nsCOMPtr<nsIDOMRequestService> rs = |
michael@0 | 48 | do_GetService("@mozilla.org/dom/dom-request-service;1"); |
michael@0 | 49 | rs->FireErrorAsync(static_cast<DOMRequest*>(this), |
michael@0 | 50 | NS_LITERAL_STRING("NotUserInput")); |
michael@0 | 51 | |
michael@0 | 52 | nsCOMPtr<nsIConsoleService> console( |
michael@0 | 53 | do_GetService("@mozilla.org/consoleservice;1")); |
michael@0 | 54 | NS_ENSURE_TRUE(console, NS_OK); |
michael@0 | 55 | |
michael@0 | 56 | nsString message = |
michael@0 | 57 | NS_LITERAL_STRING("Can only start activity from user input or chrome code"); |
michael@0 | 58 | console->LogStringMessage(message.get()); |
michael@0 | 59 | |
michael@0 | 60 | return NS_OK; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | // Instantiate a JS proxy that will do the child <-> parent communication |
michael@0 | 64 | // with the JS implementation of the backend. |
michael@0 | 65 | nsresult rv; |
michael@0 | 66 | mProxy = do_CreateInstance("@mozilla.org/dom/activities/proxy;1", &rv); |
michael@0 | 67 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 68 | |
michael@0 | 69 | JS::Rooted<JS::Value> optionsValue(aCx); |
michael@0 | 70 | if (!aOptions.ToObject(aCx, &optionsValue)) { |
michael@0 | 71 | return NS_ERROR_FAILURE; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | mProxy->StartActivity(static_cast<nsIDOMDOMRequest*>(this), optionsValue, aWindow); |
michael@0 | 75 | return NS_OK; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | Activity::~Activity() |
michael@0 | 79 | { |
michael@0 | 80 | if (mProxy) { |
michael@0 | 81 | mProxy->Cleanup(); |
michael@0 | 82 | } |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | Activity::Activity(nsPIDOMWindow* aWindow) |
michael@0 | 86 | : DOMRequest(aWindow) |
michael@0 | 87 | { |
michael@0 | 88 | MOZ_ASSERT(IsDOMBinding()); |
michael@0 | 89 | } |
michael@0 | 90 |