1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "PageInformation.h"
9 #include "mozilla/ProfileJSONWriter.h"
11 PageInformation::PageInformation(uint64_t aTabID
, uint64_t aInnerWindowID
,
12 const nsCString
& aUrl
,
13 uint64_t aEmbedderInnerWindowID
,
14 bool aIsPrivateBrowsing
)
16 mInnerWindowID(aInnerWindowID
),
18 mEmbedderInnerWindowID(aEmbedderInnerWindowID
),
19 mIsPrivateBrowsing(aIsPrivateBrowsing
) {}
21 bool PageInformation::Equals(PageInformation
* aOtherPageInfo
) const {
22 // It's enough to check inner window IDs because they are unique for each
23 // page. Therefore, we don't have to check the tab ID or url.
24 return InnerWindowID() == aOtherPageInfo
->InnerWindowID();
27 void PageInformation::StreamJSON(SpliceableJSONWriter
& aWriter
) const {
28 // Here, we are converting uint64_t to double. Both tab and Inner
29 // Window IDs are created using `nsContentUtils::GenerateProcessSpecificId`,
30 // which is specifically designed to only use 53 of the 64 bits to be lossless
31 // when passed into and out of JS as a double.
32 aWriter
.StartObjectElement();
33 aWriter
.DoubleProperty("tabID", TabID());
34 aWriter
.DoubleProperty("innerWindowID", InnerWindowID());
35 aWriter
.StringProperty("url", Url());
36 aWriter
.DoubleProperty("embedderInnerWindowID", EmbedderInnerWindowID());
37 aWriter
.BoolProperty("isPrivateBrowsing", IsPrivateBrowsing());
41 size_t PageInformation::SizeOfIncludingThis(
42 mozilla::MallocSizeOf aMallocSizeOf
) const {
43 return aMallocSizeOf(this);