2016-11-02 18:57:16 +00:00
|
|
|
// Copyright 2013 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"
|
|
|
|
|
|
|
|
#include "base/bind.h"
|
2018-01-08 09:47:25 +00:00
|
|
|
#include "base/memory/ptr_util.h"
|
2016-11-02 18:57:16 +00:00
|
|
|
#include "base/message_loop/message_loop.h"
|
|
|
|
#include "base/nix/mime_util_xdg.h"
|
|
|
|
#include "ui/views/linux_ui/linux_ui.h"
|
|
|
|
|
|
|
|
// static
|
2017-02-16 19:19:19 +00:00
|
|
|
IconLoader::IconGroup IconLoader::GroupForFilepath(
|
|
|
|
const base::FilePath& file_path) {
|
|
|
|
return base::nix::GetFileMimeType(file_path);
|
2016-11-02 18:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2018-01-08 10:21:22 +00:00
|
|
|
scoped_refptr<base::TaskRunner> IconLoader::GetReadIconTaskRunner() {
|
2016-11-02 18:57:16 +00:00
|
|
|
// ReadIcon() calls into views::LinuxUI and GTK2 code, so it must be on the UI
|
|
|
|
// thread.
|
2018-01-08 10:21:22 +00:00
|
|
|
return content::BrowserThread::GetTaskRunnerForThread(
|
|
|
|
content::BrowserThread::UI);
|
2016-11-02 18:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IconLoader::ReadIcon() {
|
|
|
|
int size_pixels = 0;
|
|
|
|
switch (icon_size_) {
|
|
|
|
case IconLoader::SMALL:
|
|
|
|
size_pixels = 16;
|
|
|
|
break;
|
|
|
|
case IconLoader::NORMAL:
|
|
|
|
size_pixels = 32;
|
|
|
|
break;
|
|
|
|
case IconLoader::LARGE:
|
|
|
|
size_pixels = 48;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
|
2018-01-08 09:47:25 +00:00
|
|
|
std::unique_ptr<gfx::Image> image;
|
|
|
|
|
2016-11-02 18:57:16 +00:00
|
|
|
views::LinuxUI* ui = views::LinuxUI::instance();
|
|
|
|
if (ui) {
|
2018-01-08 09:47:25 +00:00
|
|
|
image = base::MakeUnique<gfx::Image>(
|
|
|
|
ui->GetIconForContentType(group_, size_pixels));
|
|
|
|
if (image->IsEmpty())
|
|
|
|
image = nullptr;
|
2016-11-02 18:57:16 +00:00
|
|
|
}
|
|
|
|
|
2017-02-16 19:19:19 +00:00
|
|
|
target_task_runner_->PostTask(
|
2018-01-08 10:21:22 +00:00
|
|
|
FROM_HERE, base::BindOnce(callback_, base::Passed(&image), group_));
|
2017-02-16 19:19:19 +00:00
|
|
|
delete this;
|
2016-11-02 18:57:16 +00:00
|
|
|
}
|