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 <set> | |
10 | |
11 #include "base/bind.h" | 9 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 11 #include "base/command_line.h" |
14 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
15 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
16 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
17 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
18 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
19 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
20 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } // namespace | 186 } // namespace |
189 | 187 |
190 /////////////////////////////////////////////////////////////////////////////// | 188 /////////////////////////////////////////////////////////////////////////////// |
191 // NewTabUI | 189 // NewTabUI |
192 | 190 |
193 NewTabUI::NewTabUI(TabContents* contents) | 191 NewTabUI::NewTabUI(TabContents* contents) |
194 : ChromeWebUI(contents) { | 192 : ChromeWebUI(contents) { |
195 // Override some options on the Web UI. | 193 // Override some options on the Web UI. |
196 hide_favicon_ = true; | 194 hide_favicon_ = true; |
197 | 195 |
198 if (!NTP4BookmarkFeaturesEnabled() && | |
199 GetProfile()->GetPrefs()->GetBoolean(prefs::kEnableBookmarkBar) && | |
200 browser_defaults::bookmarks_enabled) { | |
201 set_force_bookmark_bar_visible(true); | |
202 } | |
203 | |
204 focus_location_bar_by_default_ = true; | 196 focus_location_bar_by_default_ = true; |
205 should_hide_url_ = true; | 197 should_hide_url_ = true; |
206 overridden_title_ = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); | 198 overridden_title_ = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
207 | 199 |
208 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more | 200 // We count all link clicks as AUTO_BOOKMARK, so that site can be ranked more |
209 // highly. Note this means we're including clicks on not only most visited | 201 // highly. Note this means we're including clicks on not only most visited |
210 // thumbnails, but also clicks on recently bookmarked. | 202 // thumbnails, but also clicks on recently bookmarked. |
211 link_transition_type_ = PageTransition::AUTO_BOOKMARK; | 203 link_transition_type_ = PageTransition::AUTO_BOOKMARK; |
212 | 204 |
213 if (!GetProfile()->IsOffTheRecord()) { | 205 if (!GetProfile()->IsOffTheRecord()) { |
(...skipping 29 matching lines...) Expand all Loading... |
243 NewTabHTMLSource* html_source = | 235 NewTabHTMLSource* html_source = |
244 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); | 236 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); |
245 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 237 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
246 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 238 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
247 | 239 |
248 // Listen for theme installation. | 240 // Listen for theme installation. |
249 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 241 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
250 Source<ThemeService>( | 242 Source<ThemeService>( |
251 ThemeServiceFactory::GetForProfile(GetProfile()))); | 243 ThemeServiceFactory::GetForProfile(GetProfile()))); |
252 // Listen for bookmark bar visibility changes. | 244 // Listen for bookmark bar visibility changes. |
253 registrar_.Add(this, | 245 pref_change_registrar_.Init(GetProfile()->GetPrefs()); |
254 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 246 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
255 NotificationService::AllSources()); | |
256 } | 247 } |
257 | 248 |
258 NewTabUI::~NewTabUI() { | 249 NewTabUI::~NewTabUI() { |
259 } | 250 } |
260 | 251 |
261 // The timer callback. If enough time has elapsed since the last paint | 252 // The timer callback. If enough time has elapsed since the last paint |
262 // message, we say we're done painting; otherwise, we keep waiting. | 253 // message, we say we're done painting; otherwise, we keep waiting. |
263 void NewTabUI::PaintTimeout() { | 254 void NewTabUI::PaintTimeout() { |
264 // The amount of time there must be no painting for us to consider painting | 255 // The amount of time there must be no painting for us to consider painting |
265 // finished. Observed times are in the ~1200ms range on Windows. | 256 // finished. Observed times are in the ~1200ms range on Windows. |
(...skipping 26 matching lines...) Expand all Loading... |
292 | 283 |
293 } | 284 } |
294 void NewTabUI::RenderViewCreated(RenderViewHost* render_view_host) { | 285 void NewTabUI::RenderViewCreated(RenderViewHost* render_view_host) { |
295 StartTimingPaint(render_view_host); | 286 StartTimingPaint(render_view_host); |
296 } | 287 } |
297 | 288 |
298 void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) { | 289 void NewTabUI::RenderViewReused(RenderViewHost* render_view_host) { |
299 StartTimingPaint(render_view_host); | 290 StartTimingPaint(render_view_host); |
300 } | 291 } |
301 | 292 |
| 293 bool NewTabUI::CanShowBookmarkBar() const { |
| 294 PrefService* prefs = GetProfile()->GetPrefs(); |
| 295 bool disabled_by_policy = |
| 296 prefs->IsManagedPreference(prefs::kShowBookmarkBar) && |
| 297 !prefs->GetBoolean(prefs::kShowBookmarkBar); |
| 298 return |
| 299 browser_defaults::bookmarks_enabled && |
| 300 !disabled_by_policy && |
| 301 !NTP4BookmarkFeaturesEnabled(); |
| 302 } |
| 303 |
302 void NewTabUI::Observe(int type, | 304 void NewTabUI::Observe(int type, |
303 const NotificationSource& source, | 305 const NotificationSource& source, |
304 const NotificationDetails& details) { | 306 const NotificationDetails& details) { |
305 switch (type) { | 307 switch (type) { |
306 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { | 308 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { |
307 InitializeCSSCaches(); | 309 InitializeCSSCaches(); |
308 ListValue args; | 310 ListValue args; |
309 args.Append(Value::CreateStringValue( | 311 args.Append(Value::CreateStringValue( |
310 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( | 312 ThemeServiceFactory::GetForProfile(GetProfile())->HasCustomImage( |
311 IDR_THEME_NTP_ATTRIBUTION) ? | 313 IDR_THEME_NTP_ATTRIBUTION) ? |
312 "true" : "false")); | 314 "true" : "false")); |
313 CallJavascriptFunction("themeChanged", args); | 315 CallJavascriptFunction("themeChanged", args); |
314 break; | 316 break; |
315 } | 317 } |
316 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: { | 318 case chrome::NOTIFICATION_PREF_CHANGED: { |
317 if (GetProfile()->GetPrefs()->IsManagedPreference( | 319 const std::string& pref_name = *Details<std::string>(details).ptr(); |
318 prefs::kEnableBookmarkBar)) { | 320 if (pref_name == prefs::kShowBookmarkBar) { |
319 break; | 321 if (!NTP4Enabled() && CanShowBookmarkBar()) { |
320 } | 322 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) |
321 if (!NTP4Enabled()) { | 323 CallJavascriptFunction("bookmarkBarAttached"); |
322 if (GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)) | 324 else |
323 CallJavascriptFunction("bookmarkBarAttached"); | 325 CallJavascriptFunction("bookmarkBarDetached"); |
324 else | 326 } |
325 CallJavascriptFunction("bookmarkBarDetached"); | 327 } else { |
| 328 NOTREACHED(); |
326 } | 329 } |
327 break; | 330 break; |
328 } | 331 } |
329 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: { | 332 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT: { |
330 last_paint_ = base::TimeTicks::Now(); | 333 last_paint_ = base::TimeTicks::Now(); |
331 break; | 334 break; |
332 } | 335 } |
333 default: | 336 default: |
334 CHECK(false) << "Unexpected notification: " << type; | 337 CHECK(false) << "Unexpected notification: " << type; |
335 } | 338 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 SendResponse(request_id, html_bytes); | 458 SendResponse(request_id, html_bytes); |
456 } | 459 } |
457 | 460 |
458 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 461 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
459 return "text/html"; | 462 return "text/html"; |
460 } | 463 } |
461 | 464 |
462 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 465 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
463 return false; | 466 return false; |
464 } | 467 } |
OLD | NEW |