Index: chrome/browser/ui/webui/web_ui_util.cc |
diff --git a/chrome/browser/ui/webui/web_ui_util.cc b/chrome/browser/ui/webui/web_ui_util.cc |
index 160ba0affe917651847c838cf8d3687689d815d8..81456080658352f08abdaba6b3d870a5f0d4ad9a 100644 |
--- a/chrome/browser/ui/webui/web_ui_util.cc |
+++ b/chrome/browser/ui/webui/web_ui_util.cc |
@@ -11,6 +11,8 @@ |
#include "base/memory/ref_counted_memory.h" |
#include "base/values.h" |
#include "chrome/browser/disposition_utils.h" |
+#include "googleurl/src/gurl.h" |
+#include "net/base/data_url.h" |
#include "ui/base/layout.h" |
#include "ui/base/resource/resource_bundle.h" |
#include "ui/gfx/codec/png_codec.h" |
@@ -46,6 +48,26 @@ std::string GetImageDataUrlFromResource(int res) { |
return str_url; |
} |
+gfx::ImageSkia GetImageFromDataUrl(const std::string& data_url) { |
+ std::string mime_type, charset, raw_data; |
+ if (!net::DataURL::Parse(GURL(data_url), &mime_type, &charset, &raw_data)) { |
+ LOG(ERROR) << "Invalid data URL: " << data_url; |
+ return gfx::ImageSkia(); |
+ } |
+ if (mime_type != "image/png") { |
+ LOG(WARNING) << "Data URL MIME type not supported: " << mime_type; |
+ return gfx::ImageSkia(); |
+ } |
+ SkBitmap image; |
+ if (!gfx::PNGCodec::Decode( |
+ reinterpret_cast<const unsigned char*>(raw_data.data()), |
+ raw_data.size(), &image)) { |
+ LOG(ERROR) << "Invalid image in data URL: " << data_url; |
+ return gfx::ImageSkia(); |
+ } |
+ return gfx::ImageSkia(image); |
+} |
+ |
WindowOpenDisposition GetDispositionFromClick(const ListValue* args, |
int start_index) { |
double button = 0.0; |