OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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. | |
4 | |
5 #ifndef CHROME_BROWSER_SYNC_JS_JS_CONTROLLER_H_ | |
6 #define CHROME_BROWSER_SYNC_JS_JS_CONTROLLER_H_ | |
7 #pragma once | |
8 | |
9 // See README.js for design comments. | |
10 | |
11 #include <string> | |
12 | |
13 namespace browser_sync { | |
14 | |
15 class JsArgList; | |
16 class JsEventHandler; | |
17 class JsReplyHandler; | |
18 template <typename T> class WeakHandle; | |
19 | |
20 // An interface for objects that JsEventHandlers directly interact | |
21 // with. JsEventHandlers can add themselves to receive events and | |
22 // also send messages which will eventually reach the backend. | |
23 class JsController { | |
24 public: | |
25 // Adds an event handler which will start receiving JS events (not | |
26 // immediately, so this can be called in the handler's constructor). | |
27 // Multiple event handlers are supported, but each event handler | |
28 // must be added at most once. | |
29 // | |
30 // Ideally, we'd take WeakPtrs, but we need the raw pointer values | |
31 // to be able to look them up for removal. | |
32 virtual void AddJsEventHandler(JsEventHandler* event_handler) = 0; | |
33 | |
34 // Removes the given event handler if it has been added. It will | |
35 // immediately stop receiving any JS events. | |
36 virtual void RemoveJsEventHandler(JsEventHandler* event_handler) = 0; | |
37 | |
38 // Processes a JS message. The reply (if any) will be sent to | |
39 // |reply_handler| if it is initialized. | |
40 virtual void ProcessJsMessage( | |
41 const std::string& name, const JsArgList& args, | |
42 const WeakHandle<JsReplyHandler>& reply_handler) = 0; | |
43 | |
44 protected: | |
45 virtual ~JsController() {} | |
46 }; | |
47 | |
48 } // namespace browser_sync | |
49 | |
50 #endif // CHROME_BROWSER_SYNC_JS_JS_CONTROLLER_H_ | |
OLD | NEW |