Introduce remote variants of Frame / DOMWindow classes
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2018 23:55:02 +0000 (23:55 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2018 23:55:02 +0000 (23:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184467
<rdar://problem/39011267>

Reviewed by Ryosuke Niwa.

Introduce remote variants of Frame / DOMWindow classes, for when these frames / windows
are hosted on another WebProcess. Those will be used in a follow-up patch.

The hierarchy is as follows (class naming will be improved in a follow-up patch to minimise
patch size):
- AbstractFrame: A frame that can be either local or remote (hosted on another WebProcess)
    - Frame: A local frame
    - RemoteFrame: A frame hosted on another WebProcess. A RemoteFrame's window is also remote.
- AbstractDOMWindow: A window that be either local or remote (hosted on another WebProcess)
    - DOMWindow: A local DOMWindow
    - RemoteDOMWindow: A window hosted on another WebProcess. A RemoteDOMWindow's frame is also
      remote. A RemoteDOMWindow is always cross-origin.

This patch introduces global identifiers (unique across all WebProcesses) for both Frames and
Windows. This is useful as we need to know which Frame / DOMWindow a particular RemoteFrame /
RemoteDOMWindow is pointing to.

Follow-up patch will add support for converting a local DOMWindow / Frame into a remote ones,
when a newly opened window (via window.open) is navigated cross-origin (Bug 184515).

Other things we'll need to implement in follow-ups:
- RemoteDOMWindow will need to know about its opener in order to support the window.opener
  API. Internally, the opener will be stored as a RemoteFrame so that window.opener always
  returns the current window in the opener frame (which changes upon navigation).
- Nullify a RemoteDOMWindow's frame whenever the window it is pointing to becomes frameless.
  A frameless window behaves very differently (e.g. very little API is exposed to the Web).
  This happens when either the newly opened window is either closed or navigated.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* loader/ContentFilter.cpp:
(WebCore::ContentFilter::didDecide):
* page/AbstractDOMWindow.cpp: Added.
(WebCore::AbstractDOMWindow::AbstractDOMWindow):
(WebCore::AbstractDOMWindow::~AbstractDOMWindow):
* page/AbstractDOMWindow.h: Added.
(WebCore::AbstractDOMWindow::identifier const):
* page/AbstractFrame.cpp: Added.
(WebCore::AbstractFrame::AbstractFrame):
(WebCore::AbstractFrame::~AbstractFrame):
* page/AbstractFrame.h: Added.
(WebCore::AbstractFrame::window const):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::DOMWindow):
* page/DOMWindow.h:
(isType):
* page/Frame.cpp:
(WebCore::Frame::window const):
(WebCore::Frame::virtualWindow const):
* page/Frame.h:
(isType):
* page/GlobalFrameIdentifier.h: Added.
(WebCore::GlobalFrameIdentifier::encode const):
(WebCore::GlobalFrameIdentifier::decode):
* page/GlobalWindowIdentifier.h: Added.
(WebCore::operator==):
(WebCore::GlobalWindowIdentifier::hash const):
(WebCore::GlobalWindowIdentifier::encode const):
(WebCore::GlobalWindowIdentifier::decode):
(WTF::GlobalWindowIdentifierHash::hash):
(WTF::GlobalWindowIdentifierHash::equal):
(WTF::HashTraits<WebCore::GlobalWindowIdentifier>::emptyValue):
(WTF::HashTraits<WebCore::GlobalWindowIdentifier>::constructDeletedValue):
(WTF::HashTraits<WebCore::GlobalWindowIdentifier>::isDeletedValue):

* page/RemoteDOMWindow.cpp: Added.
(WebCore::RemoteDOMWindow::RemoteDOMWindow):
(WebCore::RemoteDOMWindow::~RemoteDOMWindow):
(WebCore::RemoteDOMWindow::self const):
(WebCore::RemoteDOMWindow::location const):
(WebCore::RemoteDOMWindow::close):
(WebCore::RemoteDOMWindow::closed const):
(WebCore::RemoteDOMWindow::focus):
(WebCore::RemoteDOMWindow::blur):
(WebCore::RemoteDOMWindow::length const):
(WebCore::RemoteDOMWindow::top const):
(WebCore::RemoteDOMWindow::opener const):
(WebCore::RemoteDOMWindow::parent const):
(WebCore::RemoteDOMWindow::postMessage):
The DOM API exposed on RemoteDOMWindow is only the subset of the DOMWindow API that is exposed cross origin,
since remote DOMWindow are always from a different origin. The short-term plan is to implement these in a
follow-up by relying on IPC (synchronous when necessary) to fetch the information from the real window in
the WebProcess where it lives. Longer term, we should probably keep RemoteDOMWindow members in sync with the
DOMWindow they're pointing to, so we do not have to rely on synchronous IPC.

* page/RemoteDOMWindow.h: Added.
(isType):
* page/RemoteFrame.cpp: Added.
(WebCore::RemoteFrame::RemoteFrame):
(WebCore::RemoteFrame::~RemoteFrame):
(WebCore::RemoteFrame::virtualWindow const):
* page/RemoteFrame.h: Added.
(isType):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230613 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/loader/ContentFilter.cpp
Source/WebCore/page/AbstractDOMWindow.cpp [new file with mode: 0644]
Source/WebCore/page/AbstractDOMWindow.h [new file with mode: 0644]
Source/WebCore/page/AbstractFrame.cpp [new file with mode: 0644]
Source/WebCore/page/AbstractFrame.h [new file with mode: 0644]
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/Frame.cpp
Source/WebCore/page/Frame.h
Source/WebCore/page/GlobalFrameIdentifier.h [new file with mode: 0644]
Source/WebCore/page/GlobalWindowIdentifier.h [new file with mode: 0644]
Source/WebCore/page/RemoteDOMWindow.cpp [new file with mode: 0644]
Source/WebCore/page/RemoteDOMWindow.h [new file with mode: 0644]
Source/WebCore/page/RemoteFrame.cpp [new file with mode: 0644]
Source/WebCore/page/RemoteFrame.h [new file with mode: 0644]

index 82bd257..3e81cd8 100644 (file)
@@ -1,3 +1,105 @@
+2018-04-12  Chris Dumez  <cdumez@apple.com>
+
+        Introduce remote variants of Frame / DOMWindow classes
+        https://bugs.webkit.org/show_bug.cgi?id=184467
+        <rdar://problem/39011267>
+
+        Reviewed by Ryosuke Niwa.
+
+        Introduce remote variants of Frame / DOMWindow classes, for when these frames / windows
+        are hosted on another WebProcess. Those will be used in a follow-up patch.
+
+        The hierarchy is as follows (class naming will be improved in a follow-up patch to minimise
+        patch size):
+        - AbstractFrame: A frame that can be either local or remote (hosted on another WebProcess)
+            - Frame: A local frame
+            - RemoteFrame: A frame hosted on another WebProcess. A RemoteFrame's window is also remote.
+        - AbstractDOMWindow: A window that be either local or remote (hosted on another WebProcess)
+            - DOMWindow: A local DOMWindow
+            - RemoteDOMWindow: A window hosted on another WebProcess. A RemoteDOMWindow's frame is also
+              remote. A RemoteDOMWindow is always cross-origin.
+
+        This patch introduces global identifiers (unique across all WebProcesses) for both Frames and
+        Windows. This is useful as we need to know which Frame / DOMWindow a particular RemoteFrame /
+        RemoteDOMWindow is pointing to.
+
+        Follow-up patch will add support for converting a local DOMWindow / Frame into a remote ones,
+        when a newly opened window (via window.open) is navigated cross-origin (Bug 184515).
+
+        Other things we'll need to implement in follow-ups:
+        - RemoteDOMWindow will need to know about its opener in order to support the window.opener
+          API. Internally, the opener will be stored as a RemoteFrame so that window.opener always
+          returns the current window in the opener frame (which changes upon navigation).
+        - Nullify a RemoteDOMWindow's frame whenever the window it is pointing to becomes frameless.
+          A frameless window behaves very differently (e.g. very little API is exposed to the Web).
+          This happens when either the newly opened window is either closed or navigated.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * loader/ContentFilter.cpp:
+        (WebCore::ContentFilter::didDecide):
+        * page/AbstractDOMWindow.cpp: Added.
+        (WebCore::AbstractDOMWindow::AbstractDOMWindow):
+        (WebCore::AbstractDOMWindow::~AbstractDOMWindow):
+        * page/AbstractDOMWindow.h: Added.
+        (WebCore::AbstractDOMWindow::identifier const):
+        * page/AbstractFrame.cpp: Added.
+        (WebCore::AbstractFrame::AbstractFrame):
+        (WebCore::AbstractFrame::~AbstractFrame):
+        * page/AbstractFrame.h: Added.
+        (WebCore::AbstractFrame::window const):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::DOMWindow):
+        * page/DOMWindow.h:
+        (isType):
+        * page/Frame.cpp:
+        (WebCore::Frame::window const):
+        (WebCore::Frame::virtualWindow const):
+        * page/Frame.h:
+        (isType):
+        * page/GlobalFrameIdentifier.h: Added.
+        (WebCore::GlobalFrameIdentifier::encode const):
+        (WebCore::GlobalFrameIdentifier::decode):
+        * page/GlobalWindowIdentifier.h: Added.
+        (WebCore::operator==):
+        (WebCore::GlobalWindowIdentifier::hash const):
+        (WebCore::GlobalWindowIdentifier::encode const):
+        (WebCore::GlobalWindowIdentifier::decode):
+        (WTF::GlobalWindowIdentifierHash::hash):
+        (WTF::GlobalWindowIdentifierHash::equal):
+        (WTF::HashTraits<WebCore::GlobalWindowIdentifier>::emptyValue):
+        (WTF::HashTraits<WebCore::GlobalWindowIdentifier>::constructDeletedValue):
+        (WTF::HashTraits<WebCore::GlobalWindowIdentifier>::isDeletedValue):
+
+        * page/RemoteDOMWindow.cpp: Added.
+        (WebCore::RemoteDOMWindow::RemoteDOMWindow):
+        (WebCore::RemoteDOMWindow::~RemoteDOMWindow):
+        (WebCore::RemoteDOMWindow::self const):
+        (WebCore::RemoteDOMWindow::location const):
+        (WebCore::RemoteDOMWindow::close):
+        (WebCore::RemoteDOMWindow::closed const):
+        (WebCore::RemoteDOMWindow::focus):
+        (WebCore::RemoteDOMWindow::blur):
+        (WebCore::RemoteDOMWindow::length const):
+        (WebCore::RemoteDOMWindow::top const):
+        (WebCore::RemoteDOMWindow::opener const):
+        (WebCore::RemoteDOMWindow::parent const):
+        (WebCore::RemoteDOMWindow::postMessage):
+        The DOM API exposed on RemoteDOMWindow is only the subset of the DOMWindow API that is exposed cross origin,
+        since remote DOMWindow are always from a different origin. The short-term plan is to implement these in a
+        follow-up by relying on IPC (synchronous when necessary) to fetch the information from the real window in
+        the WebProcess where it lives. Longer term, we should probably keep RemoteDOMWindow members in sync with the
+        DOMWindow they're pointing to, so we do not have to rely on synchronous IPC.
+
+        * page/RemoteDOMWindow.h: Added.
+        (isType):
+        * page/RemoteFrame.cpp: Added.
+        (WebCore::RemoteFrame::RemoteFrame):
+        (WebCore::RemoteFrame::~RemoteFrame):
+        (WebCore::RemoteFrame::virtualWindow const):
+        * page/RemoteFrame.h: Added.
+        (isType):
+
 2018-04-12  Daniel Bates  <dabates@apple.com>
 
         Content-Type not enforced for <script> allows for XSS
