author Simon Whitehead <>
Sat, 13 May 2017 15:12:15 -0500
changeset 358329 633151f5d481d49bd39900d43e6a75d77459a7bb
parent 356511 08d888f39c153a5fd8c2aee35f4d1f609682ec92
child 363680 cc5a10e1d826a959235f81577c9ada10bcfbe648
permissions -rw-r--r--
servo: Merge #16829 - Disallow negative duration for animation and transition (from hiikezoe:disallow-negative-duration); r=emilio <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #15343 <!-- Either: --> - [X] There are tests for these changes written by @simon-whitehead . Thank you! <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: Source-Revision: 4613c0382ab76263fb8202ccf52f4c0520e44809

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at */

#ifndef TabGroup_h
#define TabGroup_h

#include "nsISupportsImpl.h"
#include "nsIPrincipal.h"
#include "nsTHashtable.h"
#include "nsString.h"

#include "mozilla/Atomics.h"
#include "mozilla/SchedulerGroup.h"
#include "mozilla/RefPtr.h"

class mozIDOMWindowProxy;
class nsIDocShellTreeItem;
class nsIDocument;
class nsPIDOMWindowOuter;

namespace mozilla {
class AbstractThread;
class ThrottledEventQueue;
namespace dom {

// Two browsing contexts are considered "related" if they are reachable from one
// another through window.opener, window.parent, or window.frames. This is the
// spec concept of a "unit of related browsing contexts"
// Two browsing contexts are considered "similar-origin" if they can be made to
// have the same origin by setting document.domain. This is the spec concept of
// a "unit of similar-origin related browsing contexts"
// A TabGroup is a set of browsing contexts which are all "related". Within a
// TabGroup, browsing contexts are broken into "similar-origin" DocGroups. In
// more detail, a DocGroup is actually a collection of documents, and a
// TabGroup is a collection of DocGroups. A TabGroup typically will contain
// (through its DocGroups) the documents from one or more tabs related by
// window.opener. A DocGroup is a member of exactly one TabGroup.

class DocGroup;

class TabGroup final : public SchedulerGroup
  class HashEntry : public nsCStringHashKey
    // NOTE: Weak reference. The DocGroup destructor removes itself from its
    // owning TabGroup.
    DocGroup* mDocGroup;
    explicit HashEntry(const nsACString* aKey);

  typedef nsTHashtable<HashEntry> DocGroupMap;

  typedef DocGroupMap::Iterator Iterator;

  friend class DocGroup;


  static TabGroup*

  // Checks if the TabChild already has a TabGroup assigned to it in
  // IPDL. Returns this TabGroup if it does. This could happen if the parent
  // process created the PBrowser and we needed to assign a TabGroup immediately
  // upon receiving the IPDL message. This method is main thread only.
  static TabGroup* GetFromActor(TabChild* aTabChild);

  static TabGroup* GetFromWindow(mozIDOMWindowProxy* aWindow);

  explicit TabGroup(bool aIsChrome = false);

  // Get the docgroup for the corresponding doc group key.
  // Returns null if the given key hasn't been seen yet.
  GetDocGroup(const nsACString& aKey);

  AddDocument(const nsACString& aKey, nsIDocument* aDocument);

  // Join the specified TabGroup, returning a reference to it. If aTabGroup is
  // nullptr, create a new tabgroup to join.
  static already_AddRefed<TabGroup>
  Join(nsPIDOMWindowOuter* aWindow, TabGroup* aTabGroup);

  void Leave(nsPIDOMWindowOuter* aWindow);

  Iterator Iter()
    return mDocGroups.Iter();

  // Returns the nsIDocShellTreeItem with the given name, searching each of the
  // docShell trees which are within this TabGroup. It will pass itself as
  // aRequestor to each docShellTreeItem which it asks to search for the name,
  // and will not search the docShellTreeItem which is passed as aRequestor.
  // This method is used in order to correctly namespace named windows based on
  // their unit of related browsing contexts.
  // It is illegal to pass in the special case-insensitive names "_blank",
  // "_self", "_parent" or "_top", as those should be handled elsewhere.
  FindItemWithName(const nsAString& aName,
                   nsIDocShellTreeItem* aRequestor,
                   nsIDocShellTreeItem* aOriginalRequestor,
                   nsIDocShellTreeItem** aFoundItem);

  nsTArray<nsPIDOMWindowOuter*> GetTopLevelWindows() const;
  const nsTArray<nsPIDOMWindowOuter*>& GetWindows() { return mWindows; }

  // This method is always safe to call off the main thread. The nsIEventTarget
  // can always be used off the main thread.
  nsIEventTarget* EventTargetFor(TaskCategory aCategory) const override;

  // Returns true if all of the TabGroup's top-level windows are in
  // the background.
  bool IsBackground() const override;

  virtual AbstractThread*
  AbstractMainThreadForImpl(TaskCategory aCategory) override;

  TabGroup* AsTabGroup() override { return this; }

  void EnsureThrottledEventQueues();


  // Thread-safe members
  Atomic<bool> mLastWindowLeft;
  Atomic<bool> mThrottledQueuesInitialized;
  const bool mIsChrome;

  // Main thread only
  DocGroupMap mDocGroups;
  nsTArray<nsPIDOMWindowOuter*> mWindows;

} // namespace dom
} // namespace mozilla

#endif // defined(TabGroup_h)