summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorcsilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-06 23:03:50 +0000
committercsilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-06 23:03:50 +0000
commit0b37b8bd4d05a07ff9e44eb72758f693295c0a97 (patch)
tree97b457d820b121abc8210d63ab9a69ed7236b175 /chrome
parent0b8ee920f975c430ecbbd8c4dfa689e433675dd3 (diff)
downloadchromium_src-0b37b8bd4d05a07ff9e44eb72758f693295c0a97.zip
chromium_src-0b37b8bd4d05a07ff9e44eb72758f693295c0a97.tar.gz
chromium_src-0b37b8bd4d05a07ff9e44eb72758f693295c0a97.tar.bz2
[ntp4] Persist app page names in preferences.
Persist app page names in the preferencs file after a user makes an edit. Also remove pageName from tile pages, its obsolete. TODO: Perform necessary steps to get this data synced with the 'apps' sync type. Review URL: http://codereview.chromium.org/7236007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91640 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/resources/ntp4/apps_page.js5
-rw-r--r--chrome/browser/resources/ntp4/most_visited_page.js5
-rw-r--r--chrome/browser/resources/ntp4/nav_dot.js15
-rw-r--r--chrome/browser/resources/ntp4/new_tab.js38
-rw-r--r--chrome/browser/resources/ntp4/tile_page.css7
-rw-r--r--chrome/browser/resources/ntp4/tile_page.js9
-rw-r--r--chrome/browser/ui/webui/ntp/app_launcher_handler.cc46
-rw-r--r--chrome/browser/ui/webui/ntp/app_launcher_handler.h7
-rw-r--r--chrome/browser/ui/webui/ntp/new_tab_ui.cc1
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/common/pref_names.h1
11 files changed, 97 insertions, 40 deletions
diff --git a/chrome/browser/resources/ntp4/apps_page.js b/chrome/browser/resources/ntp4/apps_page.js
index 097b4b1..4e08d3a 100644
--- a/chrome/browser/resources/ntp4/apps_page.js
+++ b/chrome/browser/resources/ntp4/apps_page.js
@@ -315,12 +315,11 @@ cr.define('ntp4', function() {
/**
* Creates a new AppsPage object.
- * @param {string} name The display name for the page.
* @constructor
* @extends {TilePage}
*/
- function AppsPage(name) {
- var el = new TilePage(name, appsPageGridValues);
+ function AppsPage() {
+ var el = new TilePage(appsPageGridValues);
el.__proto__ = AppsPage.prototype;
el.initialize();
diff --git a/chrome/browser/resources/ntp4/most_visited_page.js b/chrome/browser/resources/ntp4/most_visited_page.js
index 89495ef..8c4b570 100644
--- a/chrome/browser/resources/ntp4/most_visited_page.js
+++ b/chrome/browser/resources/ntp4/most_visited_page.js
@@ -264,12 +264,11 @@ cr.define('ntp4', function() {
/**
* Creates a new MostVisitedPage object.
- * @param {string} name The display name for the page.
* @constructor
* @extends {TilePage}
*/
- function MostVisitedPage(name) {
- var el = new TilePage(name, mostVisitedPageGridValues);
+ function MostVisitedPage() {
+ var el = new TilePage(mostVisitedPageGridValues);
el.__proto__ = MostVisitedPage.prototype;
el.initialize();
diff --git a/chrome/browser/resources/ntp4/nav_dot.js b/chrome/browser/resources/ntp4/nav_dot.js
index 100940d..30000f6 100644
--- a/chrome/browser/resources/ntp4/nav_dot.js
+++ b/chrome/browser/resources/ntp4/nav_dot.js
@@ -14,14 +14,15 @@ cr.define('ntp4', function() {
/**
* Creates a new navigation dot.
* @param {TilePage} page The associated TilePage.
+ * @param {string} title The title of the navigation dot.
* @param {bool} animate If true, animates into existence.
* @constructor
* @extends {HTMLLIElement}
*/
- function NavDot(page, animate) {
+ function NavDot(page, title, animate) {
var dot = cr.doc.createElement('li');
dot.__proto__ = NavDot.prototype;
- dot.initialize(page, animate);
+ dot.initialize(page, title, animate);
return dot;
}
@@ -29,17 +30,18 @@ cr.define('ntp4', function() {
NavDot.prototype = {
__proto__: HTMLLIElement.prototype,
- initialize: function(page, animate) {
+ initialize: function(page, title, animate) {
this.className = 'dot';
this.setAttribute('tabindex', 0);
this.setAttribute('role', 'button');
this.page_ = page;
+ this.title_ = title;
// TODO(estade): should there be some limit to the number of characters?
this.input_ = this.ownerDocument.createElement('input');
this.input_.setAttribute('spellcheck', false);
- this.input_.value = page.pageName;
+ this.input_.value = title;
this.appendChild(this.input_);
this.addEventListener('click', this.onClick_);
@@ -118,7 +120,7 @@ cr.define('ntp4', function() {
onInputKeyDown_: function(e) {
switch (e.keyIdentifier) {
case 'U+001B': // Escape cancels edits.
- this.input_.value = this.page_.pageName;
+ this.input_.value = this.title_;
case 'Enter': // Fall through.
this.input_.blur();
break;
@@ -132,7 +134,8 @@ cr.define('ntp4', function() {
*/
onInputBlur_: function(e) {
window.getSelection().removeAllRanges();
- // TODO(estade): persist changes to textContent.
+ this.title_ = this.input_.value;
+ ntp4.saveAppPageName(this.page_, this.title_);
},
/**
diff --git a/chrome/browser/resources/ntp4/new_tab.js b/chrome/browser/resources/ntp4/new_tab.js
index e01b348..922e3b2 100644
--- a/chrome/browser/resources/ntp4/new_tab.js
+++ b/chrome/browser/resources/ntp4/new_tab.js
@@ -148,8 +148,8 @@ cr.define('ntp4', function() {
cr.ui.decorate($('recently-closed-menu-button'), ntp4.RecentMenuButton);
chrome.send('getRecentlyClosedTabs');
- mostVisitedPage = new ntp4.MostVisitedPage('Most Visited');
- appendTilePage(mostVisitedPage);
+ mostVisitedPage = new ntp4.MostVisitedPage();
+ appendTilePage(mostVisitedPage, 'Most Visited');
chrome.send('getMostVisited');
}
@@ -211,6 +211,9 @@ cr.define('ntp4', function() {
// Get the array of apps and add any special synthesized entries
var apps = data.apps;
+ // Get a list of page names
+ var pageNames = data.appPageNames;
+
// Sort by launch index
apps.sort(function(a, b) {
return a.app_launch_index - b.app_launch_index;
@@ -221,8 +224,12 @@ cr.define('ntp4', function() {
var app = apps[i];
var pageIndex = (app.page_index || 0);
while (pageIndex >= appsPages.length) {
+ var pageName = '';
+ if (pageNames && appsPages.length < pageNames.length)
+ pageName = pageNames[appsPages.length];
+
var origPageCount = appsPages.length;
- appendTilePage(new ntp4.AppsPage('Apps'));
+ appendTilePage(new ntp4.AppsPage(), pageName);
// Confirm that appsPages is a live object, updated when a new page is
// added (otherwise we'd have an infinite loop)
assert(appsPages.length == origPageCount + 1, 'expected new page');
@@ -333,15 +340,14 @@ cr.define('ntp4', function() {
* Appends a tile page (for apps or most visited).
*
* @param {TilePage} page The page element.
- * @param {boolean=} opt_animate If true, add the class 'new' to the created
- * dot.
+ * @param {string} title The title of the tile page.
*/
- function appendTilePage(page) {
+ function appendTilePage(page, title) {
pageList.appendChild(page);
// Make a deep copy of the dot template to add a new one.
var animate = page.classList.contains('temporary');
- var newDot = new ntp4.NavDot(page, animate);
+ var newDot = new ntp4.NavDot(page, title, animate);
dotList.appendChild(newDot);
page.navigationDot = newDot;
@@ -369,9 +375,9 @@ cr.define('ntp4', function() {
* @param {Grabber.Event} e The Grabber Grab event.
*/
function enterRearrangeMode(e) {
- var tempPage = new ntp4.AppsPage('');
+ var tempPage = new ntp4.AppsPage();
tempPage.classList.add('temporary');
- appendTilePage(tempPage);
+ appendTilePage(tempPage, '');
updateSliderCards();
}
@@ -387,6 +393,7 @@ cr.define('ntp4', function() {
tempPage.parentNode.removeChild(tempPage);
} else {
tempPage.classList.remove('temporary');
+ saveAppPageName(tempPage, '');
}
}
@@ -539,6 +546,18 @@ cr.define('ntp4', function() {
mostVisitedPage.data = data;
}
+ /*
+ * Save the name of an app page.
+ * Store the app page name into the preferences store.
+ * @param {AppsPage} appPage The app page for which we wish to save.
+ * @param {string} name The name of the page.
+ */
+ function saveAppPageName(appPage, name) {
+ var index = getAppsPageIndex(appPage);
+ assert(index != -1);
+ chrome.send('saveAppPageName', [name, index]);
+ }
+
// Return an object with all the exports
return {
assert: assert,
@@ -555,6 +574,7 @@ cr.define('ntp4', function() {
setRecentlyClosedTabs: setRecentlyClosedTabs,
setMostVisitedPages: setMostVisitedPages,
showNotification: showNotification,
+ saveAppPageName: saveAppPageName
};
});
diff --git a/chrome/browser/resources/ntp4/tile_page.css b/chrome/browser/resources/ntp4/tile_page.css
index 38a0544..8d4bb48 100644
--- a/chrome/browser/resources/ntp4/tile_page.css
+++ b/chrome/browser/resources/ntp4/tile_page.css
@@ -38,13 +38,6 @@
-webkit-mask-clip: content-box;
}
-.tile-page-title {
- /* TODO(estade): title is hidden for now. We may remove it later. */
- display: none;
- font-size: 25px;
- height: 50px;
-}
-
.tile-grid {
overflow: hidden;
position: relative;
diff --git a/chrome/browser/resources/ntp4/tile_page.js b/chrome/browser/resources/ntp4/tile_page.js
index dbea9be..1374a41 100644
--- a/chrome/browser/resources/ntp4/tile_page.js
+++ b/chrome/browser/resources/ntp4/tile_page.js
@@ -302,15 +302,13 @@ cr.define('ntp4', function() {
/**
* Creates a new TilePage object. This object contains tiles and controls
* their layout.
- * @param {string} name The display name for the page.
* @param {Object} gridValues Pixel values that define the size and layout
* of the tile grid.
* @constructor
* @extends {HTMLDivElement}
*/
- function TilePage(name, gridValues) {
+ function TilePage(gridValues) {
var el = cr.doc.createElement('div');
- el.pageName = name;
el.gridValues_ = gridValues;
el.__proto__ = TilePage.prototype;
el.initialize();
@@ -364,11 +362,6 @@ cr.define('ntp4', function() {
this.content_.className = 'tile-page-content';
this.appendChild(this.content_);
- var title = this.ownerDocument.createElement('span');
- title.textContent = this.pageName;
- title.className = 'tile-page-title';
- this.content_.appendChild(title);
-
// Div that sets the vertical position of the tile grid.
this.topMargin_ = this.ownerDocument.createElement('div');
this.topMargin_.className = 'top-margin';
diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
index 5c80d1d..b975be9 100644
--- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
+++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
@@ -19,6 +19,8 @@
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/platform_util.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
@@ -30,6 +32,7 @@
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_icon_set.h"
#include "chrome/common/extensions/extension_resource.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "content/browser/disposition_utils.h"
#include "content/browser/tab_contents/tab_contents.h"
@@ -207,6 +210,8 @@ void AppLauncherHandler::RegisterMessages() {
NewCallback(this, &AppLauncherHandler::HandleSetPageIndex));
web_ui_->RegisterMessageCallback("promoSeen",
NewCallback(this, &AppLauncherHandler::HandlePromoSeen));
+ web_ui_->RegisterMessageCallback("saveAppPageName",
+ NewCallback(this, &AppLauncherHandler::HandleSaveAppPageName));
}
void AppLauncherHandler::Observe(NotificationType type,
@@ -258,10 +263,16 @@ void AppLauncherHandler::Observe(NotificationType type,
case NotificationType::PREF_CHANGED: {
if (!web_ui_->tab_contents())
break;
-
- DictionaryValue dictionary;
- FillAppDictionary(&dictionary);
- web_ui_->CallJavascriptFunction("appsPrefChangeCallback", dictionary);
+ // Handle app page renames.
+ std::string* pref_name = Details<std::string>(details).ptr();
+ if (*pref_name == prefs::kNTPAppPageNames) {
+ HandleGetApps(NULL);
+ } else {
+ // Default prefs change handling.
+ DictionaryValue dictionary;
+ FillAppDictionary(&dictionary);
+ web_ui_->CallJavascriptFunction("appsPrefChangeCallback", dictionary);
+ }
break;
}
default:
@@ -315,6 +326,13 @@ void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) {
"showLauncher",
extensions_service_->apps_promo()->ShouldShowAppLauncher(
extensions_service_->GetAppIds()));
+
+ PrefService* prefs = web_ui_->GetProfile()->GetPrefs();
+ const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames);
+ if (app_page_names && app_page_names->GetSize()) {
+ dictionary->Set("appPageNames",
+ static_cast<ListValue*>(app_page_names->DeepCopy()));
+ }
}
DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) {
@@ -396,6 +414,7 @@ void AppLauncherHandler::HandleGetApps(const ListValue* args) {
pref_change_registrar_.Init(
extensions_service_->extension_prefs()->pref_service());
pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this);
+ pref_change_registrar_.Add(prefs::kNTPAppPageNames, this);
}
}
@@ -588,6 +607,25 @@ void AppLauncherHandler::HandlePromoSeen(const ListValue* args) {
extension_misc::PROMO_BUCKET_BOUNDARY);
}
+void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) {
+ string16 name;
+ CHECK(args->GetString(0, &name));
+
+ double page_index;
+ CHECK(args->GetDouble(1, &page_index));
+
+ AutoReset<bool> auto_reset(&ignore_changes_, true);
+ PrefService* prefs = web_ui_->GetProfile()->GetPrefs();
+ ListPrefUpdate update(prefs, prefs::kNTPAppPageNames);
+ ListValue* list = update.Get();
+ list->Set(static_cast<size_t>(page_index), Value::CreateStringValue(name));
+}
+
+// static
+void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) {
+ pref_service->RegisterListPref(prefs::kNTPAppPageNames);
+}
+
// static
void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) {
UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram,
diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.h b/chrome/browser/ui/webui/ntp/app_launcher_handler.h
index fe37c87..10d2d86 100644
--- a/chrome/browser/ui/webui/ntp/app_launcher_handler.h
+++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.h
@@ -21,6 +21,7 @@ class ExtensionPrefs;
class ExtensionService;
class NotificationRegistrar;
class PrefChangeRegistrar;
+class PrefsService;
class Profile;
namespace gfx {
@@ -92,6 +93,12 @@ class AppLauncherHandler : public WebUIMessageHandler,
// Callback for the "promoSeen" message.
void HandlePromoSeen(const ListValue* args);
+ // Callback for the "saveAppPageName" message.
+ void HandleSaveAppPageName(const ListValue* args);
+
+ // Register app launcher preferences.
+ static void RegisterUserPrefs(PrefService* pref_service);
+
private:
// Records a web store launch in the appropriate histograms. |promo_active|
// specifies if the web store promotion was active.
diff --git a/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chrome/browser/ui/webui/ntp/new_tab_ui.cc
index 8eb4fbf..945471a 100644
--- a/chrome/browser/ui/webui/ntp/new_tab_ui.cc
+++ b/chrome/browser/ui/webui/ntp/new_tab_ui.cc
@@ -507,6 +507,7 @@ void NewTabUI::RegisterUserPrefs(PrefService* prefs) {
0,
PrefService::UNSYNCABLE_PREF);
+ AppLauncherHandler::RegisterUserPrefs(prefs);
MostVisitedHandler::RegisterUserPrefs(prefs);
ShownSectionsHandler::RegisterUserPrefs(prefs);
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index d6b6745..6f1f4e5 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -1166,6 +1166,9 @@ const char kNTPWebStorePromoExpire[] = "ntp.webstorepromo.expire";
// Specifies what users should maximize the NTP web store promo.
const char kNTPWebStorePromoUserGroup[] = "ntp.webstorepromo.usergroup";
+// Customized app page names that appear on the New Tab Page.
+const char kNTPAppPageNames[] = "ntp.app_page_names";
+
// The most up-to-date GPU blacklist downloaded from the web, which replaces
// the one that's installed with chrome.
const char kGpuBlacklist[] = "gpu_blacklist";
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 2dd53b1..3c4bc4b 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -404,6 +404,7 @@ extern const char kNTPWebStorePromoLink[];
extern const char kNTPWebStorePromoLogo[];
extern const char kNTPWebStorePromoExpire[];
extern const char kNTPWebStorePromoUserGroup[];
+extern const char kNTPAppPageNames[];
extern const char kGpuBlacklist[];
extern const char kGpuBlacklistUpdate[];