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

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

Issue 59903010: Ensure using chrome://thumb2/... adds the URL as a forced URL in TopSites so that a thumbnail is ca… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Take 2. Created 7 years, 1 month 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 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 21 matching lines...) Expand all
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());
42 out->push_back("<div><ul>\n"); 42 bool doing_forced_urls = true;
43 out->push_back("<div><b>Forced URLs:</b></div>\n"
44 "<div><ul>\n");
43 for (size_t i = 0; i < mvurl_list.size(); ++i) { 45 for (size_t i = 0; i < mvurl_list.size(); ++i) {
44 const history::MostVisitedURL& mvurl = mvurl_list[i]; 46 const history::MostVisitedURL& mvurl = mvurl_list[i];
47 if (doing_forced_urls && mvurl.last_forced_time.is_null()) {
48 out->push_back("</ul></div>\n"
49 "<div><b>Non-forced URLs:</b></div>\n"
50 "<div><ul>\n");
51 doing_forced_urls = false;
52 }
45 bool has_thumbnail = !base64_encoded_pngs[i].empty(); 53 bool has_thumbnail = !base64_encoded_pngs[i].empty();
46 if (has_thumbnail == want_thumbnails) { 54 if (has_thumbnail == want_thumbnails) {
47 out->push_back("<li>\n"); 55 out->push_back("<li>\n");
48 out->push_back(net::EscapeForHTML(mvurl.url.spec()) + "\n"); 56 out->push_back(net::EscapeForHTML(mvurl.url.spec()) + "\n");
49 if (want_thumbnails) { 57 if (want_thumbnails) {
50 out->push_back("<div><img class=\"thumb\" " 58 out->push_back("<div><img class=\"thumb\" "
51 "src=\"data:image/png;base64," + 59 "src=\"data:image/png;base64," +
52 base64_encoded_pngs[i] + "\"/></div>\n"); 60 base64_encoded_pngs[i] + "\"/></div>\n");
53 } 61 }
54 if (!mvurl.redirects.empty()) { 62 if (!mvurl.redirects.empty()) {
(...skipping 27 matching lines...) Expand all
82 } 90 }
83 91
84 void ThumbnailListSource::StartDataRequest( 92 void ThumbnailListSource::StartDataRequest(
85 const std::string& path, 93 const std::string& path,
86 int render_process_id, 94 int render_process_id,
87 int render_view_id, 95 int render_view_id,
88 const content::URLDataSource::GotDataCallback& callback) { 96 const content::URLDataSource::GotDataCallback& callback) {
89 profile_->GetTopSites()->GetMostVisitedURLs( 97 profile_->GetTopSites()->GetMostVisitedURLs(
90 base::Bind(&ThumbnailListSource::OnMostVisitedURLsAvailable, 98 base::Bind(&ThumbnailListSource::OnMostVisitedURLsAvailable,
91 weak_ptr_factory_.GetWeakPtr(), 99 weak_ptr_factory_.GetWeakPtr(),
92 callback), false); 100 callback), true);
93 } 101 }
94 102
95 std::string ThumbnailListSource::GetMimeType(const std::string& path) const { 103 std::string ThumbnailListSource::GetMimeType(const std::string& path) const {
96 return "text/html"; 104 return "text/html";
97 } 105 }
98 106
99 base::MessageLoop* ThumbnailListSource::MessageLoopForRequestPath( 107 base::MessageLoop* ThumbnailListSource::MessageLoopForRequestPath(
100 const std::string& path) const { 108 const std::string& path) const {
101 // TopSites can be accessed from the IO thread. 109 // TopSites can be accessed from the IO thread.
102 return thumbnail_service_.get() ? 110 return thumbnail_service_.get() ?
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 147 }
140 if (num_mv_with_thumb < num_mv) { 148 if (num_mv_with_thumb < num_mv) {
141 out.push_back("<h2>TopSites URLs without Thumbnails</h2>\n"); 149 out.push_back("<h2>TopSites URLs without Thumbnails</h2>\n");
142 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, false, &out); 150 RenderMostVisitedURLList(mvurl_list, base64_encoded_pngs, false, &out);
143 } 151 }
144 out.push_back(html_footer); 152 out.push_back(html_footer);
145 153
146 std::string out_html = JoinString(out, ""); 154 std::string out_html = JoinString(out, "");
147 callback.Run(base::RefCountedString::TakeString(&out_html)); 155 callback.Run(base::RefCountedString::TakeString(&out_html));
148 } 156 }
OLDNEW
« no previous file with comments | « chrome/browser/thumbnails/thumbnail_service_impl.cc ('k') | chrome/browser/ui/webui/ntp/thumbnail_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698