1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/hal/WindowIdentifier.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set sw=2 ts=8 et ft=cpp : */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "mozilla/dom/ContentChild.h" 1.11 +#include "WindowIdentifier.h" 1.12 +#include "nsPIDOMWindow.h" 1.13 + 1.14 +namespace mozilla { 1.15 +namespace hal { 1.16 + 1.17 +WindowIdentifier::WindowIdentifier() 1.18 + : mWindow(nullptr) 1.19 + , mIsEmpty(true) 1.20 +{ 1.21 +} 1.22 + 1.23 +WindowIdentifier::WindowIdentifier(nsIDOMWindow *window) 1.24 + : mWindow(window) 1.25 + , mIsEmpty(false) 1.26 +{ 1.27 + mID.AppendElement(GetWindowID()); 1.28 +} 1.29 + 1.30 +WindowIdentifier::WindowIdentifier(const InfallibleTArray<uint64_t> &id, nsIDOMWindow *window) 1.31 + : mID(id) 1.32 + , mWindow(window) 1.33 + , mIsEmpty(false) 1.34 +{ 1.35 + mID.AppendElement(GetWindowID()); 1.36 +} 1.37 + 1.38 +WindowIdentifier::WindowIdentifier(const WindowIdentifier &other) 1.39 + : mID(other.mID) 1.40 + , mWindow(other.mWindow) 1.41 + , mIsEmpty(other.mIsEmpty) 1.42 +{ 1.43 +} 1.44 + 1.45 +const InfallibleTArray<uint64_t>& 1.46 +WindowIdentifier::AsArray() const 1.47 +{ 1.48 + MOZ_ASSERT(!mIsEmpty); 1.49 + return mID; 1.50 +} 1.51 + 1.52 +bool 1.53 +WindowIdentifier::HasTraveledThroughIPC() const 1.54 +{ 1.55 + MOZ_ASSERT(!mIsEmpty); 1.56 + return mID.Length() >= 2; 1.57 +} 1.58 + 1.59 +void 1.60 +WindowIdentifier::AppendProcessID() 1.61 +{ 1.62 + MOZ_ASSERT(!mIsEmpty); 1.63 + mID.AppendElement(dom::ContentChild::GetSingleton()->GetID()); 1.64 +} 1.65 + 1.66 +uint64_t 1.67 +WindowIdentifier::GetWindowID() const 1.68 +{ 1.69 + MOZ_ASSERT(!mIsEmpty); 1.70 + nsCOMPtr<nsPIDOMWindow> pidomWindow = do_QueryInterface(mWindow); 1.71 + if (!pidomWindow) { 1.72 + return UINT64_MAX; 1.73 + } 1.74 + return pidomWindow->WindowID(); 1.75 +} 1.76 + 1.77 +nsIDOMWindow* 1.78 +WindowIdentifier::GetWindow() const 1.79 +{ 1.80 + MOZ_ASSERT(!mIsEmpty); 1.81 + return mWindow; 1.82 +} 1.83 + 1.84 +} // namespace hal 1.85 +} // namespace mozilla