OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_INTENTS_DISPATCHER_H_ | |
6 #define CONTENT_PUBLIC_BROWSER_WEB_INTENTS_DISPATCHER_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "content/common/content_export.h" | |
10 #include "webkit/glue/web_intent_reply_data.h" | |
11 | |
12 namespace webkit_glue { | |
13 enum WebIntentReplyType; | |
14 struct WebIntentData; | |
15 struct WebIntentReply; | |
16 } | |
17 | |
18 namespace content { | |
19 | |
20 class WebContents; | |
21 class WebContentsDelegate; | |
22 | |
23 // This class is the coordinator for dispatching web intents and seeing that | |
24 // return messages are sent to the correct invoking context. The WebContents | |
25 // for the invoking context will create one of these for each intent and hand | |
26 // a pointer to the client WebContentsDelegate code. The WebContentsDelegate | |
27 // code can then read the intent data, create UI to pick the service, and | |
28 // create a new context for that service. | |
29 // | |
30 // At that point, it should call DispatchIntent, which will deliver the intent | |
31 // to the new context. If anything goes wrong during setup, the client | |
32 // should call SendReplyMessage with an error. The dispatcher lives until the | |
33 // SendReplyMessage method is called, which will self-delete the object. | |
34 // | |
35 // The client should also register a reply notification, so it can avoid | |
36 // referencing the dispatcher after other code calls SendReplyMessage, which can | |
37 // happen if, for example, the user closes the delivery context. | |
38 class CONTENT_EXPORT WebIntentsDispatcher { | |
39 public: | |
40 // This callback type is registered for notification of |SendReplyMessage|. | |
41 typedef base::Callback<void(webkit_glue::WebIntentReplyType)> | |
42 ReplyNotification; | |
43 | |
44 // Create internal (browser-triggered) intent. This will create | |
45 // a new dispatcher with the passed intent payload |data|. The caller should | |
46 // manage dispatching it correctly. | |
47 static WebIntentsDispatcher* Create(const webkit_glue::WebIntentData& data); | |
48 | |
49 virtual ~WebIntentsDispatcher() {} | |
50 | |
51 // Get the intent data being dispatched. | |
52 virtual const webkit_glue::WebIntentData& GetIntent() = 0; | |
53 | |
54 // Attach the intent to a new context in which the service page is loaded. | |
55 // |web_contents| must not be NULL. | |
56 virtual void DispatchIntent(WebContents* web_contents) = 0; | |
57 | |
58 // Abandon current attempt to dispatch, allow new call to DispatchIntent. | |
59 virtual void ResetDispatch() = 0; | |
60 | |
61 // Return a reply to the source context which invoked the intent. | |
62 // Calls the reply notifications, if any are registered. | |
63 // Deletes |this| object after handling is complete. | |
64 virtual void SendReply(const webkit_glue::WebIntentReply& reply) = 0; | |
65 | |
66 // Register a callback to be notified when SendReplyMessage is called. | |
67 // Multiple callbacks may be registered. | |
68 virtual void RegisterReplyNotification(const ReplyNotification& closure) = 0; | |
69 }; | |
70 | |
71 } // namespace content | |
72 | |
73 #endif // CONTENT_PUBLIC_BROWSER_WEB_INTENTS_DISPATCHER_H_ | |
OLD | NEW |