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

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: Export symbol needed for test 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()));
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 // Must be called with v8 scope held.
groby-ooo-7-16 2012/10/08 19:01:04 Can we DCHECK for that?
Greg Billock 2012/10/08 21:26:35 I think I got the right thing here now. On 2012/1
144 WebIntent WebIntentsHost::CreateWebIntent(
145 WebFrame* frame, const webkit_glue::WebIntentData& intent_data) {
146 // TODO(gbillock): Remove this block when we get rid of |extras|.
147 WebVector<WebString> extras_keys(intent_data.extra_data.size());
148 WebVector<WebString> extras_values(intent_data.extra_data.size());
149 std::map<string16, string16>::const_iterator iter;
150 size_t i;
151 for (i = 0, iter = intent_data.extra_data.begin();
152 iter != intent_data.extra_data.end();
139 ++i, ++iter) { 153 ++i, ++iter) {
140 extras_keys[i] = iter->first; 154 extras_keys[i] = iter->first;
141 extras_values[i] = iter->second; 155 extras_values[i] = iter->second;
142 } 156 }
143 157
144 v8::HandleScope scope; 158 if (intent_data.data_type == webkit_glue::WebIntentData::SERIALIZED) {
145 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext(); 159 return WebIntent::create(intent_data.action, intent_data.type,
146 v8::Context::Scope cscope(ctx); 160 intent_data.data,
147 WebIntent web_intent; 161 extras_keys, extras_values);
148 162 } else if (intent_data.data_type ==
149 if (intent_->data_type == webkit_glue::WebIntentData::SERIALIZED) { 163 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( 164 v8::Local<v8::String> dataV8 = v8::String::New(
155 reinterpret_cast<const uint16_t*>(intent_->unserialized_data.data()), 165 reinterpret_cast<const uint16_t*>(intent_data.unserialized_data.data()),
156 static_cast<int>(intent_->unserialized_data.length())); 166 static_cast<int>(intent_data.unserialized_data.length()));
157 WebSerializedScriptValue serialized_data = 167 WebSerializedScriptValue serialized_data =
158 WebSerializedScriptValue::serialize(dataV8); 168 WebSerializedScriptValue::serialize(dataV8);
159 169
160 web_intent = WebIntent::create(intent_->action, intent_->type, 170 return WebIntent::create(intent_data.action, intent_data.type,
161 serialized_data.toString(), 171 serialized_data.toString(),
162 extras_keys, extras_values); 172 extras_keys, extras_values);
163 } else if (intent_->data_type == webkit_glue::WebIntentData::BLOB) { 173 } else if (intent_data.data_type == webkit_glue::WebIntentData::BLOB) {
164 DCHECK(intent_->data_type == webkit_glue::WebIntentData::BLOB);
165 web_blob_ = WebBlob::createFromFile( 174 web_blob_ = WebBlob::createFromFile(
166 WebString::fromUTF8(intent_->blob_file.AsUTF8Unsafe()), 175 WebString::fromUTF8(intent_data.blob_file.AsUTF8Unsafe()),
167 intent_->blob_length); 176 intent_data.blob_length);
168 WebSerializedScriptValue serialized_data = 177 WebSerializedScriptValue serialized_data =
169 WebSerializedScriptValue::serialize(web_blob_.toV8Value()); 178 WebSerializedScriptValue::serialize(web_blob_.toV8Value());
170 web_intent = WebIntent::create(intent_->action, intent_->type, 179 return WebIntent::create(intent_data.action, intent_data.type,
171 serialized_data.toString(), 180 serialized_data.toString(),
172 extras_keys, extras_values); 181 extras_keys, extras_values);
173 } else if (intent_->data_type == webkit_glue::WebIntentData::FILESYSTEM) { 182 } else if (intent_data.data_type == webkit_glue::WebIntentData::FILESYSTEM) {
174 const GURL origin = GURL(frame->document().securityOrigin().toString()); 183 const GURL origin = GURL(frame->document().securityOrigin().toString());
175 const GURL root_url = 184 const GURL root_url =
176 fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated); 185 fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated);
177 const std::string url = base::StringPrintf( 186 const std::string url = base::StringPrintf(
178 "%s%s/%s/", 187 "%s%s/%s/",
179 root_url.spec().c_str(), 188 root_url.spec().c_str(),
180 intent_->filesystem_id.c_str(), 189 intent_data.filesystem_id.c_str(),
181 intent_->root_name.c_str()); 190 intent_data.root_name.c_str());
182 // TODO(kmadhusu): This is a temporary hack to create a serializable file 191 // 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, 192 // system. Once we have a better way to create a serializable file system,
184 // remove this hack. 193 // remove this hack.
185 v8::Handle<v8::Value> filesystem_V8 = frame->createSerializableFileSystem( 194 v8::Handle<v8::Value> filesystem_V8 = frame->createSerializableFileSystem(
186 WebKit::WebFileSystem::TypeIsolated, 195 WebKit::WebFileSystem::TypeIsolated,
187 WebKit::WebString::fromUTF8(intent_->root_name), 196 WebKit::WebString::fromUTF8(intent_data.root_name),
188 WebKit::WebString::fromUTF8(url)); 197 WebKit::WebString::fromUTF8(url));
189 WebSerializedScriptValue serialized_data = 198 WebSerializedScriptValue serialized_data =
190 WebSerializedScriptValue::serialize(filesystem_V8); 199 WebSerializedScriptValue::serialize(filesystem_V8);
191 web_intent = WebIntent::create(intent_->action, intent_->type, 200 return WebIntent::create(intent_data.action, intent_data.type,
groby-ooo-7-16 2012/10/08 19:01:04 serialize/create is still shared across a lot of t
Greg Billock 2012/10/08 21:26:35 The trouble is the |data| -- I think we'll end up
192 serialized_data.toString(), 201 serialized_data.toString(),
193 extras_keys, extras_values); 202 extras_keys, extras_values);
203 } else if (intent_data.data_type == webkit_glue::WebIntentData::MIME_TYPE) {
204 scoped_ptr<content::V8ValueConverter> converter(
205 content::V8ValueConverter::create());
206 v8::Handle<v8::Array> dataV8 =
207 v8::Array::New(intent_data.mime_data.GetSize());
208 size_t j;
209 for (j = 0; j < intent_data.mime_data.GetSize(); ++j) {
210 const DictionaryValue* val;
211 if (!intent_data.mime_data.GetDictionary(j, &val)) continue;
212 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext();
213 v8::Handle<v8::Value> data_point_value =
214 converter->ToV8Value(val, ctx);
215 if (!data_point_value->IsObject()) continue;
216 v8::Handle<v8::Object> data_point = data_point_value->ToObject();
217 if (j == 0 && !intent_data.blob_file.empty()) {
218 // If we are carrying blob data, convert it to v8 format
219 // and set it to the "blob" property of |data_point|.
220 web_blob_ = WebBlob::createFromFile(
221 WebString::fromUTF8(intent_data.blob_file.AsUTF8Unsafe()),
222 intent_data.blob_length);
223 v8::Local<v8::String> blob_v8_key = v8::String::New("blob", 4);
224 data_point->Set(blob_v8_key, web_blob_.toV8Value());
225 }
226 dataV8->Set(j, data_point);
227 }
228
229 WebSerializedScriptValue serialized_data =
230 WebSerializedScriptValue::serialize(dataV8);
231 return WebIntent::create(intent_data.action, intent_data.type,
232 serialized_data.toString(),
233 WebVector<WebString>(), WebVector<WebString>());
194 } else { 234 } else {
195 NOTREACHED(); 235 NOTREACHED();
236 return WebIntent();
groby-ooo-7-16 2012/10/08 19:01:04 Let's take out the whole else branch and just NOTR
Greg Billock 2012/10/08 21:26:35 Done.
196 } 237 }
197
198 if (!web_intent.action().isEmpty())
199 frame->deliverIntent(web_intent, NULL, delivered_intent_client_.get());
200 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698