void NotificationResourcesLoader::start( ExecutionContext* executionContext, const WebNotificationData& notificationData) { DCHECK(!m_started); m_started = true; size_t numActions = notificationData.actions.size(); m_pendingRequestCount = 3 /* image, icon, badge */ + numActions; // TODO(johnme): ensure image is not loaded when it will not be used. // TODO(mvanouwerkerk): ensure no badge is loaded when it will not be used. loadImage(executionContext, NotificationImageLoader::Type::Image, notificationData.image, WTF::bind(&NotificationResourcesLoader::didLoadImage, wrapWeakPersistent(this))); loadImage(executionContext, NotificationImageLoader::Type::Icon, notificationData.icon, WTF::bind(&NotificationResourcesLoader::didLoadIcon, wrapWeakPersistent(this))); loadImage(executionContext, NotificationImageLoader::Type::Badge, notificationData.badge, WTF::bind(&NotificationResourcesLoader::didLoadBadge, wrapWeakPersistent(this))); m_actionIcons.resize(numActions); for (size_t i = 0; i < numActions; i++) loadImage(executionContext, NotificationImageLoader::Type::ActionIcon, notificationData.actions[i].icon, WTF::bind(&NotificationResourcesLoader::didLoadActionIcon, wrapWeakPersistent(this), i)); }
Response InspectorEmulationAgent::setVirtualTimePolicy(const String& policy, Maybe<int> budget) { if (protocol::Emulation::VirtualTimePolicyEnum::Advance == policy) { m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( WebViewScheduler::VirtualTimePolicy::ADVANCE); } else if (protocol::Emulation::VirtualTimePolicyEnum::Pause == policy) { m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( WebViewScheduler::VirtualTimePolicy::PAUSE); } else if (protocol::Emulation::VirtualTimePolicyEnum:: PauseIfNetworkFetchesPending == policy) { m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( WebViewScheduler::VirtualTimePolicy::DETERMINISTIC_LOADING); } m_webLocalFrameImpl->view()->scheduler()->enableVirtualTime(); if (budget.isJust()) { WebTaskRunner* taskRunner = Platform::current()->currentThread()->getWebTaskRunner(); long long delayMillis = static_cast<long long>(budget.fromJust()); m_virtualTimeBudgetExpiredTaskHandle = taskRunner->postDelayedCancellableTask( BLINK_FROM_HERE, WTF::bind(&InspectorEmulationAgent::virtualTimeBudgetExpired, wrapWeakPersistent(this)), delayMillis); } return Response::OK(); }
void WebGLQuery::scheduleAllowAvailabilityUpdate() { if (m_taskHandle.isActive()) return; m_taskHandle = m_taskRunner->postCancellableTask( BLINK_FROM_HERE, WTF::bind(&WebGLQuery::allowAvailabilityUpdate, wrapWeakPersistent(this))); }
MediaControls::MediaControls(HTMLMediaElement& mediaElement) : HTMLDivElement(mediaElement.document()), m_mediaElement(&mediaElement), m_overlayEnclosure(nullptr), m_overlayPlayButton(nullptr), m_overlayCastButton(nullptr), m_enclosure(nullptr), m_panel(nullptr), m_playButton(nullptr), m_timeline(nullptr), m_currentTimeDisplay(nullptr), m_durationDisplay(nullptr), m_muteButton(nullptr), m_volumeSlider(nullptr), m_toggleClosedCaptionsButton(nullptr), m_textTrackList(nullptr), m_overflowList(nullptr), m_castButton(nullptr), m_fullscreenButton(nullptr), m_downloadButton(nullptr), m_mediaEventListener(new MediaControlsMediaEventListener(this)), m_windowEventListener(MediaControlsWindowEventListener::create( this, WTF::bind(&MediaControls::hideAllMenus, wrapWeakPersistent(this)))), m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired), m_hideTimerBehaviorFlags(IgnoreNone), m_isMouseOverControls(false), m_isPausedForScrubbing(false), m_panelWidthChangedTimer(this, &MediaControls::panelWidthChangedTimerFired), m_panelWidth(0), m_keepShowingUntilTimerFires(false) {}
USB::USB(LocalFrame& frame) : ContextLifecycleObserver(frame.document()), m_clientBinding(this) { ThreadState::current()->registerPreFinalizer(this); frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_deviceManager)); m_deviceManager.set_connection_error_handler(convertToBaseCallback(WTF::bind( &USB::onDeviceManagerConnectionError, wrapWeakPersistent(this)))); m_deviceManager->SetClient(m_clientBinding.CreateInterfacePtrAndBind()); }
void PermissionStatus::startListening() { DCHECK(!m_service); connectToPermissionService(getExecutionContext(), mojo::GetProxy(&m_service)); m_service->GetNextPermissionChange( m_descriptor->Clone(), getExecutionContext()->getSecurityOrigin(), m_status, convertToBaseCallback(WTF::bind(&PermissionStatus::permissionChanged, wrapWeakPersistent(this)))); }
BudgetService::BudgetService() { Platform::current()->interfaceProvider()->getInterface( mojo::GetProxy(&m_service)); // Set a connection error handler, so that if an embedder doesn't // implement a BudgetSerice mojo service, the developer will get a // actionable information. m_service.set_connection_error_handler(convertToBaseCallback( WTF::bind(&BudgetService::onConnectionError, wrapWeakPersistent(this)))); }
void ServiceWorkerRegistrationNotifications::prepareShow( const WebNotificationData& data, std::unique_ptr<WebNotificationShowCallbacks> callbacks) { RefPtr<SecurityOrigin> origin = getExecutionContext()->getSecurityOrigin(); NotificationResourcesLoader* loader = new NotificationResourcesLoader( WTF::bind(&ServiceWorkerRegistrationNotifications::didLoadResources, wrapWeakPersistent(this), origin.release(), data, WTF::passed(std::move(callbacks)))); m_loaders.add(loader); loader->start(getExecutionContext(), data); }
void Notification::prepareShow() { DCHECK_EQ(m_state, State::Loading); if (NotificationManager::from(getExecutionContext())->permissionStatus() != mojom::blink::PermissionStatus::GRANTED) { dispatchErrorEvent(); return; } m_loader = new NotificationResourcesLoader( WTF::bind(&Notification::didLoadResources, wrapWeakPersistent(this))); m_loader->start(getExecutionContext(), m_data); }
void Sensor::updateState(Sensor::SensorState newState) { if (newState == m_state) return; m_state = newState; if (getExecutionContext()) { getExecutionContext()->postTask( BLINK_FROM_HERE, createSameThreadTask(&Sensor::notifyStateChanged, wrapWeakPersistent(this))); } updatePollingStatus(); }
bool WorkerEventQueue::enqueueEvent(Event* event) { if (m_isClosed) return false; InspectorInstrumentation::asyncTaskScheduled( event->target()->getExecutionContext(), event->type(), event); m_pendingEvents.add(event); m_executionContext->postTask( BLINK_FROM_HERE, createSameThreadTask(&WorkerEventQueue::dispatchEvent, wrapPersistent(this), wrapWeakPersistent(event))); return true; }
void Sensor::reportError(ExceptionCode code, const String& sanitizedMessage, const String& unsanitizedMessage) { updateState(Sensor::SensorState::Errored); if (getExecutionContext()) { auto error = DOMException::create(code, sanitizedMessage, unsanitizedMessage); getExecutionContext()->postTask( BLINK_FROM_HERE, createSameThreadTask(&Sensor::notifyError, wrapWeakPersistent(this), wrapPersistent(error))); } }
void PermissionStatus::permissionChanged(MojoPermissionStatus status) { if (m_status == status) return; m_status = status; dispatchEvent(Event::create(EventTypeNames::change)); m_service->GetNextPermissionChange( m_descriptor->Clone(), getExecutionContext()->getSecurityOrigin(), m_status, convertToBaseCallback(WTF::bind(&PermissionStatus::permissionChanged, wrapWeakPersistent(this)))); }
void Sensor::updateState(Sensor::SensorState newState) { if (newState == m_state) return; if (newState == SensorState::Activated && getExecutionContext()) { DCHECK_EQ(SensorState::Activating, m_state); getExecutionContext()->postTask( BLINK_FROM_HERE, createSameThreadTask(&Sensor::notifyOnActivate, wrapWeakPersistent(this))); } m_state = newState; }
void Sensor::stopListening() { DCHECK(m_sensorProxy); updateState(Sensor::SensorState::IDLE); if (m_sensorProxy->isInitialized()) { auto callback = WTF::bind(&Sensor::onStopRequestCompleted, wrapWeakPersistent(this)); DCHECK(m_configuration); m_sensorProxy->removeConfiguration(m_configuration->Clone(), std::move(callback)); } else { m_sensorProxy->removeObserver(this); } }
void SensorProxy::initialize() { if (m_state != Uninitialized) return; if (!m_provider->sensorProvider()) { handleSensorError(); return; } m_state = Initializing; auto callback = convertToBaseCallback( WTF::bind(&SensorProxy::onSensorCreated, wrapWeakPersistent(this))); m_provider->sensorProvider()->GetSensor(m_type, mojo::GetProxy(&m_sensor), callback); }
void AutoplayUmaHelper::maybeStartRecordingMutedVideoPlayMethodBecomeVisible() { if (m_source != AutoplaySource::Method || !m_element->isHTMLVideoElement() || !m_element->muted()) return; m_mutedVideoPlayMethodVisibilityObserver = new ElementVisibilityObserver( m_element, WTF::bind(&AutoplayUmaHelper:: onVisibilityChangedForMutedVideoPlayMethodBecomeVisible, wrapWeakPersistent(this))); m_mutedVideoPlayMethodVisibilityObserver->start(); if (m_element->document().domWindow()) m_element->document().domWindow()->addEventListener(EventTypeNames::unload, this, false); }
void Sensor::onSensorUpdateNotification() { if (m_state != Sensor::SensorState::Activated) return; DCHECK(m_sensorProxy); DCHECK(m_sensorProxy->isInitialized()); DCHECK(m_sensorProxy->sensorReading()); if (getExecutionContext() && m_sensorProxy->sensorReading()->isReadingUpdated(m_storedData)) { getExecutionContext()->postTask( BLINK_FROM_HERE, createSameThreadTask(&Sensor::notifySensorReadingChanged, wrapWeakPersistent(this))); } m_storedData = m_sensorProxy->sensorReading()->data(); }
ScriptPromise USB::requestDevice(ScriptState* scriptState, const USBDeviceRequestOptions& options) { ExecutionContext* executionContext = scriptState->getExecutionContext(); UseCounter::count(executionContext, UseCounter::UsbRequestDevice); ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); ScriptPromise promise = resolver->promise(); if (!m_chooserService) { LocalFrame* frame = executionContext->isDocument() ? toDocument(executionContext)->frame() : nullptr; if (!frame) { resolver->reject(DOMException::create(NotSupportedError)); return promise; } frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_chooserService)); m_chooserService.set_connection_error_handler( convertToBaseCallback(WTF::bind(&USB::onChooserServiceConnectionError, wrapWeakPersistent(this)))); } String errorMessage; if (!executionContext->isSecureContext(errorMessage)) { resolver->reject(DOMException::create(SecurityError, errorMessage)); } else if (!UserGestureIndicator::consumeUserGesture()) { resolver->reject(DOMException::create( SecurityError, "Must be handling a user gesture to show a permission request.")); } else { Vector<usb::DeviceFilterPtr> filters; if (options.hasFilters()) { filters.reserveCapacity(options.filters().size()); for (const auto& filter : options.filters()) filters.append(convertDeviceFilter(filter)); } m_chooserServiceRequests.add(resolver); m_chooserService->GetPermission( std::move(filters), convertToBaseCallback(WTF::bind( &USB::onGetPermission, wrapPersistent(this), wrapPersistent(resolver)))); } return promise; }
void Geolocation::updateGeolocationServiceConnection() { if (!getExecutionContext() || !page() || !page()->isPageVisible() || !m_updating) { m_geolocationService.reset(); m_disconnectedGeolocationService = true; return; } if (m_geolocationService) return; frame()->interfaceProvider()->getInterface( mojo::GetProxy(&m_geolocationService)); m_geolocationService.set_connection_error_handler(convertToBaseCallback( WTF::bind(&Geolocation::onGeolocationConnectionError, wrapWeakPersistent(this)))); if (m_enableHighAccuracy) m_geolocationService->SetHighAccuracy(true); queryNextPosition(); }
void Sensor::onStartRequestCompleted(bool result) { if (m_state != Sensor::SensorState::ACTIVATING) return; if (!result) { reportError( OperationError, "start() call has failed possibly due to inappropriate options."); return; } DCHECK(m_configuration); DCHECK(m_sensorProxy); auto pollCallback = WTF::bind(&Sensor::pollForData, wrapWeakPersistent(this)); DCHECK_GT(m_configuration->frequency, 0); m_polling = SensorPollingStrategy::create(1 / m_configuration->frequency, std::move(pollCallback), m_sensorProxy->reportingMode()); updateState(Sensor::SensorState::ACTIVE); }
void AutoplayUmaHelper::maybeStartRecordingMutedVideoOffscreenDuration() { if (!m_element->isHTMLVideoElement() || !m_element->muted()) return; // Start recording muted video playing offscreen duration. m_mutedVideoAutoplayOffscreenStartTimeMS = static_cast<int64_t>(monotonicallyIncreasingTimeMS()); m_isVisible = false; m_mutedVideoOffscreenDurationVisibilityObserver = new ElementVisibilityObserver( m_element, WTF::bind(&AutoplayUmaHelper:: onVisibilityChangedForMutedVideoOffscreenDuration, wrapWeakPersistent(this))); m_mutedVideoOffscreenDurationVisibilityObserver->start(); m_element->addEventListener(EventTypeNames::pause, this, false); if (m_element->document().domWindow()) m_element->document().domWindow()->addEventListener(EventTypeNames::unload, this, false); }
void Sensor::onStartRequestCompleted(bool result) { if (m_state != Sensor::SensorState::Activating) return; if (!result) { reportError( OperationError, "start() call has failed possibly due to inappropriate options."); return; } DCHECK(m_configuration); DCHECK(m_sensorProxy); auto updateCallback = WTF::bind(&Sensor::onSensorUpdateNotification, wrapWeakPersistent(this)); DCHECK_GT(m_configuration->frequency, 0); m_sensorUpdateNotifier = SensorUpdateNotificationStrategy::create( m_configuration->frequency, std::move(updateCallback)); updateState(Sensor::SensorState::Activated); }
void SensorProxy::onSensorCreated(SensorInitParamsPtr params, SensorClientRequest clientRequest) { DCHECK_EQ(Initializing, m_state); if (!params) { handleSensorError(NotFoundError, "Sensor is not present on the platform."); return; } const size_t kReadBufferSize = sizeof(ReadingBuffer); DCHECK_EQ(0u, params->buffer_offset % kReadBufferSize); m_mode = params->mode; m_defaultConfig = std::move(params->default_configuration); if (!m_defaultConfig) { handleSensorError(); return; } DCHECK(m_sensor.is_bound()); m_clientBinding.Bind(std::move(clientRequest)); m_sharedBufferHandle = std::move(params->memory); DCHECK(!m_sharedBuffer); m_sharedBuffer = m_sharedBufferHandle->MapAtOffset(kReadBufferSize, params->buffer_offset); if (!m_sharedBuffer) { handleSensorError(); return; } auto errorCallback = WTF::bind(&SensorProxy::handleSensorError, wrapWeakPersistent(this), UnknownError, String("Internal error"), String()); m_sensor.set_connection_error_handler( convertToBaseCallback(std::move(errorCallback))); m_state = Initialized; for (Observer* observer : m_observers) observer->onSensorInitialized(); }
void Sensor::startListening() { DCHECK(m_sensorProxy); updateState(Sensor::SensorState::ACTIVATING); m_sensorProxy->addObserver(this); if (!m_sensorProxy->isInitialized()) { m_sensorProxy->initialize(); return; } if (!m_configuration) { m_configuration = createSensorConfig(m_sensorOptions, *m_sensorProxy->defaultConfig()); DCHECK(m_configuration); } auto startCallback = WTF::bind(&Sensor::onStartRequestCompleted, wrapWeakPersistent(this)); m_sensorProxy->addConfiguration(m_configuration->Clone(), std::move(startCallback)); }
void ElementVisibilityObserver::start() { ExecutionContext* context = m_element->getExecutionContext(); DCHECK(context->isDocument()); Document& document = toDocument(*context); // TODO(zqzhang): IntersectionObserver does not work for RemoteFrame. // Remove this early return when it's fixed. See https://crbug.com/615156 if (isInRemoteFrame(document)) { m_element.release(); return; } DCHECK(!m_intersectionObserver); m_intersectionObserver = IntersectionObserver::create( Vector<Length>(), Vector<float>({std::numeric_limits<float>::min()}), &document, WTF::bind(&ElementVisibilityObserver::onVisibilityChanged, wrapWeakPersistent(this))); DCHECK(m_intersectionObserver); m_intersectionObserver->setInitialState( IntersectionObserver::InitialState::kAuto); m_intersectionObserver->observe(m_element.release()); }
void Sensor::pollForData() { if (m_state != Sensor::SensorState::ACTIVE) { DCHECK(m_polling); m_polling->stopPolling(); return; } DCHECK(m_sensorProxy); DCHECK(m_sensorProxy->isInitialized()); m_sensorProxy->updateSensorReading(); DCHECK(m_sensorProxy->sensorReading()); if (getExecutionContext() && m_sensorProxy->sensorReading()->isReadingUpdated(m_storedData)) { getExecutionContext()->postTask( BLINK_FROM_HERE, createSameThreadTask(&Sensor::notifySensorReadingChanged, wrapWeakPersistent(this))); } m_storedData = m_sensorProxy->sensorReading()->data(); }
void Sensor::startListening() { DCHECK(m_sensorProxy); updateState(Sensor::SensorState::Activating); m_sensorProxy->addObserver(this); if (!m_sensorProxy->isInitialized()) { m_sensorProxy->initialize(); return; } if (!m_configuration) { m_configuration = createSensorConfig(); DCHECK(m_configuration); DCHECK(m_configuration->frequency > 0 && m_configuration->frequency <= m_sensorProxy->maximumFrequency()); } auto startCallback = WTF::bind(&Sensor::onStartRequestCompleted, wrapWeakPersistent(this)); m_sensorProxy->addConfiguration(m_configuration->Clone(), std::move(startCallback)); }
ScriptPromise NavigatorShare::share(ScriptState* scriptState, const ShareData& shareData) { String errorMessage; if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { DOMException* error = DOMException::create(SecurityError, errorMessage); return ScriptPromise::rejectWithDOMException(scriptState, error); } if (!UserGestureIndicator::utilizeUserGesture()) { DOMException* error = DOMException::create( SecurityError, "Must be handling a user gesture to perform a share request."); return ScriptPromise::rejectWithDOMException(scriptState, error); } Document* doc = toDocument(scriptState->getExecutionContext()); DCHECK(doc); if (!m_service) { LocalFrame* frame = doc->frame(); DCHECK(frame); frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_service)); m_service.set_connection_error_handler(convertToBaseCallback(WTF::bind( &NavigatorShare::onConnectionError, wrapWeakPersistent(this)))); DCHECK(m_service); } ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); ShareClientImpl* client = new ShareClientImpl(this, resolver); m_clients.add(client); ScriptPromise promise = resolver->promise(); m_service->Share(shareData.hasTitle() ? shareData.title() : emptyString(), shareData.hasText() ? shareData.text() : emptyString(), doc->completeURL(shareData.url()), convertToBaseCallback(WTF::bind(&ShareClientImpl::callback, wrapPersistent(client)))); return promise; }
void Geolocation::requestPermission() { if (m_geolocationPermission != PermissionUnknown) return; LocalFrame* frame = this->frame(); if (!frame) return; m_geolocationPermission = PermissionRequested; frame->interfaceProvider()->getInterface( mojo::GetProxy(&m_permissionService)); m_permissionService.set_connection_error_handler( convertToBaseCallback(WTF::bind(&Geolocation::onPermissionConnectionError, wrapWeakPersistent(this)))); // Ask the embedder: it maintains the geolocation challenge policy itself. m_permissionService->RequestPermission( createPermissionDescriptor(mojom::blink::PermissionName::GEOLOCATION), getExecutionContext()->getSecurityOrigin(), UserGestureIndicator::processingUserGesture(), convertToBaseCallback(WTF::bind( &Geolocation::onGeolocationPermissionUpdated, wrapPersistent(this)))); }