From 61e775c0554b4289d7a6529ab17737076354e813 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Thu, 12 May 2016 13:48:01 -0700 Subject: [PATCH] Write native_mate converters for WebCache::ResourceTypeStat and friends --- .../native_mate_converters/blink_converter.cc | 30 +++++++++++++++++++ .../native_mate_converters/blink_converter.h | 13 ++++++++ 2 files changed, 43 insertions(+) diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index 0ae73e9825c8..915e766ea7ee 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -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 MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags) { return mate::ConvertToV8(isolate, dict); } +v8::Local Converter::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 Converter::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 diff --git a/atom/common/native_mate_converters/blink_converter.h b/atom/common/native_mate_converters/blink_converter.h index 514c6ab680c7..a48547e612bd 100644 --- a/atom/common/native_mate_converters/blink_converter.h +++ b/atom/common/native_mate_converters/blink_converter.h @@ -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 EditFlagsToV8(v8::Isolate* isolate, int editFlags); v8::Local MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags); +template<> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + const blink::WebCache::ResourceTypeStat& stat); +}; + +template<> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + const blink::WebCache::ResourceTypeStats& stats); +}; + } // namespace mate #endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_