Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2065)

Side by Side Diff: content/renderer/web_intents_host.cc

Issue 11026070: Add API to construct new vector interchange MIME data type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comment changes Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // TODO(gbillock): match to spec to double-check registration match before 124 // TODO(gbillock): match to spec to double-check registration match before
124 // delivery. 125 // delivery.
125 void WebIntentsHost::DidClearWindowObject(WebFrame* frame) { 126 void WebIntentsHost::DidClearWindowObject(WebFrame* frame) {
126 if (intent_.get() == NULL || frame->top() != frame) 127 if (intent_.get() == NULL || frame->top() != frame)
127 return; 128 return;
128 129
129 if (!delivered_intent_client_.get()) { 130 if (!delivered_intent_client_.get()) {
130 delivered_intent_client_.reset(new DeliveredIntentClientImpl(this)); 131 delivered_intent_client_.reset(new DeliveredIntentClientImpl(this));
131 } 132 }
132 133
133 WebVector<WebString> extras_keys(intent_->extra_data.size()); 134 v8::HandleScope scope;
134 WebVector<WebString> extras_values(intent_->extra_data.size()); 135 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext();
135 std::map<string16, string16>::iterator iter; 136 v8::Context::Scope cscope(ctx);
136 int i; 137 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
137 for (i = 0, iter = intent_->extra_data.begin(); 138
138 iter != intent_->extra_data.end(); 139 if (!web_intent.action().isEmpty())
140 frame->deliverIntent(web_intent, NULL, delivered_intent_client_.get());
141 }
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::GetCurrent().IsEmpty());
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();
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) {
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,
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()),
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::Array> dataV8 =
209 v8::Array::New(intent_data.mime_data.GetSize());
210 size_t j;
211 for (j = 0; j < intent_data.mime_data.GetSize(); ++j) {
212 const DictionaryValue* val;
213 if (!intent_data.mime_data.GetDictionary(j, &val)) continue;
214 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.
215 v8::Handle<v8::Value> data_point_value =
216 converter->ToV8Value(val, ctx);
217 if (!data_point_value->IsObject()) continue;
218 v8::Handle<v8::Object> data_point = data_point_value->ToObject();
219 if (j == 0 && !intent_data.blob_file.empty()) {
220 // If we are carrying blob data, convert it to v8 format
221 // and set it to the "blob" property of |data_point|.
222 web_blob_ = WebBlob::createFromFile(
223 WebString::fromUTF8(intent_data.blob_file.AsUTF8Unsafe()),
224 intent_data.blob_length);
225 v8::Local<v8::String> blob_v8_key = v8::String::New("blob", 4);
226 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.
227 }
228 dataV8->Set(j, data_point);
229 }
230
231 WebSerializedScriptValue serialized_data =
232 WebSerializedScriptValue::serialize(dataV8);
233 return WebIntent::create(intent_data.action, intent_data.type,
234 serialized_data.toString(),
235 WebVector<WebString>(), WebVector<WebString>());
196 } 236 }
197 237
198 if (!web_intent.action().isEmpty()) 238 NOTREACHED();
199 frame->deliverIntent(web_intent, NULL, delivered_intent_client_.get()); 239 return WebIntent();
200 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698