tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PageInformation.cpp (1900B)


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