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

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

Issue 2875943003: Cleanup: Remove dead code in NewTabUI (Closed)
Patch Set: review Created 3 years, 7 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
« no previous file with comments | « chrome/browser/ui/webui/ntp/new_tab_ui.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ntp/new_tab_ui.h" 5 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string>
8 9
9 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
10 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
11 #include "base/memory/ref_counted_memory.h" 12 #include "base/memory/ref_counted_memory.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/webui/metrics_handler.h" 16 #include "chrome/browser/ui/webui/metrics_handler.h"
16 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 17 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
17 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" 18 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
18 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" 19 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
19 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" 20 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
20 #include "chrome/browser/ui/webui/theme_handler.h" 21 #include "chrome/browser/ui/webui/theme_handler.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
22 #include "components/bookmarks/common/bookmark_pref_names.h" 23 #include "components/bookmarks/common/bookmark_pref_names.h"
23 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
24 #include "components/strings/grit/components_strings.h" 25 #include "components/strings/grit/components_strings.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/render_process_host.h" 27 #include "content/public/browser/render_process_host.h"
27 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
28 #include "content/public/browser/web_ui.h" 29 #include "content/public/browser/web_ui.h"
29 #include "extensions/browser/extension_system.h" 30 #include "extensions/browser/extension_system.h"
30 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h"
32 #include "url/gurl.h" 32 #include "url/gurl.h"
33 33
34 using content::BrowserThread; 34 using content::BrowserThread;
35 using content::WebUIController; 35 using content::WebUIController;
36 36
37 namespace { 37 namespace {
38 38
39 // Strings sent to the page via jstemplates used to set the direction of the 39 // Strings sent to the page via jstemplates used to set the direction of the
40 // HTML document based on locale. 40 // HTML document based on locale.
41 const char kRTLHtmlTextDirection[] = "rtl"; 41 const char kRTLHtmlTextDirection[] = "rtl";
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 std::string NewTabUI::NewTabHTMLSource::GetSource() const { 174 std::string NewTabUI::NewTabHTMLSource::GetSource() const {
175 return chrome::kChromeUINewTabHost; 175 return chrome::kChromeUINewTabHost;
176 } 176 }
177 177
178 void NewTabUI::NewTabHTMLSource::StartDataRequest( 178 void NewTabUI::NewTabHTMLSource::StartDataRequest(
179 const std::string& path, 179 const std::string& path,
180 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, 180 const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
181 const content::URLDataSource::GotDataCallback& callback) { 181 const content::URLDataSource::GotDataCallback& callback) {
182 DCHECK_CURRENTLY_ON(BrowserThread::UI); 182 DCHECK_CURRENTLY_ON(BrowserThread::UI);
183 183
184 std::map<std::string, std::pair<std::string, int> >::iterator it =
185 resource_map_.find(path);
186 if (it != resource_map_.end()) {
187 scoped_refptr<base::RefCountedMemory> resource_bytes(
188 it->second.second ?
189 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
190 it->second.second) :
191 new base::RefCountedStaticMemory);
192 callback.Run(resource_bytes.get());
193 return;
194 }
195
196 if (!path.empty() && path[0] != '#') { 184 if (!path.empty() && path[0] != '#') {
197 // A path under new-tab was requested; it's likely a bad relative 185 // A path under new-tab was requested; it's likely a bad relative
198 // URL from the new tab page, but in any case it's an error. 186 // URL from the new tab page, but in any case it's an error.
199 NOTREACHED() << path << " should not have been requested on the NTP"; 187 NOTREACHED() << path << " should not have been requested on the NTP";
200 callback.Run(NULL); 188 callback.Run(NULL);
201 return; 189 return;
202 } 190 }
203 191
204 content::WebContents* web_contents = wc_getter.Run(); 192 content::WebContents* web_contents = wc_getter.Run();
205 content::RenderProcessHost* render_host = 193 content::RenderProcessHost* render_host =
206 web_contents ? web_contents->GetRenderProcessHost() : nullptr; 194 web_contents ? web_contents->GetRenderProcessHost() : nullptr;
207 NTPResourceCache::WindowType win_type = NTPResourceCache::GetWindowType( 195 NTPResourceCache::WindowType win_type = NTPResourceCache::GetWindowType(
208 profile_, render_host); 196 profile_, render_host);
209 scoped_refptr<base::RefCountedMemory> html_bytes( 197 scoped_refptr<base::RefCountedMemory> html_bytes(
210 NTPResourceCacheFactory::GetForProfile(profile_)-> 198 NTPResourceCacheFactory::GetForProfile(profile_)->
211 GetNewTabHTML(win_type)); 199 GetNewTabHTML(win_type));
212 200
213 callback.Run(html_bytes.get()); 201 callback.Run(html_bytes.get());
214 } 202 }
215 203
216 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string& resource) 204 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string& resource)
217 const { 205 const {
218 std::map<std::string, std::pair<std::string, int> >::const_iterator it =
219 resource_map_.find(resource);
220 if (it != resource_map_.end())
221 return it->second.first;
222 return "text/html"; 206 return "text/html";
223 } 207 }
224 208
225 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { 209 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const {
226 return false; 210 return false;
227 } 211 }
228 212
229 std::string NewTabUI::NewTabHTMLSource::GetContentSecurityPolicyScriptSrc() 213 std::string NewTabUI::NewTabHTMLSource::GetContentSecurityPolicyScriptSrc()
230 const { 214 const {
231 // 'unsafe-inline' and google resources are added to script-src. 215 // 'unsafe-inline' and google resources are added to script-src.
(...skipping 10 matching lines...) Expand all
242 const { 226 const {
243 return "img-src chrome-search://thumb chrome-search://thumb2 " 227 return "img-src chrome-search://thumb chrome-search://thumb2 "
244 "chrome-search://theme chrome://theme data:;"; 228 "chrome-search://theme chrome://theme data:;";
245 } 229 }
246 230
247 std::string NewTabUI::NewTabHTMLSource::GetContentSecurityPolicyChildSrc() 231 std::string NewTabUI::NewTabHTMLSource::GetContentSecurityPolicyChildSrc()
248 const { 232 const {
249 return "child-src chrome-search://most-visited;"; 233 return "child-src chrome-search://most-visited;";
250 } 234 }
251 235
252 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource,
253 const char* mime_type,
254 int resource_id) {
255 DCHECK(resource);
256 DCHECK(mime_type);
257 resource_map_[std::string(resource)] =
258 std::make_pair(std::string(mime_type), resource_id);
259 }
260
261 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} 236 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {}
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/new_tab_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698