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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/webui/metrics_handler.h" | 16 #include "chrome/browser/ui/webui/metrics_handler.h" |
17 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" | 17 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" |
18 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" | 18 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h" |
19 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" | 19 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" |
20 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" | 20 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
21 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" | 21 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" |
22 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" | 22 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" |
23 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
26 #include "components/user_prefs/pref_registry_syncable.h" | 26 #include "components/user_prefs/pref_registry_syncable.h" |
27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 29 #include "content/public/browser/render_process_host.h" |
29 #include "content/public/browser/render_view_host.h" | 30 #include "content/public/browser/render_view_host.h" |
30 #include "content/public/browser/url_data_source.h" | 31 #include "content/public/browser/url_data_source.h" |
31 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
32 #include "content/public/browser/web_ui.h" | 33 #include "content/public/browser/web_ui.h" |
33 #include "grit/browser_resources.h" | 34 #include "grit/browser_resources.h" |
34 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
35 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
36 | 37 |
37 #if !defined(OS_ANDROID) | 38 #if !defined(OS_ANDROID) |
38 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 39 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) | 312 NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) |
312 : profile_(profile) { | 313 : profile_(profile) { |
313 } | 314 } |
314 | 315 |
315 std::string NewTabUI::NewTabHTMLSource::GetSource() const { | 316 std::string NewTabUI::NewTabHTMLSource::GetSource() const { |
316 return chrome::kChromeUINewTabHost; | 317 return chrome::kChromeUINewTabHost; |
317 } | 318 } |
318 | 319 |
319 void NewTabUI::NewTabHTMLSource::StartDataRequest( | 320 void NewTabUI::NewTabHTMLSource::StartDataRequest( |
320 const std::string& path, | 321 const std::string& path, |
321 bool is_incognito, | 322 int render_process_id, |
| 323 int render_view_id, |
322 const content::URLDataSource::GotDataCallback& callback) { | 324 const content::URLDataSource::GotDataCallback& callback) { |
323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
324 | 326 |
325 std::map<std::string, std::pair<std::string, int> >::iterator it = | 327 std::map<std::string, std::pair<std::string, int> >::iterator it = |
326 resource_map_.find(path); | 328 resource_map_.find(path); |
327 if (it != resource_map_.end()) { | 329 if (it != resource_map_.end()) { |
328 scoped_refptr<base::RefCountedStaticMemory> resource_bytes( | 330 scoped_refptr<base::RefCountedStaticMemory> resource_bytes( |
329 it->second.second ? | 331 it->second.second ? |
330 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 332 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
331 it->second.second) : | 333 it->second.second) : |
332 new base::RefCountedStaticMemory); | 334 new base::RefCountedStaticMemory); |
333 callback.Run(resource_bytes); | 335 callback.Run(resource_bytes); |
334 return; | 336 return; |
335 } | 337 } |
336 | 338 |
337 if (!path.empty() && path[0] != '#') { | 339 if (!path.empty() && path[0] != '#') { |
338 // 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 |
339 // 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. |
340 | 342 |
341 // TODO(dtrainor): Can remove this #if check once we update the | 343 // TODO(dtrainor): Can remove this #if check once we update the |
342 // accessibility script to no longer try to access urls like | 344 // accessibility script to no longer try to access urls like |
343 // '?2314124523523'. | 345 // '?2314124523523'. |
344 // See http://crbug.com/150252. | 346 // See http://crbug.com/150252. |
345 #if !defined(OS_ANDROID) | 347 #if !defined(OS_ANDROID) |
346 NOTREACHED() << path << " should not have been requested on the NTP"; | 348 NOTREACHED() << path << " should not have been requested on the NTP"; |
347 #endif | 349 #endif |
| 350 callback.Run(NULL); |
348 return; | 351 return; |
349 } | 352 } |
350 | 353 |
| 354 content::RenderProcessHost* render_host = |
| 355 content::RenderProcessHost::FromID(render_process_id); |
| 356 bool is_incognito = render_host->GetBrowserContext()->IsOffTheRecord(); |
351 scoped_refptr<base::RefCountedMemory> html_bytes( | 357 scoped_refptr<base::RefCountedMemory> html_bytes( |
352 NTPResourceCacheFactory::GetForProfile(profile_)-> | 358 NTPResourceCacheFactory::GetForProfile(profile_)-> |
353 GetNewTabHTML(is_incognito)); | 359 GetNewTabHTML(is_incognito)); |
354 | 360 |
355 callback.Run(html_bytes); | 361 callback.Run(html_bytes); |
356 } | 362 } |
357 | 363 |
358 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string& resource) | 364 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string& resource) |
359 const { | 365 const { |
360 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 = |
(...skipping 14 matching lines...) Expand all Loading... |
375 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, | 381 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, |
376 const char* mime_type, | 382 const char* mime_type, |
377 int resource_id) { | 383 int resource_id) { |
378 DCHECK(resource); | 384 DCHECK(resource); |
379 DCHECK(mime_type); | 385 DCHECK(mime_type); |
380 resource_map_[std::string(resource)] = | 386 resource_map_[std::string(resource)] = |
381 std::make_pair(std::string(mime_type), resource_id); | 387 std::make_pair(std::string(mime_type), resource_id); |
382 } | 388 } |
383 | 389 |
384 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} | 390 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} |
OLD | NEW |