Example #1
0
void StorageTracker::syncDeleteOrigin(const String& originIdentifier)
{
    ASSERT(!isMainThread());

    MutexLocker locker(m_databaseMutex);
    
    if (!canDeleteOrigin(originIdentifier)) {
        LOG_ERROR("Attempted to delete origin '%s' while it was being created\n", originIdentifier.ascii().data());
        return;
    }
    
    openTrackerDatabase(false);
    if (!m_database.isOpen())
        return;

    String path = databasePathForOrigin(originIdentifier);
    if (path.isEmpty()) {
        // It is possible to get a request from the API to delete the storage for an origin that
        // has no such storage.
        return;
    }
    
    SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins where origin=?");
    if (deleteStatement.prepare() != SQLResultOk) {
        LOG_ERROR("Unable to prepare deletion of origin '%s'", originIdentifier.ascii().data());
        return;
    }
    deleteStatement.bindText(1, originIdentifier);
    if (!deleteStatement.executeCommand()) {
        LOG_ERROR("Unable to execute deletion of origin '%s'", originIdentifier.ascii().data());
        return;
    }

    SQLiteFileSystem::deleteDatabaseFile(path);
    
    bool shouldDeleteTrackerFiles = false;
    {
        MutexLocker locker(m_originSetMutex);
        m_originSet.remove(originIdentifier);
        shouldDeleteTrackerFiles = m_originSet.isEmpty();
    }

    if (shouldDeleteTrackerFiles) {
        m_database.close();
        SQLiteFileSystem::deleteDatabaseFile(trackerDatabasePath());
        SQLiteFileSystem::deleteEmptyDatabaseDirectory(m_storageDirectoryPath);
    }

    {
        MutexLocker locker(m_clientMutex);
        if (m_client)
            m_client->dispatchDidModifyOrigin(originIdentifier);
    }
}
Example #2
0
bool test_14() {

	OS::get_singleton()->print("\n\nTest 14: ASCII\n");

	String s = L"Primero Leche";
	OS::get_singleton()->print("\tAscii: %s\n",s.ascii().get_data());

	String t=s.ascii().get_data();
	return (s==t);

}
void DatabaseTracker::setDatabaseDetails(SecurityOrigin* origin, const String& name, const String& displayName, unsigned long estimatedSize)
{
    String originIdentifier = origin->databaseIdentifier();
    int64_t guid = 0;

    MutexLocker lockDatabase(m_databaseGuard);

    openTrackerDatabase(CreateIfDoesNotExist);
    if (!m_database.isOpen())
        return;
    SQLiteStatement statement(m_database, "SELECT guid FROM Databases WHERE origin=? AND name=?");
    if (statement.prepare() != SQLResultOk)
        return;

    statement.bindText(1, originIdentifier);
    statement.bindText(2, name);

    int result = statement.step();
    if (result == SQLResultRow)
        guid = statement.getColumnInt64(0);
    statement.finalize();

    if (guid == 0) {
        if (result != SQLResultDone)
            LOG_ERROR("Error to determing existence of database %s in origin %s in tracker database", name.ascii().data(), originIdentifier.ascii().data());
        else {
            // This case should never occur - we should never be setting database details for a database that doesn't already exist in the tracker
            // But since the tracker file is an external resource not under complete control of our code, it's somewhat invalid to make this an ASSERT case
            // So we'll print an error instead
            LOG_ERROR("Could not retrieve guid for database %s in origin %s from the tracker database - it is invalid to set database details on a database that doesn't already exist in the tracker",
                       name.ascii().data(), originIdentifier.ascii().data());
        }
        return;
    }

    SQLiteStatement updateStatement(m_database, "UPDATE Databases SET displayName=?, estimatedSize=? WHERE guid=?");
    if (updateStatement.prepare() != SQLResultOk)
        return;

    updateStatement.bindText(1, displayName);
    updateStatement.bindInt64(2, estimatedSize);
    updateStatement.bindInt64(3, guid);

    if (updateStatement.step() != SQLResultDone) {
        LOG_ERROR("Failed to update details for database %s in origin %s", name.ascii().data(), originIdentifier.ascii().data());
        return;
    }

    if (m_client)
        m_client->dispatchDidModifyDatabase(origin, name);
}
Example #4
0
MediaPlayer::SupportsType MediaPlayerPrivate::supportsType(const String& type, const String& codecs)
{
    if (type.isNull() || type.isEmpty()) {
        LOG(Media, "MediaPlayer does not support type; type is null or empty.");
        return MediaPlayer::IsNotSupported;
    }

    // spec says we should not return "probably" if the codecs string is empty
    if (MMRPlayer::mimeTypeSupported(type.ascii().data())) {
        LOG(Media, "MediaPlayer supports type; cache contains type '%s'.", type.ascii().data());
        return codecs.isEmpty() ? MediaPlayer::MayBeSupported : MediaPlayer::IsSupported;
    }
    LOG(Media, "MediaPlayer does not support type; cache doesn't contain type '%s'.", type.ascii().data());
    return MediaPlayer::IsNotSupported;
}
bool DatabaseTracker::addDatabase(SecurityOrigin* origin, const String& name, const String& path)
{
    ASSERT(!m_databaseGuard.tryLock());
    openTrackerDatabase(CreateIfDoesNotExist);
    if (!m_database.isOpen())
        return false;

    // New database should never be added until the origin has been established
    ASSERT(hasEntryForOriginNoLock(origin));

    SQLiteStatement statement(m_database, "INSERT INTO Databases (origin, name, path) VALUES (?, ?, ?);");

    if (statement.prepare() != SQLResultOk)
        return false;

    statement.bindText(1, origin->databaseIdentifier());
    statement.bindText(2, name);
    statement.bindText(3, path);

    if (!statement.executeCommand()) {
        LOG_ERROR("Failed to add database %s to origin %s: %s\n", name.ascii().data(), origin->databaseIdentifier().ascii().data(), m_database.lastErrorMsg());
        return false;
    }

    if (m_client)
        m_client->dispatchDidModifyOrigin(origin);

    return true;
}
Example #6
0
void ParsedCookie::setMaxAge(const String& maxAge)
{
    // According to the HTTP Cookie specification (RFC6265, http://tools.ietf.org/html/rfc6265),
    // the first character can be a DIGIT or a "-", and the reminder
    // of the value can only contain DIGIT characters.
    if (maxAge.isEmpty() || (maxAge[0] != '-' && !isASCIIDigit(maxAge[0]))) {
        LOG_ERROR("Could not parse Max-Age : %s, first character can only be '-' or ascii digit.", maxAge.ascii().data());
        return;
    }

    bool ok;
    int value = maxAge.toIntStrict(&ok);

    if (!ok) {
        LOG_ERROR("Could not parse Max-Age : %s", maxAge.ascii().data());
        return;
    }
    m_expiry = value;
    m_isMaxAgeSet = true;
    m_isSession = false;

    // If maxAge value is not positive, let expiry-time be the earliest representable time.
    if (m_expiry > 0)
        m_expiry += currentTime();
    else
        m_expiry = 0;
}
Example #7
0
PassRefPtr<DatabaseSync> DatabaseSync::openDatabaseSync(ScriptExecutionContext* context, const String& name, const String& expectedVersion, const String& displayName,
                                                        unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
{
    ASSERT(context->isContextThread());

    if (!DatabaseTracker::tracker().canEstablishDatabase(context, name, displayName, estimatedSize)) {
        LOG(StorageAPI, "Database %s for origin %s not allowed to be established", name.ascii().data(), context->securityOrigin()->toString().ascii().data());
        return 0;
    }

    RefPtr<DatabaseSync> database = adoptRef(new DatabaseSync(context, name, expectedVersion, displayName, estimatedSize));

    String errorMessage;
    if (!database->performOpenAndVerify(!creationCallback, ec, errorMessage)) {
        database->logErrorMessage(errorMessage);
        DatabaseTracker::tracker().removeOpenDatabase(database.get());
        return 0;
    }

    DatabaseTracker::tracker().setDatabaseDetails(context->securityOrigin(), name, displayName, estimatedSize);

    if (database->isNew() && creationCallback.get()) {
        LOG(StorageAPI, "Invoking the creation callback for database %p\n", database.get());
        creationCallback->handleEvent(database.get());
    }

    return database;
}
Example #8
0
bool Dictionary::get(const String& propertyName, Result& result) const
{
    if (!m_dictionary.isValid())
        return false;
    
    return m_dictionary.get(propertyName.ascii().data(), result);
}
void LocalStorageDatabaseTracker::openTrackerDatabase(DatabaseOpeningStrategy openingStrategy)
{
    if (m_database.isOpen())
        return;

    String databasePath = trackerDatabasePath();

    if (!fileExists(databasePath) && openingStrategy == SkipIfNonExistent)
        return;

    if (!m_database.open(databasePath)) {
        LOG_ERROR("Failed to open databasePath %s.", databasePath.ascii().data());
        return;
    }

    // Since a WorkQueue isn't bound to a specific thread, we have to disable threading checks
    // even though we never access the database from different threads simultaneously.
    m_database.disableThreadingChecks();

    if (m_database.tableExists("Origins"))
        return;

    if (!m_database.executeCommand("CREATE TABLE Origins (origin TEXT UNIQUE ON CONFLICT REPLACE, path TEXT);"))
        LOG_ERROR("Failed to create Origins table.");
}
Example #10
0
PassRefPtr<Database> Database::openDatabase(ScriptExecutionContext* context, const String& name,
                                            const String& expectedVersion, const String& displayName,
                                            unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback,
                                            ExceptionCode& e)
{
    if (!DatabaseTracker::tracker().canEstablishDatabase(context, name, displayName, estimatedSize)) {
        LOG(StorageAPI, "Database %s for origin %s not allowed to be established", name.ascii().data(), context->securityOrigin()->toString().ascii().data());
        return 0;
    }

    RefPtr<Database> database = adoptRef(new Database(context, name, expectedVersion, displayName, estimatedSize));

    if (!database->openAndVerifyVersion(!creationCallback, e)) {
        LOG(StorageAPI, "Failed to open and verify version (expected %s) of database %s", expectedVersion.ascii().data(), database->databaseDebugName().ascii().data());
        DatabaseTracker::tracker().removeOpenDatabase(database.get());
        return 0;
    }

    DatabaseTracker::tracker().setDatabaseDetails(context->securityOrigin(), name, displayName, estimatedSize);

    context->setHasOpenDatabases();

    InspectorInstrumentation::didOpenDatabase(context, database, context->securityOrigin()->host(), name, expectedVersion);

    if (database->isNew() && creationCallback.get()) {
        LOG(StorageAPI, "Scheduling DatabaseCreationCallbackTask for database %p\n", database.get());
        database->m_scriptExecutionContext->postTask(DatabaseCreationCallbackTask::create(database, creationCallback));
    }

    return database;
}
bool SQLiteDatabase::open(const String& filename)
{
    close();

    m_openError = SQLiteFileSystem::openDatabase(filename, &m_db);
    if (m_openError != SQLITE_OK) {
        m_openErrorMessage = m_db ? sqlite3_errmsg(m_db) : "sqlite_open returned null";
        WTF_LOG_ERROR("SQLite database failed to load from %s\nCause - %s", filename.ascii().data(),
            m_openErrorMessage.data());
        sqlite3_close(m_db);
        m_db = 0;
        return false;
    }

    m_openError = sqlite3_extended_result_codes(m_db, 1);
    if (m_openError != SQLITE_OK) {
        m_openErrorMessage = sqlite3_errmsg(m_db);
        WTF_LOG_ERROR("SQLite database error when enabling extended errors - %s", m_openErrorMessage.data());
        sqlite3_close(m_db);
        m_db = 0;
        return false;
    }

    if (isOpen())
        m_openingThread = currentThread();
    else
        m_openErrorMessage = "sqlite_open returned null";

    if (!SQLiteStatement(*this, "PRAGMA temp_store = MEMORY;").executeCommand())
        WTF_LOG_ERROR("SQLite database could not set temp_store to memory");

    return isOpen();
}
TEST_P(PaintPropertyTreePrinterTest, SimpleScrollTree) {
  setBodyInnerHTML("<div style='height: 4000px;'>hello world</div>");
  String scrollTreeAsString = scrollPropertyTreeAsString(*document().view());
  EXPECT_THAT(scrollTreeAsString.ascii().data(),
              testing::MatchesRegex("root .*"
                                    "  Scroll \\(.*\\) .*"));
}
TEST_P(PaintPropertyTreePrinterTest, SimpleEffectTree) {
  setBodyInnerHTML("<div style='opacity: 0.9;'>hello world</div>");
  String effectTreeAsString = effectPropertyTreeAsString(*document().view());
  EXPECT_THAT(effectTreeAsString.ascii().data(),
              testing::MatchesRegex("root .*"
                                    "  Effect \\(LayoutBlockFlow DIV\\) .*"));
}
TEST_P(PaintPropertyTreePrinterTest, SimpleClipTree) {
  setBodyInnerHTML("hello world");
  String clipTreeAsString = clipPropertyTreeAsString(*document().view());
  EXPECT_THAT(clipTreeAsString.ascii().data(),
              testing::MatchesRegex("root .*"
                                    "  .*Clip \\(.*\\) .*"));
}
Example #15
0
//! Construct instance from given string. Also return the number of bytes
//! from given string utilized in the conversion process (zero indicates
//! given string could not be interpreted as an unsigned 64-bit integer).
inline U64::U64(const String& s, size_t* bytesUsed)
{
    char* pEnd;
    const char* p = s.ascii();
    v_ = strtoull(p, &pEnd, 0);
    *bytesUsed = pEnd - p;
}
Example #16
0
PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& filePath)
{
    if (filePath.isEmpty())
        return 0;

    File *fileData = new File(filePath);
    if (fileData->open('r') < 0) {
        LOG_ERROR("Failed to open file %s to create shared buffer", filePath.ascii().data());
        return 0;
    }

    int fileSize = fileData->getSize();
    if (fileSize <= 0) {
        fileData->close();
        delete fileData;
        return 0;
    }

    RefPtr<SharedBuffer> result = SharedBuffer::create(fileData->read(fileSize), fileSize);
    fileData->close();
    if (result->m_buffer.size() != static_cast<unsigned> (fileSize)) {
        LOG_ERROR("Failed to properly create shared buffer");
        result->m_buffer.clear();
        result = 0;
    }
    delete fileData;
    return result.release();
}
Example #17
0
bool MediaSource::isTypeSupported(const String& type)
{
    WTF_LOG(Media, "MediaSource::isTypeSupported(%s)", type.ascii().data());

    // Section 2.2 isTypeSupported() method steps.
    // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#widl-MediaSource-isTypeSupported-boolean-DOMString-type
    // 1. If type is an empty string, then return false.
    if (type.isNull() || type.isEmpty())
        return false;

    ContentType contentType(type);
    String codecs = contentType.parameter("codecs");

    // 2. If type does not contain a valid MIME type string, then return false.
    if (contentType.type().isEmpty())
        return false;

    // Note: MediaSource.isTypeSupported() returning true implies that HTMLMediaElement.canPlayType() will return "maybe" or "probably"
    // since it does not make sense for a MediaSource to support a type the HTMLMediaElement knows it cannot play.
    if (HTMLMediaElement::supportsType(contentType, String()) == WebMimeRegistry::IsNotSupported)
        return false;

    // 3. If type contains a media type or media subtype that the MediaSource does not support, then return false.
    // 4. If type contains at a codec that the MediaSource does not support, then return false.
    // 5. If the MediaSource does not support the specified combination of media type, media subtype, and codecs then return false.
    // 6. Return true.
    return MIMETypeRegistry::isSupportedMediaSourceMIMEType(contentType.type(), codecs);
}
Example #18
0
void TileGrid::drawTileMapContents(CGContextRef context, CGRect layerBounds) const
{
    CGContextSetRGBFillColor(context, 0.3, 0.3, 0.3, 1);
    CGContextFillRect(context, layerBounds);

    CGFloat scaleFactor = layerBounds.size.width / m_controller.bounds().width();

    CGFloat contextScale = scaleFactor / m_scale;
    CGContextScaleCTM(context, contextScale, contextScale);

    for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it) {
        const TileInfo& tileInfo = it->value;
        PlatformCALayer* tileLayer = tileInfo.layer.get();

        CGFloat red = 1;
        CGFloat green = 1;
        CGFloat blue = 1;
        CGFloat alpha = 1;
        if (tileInfo.hasStaleContent) {
            red = 0.25;
            green = 0.125;
            blue = 0;
        } else if (m_controller.shouldAggressivelyRetainTiles() && tileInfo.cohort != VisibleTileCohort) {
            red = 0.8;
            green = 0.8;
            blue = 0.8;
        }

        TileCohort newestCohort = newestTileCohort();
        TileCohort oldestCohort = oldestTileCohort();

        if (!m_controller.shouldAggressivelyRetainTiles() && tileInfo.cohort != VisibleTileCohort && newestCohort > oldestCohort)
            alpha = 1 - (static_cast<float>((newestCohort - tileInfo.cohort)) / (newestCohort - oldestCohort));

        CGContextSetRGBFillColor(context, red, green, blue, alpha);

        if (tileLayer->superlayer()) {
            CGContextSetLineWidth(context, 0.5 / contextScale);
            CGContextSetRGBStrokeColor(context, 0, 0, 0, 1);
        } else {
            CGContextSetLineWidth(context, 1 / contextScale);
            CGContextSetRGBStrokeColor(context, 0.2, 0.1, 0.9, 1);
        }

        CGRect frame = CGRectMake(tileLayer->position().x(), tileLayer->position().y(), tileLayer->bounds().size().width(), tileLayer->bounds().size().height());
        CGContextFillRect(context, frame);
        CGContextStrokeRect(context, frame);

        CGContextSetRGBFillColor(context, 0, 0, 0, 0.5);

        String repaintCount = String::number(m_tileRepaintCounts.get(tileLayer));

        CGContextSaveGState(context);

        tileLayer->drawTextAtPoint(context, frame.origin.x + 64, frame.origin.y + 192, CGSizeMake(3, -3), 58,
                                   repaintCount.ascii().data(), repaintCount.length());

        CGContextRestoreGState(context);
    }
}
void DecodedDataDocumentParser::appendBytes(DocumentWriter* writer , const char* data, int length, bool shouldFlush)
{
    std::cout<<"DecodedDataDocumentParser::appendBytes!!!!!!!: "<< ( data!=NULL ? strlen(data) : 0) <<std::endl;

    string dataString;

    if (data!=NULL) {

	dataString = data;
        dataString = replaceSocamPersonTags(dataString);
        dataString = replaceSocamAccelerometerTags(dataString);
        //cout<<"Result:"<<replacedData.c_str()<<endl;
	//cout<<endl<<endl<<"REPLACED DATA:"<<data<<endl<<endl;

    }

    if (!length && !shouldFlush)
        return;

    TextResourceDecoder* decoder = writer->createDecoderIfNeeded();
    String decoded = decoder->decode(dataString.c_str(), dataString.size());
    if (shouldFlush)
        decoded += decoder->flush();

    cout<<"Decoded:"<<decoded.ascii().data()<<endl;

    if (decoded.isEmpty())
        return;

    writer->reportDataReceived();

    append(decoded);
}
Example #20
0
bool MediaSource::isTypeSupported(const String& type)
{
    LOG(MediaSource, "MediaSource::isTypeSupported(%s)", type.ascii().data());

    // Section 2.2 isTypeSupported() method steps.
    // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#widl-MediaSource-isTypeSupported-boolean-DOMString-type
    // 1. If type is an empty string, then return false.
    if (type.isNull() || type.isEmpty())
        return false;

    // FIXME: Why do we convert to lowercase here, but not in MediaSource::addSourceBuffer?
    ContentType contentType(type.convertToASCIILowercase());
    String codecs = contentType.parameter("codecs");

    // 2. If type does not contain a valid MIME type string, then return false.
    if (contentType.type().isEmpty())
        return false;

    // 3. If type contains a media type or media subtype that the MediaSource does not support, then return false.
    // 4. If type contains at a codec that the MediaSource does not support, then return false.
    // 5. If the MediaSource does not support the specified combination of media type, media subtype, and codecs then return false.
    // 6. Return true.
    MediaEngineSupportParameters parameters;
    parameters.type = contentType.type();
    parameters.codecs = codecs;
    parameters.isMediaSource = true;
    MediaPlayer::SupportsType supported = MediaPlayer::supportsType(parameters, 0);

    if (codecs.isEmpty())
        return supported != MediaPlayer::IsNotSupported;

    return supported == MediaPlayer::IsSupported;
}
Example #21
0
bool AtomsX11::has_atom(String p_atom) {

	Atom atom = XInternAtom(x11_display, p_atom.ascii().get_data(), true);
	
	return atom!=None;

}
TEST(MediaConditionParserTest, Basic)
{
    // The first string represents the input string.
    // The second string represents the output string, if present.
    // Otherwise, the output string is identical to the first string.
    TestCase testCases[] = {
        {"screen", "not all"},
        {"screen and (color)", "not all"},
        {"all and (min-width:500px)", "not all"},
        {"(min-width:500px)", "(min-width: 500px)"},
        {"(min-width: -100px)", "not all"},
        {"(min-width: 100px) and print", "not all"},
        {"(min-width: 100px) and (max-width: 900px)", "(max-width: 900px) and (min-width: 100px)"},
        {"(min-width: [100px) and (max-width: 900px)", "not all"},
        {"not (min-width: 900px)", "not all and (min-width: 900px)"},
        {"not (blabla)", "not all"},
        {0, 0} // Do not remove the terminator line.
    };

    // FIXME: We should test comma-seperated media conditions
    for (unsigned i = 0; testCases[i].input; ++i) {
        CSSTokenizer::Scope scope(testCases[i].input);
        MediaQuerySet* mediaConditionQuerySet = MediaQueryParser::parseMediaCondition(scope.tokenRange());
        ASSERT_EQ(mediaConditionQuerySet->queryVector().size(), (unsigned)1);
        String queryText = mediaConditionQuerySet->queryVector()[0]->cssText();
        ASSERT_STREQ(testCases[i].output, queryText.ascii().data());
    }
}
Example #23
0
PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& filePath)
{
    if (filePath.isEmpty())
        return 0;

    String nullifiedPath = filePath;
    HANDLE fileHandle = CreateFileW(nullifiedPath.charactersWithNullTermination().data(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
    if (fileHandle == INVALID_HANDLE_VALUE) {
        LOG_ERROR("Failed to open file %s to create shared buffer, GetLastError() = %u", filePath.ascii().data(), GetLastError());
        return 0;
    }

    RefPtr<SharedBuffer> result;
    DWORD bytesToRead = GetFileSize(fileHandle, 0);
    DWORD lastError = GetLastError();

    if (bytesToRead != INVALID_FILE_SIZE || lastError == NO_ERROR) {
        Vector<char> buffer(bytesToRead);
        DWORD bytesRead;
        if (ReadFile(fileHandle, buffer.data(), bytesToRead, &bytesRead, 0) && bytesToRead == bytesRead)
            result = SharedBuffer::adoptVector(buffer);
        else
            LOG_ERROR("Failed to fully read contents of file %s, GetLastError() = %u", filePath.ascii().data(), GetLastError());
    } else
        LOG_ERROR("Failed to get filesize of file %s, GetLastError() = %u", filePath.ascii().data(), lastError);

    CloseHandle(fileHandle);
    return result.release();
}
Example #24
0
void ConfigFile::add_entry(String p_name, String p_var,String p_comment) {

	ERR_FAIL_COND(!file->is_open());

	file->store_byte_array( (Uint8*)p_name.ascii(false).get_data(), p_name.length() );
	file->store_byte('=');
	file->store_byte_array( (Uint8*)p_var.ascii(false).get_data(), p_var.length() );
	file->store_byte(' ');
	if (p_comment!="") {
		file->store_byte(';');
		file->store_byte(' ');
		file->store_byte_array( (Uint8*)p_comment.ascii(false).get_data(), p_comment.length() );
	}
	file->store_byte('\n');

}
Example #25
0
TEST(MediaConditionParserTest, Basic)
{
    // The first string represents the input string.
    // The second string represents the output string, if present.
    // Otherwise, the output string is identical to the first string.
    TestCase testCases[] = {
        {"screen", "not all"},
        {"screen and (color)", "not all"},
        {"all and (min-width:500px)", "not all"},
        {"(min-width:500px)", "(min-width: 500px)"},
        {"screen and (color), projection and (color)", "not all"},
        {"(min-width: -100px)", "not all"},
        {"(min-width: 100px) and print", "not all"},
        {"(min-width: 100px) and (max-width: 900px)", "(max-width: 900px) and (min-width: 100px)"},
        {"(min-width: [100px) and (max-width: 900px)", "not all"},
        {0, 0} // Do not remove the terminator line.
    };

    for (unsigned i = 0; testCases[i].input; ++i) {
        Vector<MediaQueryToken> tokens;
        MediaQueryTokenizer::tokenize(testCases[i].input, tokens);
        MediaQueryTokenIterator endToken;
        // Stop the input once we hit a comma token
        for (endToken = tokens.begin(); endToken != tokens.end() && endToken->type() != CommaToken; ++endToken) { }
        RefPtr<MediaQuerySet> mediaConditionQuerySet = MediaQueryParser::parseMediaCondition(tokens.begin(), endToken);
        ASSERT_EQ(mediaConditionQuerySet->queryVector().size(), (unsigned)1);
        String queryText = mediaConditionQuerySet->queryVector()[0]->cssText();
        ASSERT_STREQ(testCases[i].output, queryText.ascii().data());
    }
}
Example #26
0
//!
//! Get a line from the standard input, but don't get more than maxLength characters.
//! Trim trailing delimiter (if any) from the returned line. Return true if successful.
//! Return false otherwise (error or end-of-file).
//!
bool getline(String& line, size_t maxLength, bool doTrimLine, bool doEchoInput)
{
    char buf0[MAX_LENGTH + 1];
    char* buf = (maxLength <= MAX_LENGTH)? buf0: new char[maxLength + 1];
    buf[0] = 0;
    bool ok = (fgets(buf, static_cast<int>(maxLength), stdin) == buf); //TODO: make fgetws() work
    line = buf;

    if (doEchoInput && ok)
    {
        size_t count = 1;
        std::fwrite(line.ascii(), line.byteSize() - 1, count, stdout);
    }

    if (doTrimLine)
    {
        DelimitedTxt txt;
        txt.trimLine(line);
    }

    if (buf != buf0)
    {
        delete[] buf;
    }

    return ok;
}
static void logOpenDatabaseError(ScriptExecutionContext* context, const String& name)
{
    UNUSED_PARAM(context);
    UNUSED_PARAM(name);
    LOG(StorageAPI, "Database %s for origin %s not allowed to be established", name.ascii().data(),
        context->securityOrigin()->toString().ascii().data());
}
Example #28
0
bool SQLiteDatabase::open(const String& filename, bool forWebSQLDatabase)
{
    close();

    if (SQLiteFileSystem::openDatabase(filename, &m_db, forWebSQLDatabase) != SQLITE_OK) {
        LOG_ERROR("SQLite database failed to load from %s\nCause - %s", filename.ascii().data(),
            sqlite3_errmsg(m_db));
        sqlite3_close(m_db);
        m_db = 0;
        return false;
    }
    if (sqlite3_extended_result_codes(m_db, 1) != SQLITE_OK) {
        LOG_ERROR("SQLite database error when enabling extended errors - %s", sqlite3_errmsg(m_db));
        sqlite3_close(m_db);
        m_db = 0;
        return false;
    }

    if (isOpen())
        m_openingThread = currentThread();

    if (!SQLiteStatement(*this, "PRAGMA temp_store = MEMORY;").executeCommand())
        LOG_ERROR("SQLite database could not set temp_store to memory");

    return isOpen();
}
void InstrumentScreen::instrument_name_edited(int p_which,String p_name) {
	
	Instrument *ins=tracker->song->get_instrument( p_which );	
	if (!ins)
		return;
	
	ins->set_name( p_name.ascii().get_data() );
}
 void preconnectRequestVerification(const String& host, CrossOriginAttributeValue crossOrigin)
 {
     if (!host.isNull()) {
         EXPECT_TRUE(m_preloadRequest->isPreconnect());
         EXPECT_STREQ(m_preloadRequest->resourceURL().ascii().data(), host.ascii().data());
         EXPECT_EQ(m_preloadRequest->crossOrigin(), crossOrigin);
     }
 }