| 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/. */ |
| 6 |
|
| 7 |
#include "PageInformation.h" |
| 8 |
|
| 9 |
#include "BaseProfiler.h" |
| 10 |
|
| 11 |
#include "mozilla/BaseProfileJSONWriter.h" |
| 12 |
|
| 13 |
namespace mozilla { |
| 14 |
namespace baseprofiler { |
| 15 |
|
| 16 |
PageInformation::PageInformation(uint64_t aTabID, uint64_t aInnerWindowID, |
| 17 |
const std::string& aUrl, |
| 18 |
uint64_t aEmbedderInnerWindowID) |
| 19 |
: mTabID(aTabID), |
| 20 |
mInnerWindowID(aInnerWindowID), |
| 21 |
mUrl(aUrl), |
| 22 |
mEmbedderInnerWindowID(aEmbedderInnerWindowID), |
| 23 |
mRefCnt(0) {} |
| 24 |
|
| 25 |
bool PageInformation::Equals(PageInformation* aOtherPageInfo) const { |
| 26 |
// It's enough to check inner window IDs because they are unique for each |
| 27 |
// page. Therefore, we don't have to check the tab ID or url. |
| 28 |
return InnerWindowID() == aOtherPageInfo->InnerWindowID(); |
| 29 |
} |
| 30 |
|
| 31 |
void PageInformation::StreamJSON(SpliceableJSONWriter& aWriter) const { |
| 32 |
aWriter.StartObjectElement(); |
| 33 |
// Here, we are converting uint64_t to double. Both tab and Inner |
| 34 |
// Window IDs are created using `nsContentUtils::GenerateProcessSpecificId`, |
| 35 |
// which is specifically designed to only use 53 of the 64 bits to be lossless |
| 36 |
// when passed into and out of JS as a double. |
| 37 |
aWriter.DoubleProperty("tabID", TabID()); |
| 38 |
aWriter.DoubleProperty("innerWindowID", InnerWindowID()); |
| 39 |
aWriter.StringProperty("url", Url()); |
| 40 |
aWriter.DoubleProperty("embedderInnerWindowID", EmbedderInnerWindowID()); |
| 41 |
aWriter.EndObject(); |
| 42 |
} |
| 43 |
|
| 44 |
size_t PageInformation::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { |
| 45 |
return aMallocSizeOf(this); |
| 46 |
} |
| 47 |
|
| 48 |
} // namespace baseprofiler |
| 49 |
} // namespace mozilla |