blob: 2e1bfb364501616ba57f5d16607f861b8b7f7ee0 [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <utility>
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin_hash.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace v8 {
class Isolate;
namespace blink {
class SecurityOrigin;
class WindowAgent;
// This is a helper class to assign WindowAgent to Document.
// The instance should be created for each group of Documents that are mutually
// reachable via `window.opener`, `window.frames` or others. These Documents
// may have different origins.
// The instance is intended to have the same granularity to the group of
// browsing context, that contains auxiliary browsing contexts.
class WindowAgentFactory final : public GarbageCollected<WindowAgentFactory> {
// Returns an instance of WindowAgent for |origin|.
// This returns the same instance for origin A and origin B if either:
// - |has_potential_universal_access_privilege| is true,
// - both A and B have `file:` scheme,
// - or, they have the same scheme and the same registrable origin.
// Set |has_potential_universal_access_privilege| if an agent may be able to
// access all other agents synchronously.
// I.e. pass true to if either:
// * --disable-web-security is set,
// * --run-web-tests is set,
// * or, the Blink instance is running for Android WebView.
WindowAgent* GetAgentForOrigin(bool has_potential_universal_access_privilege,
v8::Isolate* isolate,
const SecurityOrigin* origin);
void Trace(Visitor*);
struct SchemeAndRegistrableDomain {
String scheme;
String registrable_domain;
SchemeAndRegistrableDomain(const String& scheme,
const String& registrable_domain)
: scheme(scheme), registrable_domain(registrable_domain) {}
struct SchemeAndRegistrableDomainHash {
static const bool safe_to_compare_to_empty_or_deleted = false;
static unsigned GetHash(const SchemeAndRegistrableDomain&);
static bool Equal(const SchemeAndRegistrableDomain&,
const SchemeAndRegistrableDomain&);
struct SchemeAndRegistrableDomainTraits
: SimpleClassHashTraits<SchemeAndRegistrableDomain> {
static const bool kHasIsEmptyValueFunction = true;
static bool IsEmptyValue(const SchemeAndRegistrableDomain&);
static bool IsDeletedValue(const SchemeAndRegistrableDomain& value);
static void ConstructDeletedValue(SchemeAndRegistrableDomain& slot,
bool zero_value);
// Use a shared instance of Agent for all frames if a frame may have the
// universal access privilege.
WeakMember<WindowAgent> universal_access_agent_;
// `file:` scheme URLs are hard for tracking the equality. Use a shared
// Agent for them.
WeakMember<WindowAgent> file_url_agent_;
// Use the SecurityOrigin itself as the key for opaque origins.
HeapHashMap<scoped_refptr<const SecurityOrigin>,
// Use registerable domain as the key for general tuple origins.
using TupleOriginAgents = HeapHashMap<SchemeAndRegistrableDomain,
TupleOriginAgents tuple_origin_agents_;
} // namespace blink