Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Side by Side Diff: chrome/browser/ui/webui/web_ui_util.cc

Issue 10532048: [cros] Initial WebRTC-enabled implementation of user image picker on OOBE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "googleurl/src/gurl.h"
15 #include "net/base/data_url.h"
14 #include "ui/base/layout.h" 16 #include "ui/base/layout.h"
15 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/codec/png_codec.h" 18 #include "ui/gfx/codec/png_codec.h"
17 #include "ui/gfx/image/image_skia.h" 19 #include "ui/gfx/image/image_skia.h"
18 20
19 namespace web_ui_util { 21 namespace web_ui_util {
20 22
21 std::string GetImageDataUrl(const gfx::ImageSkia& image) { 23 std::string GetImageDataUrl(const gfx::ImageSkia& image) {
22 std::vector<unsigned char> output; 24 std::vector<unsigned char> output;
23 gfx::PNGCodec::EncodeBGRASkBitmap(*image.bitmap(), false, &output); 25 gfx::PNGCodec::EncodeBGRASkBitmap(*image.bitmap(), false, &output);
(...skipping 15 matching lines...) Expand all
39 scoped_refptr<base::RefCountedMemory> raw_icon(icon_data); 41 scoped_refptr<base::RefCountedMemory> raw_icon(icon_data);
40 std::string str_url; 42 std::string str_url;
41 str_url.insert(str_url.end(), 43 str_url.insert(str_url.end(),
42 raw_icon->front(), 44 raw_icon->front(),
43 raw_icon->front() + raw_icon->size()); 45 raw_icon->front() + raw_icon->size());
44 base::Base64Encode(str_url, &str_url); 46 base::Base64Encode(str_url, &str_url);
45 str_url.insert(0, "data:image/png;base64,"); 47 str_url.insert(0, "data:image/png;base64,");
46 return str_url; 48 return str_url;
47 } 49 }
48 50
51 gfx::ImageSkia GetImageFromDataUrl(const std::string& data_url) {
52 std::string mime_type, charset, raw_data;
53 if (!net::DataURL::Parse(GURL(data_url), &mime_type, &charset, &raw_data)) {
54 LOG(ERROR) << "Invalid data URL: " << data_url;
55 return gfx::ImageSkia();
56 }
57 if (mime_type != "image/png") {
58 LOG(WARNING) << "Data URL MIME type not supported: " << mime_type;
59 return gfx::ImageSkia();
60 }
61 SkBitmap image;
62 if (!gfx::PNGCodec::Decode(
63 reinterpret_cast<const unsigned char*>(raw_data.data()),
64 raw_data.size(), &image)) {
65 LOG(ERROR) << "Invalid image in data URL: " << data_url;
66 return gfx::ImageSkia();
67 }
68 return gfx::ImageSkia(image);
69 }
70
49 WindowOpenDisposition GetDispositionFromClick(const ListValue* args, 71 WindowOpenDisposition GetDispositionFromClick(const ListValue* args,
50 int start_index) { 72 int start_index) {
51 double button = 0.0; 73 double button = 0.0;
52 bool alt_key = false; 74 bool alt_key = false;
53 bool ctrl_key = false; 75 bool ctrl_key = false;
54 bool meta_key = false; 76 bool meta_key = false;
55 bool shift_key = false; 77 bool shift_key = false;
56 78
57 CHECK(args->GetDouble(start_index++, &button)); 79 CHECK(args->GetDouble(start_index++, &button));
58 CHECK(args->GetBoolean(start_index++, &alt_key)); 80 CHECK(args->GetBoolean(start_index++, &alt_key));
59 CHECK(args->GetBoolean(start_index++, &ctrl_key)); 81 CHECK(args->GetBoolean(start_index++, &ctrl_key));
60 CHECK(args->GetBoolean(start_index++, &meta_key)); 82 CHECK(args->GetBoolean(start_index++, &meta_key));
61 CHECK(args->GetBoolean(start_index++, &shift_key)); 83 CHECK(args->GetBoolean(start_index++, &shift_key));
62 return disposition_utils::DispositionFromClick(button == 1.0, alt_key, 84 return disposition_utils::DispositionFromClick(button == 1.0, alt_key,
63 ctrl_key, meta_key, shift_key); 85 ctrl_key, meta_key, shift_key);
64 86
65 } 87 }
66 88
67 } // namespace web_ui_util 89 } // namespace web_ui_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698