summaryrefslogtreecommitdiffstats
path: root/chrome/browser/icon_loader_mac.mm
blob: e14bde7aae012ab4dd14cdf1556c8451ad82b2c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/icon_loader.h"

#import <AppKit/AppKit.h>

#include "base/message_loop.h"
#include "base/threading/thread.h"
#include "base/sys_string_conversions.h"
#include "skia/ext/skia_utils_mac.h"
#include "third_party/skia/include/core/SkBitmap.h"

void IconLoader::ReadIcon() {
  NSString* group = base::SysUTF8ToNSString(group_);
  NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
  NSImage* icon = [workspace iconForFileType:group];

  NSSize size;
  if (icon_size_ == NORMAL)
    size = NSMakeSize(32, 32);
  else if (icon_size_ == SMALL)
    size = NSMakeSize(16, 16);
  else
    return;

  bitmap_.Set(new SkBitmap(gfx::NSImageToSkBitmap(icon, size, false)));

  target_message_loop_->PostTask(FROM_HERE,
      NewRunnableMethod(this, &IconLoader::NotifyDelegate));
}