| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/webui/metrics_handler.h" | 14 #include "chrome/browser/ui/webui/metrics_handler.h" |
| 15 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 15 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 16 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" | 16 #include "chrome/browser/ui/webui/ntp/core_app_launcher_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/ntp_resource_cache.h" | 18 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
| 19 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" | 19 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" |
| 20 #include "chrome/browser/ui/webui/theme_handler.h" |
| 20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 21 #include "components/bookmarks/common/bookmark_pref_names.h" | 22 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 22 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
| 23 #include "components/strings/grit/components_strings.h" | 24 #include "components/strings/grit/components_strings.h" |
| 24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/browser/web_ui.h" | 28 #include "content/public/browser/web_ui.h" |
| 28 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 32 | 33 |
| 33 #if defined(ENABLE_THEMES) | |
| 34 #include "chrome/browser/ui/webui/theme_handler.h" | |
| 35 #endif | |
| 36 | |
| 37 using content::BrowserThread; | 34 using content::BrowserThread; |
| 38 using content::WebUIController; | 35 using content::WebUIController; |
| 39 | 36 |
| 40 namespace { | 37 namespace { |
| 41 | 38 |
| 42 // 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 |
| 43 // HTML document based on locale. | 40 // HTML document based on locale. |
| 44 const char kRTLHtmlTextDirection[] = "rtl"; | 41 const char kRTLHtmlTextDirection[] = "rtl"; |
| 45 const char kLTRHtmlTextDirection[] = "ltr"; | 42 const char kLTRHtmlTextDirection[] = "ltr"; |
| 46 | 43 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 web_ui->AddMessageHandler(new CoreAppLauncherHandler()); | 64 web_ui->AddMessageHandler(new CoreAppLauncherHandler()); |
| 68 | 65 |
| 69 ExtensionService* service = | 66 ExtensionService* service = |
| 70 extensions::ExtensionSystem::Get(profile)->extension_service(); | 67 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 71 // We might not have an ExtensionService (on ChromeOS when not logged in | 68 // We might not have an ExtensionService (on ChromeOS when not logged in |
| 72 // for example). | 69 // for example). |
| 73 if (service) | 70 if (service) |
| 74 web_ui->AddMessageHandler(new AppLauncherHandler(service)); | 71 web_ui->AddMessageHandler(new AppLauncherHandler(service)); |
| 75 } | 72 } |
| 76 | 73 |
| 77 #if defined(ENABLE_THEMES) | |
| 78 if (!profile->IsGuestSession()) | 74 if (!profile->IsGuestSession()) |
| 79 web_ui->AddMessageHandler(new ThemeHandler()); | 75 web_ui->AddMessageHandler(new ThemeHandler()); |
| 80 #endif | |
| 81 | 76 |
| 82 std::unique_ptr<NewTabHTMLSource> html_source( | 77 std::unique_ptr<NewTabHTMLSource> html_source( |
| 83 new NewTabHTMLSource(profile->GetOriginalProfile())); | 78 new NewTabHTMLSource(profile->GetOriginalProfile())); |
| 84 | 79 |
| 85 // content::URLDataSource assumes the ownership of the html_source. | 80 // content::URLDataSource assumes the ownership of the html_source. |
| 86 content::URLDataSource::Add(profile, html_source.release()); | 81 content::URLDataSource::Add(profile, html_source.release()); |
| 87 | 82 |
| 88 pref_change_registrar_.Init(profile->GetPrefs()); | 83 pref_change_registrar_.Init(profile->GetPrefs()); |
| 89 pref_change_registrar_.Add(bookmarks::prefs::kShowBookmarkBar, | 84 pref_change_registrar_.Add(bookmarks::prefs::kShowBookmarkBar, |
| 90 base::Bind(&NewTabUI::OnShowBookmarkBarChanged, | 85 base::Bind(&NewTabUI::OnShowBookmarkBarChanged, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, | 251 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, |
| 257 const char* mime_type, | 252 const char* mime_type, |
| 258 int resource_id) { | 253 int resource_id) { |
| 259 DCHECK(resource); | 254 DCHECK(resource); |
| 260 DCHECK(mime_type); | 255 DCHECK(mime_type); |
| 261 resource_map_[std::string(resource)] = | 256 resource_map_[std::string(resource)] = |
| 262 std::make_pair(std::string(mime_type), resource_id); | 257 std::make_pair(std::string(mime_type), resource_id); |
| 263 } | 258 } |
| 264 | 259 |
| 265 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} | 260 NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} |
| OLD | NEW |