OLD | NEW |
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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
326 | 326 |
327 std::map<std::string, std::pair<std::string, int> >::iterator it = | 327 std::map<std::string, std::pair<std::string, int> >::iterator it = |
328 resource_map_.find(path); | 328 resource_map_.find(path); |
329 if (it != resource_map_.end()) { | 329 if (it != resource_map_.end()) { |
330 scoped_refptr<base::RefCountedStaticMemory> resource_bytes( | 330 scoped_refptr<base::RefCountedStaticMemory> resource_bytes( |
331 it->second.second ? | 331 it->second.second ? |
332 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 332 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
333 it->second.second) : | 333 it->second.second) : |
334 new base::RefCountedStaticMemory); | 334 new base::RefCountedStaticMemory); |
335 callback.Run(resource_bytes); | 335 callback.Run(resource_bytes.get()); |
336 return; | 336 return; |
337 } | 337 } |
338 | 338 |
339 if (!path.empty() && path[0] != '#') { | 339 if (!path.empty() && path[0] != '#') { |
340 // A path under new-tab was requested; it's likely a bad relative | 340 // A path under new-tab was requested; it's likely a bad relative |
341 // URL from the new tab page, but in any case it's an error. | 341 // URL from the new tab page, but in any case it's an error. |
342 | 342 |
343 // TODO(dtrainor): Can remove this #if check once we update the | 343 // TODO(dtrainor): Can remove this #if check once we update the |
344 // accessibility script to no longer try to access urls like | 344 // accessibility script to no longer try to access urls like |
345 // '?2314124523523'. | 345 // '?2314124523523'. |
346 // See http://crbug.com/150252. | 346 // See http://crbug.com/150252. |
347 #if !defined(OS_ANDROID) | 347 #if !defined(OS_ANDROID) |
348 NOTREACHED() << path << " should not have been requested on the NTP"; | 348 NOTREACHED() << path << " should not have been requested on the NTP"; |
349 #endif | 349 #endif |
350 callback.Run(NULL); | 350 callback.Run(NULL); |
351 return; | 351 return; |
352 } | 352 } |
353 | 353 |
354 content::RenderProcessHost* render_host = | 354 content::RenderProcessHost* render_host = |
355 content::RenderProcessHost::FromID(render_process_id); | 355 content::RenderProcessHost::FromID(render_process_id); |
356 bool is_incognito = render_host->GetBrowserContext()->IsOffTheRecord(); | 356 bool is_incognito = render_host->GetBrowserContext()->IsOffTheRecord(); |
357 scoped_refptr<base::RefCountedMemory> html_bytes( | 357 scoped_refptr<base::RefCountedMemory> html_bytes( |
358 NTPResourceCacheFactory::GetForProfile(profile_)-> | 358 NTPResourceCacheFactory::GetForProfile(profile_)-> |
359 GetNewTabHTML(is_incognito)); | 359 GetNewTabHTML(is_incognito)); |
360 | 360 |
361 callback.Run(html_bytes); | 361 callback.Run(html_bytes.get()); |
362 } | 362 } |
363 | 363 |
364 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string& resource) | 364 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string& resource) |
365 const { | 365 const { |
366 std::map<std::string, std::pair<std::string, int> >::const_iterator it = | 366 std::map<std::string, std::pair<std::string, int> >::const_iterator it = |
367 resource_map_.find(resource); | 367 resource_map_.find(resource); |
368 if (it != resource_map_.end()) | 368 if (it != resource_map_.end()) |
369 return it->second.first; | 369 return it->second.first; |
370 return "text/html"; | 370 return "text/html"; |
371 } | 371 } |
372 | 372 |
373 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 373 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
374 return false; | 374 return false; |
375 } | 375 } |
376 | 376 |
377 bool NewTabUI::NewTabHTMLSource::ShouldAddContentSecurityPolicy() const { | 377 bool NewTabUI::NewTabHTMLSource::ShouldAddContentSecurityPolicy() const { |
378 return false; | 378 return false; |
379 } | 379 } |
380 | 380 |
381 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, | 381 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, |
382 const char* mime_type, | 382 const char* mime_type, |
383 int resource_id) { | 383 int resource_id) { |
384 DCHECK(resource); | 384 DCHECK(resource); |
385 DCHECK(mime_type); | 385 DCHECK(mime_type); |
386 resource_map_[std::string(resource)] = | 386 resource_map_[std::string(resource)] = |
387 std::make_pair(std::string(mime_type), resource_id); | 387 std::make_pair(std::string(mime_type), resource_id); |
388 } | 388 } |
389 | 389 |
390 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} | 390 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} |
OLD | NEW |