OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/new_tab_ui.h" | 7 #include "chrome/browser/dom_ui/new_tab_ui.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 dom_ui_->GetProfile()->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, | 296 dom_ui_->GetProfile()->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, |
297 true); | 297 true); |
298 ListValue list_value; | 298 ListValue list_value; |
299 list_value.Append(new StringValue( | 299 list_value.Append(new StringValue( |
300 l10n_util::GetStringUTF16(IDS_NEW_TAB_HOME_PAGE_SET_NOTIFICATION))); | 300 l10n_util::GetStringUTF16(IDS_NEW_TAB_HOME_PAGE_SET_NOTIFICATION))); |
301 list_value.Append(new StringValue( | 301 list_value.Append(new StringValue( |
302 l10n_util::GetStringUTF16(IDS_NEW_TAB_HOME_PAGE_HIDE_NOTIFICATION))); | 302 l10n_util::GetStringUTF16(IDS_NEW_TAB_HOME_PAGE_HIDE_NOTIFICATION))); |
303 dom_ui_->CallJavascriptFunction(L"onHomePageSet", list_value); | 303 dom_ui_->CallJavascriptFunction(L"onHomePageSet", list_value); |
304 } | 304 } |
305 | 305 |
| 306 /////////////////////////////////////////////////////////////////////////////// |
| 307 // NewTabPageClosePromoHandler |
| 308 |
| 309 // Turns off the promo line permanently when it has been explicitly closed by |
| 310 // the user. |
| 311 class NewTabPageClosePromoHandler : public DOMMessageHandler { |
| 312 public: |
| 313 NewTabPageClosePromoHandler() {} |
| 314 virtual ~NewTabPageClosePromoHandler() {} |
| 315 |
| 316 // DOMMessageHandler implementation. |
| 317 virtual void RegisterMessages(); |
| 318 |
| 319 // Callback for "closePromo". |
| 320 void HandleClosePromo(const ListValue* args); |
| 321 |
| 322 private: |
| 323 |
| 324 DISALLOW_COPY_AND_ASSIGN(NewTabPageClosePromoHandler); |
| 325 }; |
| 326 |
| 327 void NewTabPageClosePromoHandler::RegisterMessages() { |
| 328 dom_ui_->RegisterMessageCallback("closePromo", NewCallback( |
| 329 this, &NewTabPageClosePromoHandler::HandleClosePromo)); |
| 330 } |
| 331 |
| 332 void NewTabPageClosePromoHandler::HandleClosePromo( |
| 333 const ListValue* args) { |
| 334 dom_ui_->GetProfile()->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, true); |
| 335 NotificationService* service = NotificationService::current(); |
| 336 service->Notify(NotificationType::WEB_RESOURCE_STATE_CHANGED, |
| 337 Source<NewTabPageClosePromoHandler>(this), |
| 338 NotificationService::NoDetails()); |
| 339 } |
| 340 |
306 } // namespace | 341 } // namespace |
307 | 342 |
308 /////////////////////////////////////////////////////////////////////////////// | 343 /////////////////////////////////////////////////////////////////////////////// |
309 // NewTabUI | 344 // NewTabUI |
310 | 345 |
311 NewTabUI::NewTabUI(TabContents* contents) | 346 NewTabUI::NewTabUI(TabContents* contents) |
312 : DOMUI(contents) { | 347 : DOMUI(contents) { |
313 // Override some options on the DOM UI. | 348 // Override some options on the DOM UI. |
314 hide_favicon_ = true; | 349 hide_favicon_ = true; |
315 force_bookmark_bar_visible_ = true; | 350 force_bookmark_bar_visible_ = true; |
(...skipping 25 matching lines...) Expand all Loading... |
341 AddMessageHandler((new MetricsHandler())->Attach(this)); | 376 AddMessageHandler((new MetricsHandler())->Attach(this)); |
342 if (GetProfile()->IsSyncAccessible()) | 377 if (GetProfile()->IsSyncAccessible()) |
343 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); | 378 AddMessageHandler((new NewTabPageSyncHandler())->Attach(this)); |
344 ExtensionsService* service = GetProfile()->GetExtensionsService(); | 379 ExtensionsService* service = GetProfile()->GetExtensionsService(); |
345 // We might not have an ExtensionsService (on ChromeOS when not logged in | 380 // We might not have an ExtensionsService (on ChromeOS when not logged in |
346 // for example). | 381 // for example). |
347 if (service) | 382 if (service) |
348 AddMessageHandler((new AppLauncherHandler(service))->Attach(this)); | 383 AddMessageHandler((new AppLauncherHandler(service))->Attach(this)); |
349 | 384 |
350 AddMessageHandler((new NewTabPageSetHomePageHandler())->Attach(this)); | 385 AddMessageHandler((new NewTabPageSetHomePageHandler())->Attach(this)); |
| 386 AddMessageHandler((new NewTabPageClosePromoHandler())->Attach(this)); |
351 } | 387 } |
352 | 388 |
353 // Initializing the CSS and HTML can require some CPU, so do it after | 389 // Initializing the CSS and HTML can require some CPU, so do it after |
354 // we've hooked up the most visited handler. This allows the DB query | 390 // we've hooked up the most visited handler. This allows the DB query |
355 // for the new tab thumbs to happen earlier. | 391 // for the new tab thumbs to happen earlier. |
356 InitializeCSSCaches(); | 392 InitializeCSSCaches(); |
357 NewTabHTMLSource* html_source = | 393 NewTabHTMLSource* html_source = |
358 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); | 394 new NewTabHTMLSource(GetProfile()->GetOriginalProfile()); |
359 BrowserThread::PostTask( | 395 BrowserThread::PostTask( |
360 BrowserThread::IO, FROM_HERE, | 396 BrowserThread::IO, FROM_HERE, |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 | 616 |
581 scoped_refptr<RefCountedBytes> html_bytes( | 617 scoped_refptr<RefCountedBytes> html_bytes( |
582 profile_->GetNTPResourceCache()->GetNewTabHTML(is_off_the_record)); | 618 profile_->GetNTPResourceCache()->GetNewTabHTML(is_off_the_record)); |
583 | 619 |
584 SendResponse(request_id, html_bytes); | 620 SendResponse(request_id, html_bytes); |
585 } | 621 } |
586 | 622 |
587 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 623 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
588 return "text/html"; | 624 return "text/html"; |
589 } | 625 } |
OLD | NEW |