diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-25 02:56:57 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-25 02:56:57 +0000 |
commit | 67fc03984940b07daa38970e6876fcec1fce0e8e (patch) | |
tree | cc4df6d037ecc5e0a479305856fa84137d62af93 /content/browser/webui/web_ui_util.cc | |
parent | 31de2b56d10626c2328f43531931bc08348ebad2 (diff) | |
download | chromium_src-67fc03984940b07daa38970e6876fcec1fce0e8e.zip chromium_src-67fc03984940b07daa38970e6876fcec1fce0e8e.tar.gz chromium_src-67fc03984940b07daa38970e6876fcec1fce0e8e.tar.bz2 |
WebUI: Move the core files of WebUI from chrome/browser/webui to content/browser/webui.
BUG=59946
TEST=trybots
Review URL: http://codereview.chromium.org/6575054
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/webui/web_ui_util.cc')
-rw-r--r-- | content/browser/webui/web_ui_util.cc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/content/browser/webui/web_ui_util.cc b/content/browser/webui/web_ui_util.cc new file mode 100644 index 0000000..e76aaef --- /dev/null +++ b/content/browser/webui/web_ui_util.cc @@ -0,0 +1,64 @@ +// Copyright (c) 2011 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 "content/browser/webui/web_ui_util.h" + +#include <vector> + +#include "base/base64.h" +#include "base/logging.h" +#include "base/values.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/codec/png_codec.h" + +namespace web_ui_util { + +std::string GetJsonResponseFromFirstArgumentInList(const ListValue* args) { + return GetJsonResponseFromArgumentList(args, 0); +} + +std::string GetJsonResponseFromArgumentList(const ListValue* args, + size_t list_index) { + std::string result; + if (args->GetSize() <= list_index) { + NOTREACHED(); + return result; + } + + Value* value = NULL; + if (args->Get(list_index, &value)) + value->GetAsString(&result); + else + NOTREACHED(); + + return result; +} + +std::string GetImageDataUrl(const SkBitmap& bitmap) { + std::vector<unsigned char> output; + gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &output); + std::string str_url; + std::copy(output.begin(), output.end(), + std::back_inserter(str_url)); + base::Base64Encode(str_url, &str_url); + str_url.insert(0, "data:image/png;base64,"); + return str_url; +} + +std::string GetImageDataUrlFromResource(int res) { + // Load resource icon and covert to base64 encoded data url + RefCountedStaticMemory* icon_data = + ResourceBundle::GetSharedInstance().LoadDataResourceBytes(res); + if (!icon_data) + return std::string(); + scoped_refptr<RefCountedMemory> raw_icon(icon_data); + std::string str_url; + std::copy(raw_icon->front(), raw_icon->front() + raw_icon->size(), + std::back_inserter(str_url)); + base::Base64Encode(str_url, &str_url); + str_url.insert(0, "data:image/png;base64,"); + return str_url; +} + +} // namespace web_ui_util |