static PassRefPtr<FileThread> createFileThread() { RefPtr<FileThread> thread = FileThread::create(); if (!thread->start()) return 0; return thread.release(); }
static inline void startReadableStreamAsync(ReadableStream& stream) { RefPtr<ReadableStream> protectedStream = &stream; stream.scriptExecutionContext()->postTask([protectedStream](ScriptExecutionContext&) { protectedStream->start(); }); }
bool RenderThemeGtk::paintMediaSliderTrack(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r) { HTMLMediaElement* mediaElement = toParentMediaElement(o); if (!mediaElement) return false; GraphicsContext* context = paintInfo.context; context->save(); context->setStrokeStyle(NoStroke); float mediaDuration = mediaElement->duration(); float totalTrackWidth = r.width(); RenderStyle* style = o->style(); RefPtr<TimeRanges> timeRanges = mediaElement->buffered(); for (unsigned index = 0; index < timeRanges->length(); ++index) { float start = timeRanges->start(index, IGNORE_EXCEPTION); float end = timeRanges->end(index, IGNORE_EXCEPTION); float startRatio = start / mediaDuration; float lengthRatio = (end - start) / mediaDuration; if (!lengthRatio) continue; IntRect rangeRect(r); rangeRect.setWidth(lengthRatio * totalTrackWidth); if (index) rangeRect.move(startRatio * totalTrackWidth, 0); context->fillRoundedRect(RoundedRect(rangeRect, borderRadiiFromStyle(style)), style->visitedDependentColor(CSSPropertyColor), style->colorSpace()); } context->restore(); return false; }
void HostRecord::servePendingRequestsForQueue(LoaderQueue& queue, ResourceLoadPriority priority) { while (!queue.isEmpty()) { RefPtr<SchedulableLoader> loader = queue.first(); ASSERT(loader->hostRecord() == this); // This request might be from WebProcess we've lost our connection to. // If so we should just skip it. if (!loader->connectionToWebProcess()) { removeLoader(loader.get()); continue; } // For named hosts - which are only http(s) hosts - we should always enforce the connection limit. // For non-named hosts - everything but http(s) - we should only enforce the limit if the document // isn't done parsing and we don't know all stylesheets yet. // FIXME (NetworkProcess): The above comment about document parsing and stylesheets is a holdover // from the WebCore::ResourceLoadScheduler. // The behavior described was at one time important for WebCore's single threadedness. // It's possible that we don't care about it with the NetworkProcess. // We should either decide it's not important and change the above comment, or decide it is // still important and somehow account for it. bool shouldLimitRequests = !name().isNull(); if (shouldLimitRequests && limitsRequests(priority, loader->connectionToWebProcess()->isSerialLoadingEnabled())) return; m_loadersInProgress.add(loader); queue.removeFirst(); loader->start(); } }
bool RenderThemeQt::paintMediaSliderTrack(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r) { HTMLMediaElement* mediaElement = toParentMediaElement(o); if (!mediaElement) return false; QSharedPointer<StylePainter> p = getStylePainter(paintInfo); if (p.isNull() || !p->isValid()) return true; p->painter->setRenderHint(QPainter::Antialiasing, true); paintMediaBackground(p->painter, r); if (MediaPlayer* player = mediaElement->player()) { // Get the buffered parts of the media RefPtr<TimeRanges> buffered = player->buffered(); if (buffered->length() > 0 && player->duration() < std::numeric_limits<float>::infinity()) { // Set the transform and brush WorldMatrixTransformer transformer(p->painter, o, r); p->painter->setBrush(getMediaControlForegroundColor()); // Paint each buffered section for (int i = 0; i < buffered->length(); i++) { float startX = (buffered->start(i, IGNORE_EXCEPTION) / player->duration()) * 100; float width = ((buffered->end(i, IGNORE_EXCEPTION) / player->duration()) * 100) - startX; p->painter->drawRect(startX, 37, width, 26); } } } return false; }
void ResourceLoadScheduler::servePendingRequests(HostInformation* host, ResourceLoadPriority minimumPriority) { LOG(ResourceLoading, "ResourceLoadScheduler::servePendingRequests HostInformation.m_name='%s'", host->name().latin1().data()); for (int priority = ResourceLoadPriorityHighest; priority >= minimumPriority; --priority) { HostInformation::RequestQueue& requestsPending = host->requestsPending(ResourceLoadPriority(priority)); while (!requestsPending.isEmpty()) { RefPtr<ResourceLoader> resourceLoader = requestsPending.first(); // For named hosts - which are only http(s) hosts - we should always enforce the connection limit. // For non-named hosts - everything but http(s) - we should only enforce the limit if the document isn't done parsing // and we don't know all stylesheets yet. Document* document = resourceLoader->frameLoader() ? resourceLoader->frameLoader()->frame().document() : 0; bool shouldLimitRequests = !host->name().isNull() || (document && (document->parsing() || !document->haveStylesheetsLoaded())); if (shouldLimitRequests && host->limitRequests(ResourceLoadPriority(priority))) return; requestsPending.removeFirst(); host->addLoadInProgress(resourceLoader.get()); #if PLATFORM(IOS) if (!applicationIsWebProcess()) { resourceLoader->startLoading(); return; } #endif resourceLoader->start(); } } }
bool RenderThemeGtk::paintMediaSliderTrack(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r) { GraphicsContext* context = paintInfo.context; context->fillRect(FloatRect(r), m_panelColor, ColorSpaceDeviceRGB); context->fillRect(FloatRect(IntRect(r.x(), r.y() + (r.height() - m_mediaSliderHeight) / 2, r.width(), m_mediaSliderHeight)), m_sliderColor, ColorSpaceDeviceRGB); RenderStyle* style = o->style(); HTMLMediaElement* mediaElement = toParentMediaElement(o); if (!mediaElement) return false; // Draw the buffered ranges. This code is highly inspired from // Chrome for the gradient code. float mediaDuration = mediaElement->duration(); RefPtr<TimeRanges> timeRanges = mediaElement->buffered(); IntRect trackRect = r; int totalWidth = trackRect.width(); trackRect.inflate(-style->borderLeftWidth()); context->save(); context->setStrokeStyle(NoStroke); for (unsigned index = 0; index < timeRanges->length(); ++index) { ExceptionCode ignoredException; float start = timeRanges->start(index, ignoredException); float end = timeRanges->end(index, ignoredException); int width = ((end - start) * totalWidth) / mediaDuration; IntRect rangeRect; if (!index) { rangeRect = trackRect; rangeRect.setWidth(width); } else { rangeRect.setLocation(IntPoint(trackRect.x() + start / mediaDuration* totalWidth, trackRect.y())); rangeRect.setSize(IntSize(width, trackRect.height())); } // Don't bother drawing empty range. if (rangeRect.isEmpty()) continue; IntPoint sliderTopLeft = rangeRect.location(); IntPoint sliderTopRight = sliderTopLeft; sliderTopRight.move(0, rangeRect.height()); RefPtr<Gradient> gradient = Gradient::create(sliderTopLeft, sliderTopRight); Color startColor = m_panelColor; gradient->addColorStop(0.0, startColor); gradient->addColorStop(1.0, Color(startColor.red() / 2, startColor.green() / 2, startColor.blue() / 2, startColor.alpha())); context->setFillGradient(gradient); context->fillRect(rangeRect); } context->restore(); return false; }
static inline JSFunction* createStartResultFulfilledFunction(ExecState& state, ReadableStream& readableStream) { RefPtr<ReadableStream> stream = &readableStream; return JSFunction::create(state.vm(), state.callee()->globalObject(), 1, String(), [stream](ExecState*) { stream->start(); return JSValue::encode(jsUndefined()); }); }
void WorkerMessagingProxy::startWorkerContext(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode) { RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(scriptURL, userAgent, sourceCode, *this, *this, startMode, m_scriptExecutionContext->contentSecurityPolicy()->policy(), m_scriptExecutionContext->contentSecurityPolicy()->headerType()); workerThreadCreated(thread); thread->start(); InspectorInstrumentation::didStartWorkerContext(m_scriptExecutionContext.get(), this, scriptURL); }
PassRefPtr<ResourceHandle> BlobRegistryImpl::createResourceHandle(const ResourceRequest& request, ResourceHandleClient* client) { if (!shouldLoadResource(request)) return 0; RefPtr<BlobResourceHandle> handle = BlobResourceHandle::create(m_blobs.get(request.url().string()), request, client); handle->start(); return handle.release(); }
PassRefPtr<ResourceHandle> BlobRegistryImpl::createResourceHandle(const ResourceRequest& request, ResourceHandleClient* client) { RefPtr<BlobResourceHandle> handle = BlobResourceHandle::createAsync(getBlobDataFromURL(request.url()), request, client); if (!handle) return 0; handle->start(); return handle.release(); }
void PluginView::performRequest(PluginRequest* request) { // don't let a plugin start any loads if it is no longer part of a document that is being // displayed unless the loads are in the same frame as the plugin. const String& targetFrameName = request->frameLoadRequest().frameName(); if (m_parentFrame->loader()->documentLoader() != m_parentFrame->loader()->activeDocumentLoader() && (targetFrameName.isNull() || m_parentFrame->tree()->find(targetFrameName) != m_parentFrame)) return; KURL requestURL = request->frameLoadRequest().resourceRequest().url(); String jsString = scriptStringIfJavaScriptURL(requestURL); if (jsString.isNull()) { // if this is not a targeted request, create a stream for it. otherwise, // just pass it off to the loader if (targetFrameName.isEmpty()) { RefPtr<PluginStream> stream = PluginStream::create(this, m_parentFrame, request->frameLoadRequest().resourceRequest(), request->sendNotification(), request->notifyData(), plugin()->pluginFuncs(), instance(), m_plugin->quirks()); m_streams.add(stream); stream->start(); } else { m_parentFrame->loader()->load(request->frameLoadRequest().resourceRequest(), targetFrameName); // FIXME: <rdar://problem/4807469> This should be sent when the document has finished loading if (request->sendNotification()) { PluginView::setCurrentPluginView(this); JSC::JSLock::DropAllLocks dropAllLocks(false); setCallingPlugin(true); m_plugin->pluginFuncs()->urlnotify(m_instance, requestURL.string().utf8().data(), NPRES_DONE, request->notifyData()); setCallingPlugin(false); PluginView::setCurrentPluginView(0); } } return; } // Targeted JavaScript requests are only allowed on the frame that contains the JavaScript plugin // and this has been made sure in ::load. ASSERT(targetFrameName.isEmpty() || m_parentFrame->tree()->find(targetFrameName) == m_parentFrame); // Executing a script can cause the plugin view to be destroyed, so we keep a reference to the parent frame. RefPtr<Frame> parentFrame = m_parentFrame; JSValue* result = m_parentFrame->loader()->executeScript(jsString, request->shouldAllowPopups()); if (targetFrameName.isNull()) { String resultString; CString cstr; if (getString(parentFrame->script(), result, resultString)) cstr = resultString.utf8(); RefPtr<PluginStream> stream = PluginStream::create(this, m_parentFrame, request->frameLoadRequest().resourceRequest(), request->sendNotification(), request->notifyData(), plugin()->pluginFuncs(), instance(), m_plugin->quirks()); m_streams.add(stream); stream->sendJavaScriptStream(requestURL, cstr); } }
void BlobResourceHandle::loadResourceSynchronously(BlobData* blobData, const ResourceRequest& request, ResourceError& error, ResourceResponse& response, Vector<char>& data) { if (!equalIgnoringCase(request.httpMethod(), "GET")) { error = ResourceError(webKitBlobResourceDomain, methodNotAllowed, response.url(), "Request method must be GET"); return; } BlobResourceSynchronousLoader loader(error, response, data); RefPtr<BlobResourceHandle> handle = adoptRef(new BlobResourceHandle(blobData, request, &loader, false)); handle->start(); }
void InspectorIndexedDBAgent::requestDatabase(ErrorString* errorString, int requestId, const String& frameId, const String& databaseName) { Document* document = assertDocument(errorString, frameId, m_pageAgent); if (!document) return; IDBFactoryBackendInterface* idbFactory = assertIDBFactory(errorString, document); if (!idbFactory) return; RefPtr<DatabaseLoaderCallback> databaseLoaderCallback = DatabaseLoaderCallback::create(m_frontendProvider.get(), requestId); databaseLoaderCallback->start(idbFactory, document->securityOrigin(), document->frame(), databaseName); }
void WorkerMessagingProxy::startWorkerGlobalScope(const URL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode) { // FIXME: This need to be revisited when we support nested worker one day ASSERT_WITH_SECURITY_IMPLICATION(m_scriptExecutionContext->isDocument()); Document* document = static_cast<Document*>(m_scriptExecutionContext.get()); GroupSettings* settings = 0; if (document->page()) settings = &document->page()->group().groupSettings(); RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(scriptURL, userAgent, settings, sourceCode, *this, *this, startMode, document->contentSecurityPolicy()->deprecatedHeader(), document->contentSecurityPolicy()->deprecatedHeaderType(), document->topOrigin()); workerThreadCreated(thread); thread->start(); InspectorInstrumentation::didStartWorkerGlobalScope(m_scriptExecutionContext.get(), this, scriptURL); }
static bool paintMediaSlider(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) { HTMLMediaElement* mediaElement = toParentMediaElement(object); if (!mediaElement) return false; RenderStyle* style = object->style(); GraphicsContext* context = paintInfo.context; paintRoundedSliderBackground(rect, style, context); // Draw the buffered range. Since the element may have multiple buffered ranges and it'd be // distracting/'busy' to show all of them, show only the buffered range containing the current play head. RefPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered(); float duration = mediaElement->duration(); float currentTime = mediaElement->currentTime(); if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan(currentTime)) return true; for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) { float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION); float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION); if (std::isnan(start) || std::isnan(end) || start > currentTime || end < currentTime) continue; int startPosition = int(start * rect.width() / duration); int currentPosition = int(currentTime * rect.width() / duration); int endPosition = int(end * rect.width() / duration); // Add half the thumb width proportionally adjusted to the current painting position. int thumbCenter = mediaSliderThumbWidth / 2; int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width()); currentPosition += addWidth; // Draw white-ish highlight before current time. Color startColor = Color(195, 195, 195); Color endColor = Color(217, 217, 217); if (currentPosition > startPosition) paintSliderRangeHighlight(rect, style, context, startPosition, currentPosition, startColor, endColor); // Draw grey-ish highlight after current time. startColor = Color(60, 60, 60); endColor = Color(76, 76, 76); if (endPosition > currentPosition) paintSliderRangeHighlight(rect, style, context, currentPosition, endPosition, startColor, endColor); return true; } return true; }
void CCLayerTreeHost::startRateLimiter(GraphicsContext3D* context) { if (m_animating) return; ASSERT(context); RateLimiterMap::iterator it = m_rateLimiters.find(context); if (it != m_rateLimiters.end()) it->second->start(); else { RefPtr<RateLimiter> rateLimiter = RateLimiter::create(context, this); m_rateLimiters.set(context, rateLimiter); rateLimiter->start(); } }
void DefaultSharedWorkerRepository::workerScriptLoaded(SharedWorkerProxy& proxy, const String& userAgent, const String& workerScript, PassOwnPtr<MessagePortChannel> port) { MutexLocker lock(m_lock); if (proxy.closing()) return; // Another loader may have already started up a thread for this proxy - if so, just send a connect to the pre-existing thread. if (!proxy.thread()) { RefPtr<SharedWorkerThread> thread = SharedWorkerThread::create(proxy.name(), proxy.url(), userAgent, workerScript, proxy); proxy.setThread(thread); thread->start(); } proxy.thread()->runLoop().postTask(SharedWorkerConnectTask::create(port)); }
void WorkerMessagingProxy::startWorkerGlobalScope(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode) { // FIXME: This need to be revisited when we support nested worker one day ASSERT(m_executionContext->isDocument()); Document* document = toDocument(m_executionContext.get()); OwnPtrWillBeRawPtr<WorkerThreadStartupData> startupData = WorkerThreadStartupData::create(scriptURL, userAgent, sourceCode, startMode, document->contentSecurityPolicy()->deprecatedHeader(), document->contentSecurityPolicy()->deprecatedHeaderType(), m_workerClients.release()); double originTime = document->loader() ? document->loader()->timing()->referenceMonotonicTime() : monotonicallyIncreasingTime(); RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(*this, *m_workerObjectProxy.get(), originTime, startupData.release()); thread->start(); workerThreadCreated(thread); InspectorInstrumentation::didStartWorkerGlobalScope(m_executionContext.get(), this, scriptURL); }
PassRefPtr<ResourceHandle> ResourceHandle::create(NetworkingContext* context, const ResourceRequest& request, ResourceHandleClient* client, bool defersLoading, bool shouldContentSniff) { RefPtr<ResourceHandle> newHandle = adoptRef(new ResourceHandle( request, client, defersLoading, shouldContentSniff)); if (newHandle->start(context)) return newHandle.release(); return 0; }
void DefaultSharedWorkerRepository::workerScriptLoaded(SharedWorkerProxy& proxy, const String& userAgent, const String& workerScript, PassOwnPtr<MessagePortChannel> port, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType) { MutexLocker lock(m_lock); if (proxy.isClosing()) return; // Another loader may have already started up a thread for this proxy - if so, just send a connect to the pre-existing thread. if (!proxy.thread()) { RefPtr<SharedWorkerThread> thread = SharedWorkerThread::create(proxy.name(), proxy.url(), userAgent, proxy.groupSettings(), workerScript, proxy, proxy, DontPauseWorkerGlobalScopeOnStart, contentSecurityPolicy, contentSecurityPolicyType); proxy.setThread(thread); thread->start(); } proxy.thread()->runLoop().postTask(SharedWorkerConnectTask::create(port)); }
void WebWorkerClientImpl::startWorkerContext(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode) { ASSERT(m_scriptExecutionContext->isDocument()); Document* document = static_cast<Document*>(m_scriptExecutionContext.get()); GroupSettings* settings = 0; if (document->page()) settings = document->page()->group().groupSettings(); RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(scriptURL, userAgent, settings, sourceCode, *this, *this, startMode, document->contentSecurityPolicy()->deprecatedHeader(), document->contentSecurityPolicy()->deprecatedHeaderType(), document->topDocument()->securityOrigin()); m_proxy->workerThreadCreated(thread); thread->start(); InspectorInstrumentation::didStartWorkerContext(m_scriptExecutionContext.get(), m_proxy, scriptURL); }
void MediaDevices::getUserMedia(const Dictionary& options, ResolveCallback resolveCallback, RejectCallback rejectCallback, ExceptionCode& ec) const { UserMediaController* userMedia = UserMediaController::from(document() ? document()->page() : nullptr); if (!userMedia) { ec = NOT_SUPPORTED_ERR; return; } RefPtr<UserMediaRequest> request = UserMediaRequest::create(document(), userMedia, options, WTF::move(resolveCallback), WTF::move(rejectCallback), ec); if (!request) { ec = NOT_SUPPORTED_ERR; return; } request->start(); }
float MediaPlayerPrivate::percentLoaded() { if (!m_platformPlayer->duration()) return 0; float buffered = 0; RefPtr<TimeRanges> timeRanges = this->buffered(); for (unsigned i = 0; i < timeRanges->length(); ++i) { ExceptionCode ignoredException; float start = timeRanges->start(i, ignoredException); float end = timeRanges->end(i, ignoredException); buffered += end - start; } float loaded = buffered / m_platformPlayer->duration(); return loaded; }
static uint8_t* mmAllocateCodeSection( void* opaqueState, uintptr_t size, unsigned alignment, unsigned sectionID) { UNUSED_PARAM(sectionID); State& state = *static_cast<State*>(opaqueState); RELEASE_ASSERT(alignment <= jitAllocationGranule); RefPtr<ExecutableMemoryHandle> result = state.graph.m_vm.executableAllocator.allocate( state.graph.m_vm, size, state.graph.m_codeBlock, JITCompilationMustSucceed); state.jitCode->addHandle(result); return static_cast<uint8_t*>(result->start()); }
void Worker::notifyFinished(CachedResource* resource) { ASSERT(resource == m_cachedScript.get()); if (m_cachedScript->errorOccurred()) dispatchErrorEvent(); else { String userAgent = document()->frame() ? document()->frame()->loader()->userAgent(m_scriptURL) : String(); RefPtr<WorkerThread> thread = WorkerThread::create(m_scriptURL, userAgent, m_cachedScript->script(), m_messagingProxy); m_messagingProxy->workerThreadCreated(thread); thread->start(); } m_cachedScript->removeClient(this); m_cachedScript = 0; unsetPendingActivity(this); }
PassRefPtr<AudioBufferSourceNode> SoundBuffer::play(AudioNode* outputNode, float when) { if (audioBuffer) { RefPtr<AudioBufferSourceNode> sourceBuffer; sourceBuffer = context->createBufferSource(); // Connect the source node to the parsed audio data for playback sourceBuffer->setBuffer(audioBuffer.get()); // bus the sound to the mixer. WebCore::ExceptionCode ec; sourceBuffer->connect(outputNode, 0, 0, ec); sourceBuffer->start(when); return sourceBuffer; } return 0; }
void PluginView::performURLRequest(URLRequest* request) { // First, check if this is a javascript: url. if (protocolIsJavaScript(request->request().url())) { performJavaScriptURLRequest(request); return; } if (!request->target().isNull()) { performFrameLoadURLRequest(request); return; } // This request is to load a URL and create a stream. RefPtr<Stream> stream = PluginView::Stream::create(this, request->requestID(), request->request()); addStream(stream.get()); stream->start(); }
TEST(TimeRanges, AddOrder) { RefPtr<TimeRanges> rangeA = TimeRanges::create(); RefPtr<TimeRanges> rangeB = TimeRanges::create(); rangeA->add(0, 2); rangeA->add(3, 4); rangeA->add(5, 100); std::string expected = "{ [0,2) [3,4) [5,100) }"; ASSERT_RANGE(expected, rangeA); // Add the values in rangeA to rangeB in reverse order. for (int i = rangeA->length() - 1; i >= 0; --i) rangeB->add(rangeA->start(i, IGNORE_EXCEPTION), rangeA->end(i, IGNORE_EXCEPTION)); ASSERT_RANGE(expected, rangeB); }
void NavigatorMediaStream::webkitGetUserMedia(Navigator* navigator, const String& options, PassRefPtr<NavigatorUserMediaSuccessCallback> successCallback, PassRefPtr<NavigatorUserMediaErrorCallback> errorCallback, ExceptionCode& ec) { if (!successCallback) return; UserMediaController* userMedia = UserMediaController::from(navigator->frame() ? navigator->frame()->page() : 0); if (!userMedia) { ec = NOT_SUPPORTED_ERR; return; } RefPtr<UserMediaRequest> request = UserMediaRequest::create(navigator->frame()->document(), userMedia, options, successCallback, errorCallback); if (!request) { ec = NOT_SUPPORTED_ERR; return; } request->start(); }