diff options
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui_uitest.cc | 19 | ||||
-rw-r--r-- | chrome/browser/dom_ui/ntp_resource_cache.cc | 5 | ||||
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.cc | 32 | ||||
-rw-r--r-- | chrome/browser/dom_ui/tips_handler.h | 7 |
4 files changed, 43 insertions, 20 deletions
diff --git a/chrome/browser/dom_ui/new_tab_ui_uitest.cc b/chrome/browser/dom_ui/new_tab_ui_uitest.cc index 1520b6e..46996d1 100644 --- a/chrome/browser/dom_ui/new_tab_ui_uitest.cc +++ b/chrome/browser/dom_ui/new_tab_ui_uitest.cc @@ -130,16 +130,19 @@ TEST_F(NewTabUITest, HomePageLink) { // TODO(arv): Extract common patterns for doing js testing. - // Fire click + // Fire click. Because tip service is turned off for testing, we first + // force the "make this my home page" tip to appear. // TODO(arv): Find screen position of element and use a lower level click // emulation. bool result; ASSERT_TRUE(tab->ExecuteAndExtractBool(L"", L"window.domAutomationController.send(" L"(function() {" + L" tipCache = [{\"set_homepage_tip\":\"Make this the home page\"}];" + L" renderTip();" L" var e = document.createEvent('Event');" L" e.initEvent('click', true, true);" - L" var el = document.querySelector('#set-as-home-page > *');" + L" var el = document.querySelector('#tip-line > button');" L" el.dispatchEvent(e);" L" return true;" L"})()" @@ -147,17 +150,17 @@ TEST_F(NewTabUITest, HomePageLink) { &result)); ASSERT_TRUE(result); - // Make sure set as home page element is hidden. - std::wstring style_display; + // Make sure text of "set as home page" tip has been removed. + std::wstring tip_text_content; ASSERT_TRUE(tab->ExecuteAndExtractString(L"", L"window.domAutomationController.send(" L"(function() {" - L" var el = document.querySelector('#set-as-home-page');" - L" return el.style.display;" + L" var el = document.querySelector('#tip-line');" + L" return el.textContent;" L"})()" L")", - &style_display)); - ASSERT_EQ(L"none", style_display); + &tip_text_content)); + ASSERT_EQ(L"", tip_text_content); // Make sure that the notification is visible bool has_class; diff --git a/chrome/browser/dom_ui/ntp_resource_cache.cc b/chrome/browser/dom_ui/ntp_resource_cache.cc index 42a2683..8f10ffe 100644 --- a/chrome/browser/dom_ui/ntp_resource_cache.cc +++ b/chrome/browser/dom_ui/ntp_resource_cache.cc @@ -143,7 +143,6 @@ NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { // Watch for pref changes that cause us to need to invalidate the HTML cache. PrefService* pref_service = profile_->GetPrefs(); pref_service->AddPrefObserver(prefs::kShowBookmarkBar, this); - pref_service->AddPrefObserver(prefs::kHomePageIsNewTabPage, this); pref_service->AddPrefObserver(prefs::kNTPShownSections, this); // Watch for pref changes that cause us to need to invalidate the CSS cache. @@ -153,7 +152,6 @@ NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { NTPResourceCache::~NTPResourceCache() { PrefService* pref_service = profile_->GetPrefs(); pref_service->RemovePrefObserver(prefs::kShowBookmarkBar, this); - pref_service->RemovePrefObserver(prefs::kHomePageIsNewTabPage, this); pref_service->RemovePrefObserver(prefs::kNTPShownSections, this); pref_service->RemovePrefObserver(prefs::kNTPPromoLineRemaining, this); @@ -359,9 +357,6 @@ void NTPResourceCache::CreateNewTabHTML() { else localized_strings.SetString(L"syncispresent", "false"); - if (!profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) - localized_strings.SetString(L"showsetashomepage", "true"); - ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); // Control fade and resize animations. diff --git a/chrome/browser/dom_ui/tips_handler.cc b/chrome/browser/dom_ui/tips_handler.cc index ee429f7..7fd5ac1 100644 --- a/chrome/browser/dom_ui/tips_handler.cc +++ b/chrome/browser/dom_ui/tips_handler.cc @@ -4,6 +4,7 @@ #include <string> +#include "app/l10n_util.h" #include "base/string_util.h" #include "base/values.h" #include "chrome/browser/browser_process.h" @@ -14,6 +15,7 @@ #include "chrome/common/web_resource/web_resource_unpacker.h" #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" +#include "grit/generated_resources.h" DOMMessageHandler* TipsHandler::Attach(DOMUI* dom_ui) { dom_ui_ = dom_ui; @@ -28,7 +30,7 @@ void TipsHandler::RegisterMessages() { } void TipsHandler::HandleGetTips(const Value* content) { - // List containing the tips to be displayed. + // List containing the tips to be displayed. ListValue list_value; // Holds the web resource data found in the preferences cache. @@ -58,18 +60,34 @@ void TipsHandler::HandleGetTips(const Value* content) { tips_cache_->GetList( WebResourceService::kTipCachePrefName, &wr_list) && wr_list && wr_list->GetSize() > 0) { - if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) + if (wr_list->GetSize() <= static_cast<size_t>(current_tip_index)) { + // Check to see whether the home page is set to NTP; if not, add tip + // to set home page before resetting tip index to 0. current_tip_index = 0; + if (!dom_ui_->GetProfile()->GetPrefs()->GetBoolean( + prefs::kHomePageIsNewTabPage)) { + SendTip(WideToASCII(l10n_util::GetString( + IDS_NEW_TAB_MAKE_THIS_HOMEPAGE)), L"set_homepage_tip", + current_tip_index); + return; + } + } if (wr_list->GetString(current_tip_index, ¤t_tip)) { - DictionaryValue* tip_dict = new DictionaryValue(); - tip_dict->SetString(L"tip_html_text", current_tip); - list_value.Append(tip_dict); - tips_cache_->SetInteger(WebResourceService::kCurrentTipPrefName, - current_tip_index + 1); + SendTip(current_tip, L"tip_html_text", current_tip_index + 1); } } } +} +void TipsHandler::SendTip(std::string tip, std::wstring tip_type, + int tip_index) { + // List containing the tips to be displayed. + ListValue list_value; + DictionaryValue* tip_dict = new DictionaryValue(); + tip_dict->SetString(tip_type, tip); + list_value.Append(tip_dict); + tips_cache_->SetInteger(WebResourceService::kCurrentTipPrefName, + tip_index); // Send list of web resource items back out to the DOM. dom_ui_->CallJavascriptFunction(L"tips", list_value); } diff --git a/chrome/browser/dom_ui/tips_handler.h b/chrome/browser/dom_ui/tips_handler.h index a5915ec..d85d4d8 100644 --- a/chrome/browser/dom_ui/tips_handler.h +++ b/chrome/browser/dom_ui/tips_handler.h @@ -9,6 +9,8 @@ #ifndef CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ #define CHROME_BROWSER_DOM_UI_TIPS_HANDLER_H_ +#include <string> + #include "chrome/browser/dom_ui/dom_ui.h" class DictionaryValue; @@ -35,6 +37,11 @@ class TipsHandler : public DOMMessageHandler { // Make sure the string we are pushing to the NTP is a valid URL. bool IsValidURL(const std::wstring& url_string); + // Send a tip to the NTP. tip_type is "tip_html_text" if the tip is from + // the tip server, and "set_homepage_tip" if it's the tip to set the NTP + // as home page. + void SendTip(std::string tip, std::wstring tip_type, int tip_index); + // So we can push data out to the page that has called this handler. DOMUI* dom_ui_; |