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

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: Switch to switch 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"
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
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_);
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
139 ++i, ++iter) { 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 intent_data.extra_data.begin();
153 for (size_t i = 0; iter != intent_data.extra_data.end(); ++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 switch (intent_data.data_type) {
145 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext(); 159 case webkit_glue::WebIntentData::SERIALIZED: {
146 v8::Context::Scope cscope(ctx); 160 return WebIntent::create(intent_data.action, intent_data.type,
147 WebIntent web_intent; 161 intent_data.data,
162 extras_keys, extras_values);
163 }
148 164
149 if (intent_->data_type == webkit_glue::WebIntentData::SERIALIZED) { 165 case webkit_glue::WebIntentData::UNSERIALIZED: {
150 web_intent = WebIntent::create(intent_->action, intent_->type, 166 v8::Local<v8::String> dataV8 = v8::String::New(
151 intent_->data, 167 reinterpret_cast<const uint16_t*>(
152 extras_keys, extras_values); 168 intent_data.unserialized_data.data()),
153 } else if (intent_->data_type == webkit_glue::WebIntentData::UNSERIALIZED) { 169 static_cast<int>(intent_data.unserialized_data.length()));
154 v8::Local<v8::String> dataV8 = v8::String::New( 170 WebSerializedScriptValue serialized_data =
155 reinterpret_cast<const uint16_t*>(intent_->unserialized_data.data()), 171 WebSerializedScriptValue::serialize(dataV8);
156 static_cast<int>(intent_->unserialized_data.length()));
157 WebSerializedScriptValue serialized_data =
158 WebSerializedScriptValue::serialize(dataV8);
159 172
160 web_intent = WebIntent::create(intent_->action, intent_->type, 173 return WebIntent::create(intent_data.action, intent_data.type,
161 serialized_data.toString(), 174 serialized_data.toString(),
162 extras_keys, extras_values); 175 extras_keys, extras_values);
163 } else if (intent_->data_type == webkit_glue::WebIntentData::BLOB) { 176 }
164 DCHECK(intent_->data_type == webkit_glue::WebIntentData::BLOB); 177
165 web_blob_ = WebBlob::createFromFile( 178 case webkit_glue::WebIntentData::BLOB: {
166 WebString::fromUTF8(intent_->blob_file.AsUTF8Unsafe()), 179 web_blob_ = WebBlob::createFromFile(
167 intent_->blob_length); 180 WebString::fromUTF8(intent_data.blob_file.AsUTF8Unsafe()),
168 WebSerializedScriptValue serialized_data = 181 intent_data.blob_length);
169 WebSerializedScriptValue::serialize(web_blob_.toV8Value()); 182 WebSerializedScriptValue serialized_data =
170 web_intent = WebIntent::create(intent_->action, intent_->type, 183 WebSerializedScriptValue::serialize(web_blob_.toV8Value());
171 serialized_data.toString(), 184 return WebIntent::create(intent_data.action, intent_data.type,
172 extras_keys, extras_values); 185 serialized_data.toString(),
173 } else if (intent_->data_type == webkit_glue::WebIntentData::FILESYSTEM) { 186 extras_keys, extras_values);
174 const GURL origin = GURL(frame->document().securityOrigin().toString()); 187 }
175 const GURL root_url = 188
176 fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated); 189 case webkit_glue::WebIntentData::FILESYSTEM: {
177 const std::string url = base::StringPrintf( 190 const GURL origin = GURL(frame->document().securityOrigin().toString());
178 "%s%s/%s/", 191 const GURL root_url =
179 root_url.spec().c_str(), 192 fileapi::GetFileSystemRootURI(origin,
180 intent_->filesystem_id.c_str(), 193 fileapi::kFileSystemTypeIsolated);
181 intent_->root_name.c_str()); 194 const std::string url = base::StringPrintf(
182 // TODO(kmadhusu): This is a temporary hack to create a serializable file 195 "%s%s/%s/",
183 // system. Once we have a better way to create a serializable file system, 196 root_url.spec().c_str(),
184 // remove this hack. 197 intent_data.filesystem_id.c_str(),
185 v8::Handle<v8::Value> filesystem_V8 = frame->createSerializableFileSystem( 198 intent_data.root_name.c_str());
186 WebKit::WebFileSystem::TypeIsolated, 199 // TODO(kmadhusu): This is a temporary hack to create a serializable file
187 WebKit::WebString::fromUTF8(intent_->root_name), 200 // system. Once we have a better way to create a serializable file system,
188 WebKit::WebString::fromUTF8(url)); 201 // remove this hack.
189 WebSerializedScriptValue serialized_data = 202 v8::Handle<v8::Value> filesystem_V8 = frame->createSerializableFileSystem(
190 WebSerializedScriptValue::serialize(filesystem_V8); 203 WebKit::WebFileSystem::TypeIsolated,
191 web_intent = WebIntent::create(intent_->action, intent_->type, 204 WebKit::WebString::fromUTF8(intent_data.root_name),
192 serialized_data.toString(), 205 WebKit::WebString::fromUTF8(url));
193 extras_keys, extras_values); 206 WebSerializedScriptValue serialized_data =
194 } else { 207 WebSerializedScriptValue::serialize(filesystem_V8);
195 NOTREACHED(); 208 return WebIntent::create(intent_data.action, intent_data.type,
209 serialized_data.toString(),
210 extras_keys, extras_values);
211 }
212
213 case webkit_glue::WebIntentData::MIME_TYPE: {
214 scoped_ptr<content::V8ValueConverter> converter(
215 content::V8ValueConverter::create());
216 v8::Handle<v8::Value> valV8 = converter->ToV8Value(
217 &intent_data.mime_data, v8::Context::GetCurrent());
218
219 WebSerializedScriptValue serialized_data =
220 WebSerializedScriptValue::serialize(valV8);
221 return WebIntent::create(intent_data.action, intent_data.type,
222 serialized_data.toString(),
223 WebVector<WebString>(), WebVector<WebString>());
224 }
196 } 225 }
197 226
198 if (!web_intent.action().isEmpty()) 227 NOTREACHED();
199 frame->deliverIntent(web_intent, NULL, delivered_intent_client_.get()); 228 return WebIntent();
200 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698