| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 html_source->AddResource("suggestions_page.js", "application/javascript", | 152 html_source->AddResource("suggestions_page.js", "application/javascript", |
| 153 IDR_SUGGESTIONS_PAGE_JS); | 153 IDR_SUGGESTIONS_PAGE_JS); |
| 154 } | 154 } |
| 155 // ChromeURLDataManager assumes the ownership of the html_source and in some | 155 // ChromeURLDataManager assumes the ownership of the html_source and in some |
| 156 // tests immediately deletes it, so html_source should not be accessed after | 156 // tests immediately deletes it, so html_source should not be accessed after |
| 157 // this call. | 157 // this call. |
| 158 GetProfile()->GetChromeURLDataManager()->AddDataSource(html_source); | 158 GetProfile()->GetChromeURLDataManager()->AddDataSource(html_source); |
| 159 | 159 |
| 160 pref_change_registrar_.Init(GetProfile()->GetPrefs()); | 160 pref_change_registrar_.Init(GetProfile()->GetPrefs()); |
| 161 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); | 161 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
| 162 |
| 163 #if defined(ENABLE_THEMES) |
| 162 // Listen for theme installation. | 164 // Listen for theme installation. |
| 163 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 165 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 164 content::Source<ThemeService>( | 166 content::Source<ThemeService>( |
| 165 ThemeServiceFactory::GetForProfile(GetProfile()))); | 167 ThemeServiceFactory::GetForProfile(GetProfile()))); |
| 168 #endif |
| 166 } | 169 } |
| 167 | 170 |
| 168 NewTabUI::~NewTabUI() { | 171 NewTabUI::~NewTabUI() { |
| 169 g_live_new_tabs.Pointer()->erase(this); | 172 g_live_new_tabs.Pointer()->erase(this); |
| 170 } | 173 } |
| 171 | 174 |
| 172 // The timer callback. If enough time has elapsed since the last paint | 175 // The timer callback. If enough time has elapsed since the last paint |
| 173 // message, we say we're done painting; otherwise, we keep waiting. | 176 // message, we say we're done painting; otherwise, we keep waiting. |
| 174 void NewTabUI::PaintTimeout() { | 177 void NewTabUI::PaintTimeout() { |
| 175 // The amount of time there must be no painting for us to consider painting | 178 // The amount of time there must be no painting for us to consider painting |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 const content::NotificationSource& source, | 226 const content::NotificationSource& source, |
| 224 const content::NotificationDetails& details) { | 227 const content::NotificationDetails& details) { |
| 225 switch (type) { | 228 switch (type) { |
| 226 case chrome::NOTIFICATION_PREF_CHANGED: { // kShowBookmarkBar | 229 case chrome::NOTIFICATION_PREF_CHANGED: { // kShowBookmarkBar |
| 227 StringValue attached( | 230 StringValue attached( |
| 228 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? | 231 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? |
| 229 "true" : "false"); | 232 "true" : "false"); |
| 230 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); | 233 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); |
| 231 break; | 234 break; |
| 232 } | 235 } |
| 236 #if defined(ENABLE_THEMES) |
| 233 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { | 237 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { |
| 234 InitializeCSSCaches(); | 238 InitializeCSSCaches(); |
| 235 StringValue attribution( | 239 StringValue attribution( |
| 236 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( | 240 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( |
| 237 IDR_THEME_NTP_ATTRIBUTION) ? "true" : "false"); | 241 IDR_THEME_NTP_ATTRIBUTION) ? "true" : "false"); |
| 238 web_ui()->CallJavascriptFunction("ntp.themeChanged", attribution); | 242 web_ui()->CallJavascriptFunction("ntp.themeChanged", attribution); |
| 239 break; | 243 break; |
| 240 } | 244 } |
| 245 #endif |
| 241 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: { | 246 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: { |
| 242 last_paint_ = base::TimeTicks::Now(); | 247 last_paint_ = base::TimeTicks::Now(); |
| 243 break; | 248 break; |
| 244 } | 249 } |
| 245 default: | 250 default: |
| 246 CHECK(false) << "Unexpected notification: " << type; | 251 CHECK(false) << "Unexpected notification: " << type; |
| 247 } | 252 } |
| 248 } | 253 } |
| 249 | 254 |
| 250 void NewTabUI::InitializeCSSCaches() { | 255 void NewTabUI::InitializeCSSCaches() { |
| 256 #if defined(ENABLE_THEMES) |
| 251 Profile* profile = GetProfile(); | 257 Profile* profile = GetProfile(); |
| 252 ThemeSource* theme = new ThemeSource(profile); | 258 ThemeSource* theme = new ThemeSource(profile); |
| 253 profile->GetChromeURLDataManager()->AddDataSource(theme); | 259 profile->GetChromeURLDataManager()->AddDataSource(theme); |
| 260 #endif |
| 254 } | 261 } |
| 255 | 262 |
| 256 // static | 263 // static |
| 257 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 264 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
| 258 NewTabPageHandler::RegisterUserPrefs(prefs); | 265 NewTabPageHandler::RegisterUserPrefs(prefs); |
| 259 AppLauncherHandler::RegisterUserPrefs(prefs); | 266 AppLauncherHandler::RegisterUserPrefs(prefs); |
| 260 MostVisitedHandler::RegisterUserPrefs(prefs); | 267 MostVisitedHandler::RegisterUserPrefs(prefs); |
| 261 if (NewTabUI::IsSuggestionsPageEnabled()) | 268 if (NewTabUI::IsSuggestionsPageEnabled()) |
| 262 SuggestionsHandler::RegisterUserPrefs(prefs); | 269 SuggestionsHandler::RegisterUserPrefs(prefs); |
| 263 } | 270 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 } | 414 } |
| 408 | 415 |
| 409 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, | 416 void NewTabUI::NewTabHTMLSource::AddResource(const char* resource, |
| 410 const char* mime_type, | 417 const char* mime_type, |
| 411 int resource_id) { | 418 int resource_id) { |
| 412 DCHECK(resource); | 419 DCHECK(resource); |
| 413 DCHECK(mime_type); | 420 DCHECK(mime_type); |
| 414 resource_map_[std::string(resource)] = | 421 resource_map_[std::string(resource)] = |
| 415 std::make_pair(std::string(mime_type), resource_id); | 422 std::make_pair(std::string(mime_type), resource_id); |
| 416 } | 423 } |
| OLD | NEW |