diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 20:55:01 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-26 20:55:01 +0000 |
commit | 90945981628689f5b121afb3c9dc84f4c69cf6c2 (patch) | |
tree | 60541facb4c6f5b5d07b4a8bc97e7e1880731686 | |
parent | e001d41b9c174084809b80f784811303b1ef04aa (diff) | |
download | chromium_src-90945981628689f5b121afb3c9dc84f4c69cf6c2.zip chromium_src-90945981628689f5b121afb3c9dc84f4c69cf6c2.tar.gz chromium_src-90945981628689f5b121afb3c9dc84f4c69cf6c2.tar.bz2 |
Validates links which are to be passed on to the NTP by ensuring that they start with "http://" or "https://".
BUG= http://crbug.com/15457
TEST= Change cached tip link in preferences file to be invalid. Note that this tip will not be included on the NTP.
Review URL: http://codereview.chromium.org/149083
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19415 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.cc | 15 | ||||
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.h | 7 |
2 files changed, 14 insertions, 8 deletions
diff --git a/chrome/browser/dom_ui/tips_handler.cc b/chrome/browser/dom_ui/tips_handler.cc index 3df6d4a..a8ecd23 100644 --- a/chrome/browser/dom_ui/tips_handler.cc +++ b/chrome/browser/dom_ui/tips_handler.cc @@ -7,13 +7,13 @@ #include "chrome/browser/dom_ui/tips_handler.h" #include "chrome/browser/profile.h" #include "chrome/browser/web_resource/web_resource_service.h" -#include "chrome/common/web_resource/web_resource_unpacker.h" #include "chrome/common/pref_names.h" +#include "chrome/common/web_resource/web_resource_unpacker.h" +#include "chrome/common/url_constants.h" +#include "googleurl/src/gurl.h" namespace { - const int kNumTipsToShow = 2; - // TODO(mrc): l10n // This title should only appear the very first time Chrome is run with // web resources enabled; otherwise the cache should be populated. @@ -52,6 +52,7 @@ void TipsHandler::HandleGetTips(const Value* content) { title = kTipsTitleAtStartup; DictionaryValue* tip_dict = new DictionaryValue(); tip_dict->SetString(WebResourceService::kWebResourceTitle, title); + tip_dict->SetString(WebResourceService::kWebResourceURL, L""); list_value.Append(tip_dict); } else { int tip_counter = 0; @@ -60,7 +61,8 @@ void TipsHandler::HandleGetTips(const Value* content) { if (wr_dict && wr_dict->GetSize() > 0 && wr_dict->GetString(WebResourceService::kWebResourceTitle, &title) && - wr_dict->GetString(WebResourceService::kWebResourceURL, &url)) { + wr_dict->GetString(WebResourceService::kWebResourceURL, &url) && + IsValidURL(url)) { tip_dict->SetString(WebResourceService::kWebResourceTitle, title); tip_dict->SetString(WebResourceService::kWebResourceURL, url); list_value.Append(tip_dict); @@ -79,4 +81,9 @@ void TipsHandler::RegisterUserPrefs(PrefService* prefs) { WebResourceService::kDefaultResourceServer); } +bool TipsHandler::IsValidURL(const std::wstring& url_string) { + GURL url(WideToUTF8(url_string)); + return !url.is_empty() && (url.SchemeIs(chrome::kHttpScheme) || + url.SchemeIs(chrome::kHttpsScheme)); +} diff --git a/chrome/browser/dom_ui/tips_handler.h b/chrome/browser/dom_ui/tips_handler.h index a218e09..7847ba6 100644 --- a/chrome/browser/dom_ui/tips_handler.h +++ b/chrome/browser/dom_ui/tips_handler.h @@ -11,10 +11,6 @@ // "tip_cache": { // "0": { -// "index": should become time field (or not) -// "snippet": the text of the item -// "source": text describing source (i.e., "New York Post") -// "thumbnail": URL of thumbnail on popgadget server // "title": text giving title of item // "url": link to item's page // }, @@ -43,6 +39,9 @@ class TipsHandler : public DOMMessageHandler { static void RegisterUserPrefs(PrefService* prefs); private: + // Make sure the string we are pushing to the NTP is a valid URL. + bool IsValidURL(const std::wstring& url_string); + // So we can push data out to the page that has called this handler. DOMUI* dom_ui_; |