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