void NetworkResourceLoadParameters::encode(IPC::ArgumentEncoder& encoder) const
{
    encoder << identifier;
    encoder << webPageID;
    encoder << webFrameID;
    encoder << sessionID;
    encoder << request;

    encoder << static_cast<bool>(request.httpBody());
    if (request.httpBody()) {
        EncoderAdapter httpBodyEncoderAdapter;
        request.httpBody()->encode(httpBodyEncoderAdapter);
        encoder << httpBodyEncoderAdapter.dataReference();

        const Vector<FormDataElement>& elements = request.httpBody()->elements();
        size_t fileCount = 0;
        for (size_t i = 0, count = elements.size(); i < count; ++i) {
            if (elements[i].m_type == FormDataElement::encodedFile)
                ++fileCount;
        }

        SandboxExtension::HandleArray requestBodySandboxExtensions;
        requestBodySandboxExtensions.allocate(fileCount);
        size_t extensionIndex = 0;
        for (size_t i = 0, count = elements.size(); i < count; ++i) {
            const FormDataElement& element = elements[i];
            if (element.m_type == FormDataElement::encodedFile) {
                const String& path = element.m_shouldGenerateFile ? element.m_generatedFilename : element.m_filename;
                SandboxExtension::createHandle(path, SandboxExtension::ReadOnly, requestBodySandboxExtensions[extensionIndex++]);
            }
        }
        encoder << requestBodySandboxExtensions;
    }

    if (request.url().isLocalFile()) {
        SandboxExtension::Handle requestSandboxExtension;
        SandboxExtension::createHandle(request.url().fileSystemPath(), SandboxExtension::ReadOnly, requestSandboxExtension);
        encoder << requestSandboxExtension;
    }

    encoder.encodeEnum(priority);
    encoder.encodeEnum(contentSniffingPolicy);
    encoder.encodeEnum(allowStoredCredentials);
    encoder.encodeEnum(clientCredentialPolicy);
    encoder << shouldClearReferrerOnHTTPSToHTTPRedirect;
    encoder << isMainResource;
}
void NetworkResourceLoadParameters::encode(CoreIPC::ArgumentEncoder& encoder) const
{
    encoder.encode(m_identifier);
    encoder.encode(m_webPageID);
    encoder.encode(m_webFrameID);
    encoder.encode(m_request);

    encoder.encode(static_cast<bool>(m_request.httpBody()));
    if (m_request.httpBody()) {
        EncoderAdapter httpBodyEncoderAdapter;
        m_request.httpBody()->encode(httpBodyEncoderAdapter);
        encoder.encode(httpBodyEncoderAdapter.dataReference());

        const Vector<FormDataElement>& elements = m_request.httpBody()->elements();
        size_t fileCount = 0;
        for (size_t i = 0, count = elements.size(); i < count; ++i) {
            if (elements[i].m_type == FormDataElement::encodedFile)
                ++fileCount;
        }

        SandboxExtension::HandleArray requestBodySandboxExtensions;
        requestBodySandboxExtensions.allocate(fileCount);
        size_t extensionIndex = 0;
        for (size_t i = 0, count = elements.size(); i < count; ++i) {
            const FormDataElement& element = elements[i];
            if (element.m_type == FormDataElement::encodedFile) {
                const String& path = element.m_shouldGenerateFile ? element.m_generatedFilename : element.m_filename;
                SandboxExtension::createHandle(path, SandboxExtension::ReadOnly, requestBodySandboxExtensions[extensionIndex++]);
            }
        }
        encoder.encode(requestBodySandboxExtensions);
    }

    if (m_request.url().isLocalFile()) {
        SandboxExtension::Handle requestSandboxExtension;
        SandboxExtension::createHandle(m_request.url().fileSystemPath(), SandboxExtension::ReadOnly, requestSandboxExtension);
        encoder.encode(requestSandboxExtension);
    }

    encoder.encodeEnum(m_priority);
    encoder.encodeEnum(m_contentSniffingPolicy);
    encoder.encodeEnum(m_allowStoredCredentials);
    encoder.encode(m_inPrivateBrowsingMode);
}
void UserMediaPermissionRequestManagerProxy::userMediaAccessWasGranted(uint64_t userMediaID, const String& audioDeviceUID, const String& videoDeviceUID)
{
    ASSERT(!audioDeviceUID.isEmpty() || !videoDeviceUID.isEmpty());

    if (!m_page.isValid())
        return;

    if (!m_pendingUserMediaRequests.take(userMediaID))
        return;

#if ENABLE(MEDIA_STREAM)
    size_t extensionCount = 0;
    unsigned requiredExtensions = SandboxExtensionsGranted::None;
    if (!audioDeviceUID.isEmpty()) {
        requiredExtensions |= SandboxExtensionsGranted::Audio;
        extensionCount++;
    }
    if (!videoDeviceUID.isEmpty()) {
        requiredExtensions |= SandboxExtensionsGranted::Video;
        extensionCount++;
    }

    unsigned currentExtensions = m_pageSandboxExtensionsGranted.get(m_page.pageID());
    if (!(requiredExtensions & currentExtensions)) {
        ASSERT(extensionCount);
        m_pageSandboxExtensionsGranted.set(m_page.pageID(), requiredExtensions | currentExtensions);
        SandboxExtension::HandleArray handles;
        handles.allocate(extensionCount);
        if (!videoDeviceUID.isEmpty())
            SandboxExtension::createHandleForGenericExtension("com.apple.webkit.camera", handles[--extensionCount]);
        if (!audioDeviceUID.isEmpty())
            SandboxExtension::createHandleForGenericExtension("com.apple.webkit.microphone", handles[--extensionCount]);
        m_page.process().send(Messages::WebPage::GrantUserMediaDevicesSandboxExtension(handles), m_page.pageID());
    }

    m_page.process().send(Messages::WebPage::UserMediaAccessWasGranted(userMediaID, audioDeviceUID, videoDeviceUID), m_page.pageID());
#else
    UNUSED_PARAM(audioDeviceUID);
    UNUSED_PARAM(videoDeviceUID);
#endif
}