| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 web_ui->AddMessageHandler(new NTPLoginHandler()); | 126 web_ui->AddMessageHandler(new NTPLoginHandler()); |
| 127 | 127 |
| 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()); |
| 137 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
| 136 // Listen for theme installation. | 138 // Listen for theme installation. |
| 137 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 139 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 138 content::Source<ThemeService>( | 140 content::Source<ThemeService>( |
| 139 ThemeServiceFactory::GetForProfile(GetProfile()))); | 141 ThemeServiceFactory::GetForProfile(GetProfile()))); |
| 140 } | 142 } |
| 141 | 143 |
| 142 NewTabUI::~NewTabUI() { | 144 NewTabUI::~NewTabUI() { |
| 143 g_live_new_tabs.Pointer()->erase(this); | 145 g_live_new_tabs.Pointer()->erase(this); |
| 144 } | 146 } |
| 145 | 147 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 192 } |
| 191 | 193 |
| 192 void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) { | 194 void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) { |
| 193 StartTimingPaint(render_view_host); | 195 StartTimingPaint(render_view_host); |
| 194 } | 196 } |
| 195 | 197 |
| 196 void NewTabUI::Observe(int type, | 198 void NewTabUI::Observe(int type, |
| 197 const content::NotificationSource& source, | 199 const content::NotificationSource& source, |
| 198 const content::NotificationDetails& details) { | 200 const content::NotificationDetails& details) { |
| 199 switch (type) { | 201 switch (type) { |
| 202 case chrome::NOTIFICATION_PREF_CHANGED: { // kShowBookmarkBar |
| 203 StringValue attached( |
| 204 GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? |
| 205 "true" : "false"); |
| 206 web_ui()->CallJavascriptFunction("ntp4.setBookmarkBarAttached", attached); |
| 207 break; |
| 208 } |
| 200 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { | 209 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { |
| 201 InitializeCSSCaches(); | 210 InitializeCSSCaches(); |
| 202 ListValue args; | 211 StringValue attribution( |
| 203 args.Append(Value::CreateStringValue( | |
| 204 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( | 212 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( |
| 205 IDR_THEME_NTP_ATTRIBUTION) ? | 213 IDR_THEME_NTP_ATTRIBUTION) ? "true" : "false"); |
| 206 "true" : "false")); | 214 web_ui()->CallJavascriptFunction("themeChanged", attribution); |
| 207 web_ui()->CallJavascriptFunction("themeChanged", args); | |
| 208 break; | 215 break; |
| 209 } | 216 } |
| 210 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: { | 217 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: { |
| 211 last_paint_ = base::TimeTicks::Now(); | 218 last_paint_ = base::TimeTicks::Now(); |
| 212 break; | 219 break; |
| 213 } | 220 } |
| 214 default: | 221 default: |
| 215 CHECK(false) << "Unexpected notification: " << type; | 222 CHECK(false) << "Unexpected notification: " << type; |
| 216 } | 223 } |
| 217 } | 224 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 237 | 244 |
| 238 // Try to give the user a consistent experience, if possible. | 245 // Try to give the user a consistent experience, if possible. |
| 239 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) | 246 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) |
| 240 trial->UseOneTimeRandomization(); | 247 trial->UseOneTimeRandomization(); |
| 241 | 248 |
| 242 // 4% in each group. | 249 // 4% in each group. |
| 243 g_footer_group = trial->AppendGroup("FooterLink", 40); | 250 g_footer_group = trial->AppendGroup("FooterLink", 40); |
| 244 g_hint_group = trial->AppendGroup("PlusIcon", 40); | 251 g_hint_group = trial->AppendGroup("PlusIcon", 40); |
| 245 } | 252 } |
| 246 | 253 |
| 247 | |
| 248 // static | 254 // static |
| 249 bool NewTabUI::ShouldShowWebStoreFooterLink() { | 255 bool NewTabUI::ShouldShowWebStoreFooterLink() { |
| 250 const CommandLine* cli = CommandLine::ForCurrentProcess(); | 256 const CommandLine* cli = CommandLine::ForCurrentProcess(); |
| 251 return cli->HasSwitch(switches::kEnableWebStoreLink) || | 257 return cli->HasSwitch(switches::kEnableWebStoreLink) || |
| 252 WebStoreLinkExperimentGroupIs(g_footer_group); | 258 WebStoreLinkExperimentGroupIs(g_footer_group); |
| 253 } | 259 } |
| 254 | 260 |
| 255 // static | 261 // static |
| 256 bool NewTabUI::ShouldShowAppInstallHint() { | 262 bool NewTabUI::ShouldShowAppInstallHint() { |
| 257 const CommandLine* cli = CommandLine::ForCurrentProcess(); | 263 const CommandLine* cli = CommandLine::ForCurrentProcess(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 SendResponse(request_id, html_bytes); | 339 SendResponse(request_id, html_bytes); |
| 334 } | 340 } |
| 335 | 341 |
| 336 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 342 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
| 337 return "text/html"; | 343 return "text/html"; |
| 338 } | 344 } |
| 339 | 345 |
| 340 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 346 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
| 341 return false; | 347 return false; |
| 342 } | 348 } |
| OLD | NEW |