| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/web_ui_util.h" | 5 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/disposition_utils.h" | 13 #include "chrome/browser/disposition_utils.h" |
| 14 #include "ui/base/layout.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/codec/png_codec.h" | 16 #include "ui/gfx/codec/png_codec.h" |
| 16 | 17 |
| 17 namespace web_ui_util { | 18 namespace web_ui_util { |
| 18 | 19 |
| 19 std::string GetImageDataUrl(const SkBitmap& bitmap) { | 20 std::string GetImageDataUrl(const SkBitmap& bitmap) { |
| 20 std::vector<unsigned char> output; | 21 std::vector<unsigned char> output; |
| 21 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &output); | 22 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &output); |
| 22 std::string str_url; | 23 std::string str_url; |
| 23 str_url.insert(str_url.end(), output.begin(), output.end()); | 24 str_url.insert(str_url.end(), output.begin(), output.end()); |
| 24 | 25 |
| 25 base::Base64Encode(str_url, &str_url); | 26 base::Base64Encode(str_url, &str_url); |
| 26 str_url.insert(0, "data:image/png;base64,"); | 27 str_url.insert(0, "data:image/png;base64,"); |
| 27 return str_url; | 28 return str_url; |
| 28 } | 29 } |
| 29 | 30 |
| 30 std::string GetImageDataUrlFromResource(int res) { | 31 std::string GetImageDataUrlFromResource(int res) { |
| 31 // Load resource icon and covert to base64 encoded data url | 32 // Load resource icon and covert to base64 encoded data url |
| 32 base::RefCountedStaticMemory* icon_data = | 33 base::RefCountedStaticMemory* icon_data = |
| 33 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(res); | 34 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(res, |
| 35 ui::SCALE_FACTOR_100P); |
| 34 if (!icon_data) | 36 if (!icon_data) |
| 35 return std::string(); | 37 return std::string(); |
| 36 scoped_refptr<base::RefCountedMemory> raw_icon(icon_data); | 38 scoped_refptr<base::RefCountedMemory> raw_icon(icon_data); |
| 37 std::string str_url; | 39 std::string str_url; |
| 38 str_url.insert(str_url.end(), | 40 str_url.insert(str_url.end(), |
| 39 raw_icon->front(), | 41 raw_icon->front(), |
| 40 raw_icon->front() + raw_icon->size()); | 42 raw_icon->front() + raw_icon->size()); |
| 41 base::Base64Encode(str_url, &str_url); | 43 base::Base64Encode(str_url, &str_url); |
| 42 str_url.insert(0, "data:image/png;base64,"); | 44 str_url.insert(0, "data:image/png;base64,"); |
| 43 return str_url; | 45 return str_url; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 55 CHECK(args->GetBoolean(start_index++, &alt_key)); | 57 CHECK(args->GetBoolean(start_index++, &alt_key)); |
| 56 CHECK(args->GetBoolean(start_index++, &ctrl_key)); | 58 CHECK(args->GetBoolean(start_index++, &ctrl_key)); |
| 57 CHECK(args->GetBoolean(start_index++, &meta_key)); | 59 CHECK(args->GetBoolean(start_index++, &meta_key)); |
| 58 CHECK(args->GetBoolean(start_index++, &shift_key)); | 60 CHECK(args->GetBoolean(start_index++, &shift_key)); |
| 59 return disposition_utils::DispositionFromClick(button == 1.0, alt_key, | 61 return disposition_utils::DispositionFromClick(button == 1.0, alt_key, |
| 60 ctrl_key, meta_key, shift_key); | 62 ctrl_key, meta_key, shift_key); |
| 61 | 63 |
| 62 } | 64 } |
| 63 | 65 |
| 64 } // namespace web_ui_util | 66 } // namespace web_ui_util |
| OLD | NEW |