1 // Copyright (c) 2013 Intel Corporation. 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 #ifndef XWALK_APPLICATION_EXTENSION_APPLICATION_EVENT_EXTENSION_H_
6 #define XWALK_APPLICATION_EXTENSION_APPLICATION_EVENT_EXTENSION_H_
11 #include "xwalk/application/browser/event_observer.h"
12 #include "xwalk/extensions/browser/xwalk_extension_function_handler.h"
13 #include "xwalk/extensions/common/xwalk_extension.h"
16 namespace application {
17 class ApplicationEventManager;
18 class ApplicationStorage;
20 class AppEventExtensionInstance;
22 using extensions::XWalkExtension;
23 using extensions::XWalkExtensionFunctionHandler;
24 using extensions::XWalkExtensionFunctionInfo;
25 using extensions::XWalkExtensionInstance;
27 class ApplicationEventExtension : public XWalkExtension {
29 ApplicationEventExtension(ApplicationEventManager* event_manager,
30 ApplicationStorage* app_storage,
31 Application* application);
33 // XWalkExtension implementation.
34 virtual XWalkExtensionInstance* CreateInstance() OVERRIDE;
37 ApplicationEventManager* event_manager_;
38 ApplicationStorage* app_storage_;
39 Application* application_;
42 class AppEventExtensionInstance : public XWalkExtensionInstance,
43 public EventObserver {
45 AppEventExtensionInstance(ApplicationEventManager* event_manager,
46 ApplicationStorage* app_storage,
47 Application* application,
50 virtual ~AppEventExtensionInstance();
51 // XWalkExtensionInstance implementation.
52 virtual void HandleMessage(scoped_ptr<base::Value> msg) OVERRIDE;
54 // EventObserver implementation.
55 virtual void Observe(const std::string& app_id,
56 scoped_refptr<Event> event) OVERRIDE;
59 // Registered handlers for incoming JS messages.
60 void OnRegisterEvent(scoped_ptr<XWalkExtensionFunctionInfo> info);
61 void OnUnregisterEvent(scoped_ptr<XWalkExtensionFunctionInfo> info);
62 void OnDispatchEventFinish(scoped_ptr<XWalkExtensionFunctionInfo> info);
64 typedef std::map<std::string, XWalkExtensionFunctionInfo::PostResultCallback>
66 EventCallbackMap registered_events_;
67 ApplicationStorage* app_storage_;
68 Application* application_;
69 int main_routing_id_; // routing id of the main document.
71 XWalkExtensionFunctionHandler handler_;
74 } // namespace application
77 #endif // XWALK_APPLICATION_EXTENSION_APPLICATION_EVENT_EXTENSION_H_