1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This is a minimal sample of a Apps V2 app with background permission.
7 // This function gets called in the packaged app model on launch.
8 chrome
.app
.runtime
.onLaunched
.addListener(function() {
9 console
.log("Background App Launched!");
11 // We'll set up push messaging so we have something to keep the background
16 // This function gets called in the packaged app model on install.
17 chrome
.runtime
.onInstalled
.addListener(function() {
18 console
.log("Background App installed!");
21 // This function gets called in the packaged app model on shutdown.
22 chrome
.runtime
.onSuspend
.addListener(function() {
23 console
.log("Background App shutting down");
26 // Register for push messages.
27 // This should be called every time the Push Messaging App starts up.
28 function setupPush() {
29 chrome
.pushMessaging
.onMessage
.addListener(messageCallback
);
31 // Ensure that adding the listener took effect.
32 var listeners
= chrome
.pushMessaging
.onMessage
.hasListeners();
33 console
.log('registered listener for push messages ' + listeners
);
36 // This callback receives the pushed message from the push server.
37 function messageCallback(message
) {
38 console
.log("push messaging callback seen");