Write native_mate converters for WebCache::ResourceTypeStat and friends

This commit is contained in:
Paul Betts 2016-05-12 13:48:01 -07:00
parent 847d9580b7
commit 61e775c055
2 changed files with 43 additions and 0 deletions

View file

@ -12,6 +12,7 @@
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "native_mate/dictionary.h"
#include "third_party/WebKit/public/web/WebCache.h"
#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
#include "third_party/WebKit/public/web/WebFindOptions.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
@ -384,4 +385,33 @@ v8::Local<v8::Value> MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags) {
return mate::ConvertToV8(isolate, dict);
}
v8::Local<v8::Value> Converter<blink::WebCache::ResourceTypeStat>::ToV8(
v8::Isolate* isolate,
const blink::WebCache::ResourceTypeStat& stat) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.Set("count", (uint32_t)stat.count);
dict.Set("size", (uint32_t)(stat.size >> 10));
dict.Set("liveSize", (uint32_t)(stat.liveSize >> 10));
dict.Set("decodedSize", (uint32_t)(stat.decodedSize >> 10));
dict.Set("purgedSize", (uint32_t)(stat.purgedSize >> 10));
dict.Set("purgeableSize", (uint32_t)(stat.purgeableSize >> 10));
return dict.GetHandle();
}
v8::Local<v8::Value> Converter<blink::WebCache::ResourceTypeStats>::ToV8(
v8::Isolate* isolate,
const blink::WebCache::ResourceTypeStats& stats) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.Set("images", mate::ConvertToV8(isolate, stats.images));
dict.Set("cssStyleSheets", mate::ConvertToV8(isolate, stats.cssStyleSheets));
dict.Set("xslStyleSheets", mate::ConvertToV8(isolate, stats.xslStyleSheets));
dict.Set("fonts", mate::ConvertToV8(isolate, stats.fonts));
dict.Set("other", mate::ConvertToV8(isolate, stats.other));
return dict.GetHandle();
}
} // namespace mate

View file

@ -6,6 +6,7 @@
#define ATOM_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_
#include "native_mate/converter.h"
#include "third_party/WebKit/public/web/WebCache.h"
#include "third_party/WebKit/public/web/WebContextMenuData.h"
namespace blink {
@ -104,6 +105,18 @@ v8::Local<v8::Value> EditFlagsToV8(v8::Isolate* isolate, int editFlags);
v8::Local<v8::Value> MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags);
template<>
struct Converter<blink::WebCache::ResourceTypeStat> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const blink::WebCache::ResourceTypeStat& stat);
};
template<>
struct Converter<blink::WebCache::ResourceTypeStats> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const blink::WebCache::ResourceTypeStats& stats);
};
} // namespace mate
#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_