16916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott/*
26916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * Copyright 2010, The Android Open Source Project
36916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott *
46916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * Redistribution and use in source and binary forms, with or without
56916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * modification, are permitted provided that the following conditions
66916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * are met:
76916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott *  * Redistributions of source code must retain the above copyright
86916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott *    notice, this list of conditions and the following disclaimer.
96916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott *  * Redistributions in binary form must reproduce the above copyright
106916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott *    notice, this list of conditions and the following disclaimer in the
116916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott *    documentation and/or other materials provided with the distribution.
126916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott *
136916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
146916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
156916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
166916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
176916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
186916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
196916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
206916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
216916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
226916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
236916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
246916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott */
256916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott
266916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott#define LOG_TAG "WebCore"
276916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott
286916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott#include "config.h"
296916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott#include "MIMETypeRegistry.h"
3020ab751acc0d49d74648373f701f3d0c4ff187c0Steve Block
316916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott#include "PlatformString.h"
326916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott#include "WebCoreJni.h"
336916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott
3420ab751acc0d49d74648373f701f3d0c4ff187c0Steve Block#include <JNIUtility.h>
356916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott#include <jni.h>
366916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott#include <utils/Log.h>
376916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott
38f947415b59bf9cc2a85a73ef8b3f3d99c9c65199Steve Blockusing namespace android;
39f947415b59bf9cc2a85a73ef8b3f3d99c9c65199Steve Block
406916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scottnamespace WebCore {
416916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott
426916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick ScottString MIMETypeRegistry::getMIMETypeForExtension(const String& ext)
436916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott{
4409b60ab8488b362c96df8f268613aafaeebfcfa1Steve Block    ASSERT(isMainThread());
456916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott    JNIEnv* env = JSC::Bindings::getJNIEnv();
46b8a548263905542f52acfc60682693972f098d25Grace Kloba    jclass mimeClass = env->FindClass("android/webkit/MimeTypeMap");
476dd76b804786ec760bb04b137a6bf017064226dcSteve Block    ALOG_ASSERT(mimeClass, "Could not find class MimeTypeMap");
48b8a548263905542f52acfc60682693972f098d25Grace Kloba    jmethodID mimeTypeFromExtension = env->GetStaticMethodID(mimeClass,
49b8a548263905542f52acfc60682693972f098d25Grace Kloba            "mimeTypeFromExtension",
50b8a548263905542f52acfc60682693972f098d25Grace Kloba            "(Ljava/lang/String;)Ljava/lang/String;");
516dd76b804786ec760bb04b137a6bf017064226dcSteve Block    ALOG_ASSERT(mimeTypeFromExtension,
52b8a548263905542f52acfc60682693972f098d25Grace Kloba            "Could not find method mimeTypeFromExtension");
5379b35ce109b9fdca7c7e3af24996c1a2a612f1a4Steve Block    jstring extString = wtfStringToJstring(env, ext);
54b8a548263905542f52acfc60682693972f098d25Grace Kloba    jobject mimeType = env->CallStaticObjectMethod(mimeClass,
55b8a548263905542f52acfc60682693972f098d25Grace Kloba            mimeTypeFromExtension, extString);
5627dd31673790eed64c3e0e508bb900671f06bcb3Steve Block    String result = android::jstringToWtfString(env, (jstring) mimeType);
575fcdce675339c5c2cee9cf7890b84a4029c82501Steve Block    env->DeleteLocalRef(mimeClass);
586916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott    env->DeleteLocalRef(extString);
596916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott    env->DeleteLocalRef(mimeType);
606916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott    return result;
616916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott}
626916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott
631a0295103dca085437f7f17d26f2037e54c51cb5Steve Blockbool MIMETypeRegistry::isApplicationPluginMIMEType(const String&)
641a0295103dca085437f7f17d26f2037e54c51cb5Steve Block{
651a0295103dca085437f7f17d26f2037e54c51cb5Steve Block    return false;
661a0295103dca085437f7f17d26f2037e54c51cb5Steve Block}
671a0295103dca085437f7f17d26f2037e54c51cb5Steve Block
686916255e3bc5760bcaac2ec7d5057e057bd3de6aPatrick Scott}
69