summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authoravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-22 19:55:26 +0000
committeravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-22 19:55:26 +0000
commitd2a10d134c864765e7015a62f20642f398adc721 (patch)
treecd5474cc66b613b9a4640e948fd1646da112c311 /net/base
parente05212240814d77101f6a677fc38411ec05fd177 (diff)
downloadchromium_src-d2a10d134c864765e7015a62f20642f398adc721.zip
chromium_src-d2a10d134c864765e7015a62f20642f398adc721.tar.gz
chromium_src-d2a10d134c864765e7015a62f20642f398adc721.tar.bz2
Impl of platform mime typing for Mac.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1238 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/platform_mime_util_mac.mm49
1 files changed, 43 insertions, 6 deletions
diff --git a/net/base/platform_mime_util_mac.mm b/net/base/platform_mime_util_mac.mm
index 8cc3794..36d8b62 100644
--- a/net/base/platform_mime_util_mac.mm
+++ b/net/base/platform_mime_util_mac.mm
@@ -27,24 +27,61 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#import <Cocoa/Cocoa.h>
+#include <CoreServices/CoreServices.h>
#include <string>
+#include "base/scoped_cftyperef.h"
+#include "base/sys_string_conversions.h"
#include "net/base/platform_mime_util.h"
-#include "base/notimplemented.h"
namespace net {
bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
const std::wstring& ext, std::string* result) const {
- NOTIMPLEMENTED();
- return false;
+ std::wstring ext_nodot = ext;
+ if (ext_nodot.length() >= 1 && ext_nodot[0] == L'.')
+ ext_nodot.erase(ext_nodot.begin());
+ scoped_cftyperef<CFStringRef> ext_ref(base::SysWideToCFStringRef(ext_nodot));
+ if (!ext_ref)
+ return false;
+ scoped_cftyperef<CFStringRef> uti(
+ UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
+ ext_ref,
+ NULL));
+ if (!uti)
+ return false;
+ scoped_cftyperef<CFStringRef> mime_ref(
+ UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType));
+ if (!mime_ref)
+ return false;
+
+ *result = base::SysCFStringRefToUTF8(mime_ref);
+ return true;
}
bool PlatformMimeUtil::GetPreferredExtensionForMimeType(
const std::string& mime_type, std::wstring* ext) const {
- NOTIMPLEMENTED();
- return false;
+ scoped_cftyperef<CFStringRef> mime_ref(base::SysUTF8ToCFStringRef(mime_type));
+ if (!mime_ref)
+ return false;
+ scoped_cftyperef<CFStringRef> uti(
+ UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType,
+ mime_ref,
+ NULL));
+ if (!uti)
+ return false;
+ scoped_cftyperef<CFStringRef> ext_ref(
+ UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension));
+ if (!ext_ref)
+ return false;
+
+ ext_ref.reset(CFStringCreateWithFormat(kCFAllocatorDefault,
+ NULL,
+ CFSTR(".%@"),
+ ext_ref.get()));
+
+ *ext = base::SysCFStringRefToWide(ext_ref);
+ return true;
}
} // namespace net