index 8da84ae..a461719 100644 (file)
@@ -1311,6 +1311,8 @@ mathml/MathMLTokenElement.cpp
 mathml/MathMLUnderOverElement.cpp
 mathml/MathMLUnknownElement.cpp
 
+page/AbstractDOMWindow.cpp
+page/AbstractFrame.cpp
 page/AutoscrollController.cpp
 page/BarProp.cpp
 page/Base64Utilities.cpp
@@ -1370,6 +1372,8 @@ page/PerformanceTiming.cpp
 page/PerformanceUserTiming.cpp
 page/PointerLockController.cpp
 page/PrintContext.cpp
+page/RemoteDOMWindow.cpp
+page/RemoteFrame.cpp
 page/ResourceUsageData.cpp
 page/ResourceUsageOverlay.cpp
 page/ResourceUsageThread.cpp
index b797c42..a6a1380 100644 (file)
                468344E01EDDFAAA00B7795B /* DOMRectList.h in Headers */ = {isa = PBXBuildFile; fileRef = 468344DE1EDDFA5F00B7795B /* DOMRectList.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4689F1AF1267BAE100E8D380 /* FileMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = 4689F1AE1267BAE100E8D380 /* FileMetadata.h */; settings = {ATTRIBUTES = (Private, ); }; };
                46B63F6C1C6E8D19002E914B /* JSEventTargetCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B63F6B1C6E8CDF002E914B /* JSEventTargetCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               46B95195207D633400A7D2DD /* AbstractDOMWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B9518A207D632800A7D2DD /* AbstractDOMWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               46B95196207D633A00A7D2DD /* AbstractFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B9518F207D632B00A7D2DD /* AbstractFrame.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               46B95197207D634000A7D2DD /* GlobalWindowIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B95190207D632C00A7D2DD /* GlobalWindowIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               46B95198207D634700A7D2DD /* GlobalFrameIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B95191207D632D00A7D2DD /* GlobalFrameIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               46B95199207D634D00A7D2DD /* RemoteDOMWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B9518E207D632A00A7D2DD /* RemoteDOMWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               46B9519A207D635400A7D2DD /* RemoteFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 46B95192207D632E00A7D2DD /* RemoteFrame.h */; settings = {ATTRIBUTES = (Private, ); }; };
                46C696CB1E7205F700597937 /* CPUMonitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C696C91E7205E400597937 /* CPUMonitor.h */; settings = {ATTRIBUTES = (Private, ); }; };
                46C696CC1E7205FC00597937 /* CPUMonitor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46C696CA1E7205E400597937 /* CPUMonitor.cpp */; };
                46C83EFE1A9BBE2900A79A41 /* GeoNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C83EFC1A9BBE2900A79A41 /* GeoNotifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
                468344DE1EDDFA5F00B7795B /* DOMRectList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DOMRectList.h; sourceTree = "<group>"; };
                4689F1AE1267BAE100E8D380 /* FileMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileMetadata.h; sourceTree = "<group>"; };
                46B63F6B1C6E8CDF002E914B /* JSEventTargetCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSEventTargetCustom.h; sourceTree = "<group>"; };
+               46B9518A207D632800A7D2DD /* AbstractDOMWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractDOMWindow.h; sourceTree = "<group>"; };
+               46B9518C207D632900A7D2DD /* RemoteFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteFrame.cpp; sourceTree = "<group>"; };
+               46B9518D207D632A00A7D2DD /* RemoteDOMWindow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteDOMWindow.cpp; sourceTree = "<group>"; };
+               46B9518E207D632A00A7D2DD /* RemoteDOMWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteDOMWindow.h; sourceTree = "<group>"; };
+               46B9518F207D632B00A7D2DD /* AbstractFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractFrame.h; sourceTree = "<group>"; };
+               46B95190207D632C00A7D2DD /* GlobalWindowIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GlobalWindowIdentifier.h; sourceTree = "<group>"; };
+               46B95191207D632D00A7D2DD /* GlobalFrameIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GlobalFrameIdentifier.h; sourceTree = "<group>"; };
+               46B95192207D632E00A7D2DD /* RemoteFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteFrame.h; sourceTree = "<group>"; };
+               46B95193207D632F00A7D2DD /* AbstractDOMWindow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AbstractDOMWindow.cpp; sourceTree = "<group>"; };
+               46B95194207D633000A7D2DD /* AbstractFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AbstractFrame.cpp; sourceTree = "<group>"; };
                46C696C91E7205E400597937 /* CPUMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPUMonitor.h; sourceTree = "<group>"; };
                46C696CA1E7205E400597937 /* CPUMonitor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPUMonitor.cpp; sourceTree = "<group>"; };
                46C83EFB1A9BBE2900A79A41 /* GeoNotifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeoNotifier.cpp; sourceTree = "<group>"; };
                                18A6CD6F0D8F2025001DC3CE /* ios */,
                                93C09A820B064F05005ABD4D /* mac */,
                                1AF62EE114DA22A70041556C /* scrolling */,
