OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('ntp', function() { | 5 cr.define('ntp', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 var APP_LAUNCH = { | 8 var APP_LAUNCH = { |
9 // The histogram buckets (keep in sync with extension_constants.h). | 9 // The histogram buckets (keep in sync with extension_constants.h). |
10 NTP_APPS_MAXIMIZED: 0, | 10 NTP_APPS_MAXIMIZED: 0, |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 250 |
251 // This hack is here so that appContents.contextMenu will be the same as | 251 // This hack is here so that appContents.contextMenu will be the same as |
252 // this.contextMenu. | 252 // this.contextMenu. |
253 var self = this; | 253 var self = this; |
254 this.appContents_.__defineGetter__('contextMenu', function() { | 254 this.appContents_.__defineGetter__('contextMenu', function() { |
255 return self.contextMenu; | 255 return self.contextMenu; |
256 }); | 256 }); |
257 this.appContents_.addEventListener('contextmenu', | 257 this.appContents_.addEventListener('contextmenu', |
258 cr.ui.contextMenuHandler); | 258 cr.ui.contextMenuHandler); |
259 | 259 |
260 if (this.appData_.is_webstore) | |
261 this.createAppsPromoExtras_(); | |
262 | |
263 this.addEventListener('mousedown', this.onMousedown_, true); | 260 this.addEventListener('mousedown', this.onMousedown_, true); |
264 this.addEventListener('keydown', this.onKeydown_); | 261 this.addEventListener('keydown', this.onKeydown_); |
265 this.addEventListener('keyup', this.onKeyup_); | 262 this.addEventListener('keyup', this.onKeyup_); |
266 }, | 263 }, |
267 | 264 |
268 /** | 265 /** |
269 * Sets the color of the favicon dominant color bar. | 266 * Sets the color of the favicon dominant color bar. |
270 * @param {string} color The css-parsable value for the color. | 267 * @param {string} color The css-parsable value for the color. |
271 */ | 268 */ |
272 set stripeColor(color) { | 269 set stripeColor(color) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 * Removes the info bubble if there is one. | 377 * Removes the info bubble if there is one. |
381 */ | 378 */ |
382 removeBubble: function() { | 379 removeBubble: function() { |
383 if (this.currentBubbleShowing_) { | 380 if (this.currentBubbleShowing_) { |
384 this.currentBubbleShowing_.hide(); | 381 this.currentBubbleShowing_.hide(); |
385 this.currentBubbleShowing_ = null; | 382 this.currentBubbleShowing_ = null; |
386 } | 383 } |
387 }, | 384 }, |
388 | 385 |
389 /** | 386 /** |
390 * Creates the apps-promo section of the app (should only be called for the | |
391 * webstore app). | |
392 * @private | |
393 */ | |
394 createAppsPromoExtras_: function() { | |
395 this.classList.add('webstore'); | |
396 | |
397 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true); | |
398 this.appsPromoExtras_.id = ''; | |
399 this.appsPromoHeading_ = | |
400 this.appsPromoExtras_.querySelector('.apps-promo-heading'); | |
401 this.appsPromoLink_ = | |
402 this.appsPromoExtras_.querySelector('.apps-promo-link'); | |
403 this.appsPromoLink_.addEventListener('click', this.onClick_.bind(this)); | |
404 | |
405 this.appsPromoLogo_ = this.ownerDocument.createElement('img'); | |
406 this.appsPromoLogo_.className = 'apps-promo-logo'; | |
407 this.appImgContainer_.appendChild(this.appsPromoLogo_); | |
408 | |
409 this.appendChild(this.appsPromoExtras_); | |
410 }, | |
411 | |
412 /** | |
413 * Sets the apps promo appearance. If |data| is null, there is no promo. If | |
414 * |data| is non-null, it contains strings to be shown for the promo. The | |
415 * promo is only shown when the webstore app icon is alone on a page. | |
416 * @param {Object} data A dictionary that contains apps promo strings. | |
417 */ | |
418 setAppsPromoData: function(data) { | |
419 if (data) { | |
420 this.classList.add('has-promo'); | |
421 } else { | |
422 this.classList.remove('has-promo'); | |
423 return; | |
424 } | |
425 | |
426 this.appsPromoHeading_.textContent = data.promoHeader; | |
427 this.appsPromoLink_.href = data.promoLink; | |
428 this.appsPromoLink_.textContent = data.promoButton; | |
429 this.appsPromoLogo_.src = data.promoLogo; | |
430 }, | |
431 | |
432 /** | |
433 * Set the size and position of the app tile. | 387 * Set the size and position of the app tile. |
434 * @param {number} size The total size of |this|. | 388 * @param {number} size The total size of |this|. |
435 * @param {number} x The x-position. | 389 * @param {number} x The x-position. |
436 * @param {number} y The y-position. | 390 * @param {number} y The y-position. |
437 * animate. | 391 * animate. |
438 */ | 392 */ |
439 setBounds: function(size, x, y) { | 393 setBounds: function(size, x, y) { |
440 var imgSize = size * APP_IMG_SIZE_FRACTION; | 394 var imgSize = size * APP_IMG_SIZE_FRACTION; |
441 this.appImgContainer_.style.width = this.appImgContainer_.style.height = | 395 this.appImgContainer_.style.width = this.appImgContainer_.style.height = |
442 toCssPx(this.useSmallIcon_ ? 16 : imgSize); | 396 toCssPx(this.useSmallIcon_ ? 16 : imgSize); |
(...skipping 18 matching lines...) Expand all Loading... |
461 if (this.currentBubbleShowing_) | 415 if (this.currentBubbleShowing_) |
462 this.currentBubbleShowing_.resizeAndReposition(); | 416 this.currentBubbleShowing_.resizeAndReposition(); |
463 }, | 417 }, |
464 | 418 |
465 /** | 419 /** |
466 * Invoked when an app is clicked. | 420 * Invoked when an app is clicked. |
467 * @param {Event} e The click event. | 421 * @param {Event} e The click event. |
468 * @private | 422 * @private |
469 */ | 423 */ |
470 onClick_: function(e) { | 424 onClick_: function(e) { |
471 var is_promo = this.appsPromoExtras_ && | |
472 window.getComputedStyle(this.appsPromoExtras_).display != 'none'; | |
473 var url = !this.appData_.is_webstore ? '' : | 425 var url = !this.appData_.is_webstore ? '' : |
474 is_promo ? this.appsPromoLink_.href : | 426 appendParam(this.appData_.url, |
475 appendParam(this.appData_.url, | 427 'utm_source', |
476 'utm_source', | 428 'chrome-ntp-icon'); |
477 'chrome-ntp-icon'); | |
478 | 429 |
479 chrome.send('launchApp', | 430 chrome.send('launchApp', |
480 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, url, | 431 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, url, |
481 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); | 432 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); |
482 | 433 |
483 // Don't allow the click to trigger a link or anything | 434 // Don't allow the click to trigger a link or anything |
484 e.preventDefault(); | 435 e.preventDefault(); |
485 }, | 436 }, |
486 | 437 |
487 /** | 438 /** |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 /** @inheritDoc */ | 849 /** @inheritDoc */ |
899 setDropEffect: function(dataTransfer) { | 850 setDropEffect: function(dataTransfer) { |
900 var tile = ntp.getCurrentlyDraggingTile(); | 851 var tile = ntp.getCurrentlyDraggingTile(); |
901 if (tile && tile.querySelector('.app')) | 852 if (tile && tile.querySelector('.app')) |
902 ntp.setCurrentDropEffect(dataTransfer, 'move'); | 853 ntp.setCurrentDropEffect(dataTransfer, 'move'); |
903 else | 854 else |
904 ntp.setCurrentDropEffect(dataTransfer, 'copy'); | 855 ntp.setCurrentDropEffect(dataTransfer, 'copy'); |
905 }, | 856 }, |
906 }; | 857 }; |
907 | 858 |
908 AppsPage.setPromo = function(data) { | |
909 var store = document.querySelector('.webstore'); | |
910 if (store) | |
911 store.setAppsPromoData(data); | |
912 }; | |
913 | |
914 /** | 859 /** |
915 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE | 860 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE |
916 * histogram. This should only be invoked from the AppLauncherHandler. | 861 * histogram. This should only be invoked from the AppLauncherHandler. |
917 * @param {String} appID The ID of the app. | 862 * @param {String} appID The ID of the app. |
918 */ | 863 */ |
919 function launchAppAfterEnable(appId) { | 864 function launchAppAfterEnable(appId) { |
920 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); | 865 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); |
921 } | 866 } |
922 | 867 |
923 function appNotificationChanged(id, notification) { | 868 function appNotificationChanged(id, notification) { |
924 var app = $(id); | 869 var app = $(id); |
925 // The app might have been uninstalled, or notifications might be disabled. | 870 // The app might have been uninstalled, or notifications might be disabled. |
926 if (app && !app.appData.notifications_disabled) | 871 if (app && !app.appData.notifications_disabled) |
927 app.setupNotification_(notification); | 872 app.setupNotification_(notification); |
928 } | 873 } |
929 | 874 |
930 return { | 875 return { |
931 APP_LAUNCH: APP_LAUNCH, | 876 APP_LAUNCH: APP_LAUNCH, |
932 appNotificationChanged: appNotificationChanged, | 877 appNotificationChanged: appNotificationChanged, |
933 AppsPage: AppsPage, | 878 AppsPage: AppsPage, |
934 launchAppAfterEnable: launchAppAfterEnable, | 879 launchAppAfterEnable: launchAppAfterEnable, |
935 }; | 880 }; |
936 }); | 881 }); |
OLD | NEW |