Ignore:
Timestamp:
Oct 8, 2020, 5:48:35 PM (5 years ago)
Author:
[email protected]
Message:

Make it possible to send an arbitrary IPC message from JavaScript
https://bugs.webkit.org/show_bug.cgi?id=217423
<rdar://problem/69969351>

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

Added a helper function to get uint64_t out of BigInt.

  • runtime/JSBigInt.cpp:

(JSC::JSBigInt::toUint64Heap): Added.

  • runtime/JSBigInt.h:

(JSC::JSBigInt::toUint64): Added.

Source/WebKit:

This patch introduces the JavaScript API (window.IPC) to send IPC out of WebContent process.
The feature is compiled in under ASAN and Debug builds and can be enabled at runtime.

window.IPC has two methods: sendMessage and sendSyncMessage which sends an async and sync IPC respectively.
It takes the destination process name (UI, GPU, or Networking), the destination ID (e.g. WebPageProxy ID),
message ID, timeout for sendSyncMessage, and optionally IPC message arguments. The message arguments can be
passed in as a TypedArray or ArrayBuffer, or a JavaScript array that recursively describes encoded objects.

Each object can be either a TypedArray or ArrayBuffer, which will be treated as encoded message, an array
which will be encoded as a Vector with each item within the array encoded recursively, or a dictionary which
describes a specific type.

When a specific type is described via a dictionary, "value" is encoed based on "type" as follows:

  • When "type" is "String", "value" is encoded as a WTF::String, treating null or undefined as a null string.
  • When "type" is "bool", "int8_t", "int16_t", "int32_t", "int64_t", "uint8_t", "uint16_t", "uint32_t", or "uint64_t", "value" (which can be BigInt or a number) is encoded as the respective C++ type.
  • When "type" is "RGBA", "value" is used as PackedColor::RGBA to construct WebCore::Color to be encoded.
  • When "type" is "IntRect" or "FloatRect", "x", "y", "width", and "height" are treated as respective values of IntRect or FloatRect C++ objects, and the constructed *Rect is encoded.
  • When "type" is "FrameInfoData", the context object's WebFrame's FrameInfoData is encoded.

The list of IPC messages are exposed on window.IPC.messages, and VisitedLinkStore ID, WebPageProxy ID,
and frame identifiers are also exposed as static variables on window.IPC.

  • Sources.txt:
  • WebKit.xcodeproj/project.pbxproj:
  • WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:

(WebKit::WebFrameLoaderClient::dispatchDidClearWindowObjectInWorld): Inject the API if enabled.

  • WebProcess/WebPage/IPCTestingAPI.cpp: Added.

(WebKit::IPCTestingAPI::JSIPC::create): Added.
(WebKit::IPCTestingAPI::JSIPC::webFrame): Added.
(WebKit::IPCTestingAPI::JSIPC::JSIPC): Added.
(WebKit::IPCTestingAPI::JSIPC::wrapperClass): Added.
(WebKit::IPCTestingAPI::JSIPC::unwrap): Added.
(WebKit::IPCTestingAPI::JSIPC::toWrapped): Added.
(WebKit::IPCTestingAPI::JSIPC::initialize): Added.
(WebKit::IPCTestingAPI::JSIPC::finalize): Added.
(WebKit::IPCTestingAPI::JSIPC::staticFunctions): Added.
(WebKit::IPCTestingAPI::JSIPC::staticValues): Added.
(WebKit::IPCTestingAPI::convertToUint64): Added.
(WebKit::IPCTestingAPI::processTargetFromArgument): Added.
(WebKit::IPCTestingAPI::destinationIDFromArgument): Added.
(WebKit::IPCTestingAPI::messageIDFromArgument): Added.
(WebKit::IPCTestingAPI::encodeTypedArray): Added.
(WebKit::IPCTestingAPI::createTypeError): Added.
(WebKit::IPCTestingAPI::encodeRectType): Added.
(WebKit::IPCTestingAPI::encodeIntegralType): Added.
(WebKit::IPCTestingAPI::VectorEncodeHelper::encode const): Added.
(WebKit::IPCTestingAPI::encodeArgument): Added.
(WebKit::IPCTestingAPI::JSIPC::sendMessage): Added.
(WebKit::IPCTestingAPI::JSIPC::sendSyncMessage): Added.
(WebKit::IPCTestingAPI::JSIPC::visitedLinkStoreID): Added.
(WebKit::IPCTestingAPI::JSIPC::webPageProxyID): Added.
(WebKit::IPCTestingAPI::JSIPC::frameIdentifier): Added.
(WebKit::IPCTestingAPI::JSIPC::retrieveID): Added.
(WebKit::IPCTestingAPI::JSIPC::messages): Added.
(WebKit::IPCTestingAPI::inject):

  • WebProcess/WebPage/IPCTestingAPI.h: Added.
  • WebProcess/WebPage/WebFrame.h:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::m_limitsNavigationsToAppBoundDomains):
(WebKit::WebPage::updatePreferences):

  • WebProcess/WebPage/WebPage.h:

(WebKit::WebPage::ipcTestingAPIEnabled const):
(WebKit::WebPage::webPageProxyID const):
(WebKit::WebPage::visitedLinkTableID const):

Source/WTF:

Added a compile time flag (ENABLE_IPC_TESTING_API) and a runtime flag (IPCTestingAPIEnabled)
for the JavaScript API to test IPC.

  • Scripts/GeneratePreferences.rb:

(Preference::nameLower): Keep IPC uppercase.

  • Scripts/Preferences/WebPreferencesInternal.yaml: Added IPCTestingAPIEnabled.
  • wtf/PlatformEnable.h: Added ENABLE_IPC_TESTING_API.

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm: Added.

(-[IPCTestingAPIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TEST):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSBigInt.cpp

    r267373 r268239  
    30503050#endif
    30513051
     3052Optional<uint64_t> JSBigInt::toUint64Heap(JSBigInt* bigInt)
     3053{
     3054    auto length = bigInt->length();
     3055    if (!length)
     3056        return 0;
     3057    if (bigInt->sign())
     3058        return WTF::nullopt;
     3059
     3060    static_assert(sizeof(uint64_t) == sizeof(Digit) || sizeof(uint64_t) == sizeof(Digit) * 2, "Digit must be either 32-bit or 64-bit");
     3061    if (sizeof(uint64_t) == sizeof(Digit)) {
     3062        if (length > 1)
     3063            return WTF::nullopt;
     3064        return bigInt->digit(0);
     3065    }
     3066
     3067    if (length > 2)
     3068        return WTF::nullopt;
     3069    uint64_t result = bigInt->digit(0);
     3070    if (length == 1)
     3071        result += static_cast<uint64_t>(bigInt->digit(0)) << 32;
     3072    return result;
     3073}
     3074
    30523075static ALWAYS_INLINE unsigned computeHash(JSBigInt::Digit* digits, unsigned length, bool sign)
    30533076{
Note: See TracChangeset for help on using the changeset viewer.