+                               46B95193207D632F00A7D2DD /* AbstractDOMWindow.cpp */,
+                               46B9518A207D632800A7D2DD /* AbstractDOMWindow.h */,
+                               46B95194207D633000A7D2DD /* AbstractFrame.cpp */,
+                               46B9518F207D632B00A7D2DD /* AbstractFrame.h */,
                                724EE54E1DC7F25B00A91FFB /* ActivityState.h */,
                                724EE54F1DC7F25B00A91FFB /* ActivityStateChangeObserver.h */,
                                BCF48CE61370D114004E87D6 /* AdjustViewSizeOrNot.h */,
                                65CBFEF70974F607001DAC25 /* FrameView.cpp */,
                                65CBFEF80974F607001DAC25 /* FrameView.h */,
                                574D42791D594FF6002CF50E /* GlobalCrypto.idl */,
+                               46B95191207D632D00A7D2DD /* GlobalFrameIdentifier.h */,
                                7C9892451F5A07650091DC70 /* GlobalPerformance.idl */,
+                               46B95190207D632C00A7D2DD /* GlobalWindowIdentifier.h */,
                                BC94D1500C275C8B006BC617 /* History.cpp */,
                                BC94D1510C275C8B006BC617 /* History.h */,
                                BC94D1520C275C8B006BC617 /* History.idl */,
                                3772B09516535856000A49CA /* PopupOpeningObserver.h */,
                                B776D43C1104527500BEB0EC /* PrintContext.cpp */,
                                B776D43A1104525D00BEB0EC /* PrintContext.h */,
