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

Side by Side Diff: chrome/browser/ui/webui/ntp/thumbnail_list_source.cc

Issue 170743009: Revert of Adding the chrome://suggestions test page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
« no previous file with comments | « chrome/browser/ui/browser_navigator.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted_memory.h" 12 #include "base/memory/ref_counted_memory.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "chrome/browser/history/top_sites.h" 14 #include "chrome/browser/history/top_sites.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/search/instant_io_context.h" 16 #include "chrome/browser/search/instant_io_context.h"
17 #include "chrome/browser/thumbnails/thumbnail_service.h" 17 #include "chrome/browser/thumbnails/thumbnail_service.h"
18 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" 18 #include "chrome/browser/thumbnails/thumbnail_service_factory.h"
19 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
20 #include "net/base/escape.h" 20 #include "net/base/escape.h"
21 #include "net/url_request/url_request.h" 21 #include "net/url_request/url_request.h"
22 22
23 namespace { 23 namespace {
24 24
25 const char* kHtmlHeader = 25 const char* html_header =
26 "<!DOCTYPE html>\n<html>\n<head>\n<title>TopSites Thumbnails</title>\n" 26 "<!DOCTYPE HTML>\n<html>\n<head>\n<title>TopSites Thumbnails</title>\n"
27 "<meta charset=\"utf-8\">\n" 27 "<meta charset=\"utf-8\">\n"
28 "<style type=\"text/css\">\nimg.thumb {border: 1px solid black;}\n" 28 "<style type=\"text/css\">\nimg.thumb {border: 1px solid black;}\n"
29 "li {white-space: nowrap;}\n</style>\n"; 29 "li {white-space: nowrap;}\n</style>\n";
30 const char* kHtmlBody = "</head>\n<body>\n"; 30 const char* html_body = "</head>\n<body>\n";
31 const char* kHtmlFooter = "</body>\n</html>\n"; 31 const char* html_footer = "</body>\n</html>\n";
32 32
33 // If |want_thumbnails| == true, then renders elements in |mvurl_list| that have 33 // If |want_thumbnails| == true, then renders elements in |mvurl_list| that have
34 // thumbnails, with their thumbnails. Otherwise renders elements in |mvurl_list| 34 // thumbnails, with their thumbnails. Otherwise renders elements in |mvurl_list|
35 // that have no thumbnails. 35 // that have no thumbnails.
36 void RenderMostVisitedURLList( 36 void RenderMostVisitedURLList(
37 const history::MostVisitedURLList& mvurl_list, 37 const history::MostVisitedURLList& mvurl_list,
38 const std::vector<std::string>& base64_encoded_pngs, 38 const std::vector<std::string>& base64_encoded_pngs,
39 bool want_thumbnails, 39 bool want_thumbnails,
40 std::vector<std::string>* out) { 40 std::vector<std::string>* out) {
41 DCHECK_EQ(mvurl_list.size(), base64_encoded_pngs.size()); 41 DCHECK_EQ(mvurl_list.size(), base64_encoded_pngs.size());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 base::Base64Encode(std::string(data->front_as<char>(), data->size()), 132 base::Base64Encode(std::string(data->front_as<char>(), data->size()),
133 &base64_encoded_pngs[i]); 133 &base64_encoded_pngs[i]);
134 ++num_mv_with_thumb; 134 ++num_mv_with_thumb;
135 } 135 }
136 } 136 }
137 137
138 // Render HTML to embed URLs and thumbnails. 138 // Render HTML to embed URLs and thumbnails.
139 std::vector<std::string> out; 139 std::vector<std::string> out;
140 out.push_back(kHtmlHeader); 140 out.push_back(html_header);
141 out.push_back(kHtmlBody); 141 out.push_back(html_body);
142 if (num_mv_with_thumb > 0) { 142 if (num_mv_with_thumb > 0) {
143 out.push_back("<h2>TopSites URLs with Thumbnails</h2>\n"); 143 out.push_back("<h2>TopSites URLs with Thumbnails</h2>\n");
144 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, true, &out); 144 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, true, &out);
145 } 145 }
146 if (num_mv_with_thumb < num_mv) { 146 if (num_mv_with_thumb < num_mv) {
147 out.push_back("<h2>TopSites URLs without Thumbnails</h2>\n"); 147 out.push_back("<h2>TopSites URLs without Thumbnails</h2>\n");
148 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, false, &out); 148 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, false, &out);
149 } 149 }
150 out.push_back(kHtmlFooter); 150 out.push_back(html_footer);
151 151
152 std::string out_html = JoinString(out, ""); 152 std::string out_html = JoinString(out, "");
153 callback.Run(base::RefCountedString::TakeString(&out_html)); 153 callback.Run(base::RefCountedString::TakeString(&out_html));
154 } 154 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_navigator.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698