| 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('blur', this.onBlur_, true); | 262 this.addEventListener('blur', this.onBlur_, true); |
| 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 /** @inheritDoc */ | 830 /** @inheritDoc */ |
| 880 setDropEffect: function(dataTransfer) { | 831 setDropEffect: function(dataTransfer) { |
| 881 var tile = ntp.getCurrentlyDraggingTile(); | 832 var tile = ntp.getCurrentlyDraggingTile(); |
| 882 if (tile && tile.querySelector('.app')) | 833 if (tile && tile.querySelector('.app')) |
| 883 ntp.setCurrentDropEffect(dataTransfer, 'move'); | 834 ntp.setCurrentDropEffect(dataTransfer, 'move'); |
| 884 else | 835 else |
| 885 ntp.setCurrentDropEffect(dataTransfer, 'copy'); | 836 ntp.setCurrentDropEffect(dataTransfer, 'copy'); |
| 886 }, | 837 }, |
| 887 }; | 838 }; |
| 888 | 839 |
| 889 AppsPage.setPromo = function(data) { | |
| 890 var store = document.querySelector('.webstore'); | |
| 891 if (store) | |
| 892 store.setAppsPromoData(data); | |
| 893 }; | |
| 894 | |
| 895 /** | 840 /** |
| 896 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE | 841 * Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE |
| 897 * histogram. This should only be invoked from the AppLauncherHandler. | 842 * histogram. This should only be invoked from the AppLauncherHandler. |
| 898 * @param {String} appID The ID of the app. | 843 * @param {String} appID The ID of the app. |
| 899 */ | 844 */ |
| 900 function launchAppAfterEnable(appId) { | 845 function launchAppAfterEnable(appId) { |
| 901 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); | 846 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); |
| 902 } | 847 } |
| 903 | 848 |
| 904 function appNotificationChanged(id, notification) { | 849 function appNotificationChanged(id, notification) { |
| 905 var app = $(id); | 850 var app = $(id); |
| 906 // The app might have been uninstalled, or notifications might be disabled. | 851 // The app might have been uninstalled, or notifications might be disabled. |
| 907 if (app && !app.appData.notifications_disabled) | 852 if (app && !app.appData.notifications_disabled) |
| 908 app.setupNotification_(notification); | 853 app.setupNotification_(notification); |
| 909 } | 854 } |
| 910 | 855 |
| 911 return { | 856 return { |
| 912 APP_LAUNCH: APP_LAUNCH, | 857 APP_LAUNCH: APP_LAUNCH, |
| 913 appNotificationChanged: appNotificationChanged, | 858 appNotificationChanged: appNotificationChanged, |
| 914 AppsPage: AppsPage, | 859 AppsPage: AppsPage, |
| 915 launchAppAfterEnable: launchAppAfterEnable, | 860 launchAppAfterEnable: launchAppAfterEnable, |
| 916 }; | 861 }; |
| 917 }); | 862 }); |
| OLD | NEW |