OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 AddMessageHandler((new MetricsHandler())->Attach(this)); | 90 AddMessageHandler((new MetricsHandler())->Attach(this)); |
91 if (GetProfile()->IsSyncAccessible()) | 91 if (GetProfile()->IsSyncAccessible()) |
92 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); | 92 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); |
93 ExtensionService* service = GetProfile()->GetExtensionService(); | 93 ExtensionService* service = GetProfile()->GetExtensionService(); |
94 // We might not have an ExtensionService (on ChromeOS when not logged in | 94 // We might not have an ExtensionService (on ChromeOS when not logged in |
95 // for example). | 95 // for example). |
96 if (service) | 96 if (service) |
97 AddMessageHandler((new AppLauncherHandler(service))->Attach(this)); | 97 AddMessageHandler((new AppLauncherHandler(service))->Attach(this)); |
98 | 98 |
99 AddMessageHandler((new NewTabPageHandler())->Attach(this)); | 99 AddMessageHandler((new NewTabPageHandler())->Attach(this)); |
100 if (NTP4Enabled()) { | 100 AddMessageHandler((new BookmarksHandler())->Attach(this)); |
101 AddMessageHandler((new BookmarksHandler())->Attach(this)); | 101 AddMessageHandler((new FaviconWebUIHandler())->Attach(this)); |
102 AddMessageHandler((new FaviconWebUIHandler())->Attach(this)); | |
103 } | |
104 } | 102 } |
105 | 103 |
106 if (NTPLoginHandler::ShouldShow(GetProfile())) | 104 if (NTPLoginHandler::ShouldShow(GetProfile())) |
107 AddMessageHandler((new NTPLoginHandler())->Attach(this)); | 105 AddMessageHandler((new NTPLoginHandler())->Attach(this)); |
108 | 106 |
109 // Initializing the CSS and HTML can require some CPU, so do it after | 107 // Initializing the CSS and HTML can require some CPU, so do it after |
110 // we've hooked up the most visited handler. This allows the DB query | 108 // we've hooked up the most visited handler. This allows the DB query |
111 // for the new tab thumbs to happen earlier. | 109 // for the new tab thumbs to happen earlier. |
112 InitializeCSSCaches(); | 110 InitializeCSSCaches(); |
113 NewTabHTMLSource* html_source = | 111 NewTabHTMLSource* html_source = |
114 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); | 112 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); |
115 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 113 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
116 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 114 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
117 | 115 |
118 // Listen for theme installation. | 116 // Listen for theme installation. |
119 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 117 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
120 content::Source<ThemeService>( | 118 content::Source<ThemeService>( |
121 ThemeServiceFactory::GetForProfile(GetProfile()))); | 119 ThemeServiceFactory::GetForProfile(GetProfile()))); |
122 // Listen for bookmark bar visibility changes. | |
123 pref_change_registrar_.Init(GetProfile()->GetPrefs()); | |
124 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); | |
125 } | 120 } |
126 | 121 |
127 NewTabUI::~NewTabUI() { | 122 NewTabUI::~NewTabUI() { |
128 } | 123 } |
129 | 124 |
130 // The timer callback. If enough time has elapsed since the last paint | 125 // The timer callback. If enough time has elapsed since the last paint |
131 // message, we say we're done painting; otherwise, we keep waiting. | 126 // message, we say we're done painting; otherwise, we keep waiting. |
132 void NewTabUI::PaintTimeout() { | 127 void NewTabUI::PaintTimeout() { |
133 // The amount of time there must be no painting for us to consider painting | 128 // The amount of time there must be no painting for us to consider painting |
134 // finished. Observed times are in the ~1200ms range on Windows. | 129 // finished. Observed times are in the ~1200ms range on Windows. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { | 180 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { |
186 InitializeCSSCaches(); | 181 InitializeCSSCaches(); |
187 ListValue args; | 182 ListValue args; |
188 args.Append(Value::CreateStringValue( | 183 args.Append(Value::CreateStringValue( |
189 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( | 184 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( |
190 IDR_THEME_NTP_ATTRIBUTION) ? | 185 IDR_THEME_NTP_ATTRIBUTION) ? |
191 "true" : "false")); | 186 "true" : "false")); |
192 CallJavascriptFunction("themeChanged", args); | 187 CallJavascriptFunction("themeChanged", args); |
193 break; | 188 break; |
194 } | 189 } |
195 case chrome::NOTIFICATION_PREF_CHANGED: { | |
196 const std::string& pref_name = | |
197 *content::Details<std::string>(details).ptr(); | |
198 if (pref_name == prefs::kShowBookmarkBar) { | |
199 if (!NTP4Enabled() && CanShowBookmarkBar()) { | |
200 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) | |
201 CallJavascriptFunction("bookmarkBarAttached"); | |
202 else | |
203 CallJavascriptFunction("bookmarkBarDetached"); | |
Evan Stade
2011/11/30 03:42:20
technically, I think we may need this all for ntp4
Rick Byers
2011/11/30 14:29:34
Ah, ok. Sounds pretty low priority, so I'll commi
| |
204 } | |
205 } else { | |
206 NOTREACHED(); | |
207 } | |
208 break; | |
209 } | |
210 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: { | 190 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: { |
211 last_paint_ = base::TimeTicks::Now(); | 191 last_paint_ = base::TimeTicks::Now(); |
212 break; | 192 break; |
213 } | 193 } |
214 default: | 194 default: |
215 CHECK(false) << "Unexpected notification: " << type; | 195 CHECK(false) << "Unexpected notification: " << type; |
216 } | 196 } |
217 } | 197 } |
218 | 198 |
219 void NewTabUI::InitializeCSSCaches() { | 199 void NewTabUI::InitializeCSSCaches() { |
220 Profile* profile = GetProfile(); | 200 Profile* profile = GetProfile(); |
221 ThemeSource* theme = new ThemeSource(profile); | 201 ThemeSource* theme = new ThemeSource(profile); |
222 profile->GetChromeURLDataManager()->AddDataSource(theme); | 202 profile->GetChromeURLDataManager()->AddDataSource(theme); |
223 } | 203 } |
224 | 204 |
225 // static | 205 // static |
226 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { | 206 void NewTabUI::RegisterUserPrefs(PrefService* prefs) { |
227 NewTabPageHandler::RegisterUserPrefs(prefs); | 207 NewTabPageHandler::RegisterUserPrefs(prefs); |
228 AppLauncherHandler::RegisterUserPrefs(prefs); | 208 AppLauncherHandler::RegisterUserPrefs(prefs); |
229 MostVisitedHandler::RegisterUserPrefs(prefs); | 209 MostVisitedHandler::RegisterUserPrefs(prefs); |
230 if (NTP4Enabled()) | 210 BookmarksHandler::RegisterUserPrefs(prefs); |
231 BookmarksHandler::RegisterUserPrefs(prefs); | |
232 } | 211 } |
233 | 212 |
234 // static | 213 // static |
235 void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, | 214 void NewTabUI::SetURLTitleAndDirection(DictionaryValue* dictionary, |
236 const string16& title, | 215 const string16& title, |
237 const GURL& gurl) { | 216 const GURL& gurl) { |
238 dictionary->SetString("url", gurl.spec()); | 217 dictionary->SetString("url", gurl.spec()); |
239 | 218 |
240 bool using_url_as_the_title = false; | 219 bool using_url_as_the_title = false; |
241 string16 title_to_set(title); | 220 string16 title_to_set(title); |
(...skipping 19 matching lines...) Expand all Loading... | |
261 base::i18n::StringContainsStrongRTLChars(title)) { | 240 base::i18n::StringContainsStrongRTLChars(title)) { |
262 direction = kRTLHtmlTextDirection; | 241 direction = kRTLHtmlTextDirection; |
263 } else { | 242 } else { |
264 direction = kLTRHtmlTextDirection; | 243 direction = kLTRHtmlTextDirection; |
265 } | 244 } |
266 dictionary->SetString("title", title_to_set); | 245 dictionary->SetString("title", title_to_set); |
267 dictionary->SetString("direction", direction); | 246 dictionary->SetString("direction", direction); |
268 } | 247 } |
269 | 248 |
270 // static | 249 // static |
271 bool NewTabUI::NTP4Enabled() { | |
272 #if defined(TOUCH_UI) | |
273 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage); | |
274 #else | |
275 return true; | |
276 #endif | |
277 } | |
278 | |
279 // static | |
280 bool NewTabUI::NTP4BookmarkFeaturesEnabled() { | 250 bool NewTabUI::NTP4BookmarkFeaturesEnabled() { |
281 CommandLine* cl = CommandLine::ForCurrentProcess(); | 251 CommandLine* cl = CommandLine::ForCurrentProcess(); |
282 return NTP4Enabled() && cl->HasSwitch(switches::kEnableNTPBookmarkFeatures); | 252 return cl->HasSwitch(switches::kEnableNTPBookmarkFeatures); |
283 } | 253 } |
284 | 254 |
285 /////////////////////////////////////////////////////////////////////////////// | 255 /////////////////////////////////////////////////////////////////////////////// |
286 // NewTabHTMLSource | 256 // NewTabHTMLSource |
287 | 257 |
288 NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) | 258 NewTabUI::NewTabHTMLSource::NewTabHTMLSource(Profile* profile) |
289 : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()), | 259 : DataSource(chrome::kChromeUINewTabHost, MessageLoop::current()), |
290 profile_(profile) { | 260 profile_(profile) { |
291 } | 261 } |
292 | 262 |
(...skipping 16 matching lines...) Expand all Loading... | |
309 SendResponse(request_id, html_bytes); | 279 SendResponse(request_id, html_bytes); |
310 } | 280 } |
311 | 281 |
312 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 282 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
313 return "text/html"; | 283 return "text/html"; |
314 } | 284 } |
315 | 285 |
316 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 286 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
317 return false; | 287 return false; |
318 } | 288 } |
OLD | NEW |