| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/string_util.h" | 5 #include "base/string_util.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "chrome/browser/dom_ui/tips_handler.h" | 7 #include "chrome/browser/dom_ui/tips_handler.h" |
| 8 #include "chrome/browser/profile.h" | 8 #include "chrome/browser/profile.h" |
| 9 #include "chrome/browser/web_resource/web_resource_service.h" | 9 #include "chrome/browser/web_resource/web_resource_service.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/common/web_resource/web_resource_unpacker.h" | 11 #include "chrome/common/web_resource/web_resource_unpacker.h" |
| 12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // TODO(mrc): l10n | 17 // TODO(mrc): l10n |
| 18 // This title should only appear the very first time Chrome is run with | 18 // This title should only appear the very first time Chrome is run with |
| 19 // web resources enabled; otherwise the cache should be populated. | 19 // web resources enabled; otherwise the cache should be populated. |
| 20 static const wchar_t* kTipsTitleAtStartup = | 20 static const wchar_t* kTipsTitleAtStartup = |
| 21 L"Tips and recommendations to help you discover interesting websites."; | 21 L"Tips and recommendations to help you discover interesting websites."; |
| 22 } | 22 } |
| 23 | 23 |
| 24 DOMMessageHandler* TipsHandler::Attach(DOMUI* dom_ui) { | 24 DOMMessageHandler* TipsHandler::Attach(DOMUI* dom_ui) { |
| 25 dom_ui_ = dom_ui; |
| 25 tips_cache_ = dom_ui_->GetProfile()->GetPrefs()-> | 26 tips_cache_ = dom_ui_->GetProfile()->GetPrefs()-> |
| 26 GetDictionary(prefs::kNTPTipsCache); | 27 GetDictionary(prefs::kNTPTipsCache); |
| 27 return DOMMessageHandler::Attach(dom_ui); | 28 return DOMMessageHandler::Attach(dom_ui); |
| 28 } | 29 } |
| 29 | 30 |
| 30 void TipsHandler::RegisterMessages() { | 31 void TipsHandler::RegisterMessages() { |
| 31 dom_ui_->RegisterMessageCallback("getTips", | 32 dom_ui_->RegisterMessageCallback("getTips", |
| 32 NewCallback(this, &TipsHandler::HandleGetTips)); | 33 NewCallback(this, &TipsHandler::HandleGetTips)); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void TipsHandler::HandleGetTips(const Value* content) { | 36 void TipsHandler::HandleGetTips(const Value* content) { |
| 36 // List containing the tips to be displayed. | 37 // List containing the tips to be displayed. |
| 37 ListValue list_value; | 38 ListValue list_value; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 prefs->RegisterStringPref(prefs::kNTPTipsServer, | 82 prefs->RegisterStringPref(prefs::kNTPTipsServer, |
| 82 WebResourceService::kDefaultResourceServer); | 83 WebResourceService::kDefaultResourceServer); |
| 83 } | 84 } |
| 84 | 85 |
| 85 bool TipsHandler::IsValidURL(const std::wstring& url_string) { | 86 bool TipsHandler::IsValidURL(const std::wstring& url_string) { |
| 86 GURL url(WideToUTF8(url_string)); | 87 GURL url(WideToUTF8(url_string)); |
| 87 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) || | 88 return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) || |
| 88 url.SchemeIs(chrome::kHttpsScheme)); | 89 url.SchemeIs(chrome::kHttpsScheme)); |
| 89 } | 90 } |
| 90 | 91 |
| OLD | NEW |