12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/ref_counted.h" 11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/extensions/chrome_extension_function.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/extensions/api/notifications.h" 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/browser/extension_function.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/notification_types.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 16558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochclass Notification; 17558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace extensions { 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class NotificationsApiFunction : public ChromeAsyncExtensionFunction { 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Whether the current extension and channel allow the API. Public for 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // testing. 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool IsNotificationsApiAvailable(); 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationsApiFunction(); 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~NotificationsApiFunction(); 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool CreateNotification(const std::string& id, 317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) api::notifications::NotificationOptions* options); 32558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch bool UpdateNotification(const std::string& id, 33558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch api::notifications::NotificationOptions* options, 34558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch Notification* notification); 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool IsNotificationsApiEnabled() const; 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool AreExtensionNotificationsAllowed() const; 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Returns true if the API function is still allowed to run even when the 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // notifications for a notifier have been disabled. 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual bool CanRunWhileDisabled() const; 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Called inside of RunAsync. 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunNotificationsApi() = 0; 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // UITHreadExtensionFunction: 48010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual bool RunAsync() OVERRIDE; 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_center::NotificationType MapApiTemplateTypeToType( 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) api::notifications::TemplateType type); 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class NotificationsCreateFunction : public NotificationsApiFunction { 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationsCreateFunction(); 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // NotificationsApiFunction: 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunNotificationsApi() OVERRIDE; 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~NotificationsCreateFunction(); 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<api::notifications::Create::Params> params_; 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("notifications.create", NOTIFICATIONS_CREATE) 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class NotificationsUpdateFunction : public NotificationsApiFunction { 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationsUpdateFunction(); 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // NotificationsApiFunction: 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunNotificationsApi() OVERRIDE; 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~NotificationsUpdateFunction(); 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<api::notifications::Update::Params> params_; 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("notifications.update", NOTIFICATIONS_UPDATE) 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class NotificationsClearFunction : public NotificationsApiFunction { 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NotificationsClearFunction(); 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // NotificationsApiFunction: 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool RunNotificationsApi() OVERRIDE; 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~NotificationsClearFunction(); 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<api::notifications::Clear::Params> params_; 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("notifications.clear", NOTIFICATIONS_CLEAR) 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class NotificationsGetAllFunction : public NotificationsApiFunction { 103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) public: 104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NotificationsGetAllFunction(); 105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // NotificationsApiFunction: 107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual bool RunNotificationsApi() OVERRIDE; 108868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) protected: 110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual ~NotificationsGetAllFunction(); 111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) private: 113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DECLARE_EXTENSION_FUNCTION("notifications.getAll", NOTIFICATIONS_GET_ALL) 114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}; 115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 116f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class NotificationsGetPermissionLevelFunction 117f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) : public NotificationsApiFunction { 1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public: 1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NotificationsGetPermissionLevelFunction(); 1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // NotificationsApiFunction: 1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual bool CanRunWhileDisabled() const OVERRIDE; 1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual bool RunNotificationsApi() OVERRIDE; 1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) protected: 1261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual ~NotificationsGetPermissionLevelFunction(); 1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private: 1291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DECLARE_EXTENSION_FUNCTION("notifications.getPermissionLevel", 1301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NOTIFICATIONS_GET_ALL) 1311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}; 1321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace extensions 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_ 136