Ejemplo n.º 1
0
Boolean IconPackHelper::IsComposedIconComponent(
    /* [in] */ const String& tag)
{
    return tag.EqualsIgnoreCase(ICON_MASK_TAG) ||
            tag.EqualsIgnoreCase(ICON_BACK_TAG) ||
            tag.EqualsIgnoreCase(ICON_UPON_TAG);
}
ECode CHttpAuthHeader::ParseScheme(
    /* [in] */ const String& header,
    /* [out] */ String* scheme)
{
    if (header != NULL) {
        Int32 i = header.IndexOf(' ');
        if (i >= 0) {
            String localScheme = header.Substring(0, i).Trim();
            if (localScheme.EqualsIgnoreCase(DIGEST_TOKEN)) {
                mScheme = DIGEST;

                // md5 is the default algorithm!!!
                mAlgorithm = String("md5");
            } else {
                if (localScheme.EqualsIgnoreCase(BASIC_TOKEN)) {
                    mScheme = BASIC;
                }
            }

            *scheme = header.Substring(i + 1);
        }
    }

    *scheme = String(NULL);
    return NOERROR;
}
ECode CHttpAuthHeader::ParseParameter(
    /* [in] */ const String& token,
    /* [in] */ const String& value)
{
    if (token != NULL && value != NULL) {
        if (token.EqualsIgnoreCase(NONCE_TOKEN)) {
            mNonce = value;
            return NOERROR;
        }

        if (token.EqualsIgnoreCase(STALE_TOKEN)) {
            ParseStale(value);
            return NOERROR;
        }

        if (token.EqualsIgnoreCase(OPAQUE_TOKEN)) {
            mOpaque = value;
            return NOERROR;
        }

        if (token.EqualsIgnoreCase(QOP_TOKEN)) {
            mQop = value.ToLowerCase();
            return NOERROR;
        }

        if (token.EqualsIgnoreCase(ALGORITHM_TOKEN)) {
            mAlgorithm = value.ToLowerCase();
            return NOERROR;
        }
    }
    return NOERROR;
}
ECode CJDBCResultSetMetaData::FindColByName(
    /* [in] */ const String& columnName,
    /* [out] */ Int32 * value)
{
    String c = String(NULL);
    if (r != NULL && ((CJDBCResultSet *)r.Get())->tr != NULL) {
        for (Int32 i = 0; i < ((CJDBCResultSet *)r.Get())->tr->mNcolumns; i++) {
            c = (*((CJDBCResultSet *)r.Get())->tr->mColumn)[i];
            if (c != NULL) {
                if (c.EqualsIgnoreCase(columnName) == 0) {
                    *value = i + 1;
                } else {
                    Int32 k = c.IndexOf('.');
                    if (k > 0) {
                        c = c.Substring(k + 1);
                        if (c.EqualsIgnoreCase(columnName) == 0) {
                            *value = i + 1;
                        }
                    }
                }
            }
        }
    } else {
        return E_SQL_EXCEPTION;
    }
    return NOERROR;
}
Ejemplo n.º 5
0
Boolean CMediaHTTPConnection::IsLocalHost(
    /* [in] */ IURL* url)
{
    if (url == NULL) {
        return FALSE;
    }

    String host;
    url->GetHost(&host);

    if (host == NULL) {
        return FALSE;
    }

    // try {
    if (host.EqualsIgnoreCase("localhost")) {
        return TRUE;
    }
    AutoPtr<IInetAddress> addr;
    NetworkUtils::NumericToInetAddress(host, (IInetAddress**)&addr);
    Boolean b;
    if ((addr->IsLoopbackAddress(&b), b)) {
        return TRUE;
    }
    // } catch (IllegalArgumentException iex) {
    // }
    return FALSE;
}
ECode BasicHeaderElement::GetParameterByName(
    /* [in] */ const String& name,
    /* [out] */ INameValuePair** parameter)
{
    VALIDATE_NOT_NULL(parameter)
    *parameter = NULL;

    if (name.IsNull()) {
        Logger::E("BasicHeaderElement", "Name may not be null");
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }
    AutoPtr<INameValuePair> found;
    Int32 len;
    mParameters->GetLength(&len);
    for (Int32 i = 0; i < len; i++) {
        AutoPtr<IInterface> value;
        mParameters->Get(i, (IInterface**)&value);
        AutoPtr<INameValuePair> current = INameValuePair::Probe(value);
        String n;
        current->GetName(&n);
        if (n.EqualsIgnoreCase(name)) {
            found = current;
            break;
        }
    }
    *parameter = found;
    REFCOUNT_ADD(*parameter)
    return NOERROR;
}
ECode ProfileManagerService::NotificationGroupExistsByName(
    /* [in] */ const String& notificationGroupName,
    /* [out] */ Boolean* result)
{
    VALIDATE_NOT_NULL(result);

    AutoPtr<ICollection> values;
    mGroups->GetValues((ICollection**)&values);

    AutoPtr<IIterator> it;
    values->GetIterator((IIterator**)&it);
    Boolean bHasNxt = FALSE;
    while ((it->HasNext(&bHasNxt), bHasNxt)) {
        AutoPtr<IInterface> p;
        it->GetNext((IInterface**)&p);
        AutoPtr<INotificationGroup> group = INotificationGroup::Probe(p);
        String name;
        group->GetName(&name);
        if (name.EqualsIgnoreCase(notificationGroupName)) {
            *result = TRUE;
            return NOERROR;
        }
        it = IIterator::Probe(p);
    }

    *result = FALSE;
    return NOERROR;
}
ECode ProfileManagerService::ProfileExistsByName(
    /* [in] */ const String& profileName,
    /* [out] */ Boolean* result)
{
    VALIDATE_NOT_NULL(result);
    AutoPtr<ISet> entrySet;
    mProfileNames->GetEntrySet((ISet**)&entrySet);

    AutoPtr<IIterator> it;
    entrySet->GetIterator((IIterator**)&it);
    Boolean bHasNxt = FALSE;
    while ((it->HasNext(&bHasNxt), bHasNxt)) {
        AutoPtr<IInterface> p;
        it->GetNext((IInterface**)&p);
        AutoPtr<IMapEntry> entry = IMapEntry::Probe(p);
        AutoPtr<IInterface> k;
        entry->GetKey((IInterface**)&k);
        AutoPtr<ICharSequence> cs = ICharSequence::Probe(k);
        String str;
        cs->ToString(&str);
        if (str.EqualsIgnoreCase(profileName)) {
            *result = TRUE;
            return NOERROR;
        }
    }

    *result = FALSE;
    return NOERROR;
}
ECode CHttpAuthHeader::ParseParameter(
    /* [in] */ const String& parameter)
{
    if (parameter != NULL) {
        // here, we are looking for the 1st occurence of '=' only!!!
        Int32 i = parameter.IndexOf('=');
        if (i >= 0) {
            String token = parameter.Substring(0, i).Trim();
            String value =
                TrimDoubleQuotesIfAny(parameter.Substring(i + 1).Trim());

            if (HttpLog::LOGV) {
                HttpLog::V(String("HttpAuthHeader.parseParameter(): token: ") + token
                    + String(" value: ") + value);
            }

            if (token.EqualsIgnoreCase(REALM_TOKEN)) {
                mRealm = value;
            } else {
                if (mScheme == DIGEST) {
                    ParseParameter(token, value);
                }
            }
        }
    }
    return NOERROR;
}
Ejemplo n.º 10
0
Boolean IconPackHelper::ParseComposedIconComponent(
    /* [in] */ IXmlPullParser* parser,
    /* [in] */ IMap* iconPackResources)
{
    String icon;
    String tag;
    parser->GetName(&tag);
    if (!IsComposedIconComponent(tag)) {
        return FALSE;
    }

    Int32 count;
    if (parser->GetAttributeCount(&count), count >= 1) {
        if (tag.EqualsIgnoreCase(ICON_BACK_TAG)) {
            parser->GetAttributeCount(&mIconBackCount);
            for (Int32 i = 0; i < mIconBackCount; i++) {
                tag = "";
                tag.AppendFormat(ICON_BACK_FORMAT.string(), i);
                parser->GetAttributeValue(i, &icon);
                AutoPtr<IComponentName> component;
                CComponentName::New(tag, String(""), (IComponentName**)&component);
                iconPackResources->Put(component, CoreUtils::Convert(icon));
            }
        }
        else {
            parser->GetAttributeValue(0, &icon);
            AutoPtr<IComponentName> component;
            CComponentName::New(tag, String(""), (IComponentName**)&component);
            iconPackResources->Put(component, CoreUtils::Convert(icon));
        }
        return TRUE;
    }

    return FALSE;
}
Boolean CInstrumentationTestRunner::GetBooleanArgument(
    /* [in] */ IBundle* arguments,
    /* [in] */ const String& tag)
{
    String tagString;
    arguments->GetString(tag, &tagString);
    return !tagString.IsNull() && tagString.EqualsIgnoreCase("TRUE");
}
Ejemplo n.º 12
0
ECode CHttpAuthHeader::ParseStale(
    /* [in] */ const String& value)
{
    if (value != NULL) {
        if (value.EqualsIgnoreCase("true")) {
            mStale = true;
        }
    }
    return NOERROR;
}
Ejemplo n.º 13
0
Boolean Provider::CheckAttribute(
    /* [in] */ const String& servAlg,
    /* [in] */ const String& attribute,
    /* [in] */ const String& val)
{
    String attributeValue = GetPropertyIgnoreCase(servAlg + String(" ")  + attribute);
    if (!attributeValue.IsNull()) {
        if (attribute.EqualsIgnoreCase("KeySize")) {
            if (StringUtils::ParseInt32(attributeValue) >= StringUtils::ParseInt32(val)) {
                return TRUE;
            }
        }
        else { // other attributes
            if (attributeValue.EqualsIgnoreCase(val)) {
                return TRUE;
            }
        }
    }
    return FALSE;
}
Ejemplo n.º 14
0
ECode Provider::GetService(
    /* [in] */ const String& type,
    /* [in] */ const String& algorithm,
    /* [out] */ IProviderService** service)
{
    VALIDATE_NOT_NULL(service);
    *service = NULL;
    AutoLock lock(this);

    if (type.IsNull()) {
        Logger::E("Provider", "type == null");
        return E_NULL_POINTER_EXCEPTION;
    }
    else if (algorithm.IsNull()) {
        Logger::E("Provider", "algorithm == null");
        return E_NULL_POINTER_EXCEPTION;
    }

    if (type.Equals(mLastServiceName) && algorithm.EqualsIgnoreCase(mLastAlgorithm)) {
        *service = mReturnedService;
        return NOERROR;
    }

    String key = Key(type, algorithm);
    AutoPtr<ICharSequence> keyObj;
    CString::New(key, (ICharSequence**)&keyObj);
    AutoPtr<IInterface> o;
    if (mServiceTable != NULL) {
        mServiceTable->Get(keyObj, (IInterface**)&o);
    }
    if (o == NULL && mAliasTable != NULL) {
        mAliasTable->Get(keyObj, (IInterface**)&o);
    }
    if (o == NULL) {
        UpdatePropertyServiceTable();
    }
    if (o == NULL && mPropertyServiceTable != NULL) {
        mPropertyServiceTable->Get(keyObj, (IInterface**)&o);
    }
    if (o == NULL && mPropertyAliasTable != NULL) {
        mPropertyAliasTable->Get(keyObj, (IInterface**)&o);
    }

    if (o != NULL) {
        mLastServiceName = type;
        mLastAlgorithm = algorithm;
        mReturnedService = IProviderService::Probe(o);
        *service = mReturnedService;
        REFCOUNT_ADD(*service);
        return NOERROR;
    }
    *service = NULL;
    return NOERROR;
}
Ejemplo n.º 15
0
Xml::Encoding Xml::FindEncodingByName(
    /* [in] */ const String& encodingName)
{
    if (encodingName.IsNull()) {
        return Encoding::UTF_8;
    }

    if (encodingName.EqualsIgnoreCase(Encoding::US_ASCII.mExpatName)) {
        return Encoding::US_ASCII;
    }
    else if (encodingName.EqualsIgnoreCase(Encoding::UTF_8.mExpatName)) {
        return Encoding::UTF_8;
    }
    else if (encodingName.EqualsIgnoreCase(Encoding::UTF_16.mExpatName)) {
        return Encoding::UTF_16;
    }
    else if (encodingName.EqualsIgnoreCase(Encoding::ISO_8859_1.mExpatName)) {
        return Encoding::ISO_8859_1;
    }

    assert(0 && "UnsupportedEncodingException");
    return Encoding::UTF_8;
}
Ejemplo n.º 16
0
Boolean Request::CanResponseHaveBody(
    /* [in] */ IHttpRequest* request,
    /* [in] */ Int32 status)
{
    AutoPtr<IRequestLine> line;
    request->GetRequestLine((IRequestLine**)&line);
    String str;
    line->GetMethod(&str);
    if (str.EqualsIgnoreCase("HEAD")) {
        return FALSE;
    }
    return status >= IHttpStatus::SC_OK
        && status != IHttpStatus::SC_NO_CONTENT
        && status != IHttpStatus::SC_NOT_MODIFIED;
}
Ejemplo n.º 17
0
Boolean Proxy::IsLocalHost(
    /* [in] */ const String& host)
{
    if (host.IsNull()) {
        return FALSE;
    }

    if (!(host.IsNull())) {
        if (host.EqualsIgnoreCase("localhost")) {
            return TRUE;
        }
        AutoPtr<IInetAddress> address;
        NetworkUtils::NumericToInetAddress(host, (IInetAddress**)&address);
        Boolean isLoopback;
        address->IsLoopbackAddress(&isLoopback);
        if (isLoopback == TRUE) {
            return TRUE;
        }
    }

    return FALSE;
}
Ejemplo n.º 18
0
String Provider::GetPropertyIgnoreCase(
    /* [in] */ const String& key)
{
    String res;
    GetProperty(key, &res);
    if (!res.IsNull()) {
        return res;
    }
    AutoPtr<IEnumeration> names;
    PropertyNames((IEnumeration**)&names);
    Boolean hasMore;
    while (names->HasMoreElements(&hasMore), hasMore) {
        AutoPtr<IInterface> nameObj;
        names->GetNextElement((IInterface**)&nameObj);
        String propertyName;
        ICharSequence::Probe(nameObj)->ToString(&propertyName);
        if (key.EqualsIgnoreCase(propertyName)) {
            GetProperty(propertyName, &res);
            return res;
        }
    }
    return String(NULL);
}
Ejemplo n.º 19
0
ECode IconPackHelper::LoadResourcesFromXmlParser(
    /* [in] */ IXmlPullParser* parser,
    /* [in] */ IMap* iconPackResources)
{
    mIconBackCount = 0;
    Int32 eventType;
    parser->GetEventType(&eventType);
    do {
        if (eventType != IXmlPullParser::START_TAG) {
            continue;
        }

        if (ParseComposedIconComponent(parser, iconPackResources)) {
            continue;
        }

        Boolean result;
        FAIL_RETURN(ColorFilterUtils::ParseIconFilter(parser, mFilterBuilder, &result));
        if (result) {
            continue;
        }

        String strName;
        if (parser->GetName(&strName), strName.EqualsIgnoreCase(ICON_SCALE_TAG)) {
            String factor;
            parser->GetAttributeValue(String(NULL), String("factor"), &factor);
            if (factor.IsNull()) {
                Int32 count;
                if (parser->GetAttributeCount(&count), count == 1) {
                    parser->GetAttributeValue(0, &factor);
                }
            }
            iconPackResources->Put(ICON_SCALE_COMPONENT, CoreUtils::Convert(factor));
            continue;
        }

        if (parser->GetName(&strName), !strName.EqualsIgnoreCase("item")) {
            continue;
        }

        String component;
        parser->GetAttributeValue(String(NULL), String("component"), &component);
        String drawable;
        parser->GetAttributeValue(String(NULL), String("drawable"), &drawable);

        // Validate component/drawable exist
        if (TextUtils::IsEmpty(component) || TextUtils::IsEmpty(drawable)) {
            continue;
        }

        // Validate format/length of component
        if (!component.StartWith("ComponentInfo{") || !component.EndWith("}")
                || component.GetLength() < 16 || drawable.GetLength() == 0) {
            continue;
        }

        // Sanitize stored value
        component = component.Substring(14, component.GetLength() - 1).ToLowerCase();

        AutoPtr<IComponentName> name;
        if (!component.Contains("/")) {
            // Package icon reference
            CComponentName::New(component.ToLowerCase(), String(""), (IComponentName**)&name);
        }
        else {
            CComponentName::UnflattenFromString(component, (IComponentName**)&name);
        }

        if (name != NULL) {
            iconPackResources->Put(name, CoreUtils::Convert(drawable));
        }
    } while (parser->Next(&eventType), eventType != IXmlPullParser::END_DOCUMENT);
    return NOERROR;
}
Ejemplo n.º 20
0
ECode Request::ReadResponse(
    /* [in] */ IElastosHttpClientConnection* httpClientConnection)
{
    if (mCancelled){
        return NOERROR; // don't send cancelled requests
    }

    AutoPtr<IStatusLine> statusLine;
    Boolean hasBody = FALSE;
    httpClientConnection->Flush();
    Int32 statusCode = 0;

    AutoPtr<IHeaders> header;
    CHeaders::New((IHeaders**)&header);
    do {
        statusLine = NULL;
        FAIL_RETURN(httpClientConnection->ParseResponseHeader(header, (IStatusLine**)&statusLine));
        statusLine->GetStatusCode(&statusCode);
    } while (statusCode < IHttpStatus::SC_OK);
    if (HttpLog::LOGV) {
        String str;
        IObject::Probe(statusLine)->ToString(&str);
        HttpLog::V(String("Request.readResponseStatus() ") +
                StringUtils::ToString(str.GetLength()) + String(" ") + str);
    }

    AutoPtr<IProtocolVersion> v;
    statusLine->GetProtocolVersion((IProtocolVersion**)&v);
    Int32 major;
    Int32 minor;
    v->GetMajor(&major);
    v->GetMinor(&minor);
    String phrase;
    statusLine->GetReasonPhrase(&phrase);
    mEventHandler->Status(major, minor, statusCode, phrase);
    mEventHandler->Headers(header);
    AutoPtr<IHttpEntity> entity;
    AutoPtr<IHttpRequest> req = IHttpRequest::Probe(mHttpRequest);
    hasBody = CanResponseHaveBody(req, statusCode);

    if (hasBody) {
        httpClientConnection->ReceiveResponseEntity(header, (IHttpEntity**)&entity);
    }

    // restrict the range request to the servers claiming that they are
    // accepting ranges in bytes
    String ranges;
    header->GetAcceptRanges(&ranges);
    Boolean supportPartialContent = ranges.EqualsIgnoreCase("bytes");

    if (entity != NULL) {
        AutoPtr<IInputStream> is;
        entity->GetContent((IInputStream**)&is);

        // process gzip content encoding
        AutoPtr<IHeader> contentEncoding;
        entity->GetContentEncoding((IHeader**)&contentEncoding);
        AutoPtr<IInputStream> nis;
        AutoPtr<ArrayOf<Byte> > buf;
        Int32 count = 0;

        String value;
        if (contentEncoding != NULL &&
            (contentEncoding->GetValue(&value), value).Equals("gzip")) {
            ECode ec = CGZIPInputStream::New(is, (IInputStream**)&nis);
            if(FAILED(ec)) {
                // don't throw if we have a non-OK status code
                if (statusCode == IHttpStatus::SC_OK
                        || statusCode == IHttpStatus::SC_PARTIAL_CONTENT) {
                    if (supportPartialContent && count > 0) {
                        // if there is uncommited content, we should commit them
                        // as we will continue the request
                        mEventHandler->Data(buf, count);
                    }

                    if (nis != NULL) {
                        nis->Close();
                    }

                    return ec;
                }
            }
        } else {
            nis = is;
        }

        /* accumulate enough data to make it worth pushing it
         * up the stack */
        ((Connection*)mConnection.Get())->GetBuf((ArrayOf<Byte>**)&buf);
        Int32 len = 0;
        Int32 lowWater = buf->GetLength() / 2;
        while (len != -1) {
                {
                    AutoLock syncLock(mClientResource);
                    while (mLoadingPaused) {
                        // Put this (network loading) thread to sleep if WebCore
                        // has asked us to. This can happen with plugins for
                        // example, if we are streaming data but the plugin has
                        // filled its internal buffers.
                        if(FAILED(Wait())) {
                            HttpLog::E(String("Interrupted exception whilst network thread paused at WebCore's request."));
                        }
                    }
                }

            ECode ec;
            ec = nis->Read(buf, count, buf->GetLength() - count, &len);
            if(FAILED(ec)) {
                /* InflaterInputStream throws an EOFException when the
                   server truncates gzipped content.  Handle this case
                   as we do truncated non-gzipped content: no error */
                if (count > 0) {
                    // if there is uncommited content, we should commit them
                    mEventHandler->Data(buf, count);
                }
                if (HttpLog::LOGV) HttpLog::V(String("readResponse() handling "));
            }

            if (len != -1) {
                count += len;
                if (supportPartialContent) mReceivedBytes += len;
            }
            if (len == -1 || count >= lowWater) {
                if (HttpLog::LOGV) {
                    HttpLog::V(String("Request.readResponse() ") + StringUtils::ToString(count));
                }
                mEventHandler->Data(buf, count);
                count = 0;
            }
        }

        if (nis != NULL) {
            nis->Close();
        }
    }

    AutoPtr<IProtocolVersion>  ver;
    statusLine->GetProtocolVersion((IProtocolVersion**)&ver);
    Int32 type;
    header->GetConnectionType(&type);
    ((Connection*)mConnection.Get())->SetCanPersist(entity, ver, type);
    mEventHandler->EndData();
    Complete();

    if (HttpLog::LOGV) {
        String name;
        mHost->GetSchemeName(&name);
        String port;
        GetHostPort(&port);
        HttpLog::V("Request.readResponse(): done %s://%s%s",
                name.string(), port.string(), mPath.string());
    }

    return NOERROR;
}
Ejemplo n.º 21
0
String URLUtil::GuessFileName(
    /* [in] */ const String& url,
    /* [in] */ const String& contentDisposition,
    /* [in] */ const String& _mimeType)
{
    String filename;
    String extension;
    String mimeType = _mimeType;

    // If we couldn't do anything with the hint, move toward the content disposition
    if (filename.IsNull() && !contentDisposition.IsNull()) {
        filename = ParseContentDisposition(contentDisposition);
        if (!filename.IsNull()) {
            Int32 index = filename.LastIndexOf('/') + 1;
            if (index > 0) {
                filename = filename.Substring(index);
            }
        }
    }

    // If all the other http-related approaches failed, use the plain uri
    if (filename.IsNull()) {
        String decodedUrl;
        Uri::Decode(url, &decodedUrl);
        if (!decodedUrl.IsNull()) {
            Int32 queryIndex = decodedUrl.IndexOf('?');
            // If there is a query string strip it, same as desktop browsers
            if (queryIndex > 0) {
                decodedUrl = decodedUrl.Substring(0, queryIndex);
            }
            if (!decodedUrl.EndWith("/")) {
                Int32 index = decodedUrl.LastIndexOf('/') + 1;
                if (index > 0) {
                    filename = decodedUrl.Substring(index);
                }
            }
        }
    }

    // Finally, if couldn't get filename from URI, get a generic filename
    if (filename.IsNull()) {
        filename = "downloadfile";
    }

    // Split filename between base and extension
    // Add an extension if filename does not have one
    Int32 dotIndex = filename.IndexOf('.');
    if (dotIndex < 0) {
        if (!mimeType.IsNull()) {
            AutoPtr<MimeTypeMap> mimeTypeMap = MimeTypeMap::GetSingleton();
            mimeTypeMap->GetExtensionFromMimeType(mimeType, &extension);
            if (!extension.IsNull()) {
                extension = String(".") + extension;
            }
        }
        if (extension.IsNull()) {
            if (!mimeType.IsNull() && mimeType.StartWithIgnoreCase("text/")) {
                if (mimeType.EqualsIgnoreCase("text/html")) {
                    extension = ".html";
                }
                else {
                    extension = ".txt";
                }
            }
            else {
                extension = ".bin";
            }
        }
    }
    else {
        if (!mimeType.IsNull()) {
            // Compare the last segment of the extension against the mime type.
            // If there's a mismatch, discard the entire extension.
            Int32 lastDotIndex = filename.LastIndexOf('.');
            AutoPtr<MimeTypeMap> mimeTypeMap = MimeTypeMap::GetSingleton();
            String typeFromExt;
            mimeTypeMap->GetMimeTypeFromExtension(
                    filename.Substring(lastDotIndex + 1), &typeFromExt);
            if (!typeFromExt.IsNull() && !typeFromExt.EqualsIgnoreCase(mimeType)) {
                mimeTypeMap->GetExtensionFromMimeType(mimeType, &extension);
                if (!extension.IsNull()) {
                    extension = String(".") + extension;
                }
            }
        }
        if (extension.IsNull()) {
            extension = filename.Substring(dotIndex);
        }
        filename = filename.Substring(0, dotIndex);
    }

    return filename + extension;
}