Example #1
0
WorkerThreadStartupData::WorkerThreadStartupData(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode)
    : m_scriptURL(scriptURL.copy())
    , m_userAgent(userAgent.isolatedCopy())
    , m_sourceCode(sourceCode.isolatedCopy())
    , m_startMode(startMode)
{
}
 WorkerExceptionTask(const String& errorMessage, int lineNumber, const String& sourceURL, WorkerMessagingProxy* messagingProxy)
     : m_errorMessage(errorMessage.isolatedCopy())
     , m_lineNumber(lineNumber)
     , m_sourceURL(sourceURL.isolatedCopy())
     , m_messagingProxy(messagingProxy)
 {
 }
Example #3
0
NetworkCacheKey::NetworkCacheKey(const String& method, const String& partition, const String& identifier)
    : m_method(method.isolatedCopy())
    , m_partition(partition.isolatedCopy())
    , m_identifier(identifier.isolatedCopy())
    , m_hash(computeHash())
{
}
DatabaseBackendBase::DatabaseBackendBase(PassRefPtr<DatabaseBackendContext> databaseContext, const String& name,
    const String& expectedVersion, const String& displayName, unsigned long estimatedSize, DatabaseType databaseType)
    : m_databaseContext(databaseContext)
    , m_name(name.isolatedCopy())
    , m_expectedVersion(expectedVersion.isolatedCopy())
    , m_displayName(displayName.isolatedCopy())
    , m_estimatedSize(estimatedSize)
    , m_guid(0)
    , m_opened(false)
    , m_new(false)
    , m_isSyncDatabase(databaseType == DatabaseType::Sync)
{
    m_contextThreadSecurityOrigin = m_databaseContext->securityOrigin()->isolatedCopy();

    m_databaseAuthorizer = DatabaseAuthorizer::create(infoTableName);

    if (m_name.isNull())
        m_name = "";

    {
        MutexLocker locker(guidMutex());
        m_guid = guidForOriginAndName(securityOrigin()->toString(), name);
        HashSet<DatabaseBackendBase*>* hashSet = guidToDatabaseMap().get(m_guid);
        if (!hashSet) {
            hashSet = new HashSet<DatabaseBackendBase*>;
            guidToDatabaseMap().set(m_guid, hashSet);
        }

        hashSet->add(this);
    }

    m_filename = DatabaseManager::manager().fullPathForDatabase(securityOrigin(), m_name);
}
DatabaseManager::ProposedDatabase::ProposedDatabase(DatabaseManager& manager, SecurityOrigin* origin, const String& name, const String& displayName, unsigned long estimatedSize)
    : m_manager(manager)
    , m_origin(origin->isolatedCopy())
    , m_details(name.isolatedCopy(), displayName.isolatedCopy(), estimatedSize, 0, 0, 0)
{
    m_manager.addProposedDatabase(this);
}
Example #6
0
PassRefPtr<DatabaseBackendBase> DatabaseManager::openDatabaseBackend(ScriptExecutionContext* context,
    DatabaseType type, const String& name, const String& expectedVersion, const String& displayName,
    unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError& error, String& errorMessage)
{
    ASSERT(error == DatabaseError::None);

    RefPtr<DatabaseContext> databaseContext = databaseContextFor(context);
    RefPtr<DatabaseBackendContext> backendContext = databaseContext->backend();

    RefPtr<DatabaseBackendBase> backend = m_server->openDatabase(backendContext, type, name, expectedVersion,
        displayName, estimatedSize, setVersionInNewDatabase, error, errorMessage);

    if (!backend) {
        ASSERT(error != DatabaseError::None);

        switch (error) {
        case DatabaseError::DatabaseIsBeingDeleted:
        case DatabaseError::DatabaseSizeOverflowed:
        case DatabaseError::GenericSecurityError:
            logOpenDatabaseError(context, name);
            return 0;

        case DatabaseError::InvalidDatabaseState:
            logErrorMessage(context, errorMessage);
            return 0;

        case DatabaseError::DatabaseSizeExceededQuota:
            // Notify the client that we've exceeded the database quota.
            // The client may want to increase the quota, and we'll give it
            // one more try after if that is the case.
            databaseContext->databaseExceededQuota(name,
                DatabaseDetails(name.isolatedCopy(), displayName.isolatedCopy(), estimatedSize, 0));

            error = DatabaseError::None;

            backend = m_server->openDatabase(backendContext, type, name, expectedVersion,
                displayName, estimatedSize, setVersionInNewDatabase, error, errorMessage,
                AbstractDatabaseServer::RetryOpenDatabase);
            break;

        default:
            ASSERT_NOT_REACHED();
        }

        if (!backend) {
            ASSERT(error != DatabaseError::None);

            if (error == DatabaseError::InvalidDatabaseState) {
                logErrorMessage(context, errorMessage);
                return 0;
            }

            logOpenDatabaseError(context, name);
            return 0;
        }
    }

    return backend.release();
}
Example #7
0
WorkerThreadStartupData::WorkerThreadStartupData(const URL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType, const SecurityOrigin* topOrigin)
    : m_scriptURL(scriptURL.isolatedCopy())
    , m_userAgent(userAgent.isolatedCopy())
    , m_sourceCode(sourceCode.isolatedCopy())
    , m_startMode(startMode)
    , m_contentSecurityPolicy(contentSecurityPolicy.isolatedCopy())
    , m_contentSecurityPolicyType(contentSecurityPolicyType)
    , m_topOrigin(topOrigin ? &topOrigin->isolatedCopy().get() : nullptr)
{
}
WorkerThreadStartupData::WorkerThreadStartupData(const KURL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode, const String& contentSecurityPolicy, ContentSecurityPolicyHeaderType contentSecurityPolicyType, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients)
    : m_scriptURL(scriptURL.copy())
    , m_userAgent(userAgent.isolatedCopy())
    , m_sourceCode(sourceCode.isolatedCopy())
    , m_startMode(startMode)
    , m_contentSecurityPolicy(contentSecurityPolicy.isolatedCopy())
    , m_contentSecurityPolicyType(contentSecurityPolicyType)
    , m_workerClients(workerClients)
{
}
Example #9
0
WorkerThreadStartupData::WorkerThreadStartupData(const URL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicyResponseHeaders, bool shouldBypassMainWorldContentSecurityPolicy, const SecurityOrigin* topOrigin)
    : m_scriptURL(scriptURL.isolatedCopy())
    , m_userAgent(userAgent.isolatedCopy())
    , m_sourceCode(sourceCode.isolatedCopy())
    , m_startMode(startMode)
    , m_contentSecurityPolicyResponseHeaders(contentSecurityPolicyResponseHeaders.isolatedCopy())
    , m_shouldBypassMainWorldContentSecurityPolicy(shouldBypassMainWorldContentSecurityPolicy)
    , m_topOrigin(topOrigin ? &topOrigin->isolatedCopy().get() : nullptr)
{
}
void WorkerMessagingProxy::postConsoleMessageToWorkerObject(MessageSource source, MessageLevel level, const String& message, int lineNumber, int columnNumber, const String& sourceURL)
{
    String messageCopy = message.isolatedCopy();
    String sourceURLCopy = sourceURL.isolatedCopy();
    m_scriptExecutionContext->postTask([=] (ScriptExecutionContext* context) {
        if (askedToTerminate())
            return;
        context->addConsoleMessage(source, level, messageCopy, sourceURLCopy, lineNumber, columnNumber);
    });
}
void SharedWorkerProxy::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
{
    MutexLocker lock(m_workerDocumentsLock);
    String errorMessageCopy = errorMessage.isolatedCopy();
    String sourceURLCopy = sourceURL.isolatedCopy();

    for (auto& document : m_workerDocuments)
        document->postTask([=] (ScriptExecutionContext& context) {
            context.reportException(errorMessageCopy, lineNumber, columnNumber, sourceURLCopy, nullptr);
        });
}
void SharedWorkerProxy::postConsoleMessageToWorkerObject(MessageSource source, MessageLevel level, const String& message, int lineNumber, int columnNumber, const String& sourceURL)
{
    MutexLocker lock(m_workerDocumentsLock);
    String messageCopy = message.isolatedCopy();
    String sourceURLCopy = sourceURL.isolatedCopy();

    for (auto& document : m_workerDocuments)
        document->postTask([=] (ScriptExecutionContext& context) {
            context.addConsoleMessage(source, level, messageCopy, sourceURLCopy, lineNumber, columnNumber);
        });
}
Example #13
0
String threadSafeCopy(const String& string)
{
    RefPtr<StringImpl> copy(string.impl());
    if (string.isSafeToSendToAnotherThread())
        return string;
    return string.isolatedCopy();
}
Example #14
0
void WorkerThreadableWebSocketChannel::Bridge::fail(const String& reason, MessageLevel level, const String& sourceURL, unsigned lineNumber)
{
    if (hasTerminatedPeer())
        return;

    m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::fail, m_peer, reason.isolatedCopy(), level, sourceURL.isolatedCopy(), lineNumber)));
}
MediaValuesCached::MediaValuesCached(LocalFrame* frame)
{
    ASSERT(isMainThread());
    ASSERT(frame);
    // In case that frame is missing (e.g. for images that their document does not have a frame)
    // We simply leave the MediaValues object with the default MediaValuesCachedData values.
    m_data.viewportWidth = calculateViewportWidth(frame);
    m_data.viewportHeight = calculateViewportHeight(frame);
    m_data.deviceWidth = calculateDeviceWidth(frame);
    m_data.deviceHeight = calculateDeviceHeight(frame);
    m_data.devicePixelRatio = calculateDevicePixelRatio(frame);
    m_data.colorBitsPerComponent = calculateColorBitsPerComponent(frame);
    m_data.monochromeBitsPerComponent = calculateMonochromeBitsPerComponent(frame);
    m_data.primaryPointerType = calculatePrimaryPointerType(frame);
    m_data.availablePointerTypes = calculateAvailablePointerTypes(frame);
    m_data.primaryHoverType = calculatePrimaryHoverType(frame);
    m_data.availableHoverTypes = calculateAvailableHoverTypes(frame);
    m_data.defaultFontSize = calculateDefaultFontSize(frame);
    m_data.threeDEnabled = calculateThreeDEnabled(frame);
    m_data.strictMode = calculateStrictMode(frame);
    m_data.displayMode = calculateDisplayMode(frame);
    const String mediaType = calculateMediaType(frame);
    if (!mediaType.isEmpty())
        m_data.mediaType = mediaType.isolatedCopy();
}
Example #16
0
void StorageTracker::setOriginDetails(const String& originIdentifier, const String& databaseFile)
{
    if (!m_isActive)
        return;

    {
        LockHolder locker(m_originSetMutex);

        if (m_originSet.contains(originIdentifier))
            return;

        m_originSet.add(originIdentifier);
    }

    auto function = [this, originIdentifier = originIdentifier.isolatedCopy(), databaseFile = databaseFile.isolatedCopy()] {
        syncSetOriginDetails(originIdentifier, databaseFile);
    };

    if (isMainThread()) {
        ASSERT(m_thread);
        m_thread->dispatch(WTFMove(function));
    } else {
        // FIXME: This weird ping-ponging was done to fix a deadlock. We should figure out a cleaner way to avoid it instead.
        callOnMainThread([this, function = WTFMove(function)]() mutable {
            m_thread->dispatch(WTFMove(function));
        });
    }
}
inline StorageAreaSync::StorageAreaSync(PassRefPtr<StorageSyncManager> storageSyncManager, PassRefPtr<StorageAreaImpl> storageArea, const String& databaseIdentifier)
    : m_syncTimer(*this, &StorageAreaSync::syncTimerFired)
    , m_itemsCleared(false)
    , m_finalSyncScheduled(false)
    , m_storageArea(storageArea)
    , m_syncManager(storageSyncManager)
    , m_databaseIdentifier(databaseIdentifier.isolatedCopy())
    , m_clearItemsWhileSyncing(false)
    , m_syncScheduled(false)
    , m_syncInProgress(false)
    , m_databaseOpenFailed(false)
    , m_syncCloseDatabase(false)
    , m_importComplete(false)
{
    ASSERT(isMainThread());
    ASSERT(m_storageArea);
    ASSERT(m_syncManager);

    // FIXME: If it can't import, then the default WebKit behavior should be that of private browsing,
    // not silently ignoring it. https://bugs.webkit.org/show_bug.cgi?id=25894
    RefPtr<StorageAreaSync> protector(this);
    m_syncManager->dispatch([protector] {
        protector->performImport();
    });
}
Example #18
0
void CurlDownload::didReceiveHeader(const String& header)
{
    LockHolder locker(m_mutex);

    if (header == "\r\n" || header == "\n") {

        long httpCode = 0;
        CURLcode err = curl_easy_getinfo(m_curlHandle, CURLINFO_RESPONSE_CODE, &httpCode);

        if (httpCode >= 200 && httpCode < 300) {
            URL url = getCurlEffectiveURL(m_curlHandle);
            callOnMainThread([this, url = url.isolatedCopy(), protectedThis = makeRef(*this)] {
                m_response.setURL(url);
                m_response.setMimeType(extractMIMETypeFromMediaType(m_response.httpHeaderField(HTTPHeaderName::ContentType)));
                m_response.setTextEncodingName(extractCharsetFromMediaType(m_response.httpHeaderField(HTTPHeaderName::ContentType)));

                didReceiveResponse();
            });
        }
    } else {
        callOnMainThread([this, header = header.isolatedCopy(), protectedThis = makeRef(*this)] {
            int splitPos = header.find(":");
            if (splitPos != -1)
                m_response.setHTTPHeaderField(header.left(splitPos), header.substring(splitPos + 1).stripWhiteSpace());
        });
    }
}
Example #19
0
WorkerThreadableLoader::MainThreadBridge::MainThreadBridge(PassRefPtr<ThreadableLoaderClientWrapper> workerClientWrapper, WorkerLoaderProxy& loaderProxy, const String& taskMode,
    const ResourceRequest& request, const ThreadableLoaderOptions& options, const String& outgoingReferrer,
    const SecurityOrigin* securityOrigin, const ContentSecurityPolicy* contentSecurityPolicy)
    : m_workerClientWrapper(workerClientWrapper)
    , m_loaderProxy(loaderProxy)
    , m_taskMode(taskMode.isolatedCopy())
{
    ASSERT(m_workerClientWrapper.get());

    auto* requestData = request.copyData().release();
    auto* optionsCopy = options.isolatedCopy().release();

    ASSERT(securityOrigin);
    ASSERT(contentSecurityPolicy);
    auto* contentSecurityPolicyCopy = std::make_unique<ContentSecurityPolicy>(*securityOrigin).release();
    contentSecurityPolicyCopy->copyStateFrom(contentSecurityPolicy);

    StringCapture capturedOutgoingReferrer(outgoingReferrer);
    m_loaderProxy.postTaskToLoader([this, requestData, optionsCopy, contentSecurityPolicyCopy, capturedOutgoingReferrer](ScriptExecutionContext& context) {
        ASSERT(isMainThread());
        Document& document = downcast<Document>(context);

        auto request = ResourceRequest::adopt(std::unique_ptr<CrossThreadResourceRequestData>(requestData));
        request->setHTTPReferrer(capturedOutgoingReferrer.string());

        auto options = std::unique_ptr<ThreadableLoaderOptions>(optionsCopy);

        // FIXME: If the a site requests a local resource, then this will return a non-zero value but the sync path
        // will return a 0 value. Either this should return 0 or the other code path should do a callback with
        // a failure.
        m_mainThreadLoader = DocumentThreadableLoader::create(document, *this, *request, *options, std::unique_ptr<ContentSecurityPolicy>(contentSecurityPolicyCopy));
        ASSERT(m_mainThreadLoader);
    });
}
Example #20
0
WorkerThreadableLoader::MainThreadBridge::MainThreadBridge(ThreadableLoaderClientWrapper& workerClientWrapper, WorkerLoaderProxy& loaderProxy, const String& taskMode,
    ResourceRequest&& request, const ThreadableLoaderOptions& options, const String& outgoingReferrer,
    const SecurityOrigin* securityOrigin, const ContentSecurityPolicy* contentSecurityPolicy)
    : m_workerClientWrapper(&workerClientWrapper)
    , m_loaderProxy(loaderProxy)
    , m_taskMode(taskMode.isolatedCopy())
{
    ASSERT(securityOrigin);
    ASSERT(contentSecurityPolicy);

    auto securityOriginCopy = securityOrigin->isolatedCopy();
    auto contentSecurityPolicyCopy = std::make_unique<ContentSecurityPolicy>(securityOriginCopy);
    contentSecurityPolicyCopy->copyStateFrom(contentSecurityPolicy);
    contentSecurityPolicyCopy->copyUpgradeInsecureRequestStateFrom(*contentSecurityPolicy);

    auto optionsCopy = std::make_unique<LoaderTaskOptions>(options, request.httpReferrer().isNull() ? outgoingReferrer : request.httpReferrer(), WTFMove(securityOriginCopy));

    // Can we benefit from request being an r-value to create more efficiently its isolated copy?
    m_loaderProxy.postTaskToLoader([this, request = request.isolatedCopy(), options = WTFMove(optionsCopy), contentSecurityPolicyCopy = WTFMove(contentSecurityPolicyCopy)](ScriptExecutionContext& context) mutable {
        ASSERT(isMainThread());
        Document& document = downcast<Document>(context);

        // FIXME: If the site requests a local resource, then this will return a non-zero value but the sync path will return a 0 value.
        // Either this should return 0 or the other code path should call a failure callback.
        m_mainThreadLoader = DocumentThreadableLoader::create(document, *this, WTFMove(request), options->options, WTFMove(options->origin), WTFMove(contentSecurityPolicyCopy), WTFMove(options->referrer), DocumentThreadableLoader::ShouldLogError::No);
        ASSERT(m_mainThreadLoader || m_loadingFinished);
    });
}
Example #21
0
void StorageTracker::deleteOrigin(SecurityOrigin* origin)
{    
    ASSERT(m_isActive);
    ASSERT(isMainThread());
    ASSERT(m_thread);
    
    if (!m_isActive)
        return;

    // Before deleting database, we need to clear in-memory local storage data
    // in StorageArea, and to close the StorageArea db. It's possible for an
    // item to be added immediately after closing the db and cause StorageAreaSync
    // to reopen the db before the db is deleted by a StorageTracker thread.
    // In this case, reopening the db in StorageAreaSync will cancel a pending
    // StorageTracker db deletion.
    WebStorageNamespaceProvider::clearLocalStorageForOrigin(origin);

    String originId = origin->databaseIdentifier();
    
    {
        MutexLocker locker(m_originSetMutex);
        willDeleteOrigin(originId);
        m_originSet.remove(originId);
    }

    String originIdCopy = originId.isolatedCopy();
    m_thread->dispatch([this, originIdCopy] {
        syncDeleteOrigin(originIdCopy);
    });
}
Example #22
0
void DatabaseBackend::DatabaseOpenTask::doPerformTask()
{
    String errorMessage;
    m_success = database()->performOpenAndVerify(m_setVersionInNewDatabase, m_error, errorMessage);
    if (!m_success)
        m_errorMessage = errorMessage.isolatedCopy();
}
void WorkerMessagingProxy::postMessageToPageInspector(const String& message)
{
    String messageCopy = message.isolatedCopy();
    m_scriptExecutionContext->postTask([=] (ScriptExecutionContext*) {
        m_pageInspector->dispatchMessageFromWorker(messageCopy);
    });
}
Example #24
0
WorkerThreadStartupData::WorkerThreadStartupData(const URL& scriptURL, const String& userAgent, const GroupSettings* settings, const String& sourceCode, WorkerThreadStartMode startMode, const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType, const SecurityOrigin* topOrigin)
    : m_scriptURL(scriptURL.copy())
    , m_userAgent(userAgent.isolatedCopy())
    , m_sourceCode(sourceCode.isolatedCopy())
    , m_startMode(startMode)
    , m_contentSecurityPolicy(contentSecurityPolicy.isolatedCopy())
    , m_contentSecurityPolicyType(contentSecurityPolicyType)
    , m_topOrigin(topOrigin ? topOrigin->isolatedCopy() : 0)
{
    if (!settings)
        return;

    m_groupSettings = std::make_unique<GroupSettings>();
    m_groupSettings->setLocalStorageQuotaBytes(settings->localStorageQuotaBytes());
    m_groupSettings->setIndexedDBQuotaBytes(settings->indexedDBQuotaBytes());
    m_groupSettings->setIndexedDBDatabasePath(settings->indexedDBDatabasePath().isolatedCopy());
}
StorageSyncManager::StorageSyncManager(const String& path)
    : m_thread(std::make_unique<StorageThread>())
    , m_path(path.isolatedCopy())
{
    ASSERT(isMainThread());
    ASSERT(!m_path.isEmpty());
    m_thread->start();
}
 BlobRegistryContext(const URL& url, Vector<BlobPart> blobParts, const String& contentType)
     : url(url.isolatedCopy())
     , contentType(contentType.isolatedCopy())
     , blobParts(WTF::move(blobParts))
 {
     for (BlobPart& part : blobParts)
         part.detachFromCurrentThread();
 }
