OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_WEB_INTENTS_HOST_H_ | 5 #ifndef CONTENT_RENDERER_WEB_INTENTS_HOST_H_ |
6 #define CONTENT_RENDERER_WEB_INTENTS_HOST_H_ | 6 #define CONTENT_RENDERER_WEB_INTENTS_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
| 9 #include <map> |
| 10 |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "content/public/renderer/render_view_observer.h" | 12 #include "content/public/renderer/render_view_observer.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
12 #include "webkit/glue/web_intent_data.h" | 14 #include "webkit/glue/web_intent_data.h" |
13 #include "webkit/glue/web_intent_reply_data.h" | 15 #include "webkit/glue/web_intent_reply_data.h" |
14 | 16 |
15 class RenderViewImpl; | 17 class RenderViewImpl; |
16 | 18 |
17 namespace WebKit { | 19 namespace WebKit { |
| 20 class WebIntentRequest; |
18 class WebFrame; | 21 class WebFrame; |
19 } | 22 } |
20 | 23 |
21 namespace webkit_glue { | 24 namespace webkit_glue { |
22 struct WebIntentData; | 25 struct WebIntentData; |
23 } | 26 } |
24 | 27 |
25 // WebIntentsHost is a delegate for Web Intents messages. It is the | 28 // WebIntentsHost is a delegate for Web Intents messages. It is the |
26 // renderer-side handler for IPC messages delivering the intent payload data | 29 // renderer-side handler for IPC messages delivering the intent payload data |
27 // and preparing it for access by the service page. | 30 // and preparing it for access by the service page. |
28 class WebIntentsHost : public content::RenderViewObserver { | 31 class WebIntentsHost : public content::RenderViewObserver { |
29 public: | 32 public: |
30 // |render_view| must not be NULL. | 33 // |render_view| must not be NULL. |
31 explicit WebIntentsHost(RenderViewImpl* render_view); | 34 explicit WebIntentsHost(RenderViewImpl* render_view); |
32 virtual ~WebIntentsHost(); | 35 virtual ~WebIntentsHost(); |
33 | 36 |
| 37 // Called by the RenderView to register a new Web Intent invocation. |
| 38 int RegisterWebIntent(const WebKit::WebIntentRequest& request); |
| 39 |
34 // Called by the bound intent object to register the result from the service | 40 // Called by the bound intent object to register the result from the service |
35 // page. | 41 // page. |
36 void OnResult(const WebKit::WebString& data); | 42 void OnResult(const WebKit::WebString& data); |
37 void OnFailure(const WebKit::WebString& data); | 43 void OnFailure(const WebKit::WebString& data); |
38 | 44 |
39 private: | 45 private: |
40 class BoundDeliveredIntent; | 46 class BoundDeliveredIntent; |
41 | 47 |
| 48 // A counter used to assign unique IDs to web intents invocations in this |
| 49 // renderer. |
| 50 int id_counter_; |
| 51 |
| 52 // Map tracking registered Web Intent requests by assigned ID numbers to |
| 53 // correctly route any return data. |
| 54 std::map<int, WebKit::WebIntentRequest> intent_requests_; |
| 55 |
42 // RenderView::Observer implementation. | 56 // RenderView::Observer implementation. |
43 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 57 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
44 virtual void DidClearWindowObject(WebKit::WebFrame* frame) OVERRIDE; | 58 virtual void DidClearWindowObject(WebKit::WebFrame* frame) OVERRIDE; |
45 | 59 |
46 // TODO(gbillock): Do we need various ***ClientRedirect methods to implement | 60 // TODO(gbillock): Do we need various ***ClientRedirect methods to implement |
47 // intent cancelling policy? Figure this out. | 61 // intent cancelling policy? Figure this out. |
48 | 62 |
49 // On the service page, handler method for the IntentsMsg_SetWebIntent | 63 // On the service page, handler method for the IntentsMsg_SetWebIntent |
50 // message. | 64 // message. |
51 void OnSetIntent(const webkit_glue::WebIntentData& intent); | 65 void OnSetIntent(const webkit_glue::WebIntentData& intent); |
52 | 66 |
53 // On the client page, handler method for the IntentsMsg_WebIntentReply | 67 // On the client page, handler method for the IntentsMsg_WebIntentReply |
54 // message. | 68 // message. |
55 void OnWebIntentReply(webkit_glue::WebIntentReplyType reply_type, | 69 void OnWebIntentReply(webkit_glue::WebIntentReplyType reply_type, |
56 const WebKit::WebString& data, | 70 const WebKit::WebString& data, |
57 int intent_id); | 71 int intent_id); |
58 | 72 |
59 // Delivered intent data from the caller. | 73 // Delivered intent data from the caller. |
60 scoped_ptr<webkit_glue::WebIntentData> intent_; | 74 scoped_ptr<webkit_glue::WebIntentData> intent_; |
61 | 75 |
62 // Representation of the intent data as a C++ bound NPAPI object to be | 76 // Representation of the intent data as a C++ bound NPAPI object to be |
63 // injected into the Javascript context. | 77 // injected into the Javascript context. |
64 scoped_ptr<BoundDeliveredIntent> delivered_intent_; | 78 scoped_ptr<BoundDeliveredIntent> delivered_intent_; |
65 | 79 |
66 DISALLOW_COPY_AND_ASSIGN(WebIntentsHost); | 80 DISALLOW_COPY_AND_ASSIGN(WebIntentsHost); |
67 }; | 81 }; |
68 | 82 |
69 #endif // CONTENT_RENDERER_WEB_INTENTS_HOST_H_ | 83 #endif // CONTENT_RENDERER_WEB_INTENTS_HOST_H_ |
OLD | NEW |