Chromium Code Reviews| 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/renderer/render_view_impl.h" | 12 #include "content/renderer/render_view_impl.h" |
| 12 #include "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlob.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlob.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeliveredIntentCli ent.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeliveredIntentCli ent.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste m.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste m.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 26 #include "v8/include/v8.h" | |
| 27 #include "webkit/fileapi/file_system_util.h" | 27 #include "webkit/fileapi/file_system_util.h" |
| 28 #include "webkit/glue/cpp_bound_class.h" | 28 #include "webkit/glue/cpp_bound_class.h" |
| 29 | 29 |
| 30 using WebKit::WebBindings; | 30 using WebKit::WebBindings; |
| 31 using WebKit::WebBlob; | 31 using WebKit::WebBlob; |
| 32 using WebKit::WebCString; | 32 using WebKit::WebCString; |
| 33 using WebKit::WebDeliveredIntentClient; | 33 using WebKit::WebDeliveredIntentClient; |
| 34 using WebKit::WebFrame; | 34 using WebKit::WebFrame; |
| 35 using WebKit::WebIntent; | 35 using WebKit::WebIntent; |
| 36 using WebKit::WebIntentRequest; | 36 using WebKit::WebIntentRequest; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 } | 113 } |
| 114 | 114 |
| 115 void WebIntentsHost::OnFailure(const WebKit::WebString& data) { | 115 void WebIntentsHost::OnFailure(const WebKit::WebString& data) { |
| 116 Send(new IntentsHostMsg_WebIntentReply( | 116 Send(new IntentsHostMsg_WebIntentReply( |
| 117 routing_id(), webkit_glue::WEB_INTENT_REPLY_FAILURE, data)); | 117 routing_id(), webkit_glue::WEB_INTENT_REPLY_FAILURE, data)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // We set the intent payload into all top-level frame window objects. This | 120 // We set the intent payload into all top-level frame window objects. This |
| 121 // should persist the data through redirects, and not deliver it to any | 121 // should persist the data through redirects, and not deliver it to any |
| 122 // sub-frames. | 122 // sub-frames. |
| 123 // TODO(gbillock): match to spec to double-check registration match before | 123 void WebIntentsHost::DidCreateScriptContext(WebKit::WebFrame* frame, |
| 124 // delivery. | 124 v8::Handle<v8::Context> ctx, |
| 125 void WebIntentsHost::DidClearWindowObject(WebFrame* frame) { | 125 int extension_group, |
| 126 int world_id) { | |
| 126 if (intent_.get() == NULL || frame->top() != frame) | 127 if (intent_.get() == NULL || frame->top() != frame) |
| 127 return; | 128 return; |
| 128 | 129 |
| 130 if (ctx != frame->mainWorldScriptContext()) | |
| 131 return; | |
| 132 | |
| 129 if (!delivered_intent_client_.get()) { | 133 if (!delivered_intent_client_.get()) { |
| 130 delivered_intent_client_.reset(new DeliveredIntentClientImpl(this)); | 134 delivered_intent_client_.reset(new DeliveredIntentClientImpl(this)); |
| 131 } | 135 } |
| 132 | 136 |
| 133 WebVector<WebString> extras_keys(intent_->extra_data.size()); | 137 WebIntent web_intent = CreateWebIntent(frame, *(intent_.get())); |
|
jamesr
2012/10/15 01:58:29
scoped_ptr<> has an operator* so you can say just
Greg Billock
2012/10/15 19:23:33
Done.
| |
| 134 WebVector<WebString> extras_values(intent_->extra_data.size()); | 138 |
| 135 std::map<string16, string16>::iterator iter; | 139 if (!web_intent.action().isEmpty()) |
| 136 int i; | 140 frame->deliverIntent(web_intent, NULL, delivered_intent_client_.get()); |
| 137 for (i = 0, iter = intent_->extra_data.begin(); | 141 } |
| 138 iter != intent_->extra_data.end(); | 142 |
| 143 WebIntent WebIntentsHost::CreateWebIntent( | |
| 144 WebFrame* frame, const webkit_glue::WebIntentData& intent_data) { | |
| 145 // Must be called with v8 scope held. | |
| 146 DCHECK(v8::Context::InContext()); | |
| 147 | |
| 148 // TODO(gbillock): Remove this block when we get rid of |extras|. | |
| 149 WebVector<WebString> extras_keys(intent_data.extra_data.size()); | |
| 150 WebVector<WebString> extras_values(intent_data.extra_data.size()); | |
| 151 std::map<string16, string16>::const_iterator iter; | |
| 152 size_t i; | |
| 153 for (i = 0, iter = intent_data.extra_data.begin(); | |
|
jamesr
2012/10/15 01:58:29
nit: i would scope the loop counter and iterator i
Greg Billock
2012/10/15 19:23:33
The compiler gets confused that the two initializa
| |
| 154 iter != intent_data.extra_data.end(); | |
| 139 ++i, ++iter) { | 155 ++i, ++iter) { |
| 140 extras_keys[i] = iter->first; | 156 extras_keys[i] = iter->first; |
| 141 extras_values[i] = iter->second; | 157 extras_values[i] = iter->second; |
| 142 } | 158 } |
| 143 | 159 |
| 144 v8::HandleScope scope; | 160 if (intent_data.data_type == webkit_glue::WebIntentData::SERIALIZED) { |
|
jamesr
2012/10/15 01:58:29
This big else-if ladder chain should be a switch s
Greg Billock
2012/10/15 19:23:33
Done.
| |
| 145 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext(); | 161 return WebIntent::create(intent_data.action, intent_data.type, |
| 146 v8::Context::Scope cscope(ctx); | 162 intent_data.data, |
|
jamesr
2012/10/15 01:58:29
this doesn't appear to be aligned correctly
Greg Billock
2012/10/15 19:23:33
Weird. It shows up right in my editor. Deletion do
| |
| 147 WebIntent web_intent; | 163 extras_keys, extras_values); |
| 148 | 164 } else if (intent_data.data_type == |
| 149 if (intent_->data_type == webkit_glue::WebIntentData::SERIALIZED) { | 165 webkit_glue::WebIntentData::UNSERIALIZED) { |
| 150 web_intent = WebIntent::create(intent_->action, intent_->type, | |
| 151 intent_->data, | |
| 152 extras_keys, extras_values); | |
| 153 } else if (intent_->data_type == webkit_glue::WebIntentData::UNSERIALIZED) { | |
| 154 v8::Local<v8::String> dataV8 = v8::String::New( | 166 v8::Local<v8::String> dataV8 = v8::String::New( |
| 155 reinterpret_cast<const uint16_t*>(intent_->unserialized_data.data()), | 167 reinterpret_cast<const uint16_t*>(intent_data.unserialized_data.data()), |
|
jamesr
2012/10/15 01:58:29
I'm a bit surprised by this reinterpret_cast<> - u
Greg Billock
2012/10/15 19:23:33
Agreed this is unexpected. The windows compiler ge
| |
| 156 static_cast<int>(intent_->unserialized_data.length())); | 168 static_cast<int>(intent_data.unserialized_data.length())); |
| 157 WebSerializedScriptValue serialized_data = | 169 WebSerializedScriptValue serialized_data = |
| 158 WebSerializedScriptValue::serialize(dataV8); | 170 WebSerializedScriptValue::serialize(dataV8); |
| 159 | 171 |
| 160 web_intent = WebIntent::create(intent_->action, intent_->type, | 172 return WebIntent::create(intent_data.action, intent_data.type, |
| 161 serialized_data.toString(), | 173 serialized_data.toString(), |
| 162 extras_keys, extras_values); | 174 extras_keys, extras_values); |
| 163 } else if (intent_->data_type == webkit_glue::WebIntentData::BLOB) { | 175 } else if (intent_data.data_type == webkit_glue::WebIntentData::BLOB) { |
| 164 DCHECK(intent_->data_type == webkit_glue::WebIntentData::BLOB); | |
| 165 web_blob_ = WebBlob::createFromFile( | 176 web_blob_ = WebBlob::createFromFile( |
| 166 WebString::fromUTF8(intent_->blob_file.AsUTF8Unsafe()), | 177 WebString::fromUTF8(intent_data.blob_file.AsUTF8Unsafe()), |
| 167 intent_->blob_length); | 178 intent_data.blob_length); |
| 168 WebSerializedScriptValue serialized_data = | 179 WebSerializedScriptValue serialized_data = |
| 169 WebSerializedScriptValue::serialize(web_blob_.toV8Value()); | 180 WebSerializedScriptValue::serialize(web_blob_.toV8Value()); |
| 170 web_intent = WebIntent::create(intent_->action, intent_->type, | 181 return WebIntent::create(intent_data.action, intent_data.type, |
| 171 serialized_data.toString(), | 182 serialized_data.toString(), |
| 172 extras_keys, extras_values); | 183 extras_keys, extras_values); |
| 173 } else if (intent_->data_type == webkit_glue::WebIntentData::FILESYSTEM) { | 184 } else if (intent_data.data_type == webkit_glue::WebIntentData::FILESYSTEM) { |
| 174 const GURL origin = GURL(frame->document().securityOrigin().toString()); | 185 const GURL origin = GURL(frame->document().securityOrigin().toString()); |
| 175 const GURL root_url = | 186 const GURL root_url = |
| 176 fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated); | 187 fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated); |
| 177 const std::string url = base::StringPrintf( | 188 const std::string url = base::StringPrintf( |
| 178 "%s%s/%s/", | 189 "%s%s/%s/", |
| 179 root_url.spec().c_str(), | 190 root_url.spec().c_str(), |
| 180 intent_->filesystem_id.c_str(), | 191 intent_data.filesystem_id.c_str(), |
| 181 intent_->root_name.c_str()); | 192 intent_data.root_name.c_str()); |
| 182 // TODO(kmadhusu): This is a temporary hack to create a serializable file | 193 // TODO(kmadhusu): This is a temporary hack to create a serializable file |
| 183 // system. Once we have a better way to create a serializable file system, | 194 // system. Once we have a better way to create a serializable file system, |
| 184 // remove this hack. | 195 // remove this hack. |
| 185 v8::Handle<v8::Value> filesystem_V8 = frame->createSerializableFileSystem( | 196 v8::Handle<v8::Value> filesystem_V8 = frame->createSerializableFileSystem( |
| 186 WebKit::WebFileSystem::TypeIsolated, | 197 WebKit::WebFileSystem::TypeIsolated, |
| 187 WebKit::WebString::fromUTF8(intent_->root_name), | 198 WebKit::WebString::fromUTF8(intent_data.root_name), |
| 188 WebKit::WebString::fromUTF8(url)); | 199 WebKit::WebString::fromUTF8(url)); |
| 189 WebSerializedScriptValue serialized_data = | 200 WebSerializedScriptValue serialized_data = |
| 190 WebSerializedScriptValue::serialize(filesystem_V8); | 201 WebSerializedScriptValue::serialize(filesystem_V8); |
| 191 web_intent = WebIntent::create(intent_->action, intent_->type, | 202 return WebIntent::create(intent_data.action, intent_data.type, |
| 192 serialized_data.toString(), | 203 serialized_data.toString(), |
| 193 extras_keys, extras_values); | 204 extras_keys, extras_values); |
| 194 } else { | 205 } else if (intent_data.data_type == webkit_glue::WebIntentData::MIME_TYPE) { |
| 195 NOTREACHED(); | 206 scoped_ptr<content::V8ValueConverter> converter( |
| 207 content::V8ValueConverter::create()); | |
| 208 v8::Handle<v8::Value> valV8 = converter->ToV8Value( | |
| 209 &intent_data.mime_data, v8::Context::GetCurrent()); | |
| 210 | |
| 211 WebSerializedScriptValue serialized_data = | |
| 212 WebSerializedScriptValue::serialize(valV8); | |
| 213 return WebIntent::create(intent_data.action, intent_data.type, | |
| 214 serialized_data.toString(), | |
| 215 WebVector<WebString>(), WebVector<WebString>()); | |
| 196 } | 216 } |
| 197 | 217 |
| 198 if (!web_intent.action().isEmpty()) | 218 NOTREACHED(); |
| 199 frame->deliverIntent(web_intent, NULL, delivered_intent_client_.get()); | 219 return WebIntent(); |
| 200 } | 220 } |
| OLD | NEW |