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

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: 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 v8::Local<v8::String> dataV8 = v8::String::New( 155 v8::Local<v8::String> dataV8 = v8::String::New(
155 reinterpret_cast<const uint16_t*>(intent_->unserialized_data.data()), 156 reinterpret_cast<const uint16_t*>(intent_->unserialized_data.data()),
156 static_cast<int>(intent_->unserialized_data.length())); 157 static_cast<int>(intent_->unserialized_data.length()));
157 WebSerializedScriptValue serialized_data = 158 WebSerializedScriptValue serialized_data =
158 WebSerializedScriptValue::serialize(dataV8); 159 WebSerializedScriptValue::serialize(dataV8);
159 160
160 web_intent = WebIntent::create(intent_->action, intent_->type, 161 web_intent = WebIntent::create(intent_->action, intent_->type,
161 serialized_data.toString(), 162 serialized_data.toString(),
162 extras_keys, extras_values); 163 extras_keys, extras_values);
163 } else if (intent_->data_type == webkit_glue::WebIntentData::BLOB) { 164 } else if (intent_->data_type == webkit_glue::WebIntentData::BLOB) {
164 DCHECK(intent_->data_type == webkit_glue::WebIntentData::BLOB);
165 web_blob_ = WebBlob::createFromFile( 165 web_blob_ = WebBlob::createFromFile(
166 WebString::fromUTF8(intent_->blob_file.AsUTF8Unsafe()), 166 WebString::fromUTF8(intent_->blob_file.AsUTF8Unsafe()),
167 intent_->blob_length); 167 intent_->blob_length);
168 WebSerializedScriptValue serialized_data = 168 WebSerializedScriptValue serialized_data =
169 WebSerializedScriptValue::serialize(web_blob_.toV8Value()); 169 WebSerializedScriptValue::serialize(web_blob_.toV8Value());
170 web_intent = WebIntent::create(intent_->action, intent_->type, 170 web_intent = WebIntent::create(intent_->action, intent_->type,
171 serialized_data.toString(), 171 serialized_data.toString(),
172 extras_keys, extras_values); 172 extras_keys, extras_values);
173 } else if (intent_->data_type == webkit_glue::WebIntentData::FILESYSTEM) { 173 } else if (intent_->data_type == webkit_glue::WebIntentData::FILESYSTEM) {
174 const GURL origin = GURL(frame->document().securityOrigin().toString()); 174 const GURL origin = GURL(frame->document().securityOrigin().toString());
175 const GURL root_url = 175 const GURL root_url =
176 fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated); 176 fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated);
177 const std::string url = base::StringPrintf( 177 const std::string url = base::StringPrintf(
178 "%s%s/%s/", 178 "%s%s/%s/",
179 root_url.spec().c_str(), 179 root_url.spec().c_str(),
180 intent_->filesystem_id.c_str(), 180 intent_->filesystem_id.c_str(),
181 intent_->root_name.c_str()); 181 intent_->root_name.c_str());
182 // TODO(kmadhusu): This is a temporary hack to create a serializable file 182 // 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, 183 // system. Once we have a better way to create a serializable file system,
184 // remove this hack. 184 // remove this hack.
185 v8::Handle<v8::Value> filesystem_V8 = frame->createSerializableFileSystem( 185 v8::Handle<v8::Value> filesystem_V8 = frame->createSerializableFileSystem(
186 WebKit::WebFileSystem::TypeIsolated, 186 WebKit::WebFileSystem::TypeIsolated,
187 WebKit::WebString::fromUTF8(intent_->root_name), 187 WebKit::WebString::fromUTF8(intent_->root_name),
188 WebKit::WebString::fromUTF8(url)); 188 WebKit::WebString::fromUTF8(url));
189 WebSerializedScriptValue serialized_data = 189 WebSerializedScriptValue serialized_data =
190 WebSerializedScriptValue::serialize(filesystem_V8); 190 WebSerializedScriptValue::serialize(filesystem_V8);
191 web_intent = WebIntent::create(intent_->action, intent_->type, 191 web_intent = WebIntent::create(intent_->action, intent_->type,
192 serialized_data.toString(), 192 serialized_data.toString(),
193 extras_keys, extras_values); 193 extras_keys, extras_values);
194 } else if (intent_->data_type == webkit_glue::WebIntentData::MIME_TYPE) {
195 // Do stuffs.
groby-ooo-7-16 2012/10/05 17:56:35 You're fixing that comment, right? ;)
Greg Billock 2012/10/05 22:03:26 :-) On 2012/10/05 17:56:35, groby wrote:
196 scoped_ptr<content::V8ValueConverter> converter(
197 content::V8ValueConverter::create());
198 v8::Handle<v8::Array> dataV8 = v8::Array::New(intent_->mime_data.GetSize());
199 size_t j;
200 for (j = 0; j < intent_->mime_data.GetSize(); ++j) {
201 const DictionaryValue* val;
202 if (!intent_->mime_data.GetDictionary(j, &val)) continue;
203 v8::Handle<v8::Value> data_point_value =
204 converter->ToV8Value(val, ctx);
205 if (!data_point_value->IsObject()) continue;
206 v8::Handle<v8::Object> data_point = data_point_value->ToObject();
207 if (j == 0 && !intent_->blob_file.empty()) {
groby-ooo-7-16 2012/10/05 17:56:35 This seems odd in here. Can we actually have blob
Greg Billock 2012/10/05 22:03:26 Yes. It's just a struct. I'm not sure how else to
208 // If we are carrying blob data, convert it to v8 format
209 // and set it to the "blob" property of |data_point|.
210 web_blob_ = WebBlob::createFromFile(
211 WebString::fromUTF8(intent_->blob_file.AsUTF8Unsafe()),
212 intent_->blob_length);
213 v8::Local<v8::String> blob_v8_key = v8::String::New("blob", 4);
214 data_point->Set(blob_v8_key, web_blob_.toV8Value());
215 }
216 dataV8->Set(j, data_point);
217 }
218
219 WebSerializedScriptValue serialized_data =
220 WebSerializedScriptValue::serialize(dataV8);
221 web_intent = WebIntent::create(intent_->action, intent_->type,
groby-ooo-7-16 2012/10/05 17:56:35 Can we take the last two lines out of all the sepa
Greg Billock 2012/10/05 22:03:26 Good point. Will do. On 2012/10/05 17:56:35, grob
222 serialized_data.toString(),
223 extras_keys, extras_values);
194 } else { 224 } else {
195 NOTREACHED(); 225 NOTREACHED();
196 } 226 }
197 227
198 if (!web_intent.action().isEmpty()) 228 if (!web_intent.action().isEmpty())
199 frame->deliverIntent(web_intent, NULL, delivered_intent_client_.get()); 229 frame->deliverIntent(web_intent, NULL, delivered_intent_client_.get());
200 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698