OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ntp/thumbnail_list_source.h" | 5 #include "chrome/browser/ui/webui/ntp/thumbnail_list_source.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 const content::URLDataSource::GotDataCallback& callback, | 122 const content::URLDataSource::GotDataCallback& callback, |
123 const history::MostVisitedURLList& mvurl_list) { | 123 const history::MostVisitedURLList& mvurl_list) { |
124 const size_t num_mv = mvurl_list.size(); | 124 const size_t num_mv = mvurl_list.size(); |
125 size_t num_mv_with_thumb = 0; | 125 size_t num_mv_with_thumb = 0; |
126 | 126 |
127 // Encode all available thumbnails and store into |base64_encoded_pngs|. | 127 // Encode all available thumbnails and store into |base64_encoded_pngs|. |
128 std::vector<std::string> base64_encoded_pngs(num_mv); | 128 std::vector<std::string> base64_encoded_pngs(num_mv); |
129 for (size_t i = 0; i < num_mv; ++i) { | 129 for (size_t i = 0; i < num_mv; ++i) { |
130 scoped_refptr<base::RefCountedMemory> data; | 130 scoped_refptr<base::RefCountedMemory> data; |
131 if (thumbnail_service_->GetPageThumbnail(mvurl_list[i].url, false, &data)) { | 131 if (thumbnail_service_->GetPageThumbnail(mvurl_list[i].url, false, &data)) { |
132 std::string data_str; | 132 base::Base64Encode(std::string(data->front_as<char>(), data->size()), |
133 data_str.assign(reinterpret_cast<const char*>(data->front()), | 133 &base64_encoded_pngs[i]); |
134 data->size()); | |
135 base::Base64Encode(data_str, &base64_encoded_pngs[i]); | |
136 ++num_mv_with_thumb; | 134 ++num_mv_with_thumb; |
137 } | 135 } |
138 } | 136 } |
139 | 137 |
140 // Render HTML to embed URLs and thumbnails. | 138 // Render HTML to embed URLs and thumbnails. |
141 std::vector<std::string> out; | 139 std::vector<std::string> out; |
142 out.push_back(html_header); | 140 out.push_back(html_header); |
143 out.push_back(html_body); | 141 out.push_back(html_body); |
144 if (num_mv_with_thumb > 0) { | 142 if (num_mv_with_thumb > 0) { |
145 out.push_back("<h2>TopSites URLs with Thumbnails</h2>\n"); | 143 out.push_back("<h2>TopSites URLs with Thumbnails</h2>\n"); |
146 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, true, &out); | 144 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, true, &out); |
147 } | 145 } |
148 if (num_mv_with_thumb < num_mv) { | 146 if (num_mv_with_thumb < num_mv) { |
149 out.push_back("<h2>TopSites URLs without Thumbnails</h2>\n"); | 147 out.push_back("<h2>TopSites URLs without Thumbnails</h2>\n"); |
150 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, false, &out); | 148 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, false, &out); |
151 } | 149 } |
152 out.push_back(html_footer); | 150 out.push_back(html_footer); |
153 | 151 |
154 std::string out_html = JoinString(out, ""); | 152 std::string out_html = JoinString(out, ""); |
155 callback.Run(base::RefCountedString::TakeString(&out_html)); | 153 callback.Run(base::RefCountedString::TakeString(&out_html)); |
156 } | 154 } |
OLD | NEW |