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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 } | 355 } |
356 | 356 |
357 Profile* NewTabUI::GetProfile() const { | 357 Profile* NewTabUI::GetProfile() const { |
358 return Profile::FromWebUI(web_ui()); | 358 return Profile::FromWebUI(web_ui()); |
359 } | 359 } |
360 | 360 |
361 /////////////////////////////////////////////////////////////////////////////// | 361 /////////////////////////////////////////////////////////////////////////////// |
362 // NewTabHTMLSource | 362 // NewTabHTMLSource |
363 | 363 |
364 NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) | 364 NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) |
365 : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()), | 365 : profile_(profile) { |
366 profile_(profile) { | 366 } |
| 367 |
| 368 std::string NewTabUI::NewTabHTMLSource::GetSource() { |
| 369 return chrome::kChromeUINewTabHost; |
367 } | 370 } |
368 | 371 |
369 void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path, | 372 void NewTabUI::NewTabHTMLSource::StartDataRequest(const std::string& path, |
370 bool is_incognito, | 373 bool is_incognito, |
371 int request_id) { | 374 int request_id) { |
372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
373 | 376 |
374 std::map<std::string, std::pair<std::string, int> >::iterator it = | 377 std::map<std::string, std::pair<std::string, int> >::iterator it = |
375 resource_map_.find(path); | 378 resource_map_.find(path); |
376 if (it != resource_map_.end()) { | 379 if (it != resource_map_.end()) { |
377 scoped_refptr<base::RefCountedStaticMemory> resource_bytes( | 380 scoped_refptr<base::RefCountedStaticMemory> resource_bytes( |
378 it->second.second ? | 381 it->second.second ? |
379 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 382 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
380 it->second.second) : | 383 it->second.second) : |
381 new base::RefCountedStaticMemory); | 384 new base::RefCountedStaticMemory); |
382 SendResponse(request_id, resource_bytes); | 385 url_data_source()->SendResponse(request_id, resource_bytes); |
383 return; | 386 return; |
384 } | 387 } |
385 | 388 |
386 if (!path.empty() && path[0] != '#') { | 389 if (!path.empty() && path[0] != '#') { |
387 // A path under new-tab was requested; it's likely a bad relative | 390 // A path under new-tab was requested; it's likely a bad relative |
388 // URL from the new tab page, but in any case it's an error. | 391 // URL from the new tab page, but in any case it's an error. |
389 | 392 |
390 // TODO(dtrainor): Can remove this #if check once we update the | 393 // TODO(dtrainor): Can remove this #if check once we update the |
391 // accessibility script to no longer try to access urls like | 394 // accessibility script to no longer try to access urls like |
392 // '?2314124523523'. | 395 // '?2314124523523'. |
393 // See http://crbug.com/150252. | 396 // See http://crbug.com/150252. |
394 #if !defined(OS_ANDROID) | 397 #if !defined(OS_ANDROID) |
395 NOTREACHED() << path << " should not have been requested on the NTP"; | 398 NOTREACHED() << path << " should not have been requested on the NTP"; |
396 #endif | 399 #endif |
397 return; | 400 return; |
398 } | 401 } |
399 | 402 |
400 scoped_refptr<base::RefCountedMemory> html_bytes( | 403 scoped_refptr<base::RefCountedMemory> html_bytes( |
401 NTPResourceCacheFactory::GetForProfile(profile_)-> | 404 NTPResourceCacheFactory::GetForProfile(profile_)-> |
402 GetNewTabHTML(is_incognito)); | 405 GetNewTabHTML(is_incognito)); |
403 | 406 |
404 SendResponse(request_id, html_bytes); | 407 url_data_source()->SendResponse(request_id, html_bytes); |
405 } | 408 } |
406 | 409 |
407 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string& resource) | 410 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string& resource) |
408 const { | 411 const { |
409 std::map<std::string, std::pair<std::string, int> >::const_iterator it = | 412 std::map<std::string, std::pair<std::string, int> >::const_iterator it = |
410 resource_map_.find(resource); | 413 resource_map_.find(resource); |
411 if (it != resource_map_.end()) | 414 if (it != resource_map_.end()) |
412 return it->second.first; | 415 return it->second.first; |
413 return "text/html"; | 416 return "text/html"; |
414 } | 417 } |
415 | 418 |
416 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 419 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
417 return false; | 420 return false; |
418 } | 421 } |
419 | 422 |
420 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, | 423 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, |
421 const char* mime_type, | 424 const char* mime_type, |
422 int resource_id) { | 425 int resource_id) { |
423 DCHECK(resource); | 426 DCHECK(resource); |
424 DCHECK(mime_type); | 427 DCHECK(mime_type); |
425 resource_map_[std::string(resource)] = | 428 resource_map_[std::string(resource)] = |
426 std::make_pair(std::string(mime_type), resource_id); | 429 std::make_pair(std::string(mime_type), resource_id); |
427 } | 430 } |
428 | 431 |
429 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} | 432 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} |
OLD | NEW |