Chromium Code Reviews| Index: content/renderer/web_intents_host.cc |
| diff --git a/content/renderer/web_intents_host.cc b/content/renderer/web_intents_host.cc |
| index 9c60da3529fcf5f99ced41035fcc56b57fa0142a..078bb83420ccfdac89fd361d79f40156084b59b4 100644 |
| --- a/content/renderer/web_intents_host.cc |
| +++ b/content/renderer/web_intents_host.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/bind_helpers.h" |
| #include "base/utf_string_conversions.h" |
| #include "content/common/intents_messages.h" |
| +#include "content/public/renderer/v8_value_converter.h" |
| #include "content/renderer/render_view_impl.h" |
| #include "ipc/ipc_message.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| @@ -130,71 +131,110 @@ void WebIntentsHost::DidClearWindowObject(WebFrame* frame) { |
| delivered_intent_client_.reset(new DeliveredIntentClientImpl(this)); |
| } |
| - WebVector<WebString> extras_keys(intent_->extra_data.size()); |
| - WebVector<WebString> extras_values(intent_->extra_data.size()); |
| - std::map<string16, string16>::iterator iter; |
| - int i; |
| - for (i = 0, iter = intent_->extra_data.begin(); |
| - iter != intent_->extra_data.end(); |
| + v8::HandleScope scope; |
| + v8::Local<v8::Context> ctx = frame->mainWorldScriptContext(); |
| + v8::Context::Scope cscope(ctx); |
| + WebIntent web_intent = CreateWebIntent(frame, *(intent_.get())); |
|
abarth-chromium
2012/10/11 19:29:34
Why do you need to enter a V8 context before creat
Greg Billock
2012/10/11 19:48:54
The comment says "Returns the V8 context for this
|
| + |
| + if (!web_intent.action().isEmpty()) |
| + frame->deliverIntent(web_intent, NULL, delivered_intent_client_.get()); |
| +} |
| + |
| +WebIntent WebIntentsHost::CreateWebIntent( |
| + WebFrame* frame, const webkit_glue::WebIntentData& intent_data) { |
| + // Must be called with v8 scope held. |
| + DCHECK(!v8::Context::GetCurrent().IsEmpty()); |
| + |
| + // TODO(gbillock): Remove this block when we get rid of |extras|. |
| + WebVector<WebString> extras_keys(intent_data.extra_data.size()); |
| + WebVector<WebString> extras_values(intent_data.extra_data.size()); |
| + std::map<string16, string16>::const_iterator iter; |
| + size_t i; |
| + for (i = 0, iter = intent_data.extra_data.begin(); |
| + iter != intent_data.extra_data.end(); |
| ++i, ++iter) { |
| extras_keys[i] = iter->first; |
| extras_values[i] = iter->second; |
| } |
| - v8::HandleScope scope; |
| - v8::Local<v8::Context> ctx = frame->mainWorldScriptContext(); |
| - v8::Context::Scope cscope(ctx); |
| - WebIntent web_intent; |
| - |
| - if (intent_->data_type == webkit_glue::WebIntentData::SERIALIZED) { |
| - web_intent = WebIntent::create(intent_->action, intent_->type, |
| - intent_->data, |
| - extras_keys, extras_values); |
| - } else if (intent_->data_type == webkit_glue::WebIntentData::UNSERIALIZED) { |
| + if (intent_data.data_type == webkit_glue::WebIntentData::SERIALIZED) { |
| + return WebIntent::create(intent_data.action, intent_data.type, |
| + intent_data.data, |
| + extras_keys, extras_values); |
| + } else if (intent_data.data_type == |
| + webkit_glue::WebIntentData::UNSERIALIZED) { |
| v8::Local<v8::String> dataV8 = v8::String::New( |
| - reinterpret_cast<const uint16_t*>(intent_->unserialized_data.data()), |
| - static_cast<int>(intent_->unserialized_data.length())); |
| + reinterpret_cast<const uint16_t*>(intent_data.unserialized_data.data()), |
| + static_cast<int>(intent_data.unserialized_data.length())); |
| WebSerializedScriptValue serialized_data = |
| WebSerializedScriptValue::serialize(dataV8); |
| - web_intent = WebIntent::create(intent_->action, intent_->type, |
| - serialized_data.toString(), |
| - extras_keys, extras_values); |
| - } else if (intent_->data_type == webkit_glue::WebIntentData::BLOB) { |
| - DCHECK(intent_->data_type == webkit_glue::WebIntentData::BLOB); |
| + return WebIntent::create(intent_data.action, intent_data.type, |
| + serialized_data.toString(), |
| + extras_keys, extras_values); |
| + } else if (intent_data.data_type == webkit_glue::WebIntentData::BLOB) { |
| web_blob_ = WebBlob::createFromFile( |
| - WebString::fromUTF8(intent_->blob_file.AsUTF8Unsafe()), |
| - intent_->blob_length); |
| + WebString::fromUTF8(intent_data.blob_file.AsUTF8Unsafe()), |
| + intent_data.blob_length); |
| WebSerializedScriptValue serialized_data = |
| WebSerializedScriptValue::serialize(web_blob_.toV8Value()); |
| - web_intent = WebIntent::create(intent_->action, intent_->type, |
| - serialized_data.toString(), |
| - extras_keys, extras_values); |
| - } else if (intent_->data_type == webkit_glue::WebIntentData::FILESYSTEM) { |
| + return WebIntent::create(intent_data.action, intent_data.type, |
| + serialized_data.toString(), |
| + extras_keys, extras_values); |
| + } else if (intent_data.data_type == webkit_glue::WebIntentData::FILESYSTEM) { |
| const GURL origin = GURL(frame->document().securityOrigin().toString()); |
| const GURL root_url = |
| fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated); |
| const std::string url = base::StringPrintf( |
| "%s%s/%s/", |
| root_url.spec().c_str(), |
| - intent_->filesystem_id.c_str(), |
| - intent_->root_name.c_str()); |
| + intent_data.filesystem_id.c_str(), |
| + intent_data.root_name.c_str()); |
| // TODO(kmadhusu): This is a temporary hack to create a serializable file |
| // system. Once we have a better way to create a serializable file system, |
| // remove this hack. |
| v8::Handle<v8::Value> filesystem_V8 = frame->createSerializableFileSystem( |
| WebKit::WebFileSystem::TypeIsolated, |
| - WebKit::WebString::fromUTF8(intent_->root_name), |
| + WebKit::WebString::fromUTF8(intent_data.root_name), |
| WebKit::WebString::fromUTF8(url)); |
| WebSerializedScriptValue serialized_data = |
| WebSerializedScriptValue::serialize(filesystem_V8); |
| - web_intent = WebIntent::create(intent_->action, intent_->type, |
| - serialized_data.toString(), |
| - extras_keys, extras_values); |
| - } else { |
| - NOTREACHED(); |
| + return WebIntent::create(intent_data.action, intent_data.type, |
| + serialized_data.toString(), |
| + extras_keys, extras_values); |
| + } else if (intent_data.data_type == webkit_glue::WebIntentData::MIME_TYPE) { |
| + scoped_ptr<content::V8ValueConverter> converter( |
| + content::V8ValueConverter::create()); |
| + v8::Handle<v8::Array> dataV8 = |
| + v8::Array::New(intent_data.mime_data.GetSize()); |
| + size_t j; |
| + for (j = 0; j < intent_data.mime_data.GetSize(); ++j) { |
| + const DictionaryValue* val; |
| + if (!intent_data.mime_data.GetDictionary(j, &val)) continue; |
| + v8::Local<v8::Context> ctx = frame->mainWorldScriptContext(); |
|
abarth-chromium
2012/10/11 19:29:34
Do we need to call this API for every iteration of
Greg Billock
2012/10/11 19:48:54
This needs to be the same as the current context.
|
| + v8::Handle<v8::Value> data_point_value = |
| + converter->ToV8Value(val, ctx); |
| + if (!data_point_value->IsObject()) continue; |
| + v8::Handle<v8::Object> data_point = data_point_value->ToObject(); |
| + if (j == 0 && !intent_data.blob_file.empty()) { |
| + // If we are carrying blob data, convert it to v8 format |
| + // and set it to the "blob" property of |data_point|. |
| + web_blob_ = WebBlob::createFromFile( |
| + WebString::fromUTF8(intent_data.blob_file.AsUTF8Unsafe()), |
| + intent_data.blob_length); |
| + v8::Local<v8::String> blob_v8_key = v8::String::New("blob", 4); |
| + data_point->Set(blob_v8_key, web_blob_.toV8Value()); |
|
abarth-chromium
2012/10/11 19:29:34
How do you know that this call to Set won't call a
Greg Billock
2012/10/11 19:48:54
This is data-for-serialization that I'm creating.
|
| + } |
| + dataV8->Set(j, data_point); |
| + } |
| + |
| + WebSerializedScriptValue serialized_data = |
| + WebSerializedScriptValue::serialize(dataV8); |
| + return WebIntent::create(intent_data.action, intent_data.type, |
| + serialized_data.toString(), |
| + WebVector<WebString>(), WebVector<WebString>()); |
| } |
| - if (!web_intent.action().isEmpty()) |
| - frame->deliverIntent(web_intent, NULL, delivered_intent_client_.get()); |
| + NOTREACHED(); |
| + return WebIntent(); |
| } |