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

Unified Diff: content/renderer/web_intents_host.cc

Issue 9651020: Pass content-type resources to web intents. Goes through download, then invokes the p… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move code embedder-side Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/web_intents_host.cc
diff --git a/content/renderer/web_intents_host.cc b/content/renderer/web_intents_host.cc
index 1c38eb8348799d03b3041dd31fd0ca9bd54a44b2..c096e4c7da6d43f6747e09794b1b0184ccf27dd6 100644
--- a/content/renderer/web_intents_host.cc
+++ b/content/renderer/web_intents_host.cc
@@ -6,10 +6,12 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
+#include "base/utf_string_conversions.h"
#include "content/common/intents_messages.h"
#include "content/renderer/render_view_impl.h"
#include "ipc/ipc_message.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebBlob.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
@@ -19,6 +21,7 @@
#include "webkit/glue/cpp_bound_class.h"
using WebKit::WebBindings;
+using WebKit::WebBlob;
using WebKit::WebCString;
using WebKit::WebFrame;
using WebKit::WebIntentRequest;
@@ -36,6 +39,7 @@ class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
WebFrame* frame) {
action_ = WebString(intent.action).utf8();
type_ = WebString(intent.type).utf8();
+ extra_data_ = intent.extra_data;
parent_ = parent;
v8::HandleScope scope;
@@ -48,11 +52,15 @@ class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
WebSerializedScriptValue::fromString(WebString(intent.data));
DCHECK(!ssv.isNull());
data_obj = v8::Local<v8::Value>::New(ssv.deserialize());
- } else {
- DCHECK(intent.data_type == webkit_glue::WebIntentData::UNSERIALIZED);
+ } else if (intent.data_type == webkit_glue::WebIntentData::UNSERIALIZED) {
data_obj = v8::String::New(
reinterpret_cast<const uint16_t*>(intent.unserialized_data.data()),
static_cast<int>(intent.unserialized_data.length()));
+ } else {
+ DCHECK(intent.data_type == webkit_glue::WebIntentData::BLOB);
+ WebBlob web_blob = WebBlob::createFromFile(
+ WebString::fromUTF8(intent.blob_file), intent.blob_length);
+ data_obj = v8::Local<v8::Value>::New(web_blob.toV8Value());
}
data_val_.reset(new CppVariant);
@@ -64,6 +72,8 @@ class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
base::Unretained(this)));
BindGetterCallback("data", base::Bind(&BoundDeliveredIntent::getData,
base::Unretained(this)));
+ BindCallback("getExtra", base::Bind(&BoundDeliveredIntent::getExtra,
+ base::Unretained(this)));
BindCallback("postResult", base::Bind(&BoundDeliveredIntent::postResult,
base::Unretained(this)));
BindCallback("postFailure", base::Bind(&BoundDeliveredIntent::postFailure,
@@ -121,10 +131,27 @@ class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
result->Set(*data_val_.get());
}
+ void getExtra(const CppArgumentList& args, CppVariant* result) {
jam 2012/03/29 02:33:51 nit: all these functions need to follow the chrome
Greg Billock 2012/03/29 17:33:03 Done.
+ if (args.size() != 1) {
+ WebBindings::setException(NULL, "Must pass one argument to getExtra");
+ return;
+ }
+
+ WebString str = SerializeCppVariant(args[0]);
+ std::map<string16, string16>::const_iterator iter = extra_data_.find(str);
+ if (iter == extra_data_.end()) {
+ result->SetNull();
+ return;
+ }
+ std::string val = UTF16ToUTF8(iter->second);
+ result->Set(val);
+ }
+
private:
// Intent data suitable for surfacing to Javascript callers.
WebCString action_;
WebCString type_;
+ std::map<string16, string16> extra_data_;
scoped_ptr<CppVariant> data_val_;
// The dispatcher object, for forwarding postResult/postFailure calls.

Powered by Google App Engine
This is Rietveld 408576698