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))); } }
ScriptPromise USB::getDevices(ScriptState* scriptState) { ExecutionContext* executionContext = scriptState->getExecutionContext(); UseCounter::count(executionContext, UseCounter::UsbGetDevices); ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); ScriptPromise promise = resolver->promise(); if (!m_deviceManager) { resolver->reject(DOMException::create(NotSupportedError)); } else { String errorMessage; if (!executionContext->isSecureContext(errorMessage)) { resolver->reject(DOMException::create(SecurityError, errorMessage)); } else { m_deviceManagerRequests.add(resolver); m_deviceManager->GetDevices( nullptr, convertToBaseCallback(WTF::bind(&USB::onGetDevices, wrapPersistent(this), wrapPersistent(resolver)))); } } return promise; }
ScriptPromise BudgetService::getCost(ScriptState* scriptState, const AtomicString& operation) { DCHECK(m_service); String errorMessage; if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) return ScriptPromise::rejectWithDOMException( scriptState, DOMException::create(SecurityError, errorMessage)); mojom::blink::BudgetOperationType type = stringToOperationType(operation); if (type == mojom::blink::BudgetOperationType::INVALID_OPERATION) return ScriptPromise::rejectWithDOMException( scriptState, DOMException::create(NotSupportedError, "Invalid operation type specified")); ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); ScriptPromise promise = resolver->promise(); // Get the cost for the action from the browser BudgetService. m_service->GetCost(type, convertToBaseCallback(WTF::bind( &BudgetService::gotCost, wrapPersistent(this), wrapPersistent(resolver)))); return promise; }
void VibrationController::doVibrate(TimerBase* timer) { DCHECK(timer == &m_timerDoVibrate); if (m_pattern.isEmpty()) m_isRunning = false; if (!m_isRunning || m_isCallingCancel || m_isCallingVibrate || !getExecutionContext() || !page()->isPageVisible()) return; if (m_service) { m_isCallingVibrate = true; m_service->Vibrate(m_pattern[0], convertToBaseCallback(WTF::bind( &VibrationController::didVibrate, wrapPersistent(this)))); } }
void SearchInputType::startSearchEventTimer() { DCHECK(element().layoutObject()); unsigned length = element().innerEditorValue().length(); if (!length) { m_searchEventTimer.stop(); element().document().postTask( BLINK_FROM_HERE, createSameThreadTask(&HTMLInputElement::onSearch, wrapPersistent(&element()))); return; } // After typing the first key, we wait 0.5 seconds. // After the second key, 0.4 seconds, then 0.3, then 0.2 from then on. m_searchEventTimer.startOneShot(max(0.2, 0.6 - 0.1 * length), BLINK_FROM_HERE); }
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)))); }
void DirectoryReader::readEntries(EntriesCallback* entriesCallback, ErrorCallback* errorCallback) { if (!m_isReading) { m_isReading = true; filesystem()->readDirectory(this, m_fullPath, new EntriesCallbackHelper(this), new ErrorCallbackHelper(this)); } if (m_error) { filesystem()->reportError(ScriptErrorCallback::wrap(errorCallback), m_error); return; } if (m_entriesCallback) { // Non-null m_entriesCallback means multiple readEntries() calls are made // concurrently. We don't allow doing it. filesystem()->reportError(ScriptErrorCallback::wrap(errorCallback), FileError::kInvalidStateErr); return; } if (!m_hasMoreEntries || !m_entries.isEmpty()) { if (entriesCallback) DOMFileSystem::scheduleCallback( filesystem()->getExecutionContext(), createSameThreadTask(&EntriesCallback::handleEvent, wrapPersistent(entriesCallback), PersistentHeapVector<Member<Entry>>(m_entries))); m_entries.clear(); return; } m_entriesCallback = entriesCallback; m_errorCallback = errorCallback; }
void Notification::close() { if (m_state != State::Showing) return; // Schedule the "close" event to be fired for non-persistent notifications. // Persistent notifications won't get such events for programmatic closes. if (m_type == Type::NonPersistent) { getExecutionContext()->postTask( BLINK_FROM_HERE, createSameThreadTask(&Notification::dispatchCloseEvent, wrapPersistent(this))); m_state = State::Closing; notificationManager()->close(this); return; } m_state = State::Closed; SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); DCHECK(origin); notificationManager()->closePersistent(WebSecurityOrigin(origin), m_data.tag, m_notificationId); }
void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemType type, long long size, std::unique_ptr<AsyncFileSystemCallbacks> callbacks) { CallbackWrapper* wrapper = new CallbackWrapper(std::move(callbacks)); requestFileSystemAccessInternal(context, WTF::bind(&LocalFileSystem::fileSystemAllowedInternal, wrapPersistent(this), wrapPersistent(context), type, wrapPersistent(wrapper)), WTF::bind(&LocalFileSystem::fileSystemNotAllowedInternal, wrapPersistent(this), wrapPersistent(context), wrapPersistent(wrapper))); }
void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType type, std::unique_ptr<AsyncFileSystemCallbacks> callbacks) { ASSERT(context); ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument()); CallbackWrapper* wrapper = new CallbackWrapper(std::move(callbacks)); requestFileSystemAccessInternal(context, WTF::bind(&LocalFileSystem::deleteFileSystemInternal, wrapPersistent(this), wrapPersistent(context), type, wrapPersistent(wrapper)), WTF::bind(&LocalFileSystem::fileSystemNotAllowedInternal, wrapPersistent(this), wrapPersistent(context), wrapPersistent(wrapper))); }
std::unique_ptr<ExecutionContextTask> StorageErrorCallback::createSameThreadTask(StorageErrorCallback* callback, ExceptionCode ec) { return blink::createSameThreadTask(&StorageErrorCallback::run, wrapPersistent(callback), ec); }
void Geolocation::queryNextPosition() { m_geolocationService->QueryNextPosition(convertToBaseCallback( WTF::bind(&Geolocation::onPositionUpdated, wrapPersistent(this)))); }
Database* DatabaseManager::openDatabase(ExecutionContext* context, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize, DatabaseCallback* creationCallback, DatabaseError& error, String& errorMessage) { ASSERT(error == DatabaseError::None); bool setVersionInNewDatabase = !creationCallback; Database* database = openDatabaseInternal(context, name, expectedVersion, displayName, estimatedSize, setVersionInNewDatabase, error, errorMessage); if (!database) return nullptr; databaseContextFor(context)->setHasOpenDatabases(); DatabaseClient::from(context)->didOpenDatabase(database, context->getSecurityOrigin()->host(), name, expectedVersion); if (database->isNew() && creationCallback) { WTF_LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for database %p\n", database); database->getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&databaseCallbackHandleEvent, wrapPersistent(creationCallback), wrapPersistent(database)), "openDatabase"); } ASSERT(database); return database; }
void ContentDecryptionModuleResultPromise::reject(ExceptionCode code, const String& errorMessage) { // Reject the promise asynchronously. This avoids problems when gc is // destroying objects that result in unfulfilled promises being rejected. // (Resolving promises is still done synchronously as there may be events // already posted that need to happen only after the promise is resolved.) // TODO(jrummell): Make resolving a promise asynchronous as well (including // making sure events still happen after the promise is resolved). getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&ContentDecryptionModuleResultPromise::rejectInternal, wrapPersistent(this), code, errorMessage)); }
void VRController::getDisplays(std::unique_ptr<VRGetDevicesCallback> callback) { if (!m_service) { callback->onError(); return; } m_pendingGetDevicesCallbacks.append(std::move(callback)); m_service->GetDisplays(createBaseCallback(WTF::bind(&VRController::onGetDisplays, wrapPersistent(this)))); }