void UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame(uint64_t userMediaID, uint64_t frameID, String userMediaDocumentOriginIdentifier, String topLevelDocumentOriginIdentifier, const WebCore::MediaConstraintsData& audioConstraintsData, const WebCore::MediaConstraintsData& videoConstraintsData) { #if ENABLE(MEDIA_STREAM) auto invalidHandler = [this, userMediaID](const String& invalidConstraint) { if (!m_page.isValid()) return; denyRequest(userMediaID, UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::InvalidConstraint, invalidConstraint); }; auto validHandler = [this, userMediaID, frameID, userMediaDocumentOriginIdentifier, topLevelDocumentOriginIdentifier](const Vector<String>&& audioDeviceUIDs, const Vector<String>&& videoDeviceUIDs) { if (!m_page.isValid()) return; if (videoDeviceUIDs.isEmpty() && audioDeviceUIDs.isEmpty()) { denyRequest(userMediaID, UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::NoConstraints, ""); return; } auto userMediaOrigin = API::SecurityOrigin::create(SecurityOriginData::fromDatabaseIdentifier(userMediaDocumentOriginIdentifier)->securityOrigin()); auto topLevelOrigin = API::SecurityOrigin::create(SecurityOriginData::fromDatabaseIdentifier(topLevelDocumentOriginIdentifier)->securityOrigin()); auto request = createRequest(userMediaID, audioDeviceUIDs, videoDeviceUIDs); if (!m_page.uiClient().decidePolicyForUserMediaPermissionRequest(m_page, *m_page.process().webFrame(frameID), *userMediaOrigin.get(), *topLevelOrigin.get(), request.get())) { m_pendingUserMediaRequests.take(userMediaID); request->deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::UserMediaDisabled); } }; auto audioConstraints = MediaConstraintsImpl::create(audioConstraintsData); auto videoConstraints = MediaConstraintsImpl::create(videoConstraintsData); syncWithWebCorePrefs(); RealtimeMediaSourceCenter::singleton().validateRequestConstraints(validHandler, invalidHandler, audioConstraints, videoConstraints); #else UNUSED_PARAM(userMediaID); UNUSED_PARAM(frameID); UNUSED_PARAM(userMediaDocumentOriginIdentifier); UNUSED_PARAM(topLevelDocumentOriginIdentifier); UNUSED_PARAM(audioConstraintsData); UNUSED_PARAM(videoConstraintsData); #endif }
void UserMediaPermissionRequestManagerProxy::userMediaAccessWasDenied(uint64_t userMediaID, UserMediaPermissionRequestProxy::UserMediaAccessDenialReason reason) { if (!m_page.isValid()) return; if (!m_pendingUserMediaRequests.take(userMediaID)) return; denyRequest(userMediaID, reason, ""); }
/* parseMessage * Reads message from client */ static int parseMessage(int newsockfd) { char buffer[BUFSIZ]; int n; /* Initialize buffers */ char *wholeMessage = (char*) malloc(READBUFFERSIZE*sizeof(char)); memset(wholeMessage, 0, READBUFFERSIZE); memset(buffer, 0, BUFSIZ); /* Start reading */ n = read(newsockfd, buffer, BUFSIZ); if (n < 0) { fprintf(stderr,"Error: failed to read from socket\n"); return -1; } /* reading a result message, must call read several times */ else if(n > 10) { /* Discard garbage at the end */ buffer[n] = '\0'; /* append to wholeMessage */ strcat(wholeMessage, buffer); /* Clear buffer before reading next chunk */ memset(buffer, 0, BUFSIZ); do { n = read(newsockfd, buffer, BUFSIZ); if (n < 0) { fprintf(stderr,"Error: failed to read from socket\n"); return -1; } else { /* Discard garbage at the end */ buffer[n] = '\0'; /* append to wholeMessage */ strcat(wholeMessage, buffer); /* Clear buffer before reading next chunk */ memset(buffer, 0, BUFSIZ); } } while(n > 0); } /* reading a request message, one read is enough */ else { strcpy(wholeMessage, buffer); } char* result = strdup(wholeMessage); /* Free wholeMessage */ free(wholeMessage); /* Parse message from client */ /* Check first digit of message and verify if it is a * a result or a request */ char *pch; pch = strtok(result, ":"); if(pch[0] == RESULT) { /* Parse rest of the message */ parseResult(pch); } else if(pch[0] == REQUEST) { /* Send hint to the client */ int workingSize; int hint = parseRequest(pch, &workingSize); int ret; if(hint) ret = sendHint(newsockfd, workingSize); else ret = denyRequest(newsockfd); } close(newsockfd); /* Free memory */ free(result); return 1; }