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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // Initializing the CSS and HTML can require some CPU, so do it after | 128 // Initializing the CSS and HTML can require some CPU, so do it after |
129 // we've hooked up the most visited handler. This allows the DB query | 129 // we've hooked up the most visited handler. This allows the DB query |
130 // for the new tab thumbs to happen earlier. | 130 // for the new tab thumbs to happen earlier. |
131 InitializeCSSCaches(); | 131 InitializeCSSCaches(); |
132 NewTabHTMLSource* html_source = | 132 NewTabHTMLSource* html_source = |
133 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); | 133 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); |
134 GetProfile()->GetChromeURLDataManager()->AddDataSource(html_source); | 134 GetProfile()->GetChromeURLDataManager()->AddDataSource(html_source); |
135 | 135 |
136 pref_change_registrar_.Init(GetProfile()->GetPrefs()); | 136 pref_change_registrar_.Init(GetProfile()->GetPrefs()); |
137 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); | 137 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
138 | |
139 #if !defined(OS_ANDROID) | |
Elliot Glaysher
2012/03/07 23:52:46
Comment about why this is temporary
Ted C
2012/03/08 19:42:08
Done. Comment added. I will also look into creat
| |
138 // Listen for theme installation. | 140 // Listen for theme installation. |
139 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 141 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
140 content::Source<ThemeService>( | 142 content::Source<ThemeService>( |
141 ThemeServiceFactory::GetForProfile(GetProfile()))); | 143 ThemeServiceFactory::GetForProfile(GetProfile()))); |
144 #endif | |
142 } | 145 } |
143 | 146 |
144 NewTabUI::~NewTabUI() { | 147 NewTabUI::~NewTabUI() { |
145 g_live_new_tabs.Pointer()->erase(this); | 148 g_live_new_tabs.Pointer()->erase(this); |
146 } | 149 } |
147 | 150 |
148 // The timer callback. If enough time has elapsed since the last paint | 151 // The timer callback. If enough time has elapsed since the last paint |
149 // message, we say we're done painting; otherwise, we keep waiting. | 152 // message, we say we're done painting; otherwise, we keep waiting. |
150 void NewTabUI::PaintTimeout() { | 153 void NewTabUI::PaintTimeout() { |
151 // The amount of time there must be no painting for us to consider painting | 154 // 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... | |
199 const content::NotificationSource& source, | 202 const content::NotificationSource& source, |
200 const content::NotificationDetails& details) { | 203 const content::NotificationDetails& details) { |
201 switch (type) { | 204 switch (type) { |
202 case chrome::NOTIFICATION_PREF_CHANGED: { // kShowBookmarkBar | 205 case chrome::NOTIFICATION_PREF_CHANGED: { // kShowBookmarkBar |
203 StringValue attached( | 206 StringValue attached( |
204 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? | 207 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? |
205 "true" : "false"); | 208 "true" : "false"); |
206 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); | 209 web_ui()->CallJavascriptFunction("ntp.setBookmarkBarAttached", attached); |
207 break; | 210 break; |
208 } | 211 } |
212 #if !defined(OS_ANDROID) | |
209 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { | 213 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { |
210 InitializeCSSCaches(); | 214 InitializeCSSCaches(); |
211 StringValue attribution( | 215 StringValue attribution( |
212 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( | 216 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( |
213 IDR_THEME_NTP_ATTRIBUTION) ? "true" : "false"); | 217 IDR_THEME_NTP_ATTRIBUTION) ? "true" : "false"); |
214 web_ui()->CallJavascriptFunction("ntp.themeChanged", attribution); | 218 web_ui()->CallJavascriptFunction("ntp.themeChanged", attribution); |
215 break; | 219 break; |
216 } | 220 } |
221 #endif | |
217 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: { | 222 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: { |
218 last_paint_ = base::TimeTicks::Now(); | 223 last_paint_ = base::TimeTicks::Now(); |
219 break; | 224 break; |
220 } | 225 } |
221 default: | 226 default: |
222 CHECK(false) << "Unexpected notification: " << type; | 227 CHECK(false) << "Unexpected notification: " << type; |
223 } | 228 } |
224 } | 229 } |
225 | 230 |
226 void NewTabUI::InitializeCSSCaches() { | 231 void NewTabUI::InitializeCSSCaches() { |
232 #if !defined(OS_ANDROID) | |
227 Profile* profile = GetProfile(); | 233 Profile* profile = GetProfile(); |
228 ThemeSource* theme = new ThemeSource(profile); | 234 ThemeSource* theme = new ThemeSource(profile); |
229 profile->GetChromeURLDataManager()->AddDataSource(theme); | 235 profile->GetChromeURLDataManager()->AddDataSource(theme); |
236 #endif | |
230 } | 237 } |
231 | 238 |
232 // static | 239 // static |
233 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 240 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
234 NewTabPageHandler::RegisterUserPrefs(prefs); | 241 NewTabPageHandler::RegisterUserPrefs(prefs); |
235 AppLauncherHandler::RegisterUserPrefs(prefs); | 242 AppLauncherHandler::RegisterUserPrefs(prefs); |
236 MostVisitedHandler::RegisterUserPrefs(prefs); | 243 MostVisitedHandler::RegisterUserPrefs(prefs); |
237 } | 244 } |
238 | 245 |
239 // static | 246 // static |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 SendResponse(request_id, html_bytes); | 346 SendResponse(request_id, html_bytes); |
340 } | 347 } |
341 | 348 |
342 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 349 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
343 return "text/html"; | 350 return "text/html"; |
344 } | 351 } |
345 | 352 |
346 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 353 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
347 return false; | 354 return false; |
348 } | 355 } |
OLD | NEW |