+                               46B9518D207D632A00A7D2DD /* RemoteDOMWindow.cpp */,
+                               46B9518E207D632A00A7D2DD /* RemoteDOMWindow.h */,
+                               46B9518C207D632900A7D2DD /* RemoteFrame.cpp */,
+                               46B95192207D632E00A7D2DD /* RemoteFrame.h */,
                                A5071E8A1C56FAFA009951BE /* ResourceUsageData.cpp */,
                                A5071E821C56D079009951BE /* ResourceUsageData.h */,
                                ADBAD6EC1BCDD95000381325 /* ResourceUsageOverlay.cpp */,
                        files = (
                                7CD0E2B81F80A4820016A4CE /* AbortController.h in Headers */,
                                7CD0E2BF1F80A56E0016A4CE /* AbortSignal.h in Headers */,
+                               46B95195207D633400A7D2DD /* AbstractDOMWindow.h in Headers */,
+                               46B95196207D633A00A7D2DD /* AbstractFrame.h in Headers */,
                                F48223131E386E240066FC79 /* AbstractPasteboard.h in Headers */,
                                41E1B1D10FF5986900576B3B /* AbstractWorker.h in Headers */,
                                29A8122E0FBB9C1D00510293 /* AccessibilityARIAGridCell.h in Headers */,
                                0FB6252F18DE1B1500A07C05 /* GeometryUtilities.h in Headers */,
                                46C83EFE1A9BBE2900A79A41 /* GeoNotifier.h in Headers */,
                                9746AF2A14F4DDE6003E7A70 /* Geoposition.h in Headers */,
+                               46B95198207D634700A7D2DD /* GlobalFrameIdentifier.h in Headers */,
+                               46B95197207D634000A7D2DD /* GlobalWindowIdentifier.h in Headers */,
                                086BBD0F136039C2008B15D8 /* Glyph.h in Headers */,
                                B2C3DA6C0D006CD600EF6F26 /* GlyphBuffer.h in Headers */,
                                C5D4AA7A116BAFB60069CA93 /* GlyphMetricsMap.h in Headers */,
                                A578F43F1DE0B630003DFC6A /* RejectedPromiseTracker.h in Headers */,
                                CDFC360618CA61C20026E56F /* RemoteCommandListener.h in Headers */,
                                CD8ACA891D237AA200ECC59E /* RemoteCommandListenerMac.h in Headers */,
+                               46B95199207D634D00A7D2DD /* RemoteDOMWindow.h in Headers */,
+                               46B9519A207D635400A7D2DD /* RemoteFrame.h in Headers */,
                                D06C0D8F0CFD11460065F43F /* RemoveFormatCommand.h in Headers */,
                                93309E05099E64920056E581 /* RemoveNodeCommand.h in Headers */,
                                93309E07099E64920056E581 /* RemoveNodePreservingChildrenCommand.h in Headers */,
index 46680ab..e299019 100644 (file)
@@ -231,7 +231,7 @@ void ContentFilter::didDecide(State state)
     RefPtr<Frame> frame { m_documentLoader.frame() };
     String unblockRequestDeniedScript { m_blockingContentFilter->unblockRequestDeniedScript() };
     if (!unblockRequestDeniedScript.isEmpty() && frame) {
-        static_assert(std::is_base_of<ThreadSafeRefCounted<Frame>, Frame>::value, "Frame must be ThreadSafeRefCounted.");
+        static_assert(std::is_base_of<ThreadSafeRefCounted<AbstractFrame>, Frame>::value, "AbstractFrame must be ThreadSafeRefCounted.");
         unblockHandler.wrapWithDecisionHandler([frame = WTFMove(frame), script = unblockRequestDeniedScript.isolatedCopy()](bool unblocked) {
             if (!unblocked)
                 frame->script().executeScript(script);
diff --git a/Source/WebCore/page/AbstractDOMWindow.cpp b/Source/WebCore/page/AbstractDOMWindow.cpp
new file mode 100644 (file)
index 0000000..ba74519
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AbstractDOMWindow.h"
+
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+HashMap<GlobalWindowIdentifier, AbstractDOMWindow*>& AbstractDOMWindow::allWindows()
+{
+    ASSERT(isMainThread());
+    static NeverDestroyed<HashMap<GlobalWindowIdentifier, AbstractDOMWindow*>> map;
+    return map;
+}
+
+AbstractDOMWindow::AbstractDOMWindow(GlobalWindowIdentifier&& identifier)
+    : m_identifier(WTFMove(identifier))
+{
+    ASSERT(!allWindows().contains(identifier));
+    allWindows().add(identifier, this);
+}
+
+AbstractDOMWindow::~AbstractDOMWindow()
+{
+    ASSERT(allWindows().contains(identifier()));
+    allWindows().remove(identifier());
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/page/AbstractDOMWindow.h b/Source/WebCore/page/AbstractDOMWindow.h
new file mode 100644 (file)
index 0000000..5a5debd
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "Base64Utilities.h"
+#include "EventTarget.h"
+#include "GlobalWindowIdentifier.h"
+#include <wtf/HashMap.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class AbstractFrame;
+
+// FIXME: Rename DOMWindow to LocalWindow and AbstractDOMWindow to DOMWindow.
+class AbstractDOMWindow : public RefCounted<AbstractDOMWindow>, public EventTargetWithInlineData {
+public:
+    virtual ~AbstractDOMWindow();
+
+    static HashMap<GlobalWindowIdentifier, AbstractDOMWindow*>& allWindows();
+
+    const GlobalWindowIdentifier& identifier() const { return m_identifier; }
+
+    virtual AbstractFrame* frame() const = 0;
+
+    virtual bool isLocalDOMWindow() const = 0;
+    virtual bool isRemoteDOMWindow() const = 0;
+
+    using RefCounted::ref;
+    using RefCounted::deref;
+
+protected:
+    explicit AbstractDOMWindow(GlobalWindowIdentifier&&);
+
+    EventTargetInterface eventTargetInterface() const final { return DOMWindowEventTargetInterfaceType; }
+    void refEventTarget() final { ref(); }
+    void derefEventTarget() final { deref(); }
+
+private:
+    GlobalWindowIdentifier m_identifier;
+};
+
+} // namespace WebCore
diff --git a/Source/WebCore/page/AbstractFrame.cpp b/Source/WebCore/page/AbstractFrame.cpp
new file mode 100644 (file)
index 0000000..2f0f6da
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AbstractFrame.h"
+
+namespace WebCore {
+
+AbstractFrame::AbstractFrame()
+{
+}
+
+AbstractFrame::~AbstractFrame()
+{
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/page/AbstractFrame.h b/Source/WebCore/page/AbstractFrame.h
new file mode 100644 (file)
index 0000000..56115eb
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/ThreadSafeRefCounted.h>
+#include <wtf/UniqueRef.h>
+
+namespace WebCore {
+
+class AbstractDOMWindow;
+class WindowProxyController;
+
+// FIXME: Rename Frame to LocalFrame and AbstractFrame to Frame.
+class AbstractFrame : public ThreadSafeRefCounted<AbstractFrame> {
+public:
+    virtual ~AbstractFrame();
+
+    virtual bool isLocalFrame() const = 0;
+    virtual bool isRemoteFrame() const = 0;
+
+    AbstractDOMWindow* window() const { return virtualWindow(); }
+
+protected:
+    AbstractFrame();
+
+private:
+    virtual AbstractDOMWindow* virtualWindow() const = 0;
+};
+
+} // namespace WebCore
index 90c3e8e..0210b08 100644 (file)
@@ -401,7 +401,8 @@ void DOMWindow::setCanShowModalDialogOverride(bool allow)
 }
 
 DOMWindow::DOMWindow(Document& document)
-    : ContextDestructionObserver(&document)
+    : AbstractDOMWindow(GlobalWindowIdentifier { Process::identifier(), generateObjectIdentifier<WindowIdentifierType>() })
+    , ContextDestructionObserver(&document)
     , FrameDestructionObserver(document.frame())
 {
     ASSERT(frame());
index 4c66b72..499a558 100644 (file)
 
 #pragma once
 
+#include "AbstractDOMWindow.h"
 #include "Base64Utilities.h"
 #include "ContextDestructionObserver.h"
-#include "EventTarget.h"
 #include "ExceptionOr.h"
+#include "Frame.h"
 #include "FrameDestructionObserver.h"
 #include "ImageBitmap.h"
 #include "ScrollToOptions.h"
@@ -87,9 +88,9 @@ struct WindowFeatures;
 enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList };
 
 // FIXME: DOMWindow shouldn't subclass FrameDestructionObserver and instead should get to Frame via its Document.
+// FIXME: Rename DOMWindow to LocalWindow and AbstractDOMWindow to DOMWindow.
 class DOMWindow final
-    : public RefCounted<DOMWindow>
-    , public EventTargetWithInlineData
+    : public AbstractDOMWindow
     , public ContextDestructionObserver
     , public FrameDestructionObserver
     , public Base64Utilities
@@ -198,6 +199,8 @@ public:
     DOMWindow* parent() const;
     DOMWindow* top() const;
 
+    Frame* frame() const final { return FrameDestructionObserver::frame(); }
+
     String origin() const;
 
     // DOM Level 2 AbstractView Interface
@@ -276,9 +279,6 @@ public:
 
     void finishedLoading();
 
-    using RefCounted::ref;
-    using RefCounted::deref;
-
     // HTML 5 key/value storage
     ExceptionOr<Storage*> sessionStorage() const;
     ExceptionOr<Storage*> localStorage() const;
@@ -338,18 +338,17 @@ public:
 private:
     explicit DOMWindow(Document&);
 
-    EventTargetInterface eventTargetInterface() const final { return DOMWindowEventTargetInterfaceType; }
     ScriptExecutionContext* scriptExecutionContext() const final { return ContextDestructionObserver::scriptExecutionContext(); }
 
+    bool isLocalDOMWindow() const final { return true; }
+    bool isRemoteDOMWindow() const final { return false; }
+
     Page* page();
     bool allowedToChangeWindowGeometry() const;
 
     void frameDestroyed() final;
     void willDetachPage() final;
 
-    void refEventTarget() final { ref(); }
-    void derefEventTarget() final { deref(); }
-
     static RefPtr<Frame> createWindow(const String& urlString, const AtomicString& frameName, const WindowFeatures&, DOMWindow& activeWindow, Frame& firstFrame, Frame& openerFrame, const WTF::Function<void(DOMWindow&)>& prepareDialogFunction = nullptr);
     bool isInsecureScriptAccess(DOMWindow& activeWindow, const String& urlString);
 
@@ -432,5 +431,6 @@ inline String DOMWindow::defaultStatus() const
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::DOMWindow)
+    static bool isType(const WebCore::AbstractDOMWindow& window) { return window.isLocalDOMWindow(); }
     static bool isType(const WebCore::EventTarget& target) { return target.eventTargetInterface() == WebCore::DOMWindowEventTargetInterfaceType; }
 SPECIALIZE_TYPE_TRAITS_END()
index 29ba80c..2c6c0dd 100644 (file)
@@ -943,6 +943,16 @@ void Frame::createView(const IntSize& viewportSize, const Color& backgroundColor
         view()->setCanHaveScrollbars(owner->scrollingMode() != ScrollbarAlwaysOff);
 }
 
+DOMWindow* Frame::window() const
+{
+    return document() ? document()->domWindow() : nullptr;
+}
+
+AbstractDOMWindow* Frame::virtualWindow() const
+{
+    return window();
+}
+
 String Frame::layerTreeAsText(LayerTreeFlags flags) const
 {
     document()->updateLayout();
index b35b8fd..ded96f8 100644 (file)
 
 #pragma once
 
+#include "AbstractFrame.h"
 #include "AdjustViewSizeOrNot.h"
 #include "FrameTree.h"
 #include "ScrollTypes.h"
 #include "UserScriptTypes.h"
 #include <wtf/HashSet.h>
-#include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/UniqueRef.h>
 
 #if PLATFORM(IOS)
@@ -61,6 +61,7 @@ namespace WebCore {
 
 class CSSAnimationController;
 class Color;
+class DOMWindow;
 class Document;
 class Editor;
 class Element;
@@ -117,7 +118,8 @@ enum {
 };
 typedef unsigned LayerTreeFlags;
 
-class Frame final : public ThreadSafeRefCounted<Frame> {
+// FIXME: Rename Frame to LocalFrame and AbstractFrame to Frame.
+class Frame final : public AbstractFrame {
 public:
     WEBCORE_EXPORT static Ref<Frame> create(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
 
@@ -134,6 +136,8 @@ public:
 
     WEBCORE_EXPORT ~Frame();
 
+    DOMWindow* window() const;
+
     void addDestructionObserver(FrameDestructionObserver*);
     void removeDestructionObserver(FrameDestructionObserver*);
 
@@ -291,6 +295,11 @@ private:
 
     void dropChildren();
 
+    bool isLocalFrame() const final { return true; }
+    bool isRemoteFrame() const final { return false; }
+
+    AbstractDOMWindow* virtualWindow() const final;
+
     HashSet<FrameDestructionObserver*> m_destructionObservers;
 
     Frame& m_mainFrame;
@@ -390,3 +399,7 @@ inline Frame& Frame::mainFrame() const
 }
 
 } // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Frame)
+    static bool isType(const WebCore::AbstractFrame& frame) { return frame.isLocalFrame(); }
+SPECIALIZE_TYPE_TRAITS_END()
diff --git a/Source/WebCore/page/GlobalFrameIdentifier.h b/Source/WebCore/page/GlobalFrameIdentifier.h
new file mode 100644 (file)
index 0000000..536ee37
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/Optional.h>
+
+namespace WebCore {
+
+// Frame identifier that is unique across all WebContent processes.
+struct GlobalFrameIdentifier {
+    uint64_t pageID;
+    uint64_t frameID;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static std::optional<GlobalFrameIdentifier> decode(Decoder&);
+};
+
+template<class Encoder>
+void GlobalFrameIdentifier::encode(Encoder& encoder) const
+{
+    encoder << pageID << frameID;
+}
+
+template<class Decoder>
+std::optional<GlobalFrameIdentifier> GlobalFrameIdentifier::decode(Decoder& decoder)
+{
+    std::optional<uint64_t> pageID;
+    decoder >> pageID;
+    if (!pageID)
+        return std::nullopt;
+
+    std::optional<uint64_t> frameID;
+    decoder >> frameID;
+    if (!frameID)
+        return std::nullopt;
+
+    return { { WTFMove(*pageID), WTFMove(*frameID) } };
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/page/GlobalWindowIdentifier.h b/Source/WebCore/page/GlobalWindowIdentifier.h
new file mode 100644 (file)
index 0000000..215a746
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "Process.h"
+#include <wtf/HashTraits.h>
+#include <wtf/ObjectIdentifier.h>
+
+namespace WebCore {
+
+enum WindowIdentifierType { };
+using WindowIdentifier = ObjectIdentifier<WindowIdentifierType>;
+
+// Window identifier that is unique across all WebContent processes.
+struct GlobalWindowIdentifier {
+    ProcessIdentifier processIdentifier;
+    WindowIdentifier windowIdentifier;
+
+    unsigned hash() const;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static std::optional<GlobalWindowIdentifier> decode(Decoder&);
+};
+
+inline bool operator==(const GlobalWindowIdentifier& a, const GlobalWindowIdentifier& b)
+{
+    return a.processIdentifier == b.processIdentifier &&  a.windowIdentifier == b.windowIdentifier;
+}
+
+inline unsigned GlobalWindowIdentifier::hash() const
+{
+    uint64_t identifiers[2];
+    identifiers[0] = processIdentifier.toUInt64();
+    identifiers[1] = windowIdentifier.toUInt64();
+
+    return StringHasher::hashMemory(identifiers, sizeof(identifiers));
+}
+
+template<class Encoder>
+void GlobalWindowIdentifier::encode(Encoder& encoder) const
+{
+    encoder << processIdentifier << windowIdentifier;
+}
+
+template<class Decoder>
+std::optional<GlobalWindowIdentifier> GlobalWindowIdentifier::decode(Decoder& decoder)
+{
+    std::optional<ProcessIdentifier> processIdentifier;
+    decoder >> processIdentifier;
+    if (!processIdentifier)
+        return std::nullopt;
+
+    std::optional<WindowIdentifier> windowIdentifier;
+    decoder >> windowIdentifier;
+    if (!windowIdentifier)
+        return std::nullopt;
+
+    return { { WTFMove(*processIdentifier), WTFMove(*windowIdentifier) } };
+}
+
+} // namespace WebCore
+
+namespace WTF {
+
+struct GlobalWindowIdentifierHash {
+    static unsigned hash(const WebCore::GlobalWindowIdentifier& key) { return key.hash(); }
+    static bool equal(const WebCore::GlobalWindowIdentifier& a, const WebCore::GlobalWindowIdentifier& b) { return a == b; }
+    static const bool safeToCompareToEmptyOrDeleted = true;
+};
+
+template<> struct HashTraits<WebCore::GlobalWindowIdentifier> : GenericHashTraits<WebCore::GlobalWindowIdentifier> {
+    static WebCore::GlobalWindowIdentifier emptyValue() { return { }; }
+
+    static void constructDeletedValue(WebCore::GlobalWindowIdentifier& slot) { slot.windowIdentifier = makeObjectIdentifier<WebCore::WindowIdentifierType>(std::numeric_limits<uint64_t>::max()); }
+    static bool isDeletedValue(const WebCore::GlobalWindowIdentifier& slot) { return slot.windowIdentifier.toUInt64() == std::numeric_limits<uint64_t>::max(); }
+};
+
+template<> struct DefaultHash<WebCore::GlobalWindowIdentifier> {
+    typedef GlobalWindowIdentifierHash Hash;
+};
+
+} // namespace WTF
diff --git a/Source/WebCore/page/RemoteDOMWindow.cpp b/Source/WebCore/page/RemoteDOMWindow.cpp
new file mode 100644 (file)
index 0000000..f7ce10e
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RemoteDOMWindow.h"
+
+#include "RemoteFrame.h"
+#include <JavaScriptCore/JSCJSValue.h>
+#include <JavaScriptCore/JSCJSValueInlines.h>
+
+namespace WebCore {
+
+RemoteDOMWindow::RemoteDOMWindow(Ref<RemoteFrame>&& frame, GlobalWindowIdentifier&& identifier)
+    : AbstractDOMWindow(WTFMove(identifier))
+    , m_frame(WTFMove(frame))
+{
+    m_frame->setWindow(this);
+}
+
+RemoteDOMWindow::~RemoteDOMWindow()
+{
+    if (m_frame)
+        m_frame->setWindow(nullptr);
+}
+
+RemoteDOMWindow* RemoteDOMWindow::self() const
+{
+    if (!m_frame)
+        return nullptr;
+    return const_cast<RemoteDOMWindow*>(this);
+}
+
+Location* RemoteDOMWindow::location() const
+{
+    // FIXME: Implemented this.
+    return nullptr;
+}
+
+void RemoteDOMWindow::close(Document&)
+{
+    // FIXME: Implemented this.
+}
+
+bool RemoteDOMWindow::closed() const
+{
+    return !m_frame;
+}
+
+void RemoteDOMWindow::focus(DOMWindow& incumbentWindow)
+{
+    UNUSED_PARAM(incumbentWindow);
+    // FIXME: Implemented this.
+}
+
+void RemoteDOMWindow::blur()
+{
+    // FIXME: Implemented this.
+}
+
+unsigned RemoteDOMWindow::length() const
+{
+    // FIXME: Implemented this.
+    return 0;
+}
+
+RemoteDOMWindow* RemoteDOMWindow::top() const
+{
+    if (!m_frame)
+        return nullptr;
+
+    // FIXME: Implemented this.
+    return const_cast<RemoteDOMWindow*>(this);
+}
+
+DOMWindow* RemoteDOMWindow::opener() const
+{
+    // FIXME: Implemented this.
+    return nullptr;
+}
+
+RemoteDOMWindow* RemoteDOMWindow::parent() const
+{
+    if (!m_frame)
+        return nullptr;
+
+    // FIXME: Implemented this.
+    return const_cast<RemoteDOMWindow*>(this);
+}
+
+ExceptionOr<void> RemoteDOMWindow::postMessage(JSC::ExecState&, DOMWindow& incumbentWindow, JSC::JSValue message, const String& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&&)
+{
+    UNUSED_PARAM(incumbentWindow);
+    UNUSED_PARAM(message);
+    UNUSED_PARAM(targetOrigin);
+
+    // FIXME: Implemented this.
+    return Exception { NotSupportedError };
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/page/RemoteDOMWindow.h b/Source/WebCore/page/RemoteDOMWindow.h
new file mode 100644 (file)
index 0000000..1089a98
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "AbstractDOMWindow.h"
+#include "RemoteFrame.h"
+#include <wtf/TypeCasts.h>
+
+namespace JSC {
+class ExecState;
+class JSObject;
+class JSValue;
+template<typename> class Strong;
+}
+
+namespace WebCore {
+
+class DOMWindow;
+class Document;
+class Location;
+
+class RemoteDOMWindow final : public AbstractDOMWindow {
+public:
+    static Ref<RemoteDOMWindow> create(Ref<RemoteFrame>&& frame, GlobalWindowIdentifier&& identifier)
+    {
+        return adoptRef(*new RemoteDOMWindow(WTFMove(frame), WTFMove(identifier)));
+    }
+
+    ~RemoteDOMWindow() final;
+
+    RemoteFrame* frame() const final { return m_frame.get(); }
+    ScriptExecutionContext* scriptExecutionContext() const final { return nullptr; }
+
+    // DOM API exposed cross-origin.
+    RemoteDOMWindow* self() const;
+    Location* location() const;
+    void close(Document&);
+    bool closed() const;
+    void focus(DOMWindow& incumbentWindow);
+    void blur();
+    unsigned length() const;
+    RemoteDOMWindow* top() const;
+    DOMWindow* opener() const;
+    RemoteDOMWindow* parent() const;
+    ExceptionOr<void> postMessage(JSC::ExecState&, DOMWindow& incumbentWindow, JSC::JSValue message, const String& targetOrigin, Vector<JSC::Strong<JSC::JSObject>>&&);
+
+private:
+    WEBCORE_EXPORT RemoteDOMWindow(Ref<RemoteFrame>&&, GlobalWindowIdentifier&&);
+
+    bool isRemoteDOMWindow() const final { return true; }
+    bool isLocalDOMWindow() const final { return false; }
+
+    RefPtr<RemoteFrame> m_frame;
+};
+
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::RemoteDOMWindow)
+    static bool isType(const WebCore::AbstractDOMWindow& window) { return window.isRemoteDOMWindow(); }
+SPECIALIZE_TYPE_TRAITS_END()
diff --git a/Source/WebCore/page/RemoteFrame.cpp b/Source/WebCore/page/RemoteFrame.cpp
new file mode 100644 (file)
index 0000000..2010c37
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RemoteFrame.h"
+
+#include "RemoteDOMWindow.h"
+
+namespace WebCore {
+
+RemoteFrame::RemoteFrame(GlobalFrameIdentifier&& frameIdentifier)
+    : m_identifier(WTFMove(frameIdentifier))
+{
+}
+
+RemoteFrame::~RemoteFrame()
+{
+}
+
+AbstractDOMWindow* RemoteFrame::virtualWindow() const
+{
+    return window();
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/page/RemoteFrame.h b/Source/WebCore/page/RemoteFrame.h
new file mode 100644 (file)
index 0000000..36fc3fb
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "AbstractFrame.h"
+#include "GlobalFrameIdentifier.h"
+#include <wtf/Ref.h>
+#include <wtf/TypeCasts.h>
+
+namespace WebCore {
+
+class RemoteDOMWindow;
+
+class RemoteFrame final : public AbstractFrame {
+public:
+    static Ref<RemoteFrame> create(GlobalFrameIdentifier&& frameIdentifier)
+    {
+        return adoptRef(* new RemoteFrame(WTFMove(frameIdentifier)));
+    }
+    ~RemoteFrame();
+
+    const GlobalFrameIdentifier& identifier() const { return m_identifier; }
+
+    void setWindow(RemoteDOMWindow* window) { m_window = window; }
+    RemoteDOMWindow* window() const { return m_window; }
+
+private:
+    WEBCORE_EXPORT explicit RemoteFrame(GlobalFrameIdentifier&&);
+
+    bool isRemoteFrame() const final { return true; }
+    bool isLocalFrame() const final { return false; }
+
+    AbstractDOMWindow* virtualWindow() const final;
+
+    GlobalFrameIdentifier m_identifier;
+    RemoteDOMWindow* m_window { nullptr };
+};
+
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::RemoteFrame)
+    static bool isType(const WebCore::AbstractFrame& frame) { return frame.isRemoteFrame(); }
+SPECIALIZE_TYPE_TRAITS_END()