create iconmanager as singleton class and cleanup code (#1)
* create iconmanager as singleton class and cleanup code
This commit is contained in:
parent
1b3cd87fc9
commit
b25b141642
15 changed files with 275 additions and 216 deletions
|
@ -30,6 +30,7 @@
|
|||
#include "base/path_service.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "brightray/browser/brightray_paths.h"
|
||||
#include "chrome/browser/icon_manager.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "content/public/browser/browser_accessibility_state.h"
|
||||
#include "content/public/browser/client_certificate_delegate.h"
|
||||
|
@ -314,6 +315,26 @@ struct Converter<Browser::LoginItemSettings> {
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<IconLoader::IconSize> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
IconLoader::IconSize* out) {
|
||||
std::string icon_size_string;
|
||||
if (!ConvertFromV8(isolate, val, &icon_size_string))
|
||||
return false;
|
||||
if (icon_size_string == "small")
|
||||
*out = IconLoader::IconSize::SMALL;
|
||||
else if (icon_size_string == "normal")
|
||||
*out = IconLoader::IconSize::NORMAL;
|
||||
else if (icon_size_string == "large")
|
||||
*out = IconLoader::IconSize::LARGE;
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<content::CertificateRequestResultType> {
|
||||
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
||||
|
@ -462,6 +483,11 @@ int ImportIntoCertStore(
|
|||
}
|
||||
#endif
|
||||
|
||||
void OnIconDataAvailable(const App::FileIconCallback& callback,
|
||||
gfx::Image* icon) {
|
||||
callback.Run(icon ? *icon : gfx::Image());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
App::App(v8::Isolate* isolate) {
|
||||
|
@ -841,6 +867,19 @@ JumpListResult App::SetJumpList(v8::Local<v8::Value> val,
|
|||
}
|
||||
#endif // defined(OS_WIN)
|
||||
|
||||
void App::GetFileIcon(const base::FilePath& path,
|
||||
IconLoader::IconSize icon_size,
|
||||
const FileIconCallback& callback) {
|
||||
IconManager* icon_manager = IconManager::GetInstance();
|
||||
gfx::Image* icon = icon_manager->LookupIconFromFilepath(path, icon_size);
|
||||
if (icon) {
|
||||
callback.Run(*icon);
|
||||
} else {
|
||||
icon_manager->LoadIcon(path, icon_size,
|
||||
base::Bind(&OnIconDataAvailable, callback));
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Handle<App> App::Create(v8::Isolate* isolate) {
|
||||
return mate::CreateHandle(isolate, new App(isolate));
|
||||
|
@ -909,7 +948,8 @@ void App::BuildPrototype(
|
|||
.SetMethod("isAccessibilitySupportEnabled",
|
||||
&App::IsAccessibilitySupportEnabled)
|
||||
.SetMethod("disableHardwareAcceleration",
|
||||
&App::DisableHardwareAcceleration);
|
||||
&App::DisableHardwareAcceleration)
|
||||
.SetMethod("getFileIcon", &App::GetFileIcon);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/browser_observer.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "chrome/browser/icon_loader.h"
|
||||
#include "chrome/browser/process_singleton.h"
|
||||
#include "content/public/browser/gpu_data_manager_observer.h"
|
||||
#include "native_mate/handle.h"
|
||||
|
@ -43,6 +44,8 @@ class App : public AtomBrowserClient::Delegate,
|
|||
public BrowserObserver,
|
||||
public content::GpuDataManagerObserver {
|
||||
public:
|
||||
using FileIconCallback = base::Callback<void(const gfx::Image&)>;
|
||||
|
||||
static mate::Handle<App> Create(v8::Isolate* isolate);
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
|
@ -129,6 +132,9 @@ class App : public AtomBrowserClient::Delegate,
|
|||
void ImportCertificate(const base::DictionaryValue& options,
|
||||
const net::CompletionCallback& callback);
|
||||
#endif
|
||||
void GetFileIcon(const base::FilePath& path,
|
||||
IconLoader::IconSize icon_size,
|
||||
const FileIconCallback& callback);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Get the current Jump List settings.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue