OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_icon_source.h" | 5 #include "chrome/browser/ui/webui/extension_icon_source.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 *image = SkBitmapOperations::CreateHSLShiftedBitmap(*image, shift); | 45 *image = SkBitmapOperations::CreateHSLShiftedBitmap(*image, shift); |
46 } | 46 } |
47 | 47 |
48 SkBitmap* ToBitmap(const unsigned char* data, size_t size) { | 48 SkBitmap* ToBitmap(const unsigned char* data, size_t size) { |
49 webkit_glue::ImageDecoder decoder; | 49 webkit_glue::ImageDecoder decoder; |
50 SkBitmap* decoded = new SkBitmap(); | 50 SkBitmap* decoded = new SkBitmap(); |
51 *decoded = decoder.Decode(data, size); | 51 *decoded = decoder.Decode(data, size); |
52 return decoded; | 52 return decoded; |
53 } | 53 } |
54 | 54 |
55 SkBitmap* LoadImageByResourceId(int resource_id) { | |
56 std::string contents = ResourceBundle::GetSharedInstance() | |
57 .GetRawDataResource(resource_id).as_string(); | |
58 | |
59 // Convert and return it. | |
60 const unsigned char* data = | |
61 reinterpret_cast<const unsigned char*>(contents.data()); | |
62 return ToBitmap(data, contents.length()); | |
63 } | |
64 | |
65 } // namespace | 55 } // namespace |
66 | 56 |
67 | 57 |
68 ExtensionIconSource::ExtensionIconSource(Profile* profile) | 58 ExtensionIconSource::ExtensionIconSource(Profile* profile) |
69 : DataSource(chrome::kChromeUIExtensionIconHost, MessageLoop::current()), | 59 : DataSource(chrome::kChromeUIExtensionIconHost, MessageLoop::current()), |
70 profile_(profile), | 60 profile_(profile), |
71 next_tracker_id_(0) { | 61 next_tracker_id_(0) { |
72 tracker_.reset(new ImageLoadingTracker(this)); | 62 tracker_.reset(new ImageLoadingTracker(this)); |
73 } | 63 } |
74 | 64 |
(...skipping 18 matching lines...) Expand all Loading... |
93 GURL icon_url(base::StringPrintf("%s%s/%d/%d%s", | 83 GURL icon_url(base::StringPrintf("%s%s/%d/%d%s", |
94 chrome::kChromeUIExtensionIconURL, | 84 chrome::kChromeUIExtensionIconURL, |
95 extension->id().c_str(), | 85 extension->id().c_str(), |
96 icon_size, | 86 icon_size, |
97 match, | 87 match, |
98 grayscale ? "?grayscale=true" : "")); | 88 grayscale ? "?grayscale=true" : "")); |
99 CHECK(icon_url.is_valid()); | 89 CHECK(icon_url.is_valid()); |
100 return icon_url; | 90 return icon_url; |
101 } | 91 } |
102 | 92 |
| 93 // static |
| 94 SkBitmap* ExtensionIconSource::LoadImageByResourceId(int resource_id) { |
| 95 std::string contents = ResourceBundle::GetSharedInstance() |
| 96 .GetRawDataResource(resource_id).as_string(); |
| 97 |
| 98 // Convert and return it. |
| 99 const unsigned char* data = |
| 100 reinterpret_cast<const unsigned char*>(contents.data()); |
| 101 return ToBitmap(data, contents.length()); |
| 102 } |
| 103 |
103 std::string ExtensionIconSource::GetMimeType(const std::string&) const { | 104 std::string ExtensionIconSource::GetMimeType(const std::string&) const { |
104 // We need to explicitly return a mime type, otherwise if the user tries to | 105 // We need to explicitly return a mime type, otherwise if the user tries to |
105 // drag the image they get no extension. | 106 // drag the image they get no extension. |
106 return "image/png"; | 107 return "image/png"; |
107 } | 108 } |
108 | 109 |
109 void ExtensionIconSource::StartDataRequest(const std::string& path, | 110 void ExtensionIconSource::StartDataRequest(const std::string& path, |
110 bool is_incognito, | 111 bool is_incognito, |
111 int request_id) { | 112 int request_id) { |
112 // This is where everything gets started. First, parse the request and make | 113 // This is where everything gets started. First, parse the request and make |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 312 |
312 void ExtensionIconSource::ClearData(int request_id) { | 313 void ExtensionIconSource::ClearData(int request_id) { |
313 std::map<int, ExtensionIconRequest*>::iterator i = | 314 std::map<int, ExtensionIconRequest*>::iterator i = |
314 request_map_.find(request_id); | 315 request_map_.find(request_id); |
315 if (i == request_map_.end()) | 316 if (i == request_map_.end()) |
316 return; | 317 return; |
317 | 318 |
318 delete i->second; | 319 delete i->second; |
319 request_map_.erase(i); | 320 request_map_.erase(i); |
320 } | 321 } |
OLD | NEW |