diff options
-rw-r--r-- | chrome/app/generated_resources.grd | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 47 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.css | 23 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.html | 7 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.js | 30 |
5 files changed, 110 insertions, 1 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index b4cc79e..eb010ea 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4068,6 +4068,10 @@ each locale. --> desc="Previous link"> previous </message> + <message name="IDS_NEW_TAB_MAKE_THIS_HOMEPAGE" + desc="Text for link that sets new tab page as home page"> + Make this my home page + </message> <!-- SafeBrowsing --> <message name="IDS_SAFE_BROWSING_MALWARE_TITLE" desc="SafeBrowsing Malware HTML title"> diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index e3d2182..1742b0a 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -340,6 +340,8 @@ void NewTabHTMLSource::StartDataRequest(const std::string& path, l10n_util::GetString(IDS_NEW_TAB_FIRST_RUN_NOTIFICATION)); localized_strings.SetString(L"closefirstrunnotification", l10n_util::GetString(IDS_NEW_TAB_CLOSE_FIRST_RUN_NOTIFICATION)); + localized_strings.SetString(L"makethishomepage", + l10n_util::GetString(IDS_NEW_TAB_MAKE_THIS_HOMEPAGE)); // Don't initiate the sync related message passing with the page if the sync // code is not present. @@ -348,6 +350,9 @@ void NewTabHTMLSource::StartDataRequest(const std::string& path, else localized_strings.SetString(L"syncispresent", "false"); + if (!profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) + localized_strings.SetString(L"showsetashomepage", "true"); + SetFontAndTextDirection(&localized_strings); // Let the tab know whether it's the first tab being viewed. @@ -1481,6 +1486,46 @@ void MetricsHandler::HandleMetrics(const Value* content) { } } +/////////////////////////////////////////////////////////////////////////////// +// NewTabPageSetHomepageHandler + +// Sets the new tab page as homepage when user clicks on "make this my homepage" +// link. +class NewTabPageSetHomepageHandler : public DOMMessageHandler { + public: + NewTabPageSetHomepageHandler() {} + virtual ~NewTabPageSetHomepageHandler() {} + + // DOMMessageHandler implementation. + virtual void RegisterMessages(); + + // Callback for "SetHomepageLinkClicked". + void HandleSetHomepageLinkClicked(const Value* value); + + private: + + DISALLOW_COPY_AND_ASSIGN(NewTabPageSetHomepageHandler); +}; + +void NewTabPageSetHomepageHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("SetHomepageLinkClicked", NewCallback( + this, &NewTabPageSetHomepageHandler::HandleSetHomepageLinkClicked)); +} + +void NewTabPageSetHomepageHandler::HandleSetHomepageLinkClicked( + const Value* value) { + dom_ui_->GetProfile()->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, + true); + // TODO(rahulk): Show some kind of notification that new tab page has been + // set as homepage. This tip only shows up for a brief moment and disappears + // when new tab page gets refreshed. + ListValue list_value; + DictionaryValue* tip_dict = new DictionaryValue(); + tip_dict->SetString(L"tip_html_text", L"Welcome to your home page!"); + list_value.Append(tip_dict); + dom_ui_->CallJavascriptFunction(L"tips", list_value); +} + } // namespace /////////////////////////////////////////////////////////////////////////////// @@ -1543,6 +1588,8 @@ NewTabUI::NewTabUI(TabContents* contents) } #endif + AddMessageHandler((new NewTabPageSetHomepageHandler())->Attach(this)); + // In testing mode there may not be an I/O thread. if (g_browser_process->io_thread()) { g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, diff --git a/chrome/browser/resources/new_new_tab.css b/chrome/browser/resources/new_new_tab.css index a2af6fb0..dc653cf 100644 --- a/chrome/browser/resources/new_new_tab.css +++ b/chrome/browser/resources/new_new_tab.css @@ -512,6 +512,29 @@ html[dir='rtl'] .item { margin: 0 10px; } +/* TODO(rahulk): The following two classes control the looks of Make this my +homepage link and need to be refined. */ +#set-as-homepage { + -webkit-transition: height .15s, opacity .15s; + padding: 5px 0; + margin: 10px 0; + white-space: nowrap; + opacity: 0; + overflow-x: hidden; + text-align: center; +} + +#set-as-homepage > * { + display: inline-block; + max-width: none; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + font-size: 100%; + margin: 0 10px; + text-align: center; +} + #view-toolbar { -webkit-user-select: none; text-align: right; diff --git a/chrome/browser/resources/new_new_tab.html b/chrome/browser/resources/new_new_tab.html index 4c1db94..f11bf04 100644 --- a/chrome/browser/resources/new_new_tab.html +++ b/chrome/browser/resources/new_new_tab.html @@ -1,5 +1,5 @@ <!DOCTYPE html> -<html i18n-values="dir:textdirection;firstview:firstview;bookmarkbarattached:bookmarkbarattached;hasattribution:hasattribution;anim:anim;syncispresent:syncispresent"> +<html i18n-values="dir:textdirection;firstview:firstview;bookmarkbarattached:bookmarkbarattached;hasattribution:hasattribution;anim:anim;syncispresent:syncispresent;showsetashomepage:showsetashomepage"> <meta charset="utf-8"> <title i18n-content="title"></title> @@ -225,6 +225,11 @@ document.write('<link id="themecss" rel="stylesheet" ' + <span><a href=""> </a></span> </div> + <div id="set-as-homepage"> + <span> + </span> + </div> + <div id="tip-line"> </div> diff --git a/chrome/browser/resources/new_new_tab.js b/chrome/browser/resources/new_new_tab.js index 7ba8af3..af789d8 100644 --- a/chrome/browser/resources/new_new_tab.js +++ b/chrome/browser/resources/new_new_tab.js @@ -1336,6 +1336,10 @@ document.addEventListener('DOMContentLoaded', bind(logEvent, global, document.addEventListener('DOMContentLoaded', callGetSyncMessageIfSyncIsPresent); +// This link allows user to make new tab page as homepage from the new tab +// page itself (without going to Options dialog box). +document.addEventListener('DOMContentLoaded', showSetAsHomepageLink); + /** * The sync code is not yet built by default on all platforms so we have to * make sure we don't send the initial sync message to the backend unless the @@ -1347,6 +1351,32 @@ function callGetSyncMessageIfSyncIsPresent() { } } +function setAsHomePageLinkClicked() { + chrome.send('SetHomepageLinkClicked'); +} + +function showSetAsHomepageLink() { + var setAsHomepageElement = $('set-as-homepage'); + var style = setAsHomepageElement.style; + if (document.documentElement.getAttribute("showsetashomepage") != "true") { + // Hide the section (if new tab page is already homepage). + style.opacity = style.height = 0; + return; + } + + style.height = ''; + style.opacity = 1; + var spanElement = setAsHomepageElement.firstElementChild; + var linkElement = spanElement.firstElementChild; + if (!linkElement) { + linkElement = document.createElement('a'); + linkElement.href = ''; + linkElement.textContent = localStrings.getString('makethishomepage'); + linkElement.addEventListener('click', setAsHomePageLinkClicked); + spanElement.appendChild(linkElement); + } +} + function hideAllMenus() { optionMenu.hide(); } |