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 #include "content/renderer/web_intents_host.h" | 5 #include "content/renderer/web_intents_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "content/common/intents_messages.h" | 10 #include "content/common/intents_messages.h" |
11 #include "content/public/renderer/v8_value_converter.h" | 11 #include "content/public/renderer/v8_value_converter.h" |
12 #include "content/renderer/render_view_impl.h" | 12 #include "content/renderer/render_view_impl.h" |
13 #include "ipc/ipc_message.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlob.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlob.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeliveredIntentCli
ent.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeliveredIntentCli
ent.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste
m.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste
m.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize
dScriptValue.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize
dScriptValue.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
27 #include "webkit/fileapi/file_system_util.h" | 26 #include "webkit/fileapi/file_system_util.h" |
28 #include "webkit/glue/cpp_bound_class.h" | 27 #include "webkit/glue/cpp_bound_class.h" |
29 | 28 |
30 using WebKit::WebBindings; | 29 using WebKit::WebBindings; |
31 using WebKit::WebBlob; | 30 using WebKit::WebBlob; |
32 using WebKit::WebCString; | 31 using WebKit::WebCString; |
33 using WebKit::WebDeliveredIntentClient; | 32 using WebKit::WebDeliveredIntentClient; |
34 using WebKit::WebFrame; | 33 using WebKit::WebFrame; |
35 using WebKit::WebIntent; | 34 using WebKit::WebIntent; |
36 using WebKit::WebIntentRequest; | 35 using WebKit::WebIntentRequest; |
37 using WebKit::WebString; | 36 using WebKit::WebString; |
38 using WebKit::WebSerializedScriptValue; | 37 using WebKit::WebSerializedScriptValue; |
39 using WebKit::WebVector; | 38 using WebKit::WebVector; |
40 | 39 |
| 40 namespace content { |
| 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 // Reads reply value, either from the data field, or the data_file field. | 44 // Reads reply value, either from the data field, or the data_file field. |
44 WebSerializedScriptValue GetReplyValue( | 45 WebSerializedScriptValue GetReplyValue( |
45 const webkit_glue::WebIntentReply& reply) { | 46 const webkit_glue::WebIntentReply& reply) { |
46 if (reply.data_file_size > -1) { | 47 if (reply.data_file_size > -1) { |
47 // TODO(smckay): seralize the blob value in the web intent script | 48 // TODO(smckay): seralize the blob value in the web intent script |
48 // context. We simply don't know how to do this at this time. | 49 // context. We simply don't know how to do this at this time. |
49 // The following code kills the renderer when we call toV8Value. | 50 // The following code kills the renderer when we call toV8Value. |
50 // v8::HandleScope scope; | 51 // v8::HandleScope scope; |
(...skipping 27 matching lines...) Expand all Loading... |
78 } | 79 } |
79 | 80 |
80 virtual void destroy() OVERRIDE { | 81 virtual void destroy() OVERRIDE { |
81 } | 82 } |
82 | 83 |
83 private: | 84 private: |
84 WebIntentsHost* host_; | 85 WebIntentsHost* host_; |
85 }; | 86 }; |
86 | 87 |
87 WebIntentsHost::WebIntentsHost(RenderViewImpl* render_view) | 88 WebIntentsHost::WebIntentsHost(RenderViewImpl* render_view) |
88 : content::RenderViewObserver(render_view), | 89 : RenderViewObserver(render_view), |
89 id_counter_(0) { | 90 id_counter_(0) { |
90 } | 91 } |
91 | 92 |
92 WebIntentsHost::~WebIntentsHost() { | 93 WebIntentsHost::~WebIntentsHost() { |
93 } | 94 } |
94 | 95 |
95 int WebIntentsHost::RegisterWebIntent( | 96 int WebIntentsHost::RegisterWebIntent( |
96 const WebIntentRequest& request) { | 97 const WebIntentRequest& request) { |
97 int id = id_counter_++; | 98 int id = id_counter_++; |
98 intent_requests_[id] = request; | 99 intent_requests_[id] = request; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 WebKit::WebString::fromUTF8(intent_data.root_name), | 231 WebKit::WebString::fromUTF8(intent_data.root_name), |
231 WebKit::WebString::fromUTF8(url)); | 232 WebKit::WebString::fromUTF8(url)); |
232 WebSerializedScriptValue serialized_data = | 233 WebSerializedScriptValue serialized_data = |
233 WebSerializedScriptValue::serialize(filesystem_V8); | 234 WebSerializedScriptValue::serialize(filesystem_V8); |
234 return WebIntent::create(intent_data.action, intent_data.type, | 235 return WebIntent::create(intent_data.action, intent_data.type, |
235 serialized_data.toString(), | 236 serialized_data.toString(), |
236 extras_keys, extras_values); | 237 extras_keys, extras_values); |
237 } | 238 } |
238 | 239 |
239 case webkit_glue::WebIntentData::MIME_TYPE: { | 240 case webkit_glue::WebIntentData::MIME_TYPE: { |
240 scoped_ptr<content::V8ValueConverter> converter( | 241 scoped_ptr<V8ValueConverter> converter( |
241 content::V8ValueConverter::create()); | 242 V8ValueConverter::create()); |
242 v8::Handle<v8::Value> valV8 = converter->ToV8Value( | 243 v8::Handle<v8::Value> valV8 = converter->ToV8Value( |
243 &intent_data.mime_data, v8::Context::GetCurrent()); | 244 &intent_data.mime_data, v8::Context::GetCurrent()); |
244 | 245 |
245 WebSerializedScriptValue serialized_data = | 246 WebSerializedScriptValue serialized_data = |
246 WebSerializedScriptValue::serialize(valV8); | 247 WebSerializedScriptValue::serialize(valV8); |
247 return WebIntent::create(intent_data.action, intent_data.type, | 248 return WebIntent::create(intent_data.action, intent_data.type, |
248 serialized_data.toString(), | 249 serialized_data.toString(), |
249 WebVector<WebString>(), WebVector<WebString>()); | 250 WebVector<WebString>(), WebVector<WebString>()); |
250 } | 251 } |
251 } | 252 } |
252 | 253 |
253 NOTREACHED(); | 254 NOTREACHED(); |
254 return WebIntent(); | 255 return WebIntent(); |
255 } | 256 } |
| 257 |
| 258 } // namespace content |
OLD | NEW |