void WorkerMessagingProxy::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
{
    String errorMessageCopy = errorMessage.isolatedCopy();
    String sourceURLCopy = sourceURL.isolatedCopy();
    m_scriptExecutionContext->postTask([=] (ScriptExecutionContext* context) {
        Worker* workerObject = this->workerObject();
        if (!workerObject)
            return;

        // We don't bother checking the askedToTerminate() flag here, because exceptions should *always* be reported even if the thread is terminated.
        // This is intentionally different than the behavior in MessageWorkerTask, because terminated workers no longer deliver messages (section 4.6 of the WebWorker spec), but they do report exceptions.

        bool errorHandled = !workerObject->dispatchEvent(ErrorEvent::create(errorMessageCopy, sourceURLCopy, lineNumber, columnNumber));
        if (!errorHandled)
            context->reportException(errorMessageCopy, lineNumber, columnNumber, sourceURLCopy, 0);
    });
}
SharedWorkerProxy::SharedWorkerProxy(const String& name, const KURL& url, PassRefPtr<SecurityOrigin> origin)
    : m_closing(false)
    , m_name(name.isolatedCopy())
    , m_url(url.copy())
    , m_origin(origin)
{
    // We should be the sole owner of the SecurityOrigin, as we will free it on another thread.
    ASSERT(m_origin->hasOneRef());
}
Example #29
0
SharedWorkerThread::SharedWorkerThread(
    const String& name,
    PassRefPtr<WorkerLoaderProxy> workerLoaderProxy,
    WorkerReportingProxy& workerReportingProxy)
    : WorkerThread(std::move(workerLoaderProxy), workerReportingProxy),
      m_workerBackingThread(
          WorkerBackingThread::create("SharedWorker Thread",
                                      BlinkGC::PerThreadHeapMode)),
      m_name(name.isolatedCopy()) {}
Example #30
0
StorageTracker::StorageTracker(const String& storagePath)
    : m_storageDirectoryPath(storagePath.isolatedCopy())
    , m_client(0)
    , m_thread(std::make_unique<StorageThread>())
    , m_isActive(false)
    , m_needsInitialization(false)
    , m_StorageDatabaseIdleInterval(DefaultStorageDatabaseIdleInterval)
{
}