Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(650)

Side by Side Diff: chrome/browser/resources/ntp/apps.js

Issue 5750005: Default apps promo was getting expired early if NTP open. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/default_apps_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 var MAX_APPS_PER_ROW = []; 5 var MAX_APPS_PER_ROW = [];
6 MAX_APPS_PER_ROW[LayoutMode.SMALL] = 4; 6 MAX_APPS_PER_ROW[LayoutMode.SMALL] = 4;
7 MAX_APPS_PER_ROW[LayoutMode.NORMAL] = 6; 7 MAX_APPS_PER_ROW[LayoutMode.NORMAL] = 6;
8 8
9 // The URL prefix used in the app link 'ping' attributes. 9 // The URL prefix used in the app link 'ping' attributes.
10 var PING_APP_LAUNCH_PREFIX = 'record-app-launch'; 10 var PING_APP_LAUNCH_PREFIX = 'record-app-launch';
11 11
12 // The URL prefix used in the webstore link 'ping' attributes. 12 // The URL prefix used in the webstore link 'ping' attributes.
13 var PING_WEBSTORE_LAUNCH_PREFIX = 'record-webstore-launch'; 13 var PING_WEBSTORE_LAUNCH_PREFIX = 'record-webstore-launch';
14 14
15 function getAppsCallback(data) { 15 function getAppsCallback(data) {
16 logEvent('received apps'); 16 logEvent('received apps');
17
18 // In the case of prefchange-triggered updates, we don't receive this flag.
19 // Just leave it set as it was before in that case.
20 if ('showPromo' in data)
21 apps.showPromo = data.showPromo;
22
17 var appsSection = $('apps'); 23 var appsSection = $('apps');
18 var appsSectionContent = $('apps-content'); 24 var appsSectionContent = $('apps-content');
19 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; 25 var appsMiniview = appsSection.getElementsByClassName('miniview')[0];
20 var appsPromo = $('apps-promo'); 26 var appsPromo = $('apps-promo');
21 var appsPromoPing = PING_WEBSTORE_LAUNCH_PREFIX + '+' + data.showPromo; 27 var appsPromoPing = PING_WEBSTORE_LAUNCH_PREFIX + '+' + apps.showPromo;
22 var webStoreEntry; 28 var webStoreEntry;
23 29
24 // Hide menu options that are not supported on the OS or windowing system. 30 // Hide menu options that are not supported on the OS or windowing system.
25 31
26 // The "Launch as Window" menu option. 32 // The "Launch as Window" menu option.
27 $('apps-launch-type-window-menu-item').style.display = 33 $('apps-launch-type-window-menu-item').style.display =
28 (data.disableAppWindowLaunch ? 'none' : 'inline'); 34 (data.disableAppWindowLaunch ? 'none' : 'inline');
29 35
30 // The "Create App Shortcut" menu option. 36 // The "Create App Shortcut" menu option.
31 $('apps-create-shortcut-command-menu-item').style.display = 37 $('apps-create-shortcut-command-menu-item').style.display =
32 (data.disableCreateAppShortcut ? 'none' : 'inline'); 38 (data.disableCreateAppShortcut ? 'none' : 'inline');
33 39
34 appsMiniview.textContent = ''; 40 appsMiniview.textContent = '';
35 appsSectionContent.textContent = ''; 41 appsSectionContent.textContent = '';
36 42
37 apps.showPromo = data.showPromo;
38
39 data.apps.sort(function(a,b) { 43 data.apps.sort(function(a,b) {
40 return a.app_launch_index - b.app_launch_index; 44 return a.app_launch_index - b.app_launch_index;
41 }); 45 });
42 46
43 clearClosedMenu(apps.menu); 47 clearClosedMenu(apps.menu);
44 if (data.apps.length == 0 && !data.showLauncher) { 48 if (data.apps.length == 0 && !data.showLauncher) {
45 appsSection.classList.add('disabled'); 49 appsSection.classList.add('disabled');
46 layoutSections(); 50 layoutSections();
47 } else { 51 } else {
48 data.apps.forEach(function(app) { 52 data.apps.forEach(function(app) {
49 appsSectionContent.appendChild(apps.createElement(app)); 53 appsSectionContent.appendChild(apps.createElement(app));
50 }); 54 });
51 55
52 webStoreEntry = apps.createWebStoreElement(); 56 webStoreEntry = apps.createWebStoreElement();
53 webStoreEntry.querySelector('a').setAttribute('ping', appsPromoPing); 57 webStoreEntry.querySelector('a').setAttribute('ping', appsPromoPing);
54 appsSectionContent.appendChild(webStoreEntry); 58 appsSectionContent.appendChild(webStoreEntry);
55 59
56 data.apps.slice(0, MAX_MINIVIEW_ITEMS).forEach(function(app) { 60 data.apps.slice(0, MAX_MINIVIEW_ITEMS).forEach(function(app) {
57 appsMiniview.appendChild(apps.createMiniviewElement(app)); 61 appsMiniview.appendChild(apps.createMiniviewElement(app));
58 addClosedMenuEntryWithLink(apps.menu, apps.createClosedMenuElement(app)); 62 addClosedMenuEntryWithLink(apps.menu, apps.createClosedMenuElement(app));
59 }); 63 });
60 64
61 if (!(shownSections & MINIMIZED_APPS)) { 65 if (!(shownSections & MINIMIZED_APPS)) {
62 appsSection.classList.remove('disabled'); 66 appsSection.classList.remove('disabled');
63 } 67 }
64 } 68 }
65 addClosedMenuFooter(apps.menu, 'apps', MINIMIZED_APPS, Section.APPS); 69 addClosedMenuFooter(apps.menu, 'apps', MINIMIZED_APPS, Section.APPS);
66 70
67 apps.loaded = true; 71 apps.loaded = true;
68 if (data.showPromo) 72 if (apps.showPromo)
69 document.documentElement.classList.add('apps-promo-visible'); 73 document.documentElement.classList.add('apps-promo-visible');
70 else 74 else
71 document.documentElement.classList.remove('apps-promo-visible'); 75 document.documentElement.classList.remove('apps-promo-visible');
72 $('apps-promo-link').setAttribute('ping', appsPromoPing); 76 $('apps-promo-link').setAttribute('ping', appsPromoPing);
73 maybeDoneLoading(); 77 maybeDoneLoading();
74 78
75 if (data.apps.length > 0 && isDoneLoading()) { 79 if (data.apps.length > 0 && isDoneLoading()) {
76 if (!data.showPromo && data.apps.length >= MAX_APPS_PER_ROW[layoutMode]) 80 if (!apps.showPromo && data.apps.length >= MAX_APPS_PER_ROW[layoutMode])
77 webStoreEntry.classList.add('loner'); 81 webStoreEntry.classList.add('loner');
78 else 82 else
79 webStoreEntry.classList.remove('loner'); 83 webStoreEntry.classList.remove('loner');
80 84
81 updateMiniviewClipping(appsMiniview); 85 updateMiniviewClipping(appsMiniview);
82 layoutSections(); 86 layoutSections();
83 } 87 }
84 } 88 }
85 89
86 function appsPrefChangeCallback(data) { 90 function appsPrefChangeCallback(data) {
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 var elm = createElement({ 334 var elm = createElement({
331 'id': 'web-store-entry', 335 'id': 'web-store-entry',
332 'name': localStrings.getString('web_store_title'), 336 'name': localStrings.getString('web_store_title'),
333 'launch_url': localStrings.getString('web_store_url') 337 'launch_url': localStrings.getString('web_store_url')
334 }); 338 });
335 elm.setAttribute('app-id', 'web-store-entry'); 339 elm.setAttribute('app-id', 'web-store-entry');
336 return elm; 340 return elm;
337 } 341 }
338 }; 342 };
339 })(); 343 })();
OLDNEW
« no previous file with comments | « chrome/browser/extensions/default_apps_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698