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

Unified Diff: content/renderer/web_intents_host.cc

Issue 10412058: Change to use webkit intent delivery. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Get v8 context scope for unserialized/blob delivery Created 8 years, 7 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
« no previous file with comments | « content/renderer/web_intents_host.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/web_intents_host.cc
diff --git a/content/renderer/web_intents_host.cc b/content/renderer/web_intents_host.cc
index b4338f0b50df025fe86f6bfa234dab30ffae6003..1b06272378c738f9b23e012b3468810f7536c17c 100644
--- a/content/renderer/web_intents_host.cc
+++ b/content/renderer/web_intents_host.cc
@@ -12,161 +12,47 @@
#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/WebDeliveredIntentClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
#include "v8/include/v8.h"
#include "webkit/glue/cpp_bound_class.h"
using WebKit::WebBindings;
using WebKit::WebBlob;
using WebKit::WebCString;
+using WebKit::WebDeliveredIntentClient;
using WebKit::WebFrame;
+using WebKit::WebIntent;
using WebKit::WebIntentRequest;
using WebKit::WebString;
using WebKit::WebSerializedScriptValue;
-using webkit_glue::CppArgumentList;
-using webkit_glue::CppBoundClass;
-using webkit_glue::CppVariant;
-
-// This class encapsulates the API the Intent object will expose to Javascript.
-// It is made available to the Javascript runtime in the service page using
-// NPAPI methods as with plugin/Javascript interaction objects and other
-// browser-provided Javascript API objects on |window|.
-class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
- public:
- BoundDeliveredIntent(const webkit_glue::WebIntentData& intent,
- WebIntentsHost* parent,
- WebFrame* frame) {
- action_ = WebString(intent.action).utf8();
- type_ = WebString(intent.type).utf8();
- extra_data_ = intent.extra_data;
- parent_ = parent;
-
- v8::HandleScope scope;
- v8::Local<v8::Context> ctx = frame->mainWorldScriptContext();
- v8::Context::Scope cscope(ctx);
- v8::Local<v8::Value> data_obj;
-
- if (intent.data_type == webkit_glue::WebIntentData::SERIALIZED) {
- WebSerializedScriptValue ssv =
- WebSerializedScriptValue::fromString(WebString(intent.data));
- DCHECK(!ssv.isNull());
- data_obj = v8::Local<v8::Value>::New(ssv.deserialize());
- } 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);
- web_blob_ = WebBlob::createFromFile(
- WebString::fromUTF8(intent.blob_file.AsUTF8Unsafe()),
- intent.blob_length);
- data_obj = v8::Local<v8::Value>::New(web_blob_.toV8Value());
- }
-
- data_val_.reset(new CppVariant);
- WebBindings::toNPVariant(data_obj, frame->windowObject(), data_val_.get());
-
- BindGetterCallback("action", base::Bind(&BoundDeliveredIntent::GetAction,
- base::Unretained(this)));
- BindGetterCallback("type", base::Bind(&BoundDeliveredIntent::GetType,
- 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,
- base::Unretained(this)));
- }
-
- virtual ~BoundDeliveredIntent() {
- }
-
- WebString SerializeCppVariant(const CppVariant& val) {
- v8::HandleScope scope;
- v8::Handle<v8::Value> v8obj = WebBindings::toV8Value(&val);
-
- WebSerializedScriptValue ssv =
- WebSerializedScriptValue::serialize(v8obj);
- if (ssv.isNull())
- return WebKit::WebString();
-
- return ssv.toString();
- }
-
- void PostResult(const CppArgumentList& args, CppVariant* retval) {
- if (args.size() != 1) {
- WebBindings::setException(NULL, "Must pass one argument to postResult");
- return;
- }
-
- WebString str = SerializeCppVariant(args[0]);
- parent_->OnResult(str);
- }
-
- void PostFailure(const CppArgumentList& args, CppVariant* retval) {
- if (args.size() != 1) {
- WebBindings::setException(NULL, "Must pass one argument to postFailure");
- return;
- }
- WebString str = SerializeCppVariant(args[0]);
- parent_->OnFailure(str);
- }
-
- void GetAction(CppVariant* result) {
- std::string action;
- action.assign(action_.data(), action_.length());
- result->Set(action);
- }
+class DeliveredIntentClientImpl : public WebDeliveredIntentClient {
+ public:
+ explicit DeliveredIntentClientImpl(WebIntentsHost* host) : host_(host) {}
+ virtual ~DeliveredIntentClientImpl() {}
- void GetType(CppVariant* result) {
- std::string type;
- type.assign(type_.data(), type_.length());
- result->Set(type);
+ virtual void postResult(const WebSerializedScriptValue& data) const OVERRIDE {
darin (slow to review) 2012/06/05 18:22:18 Note: We often do not use OVERRIDE when implementi
Greg Billock 2012/06/05 19:55:45 Took 'em out. On 2012/06/05 18:22:18, darin wrote
+ host_->OnResult(data.toString());
}
- void GetData(CppVariant* result) {
- result->Set(*data_val_.get());
+ virtual void postFailure(const WebSerializedScriptValue& data) const
+ OVERRIDE {
+ host_->OnFailure(data.toString());
}
- void GetExtra(const CppArgumentList& args, CppVariant* result) {
- if (args.size() != 1) {
- WebBindings::setException(NULL, "Must pass one argument to getExtra");
- return;
- }
-
- if (!args[0].isString()) {
- WebBindings::setException(NULL, "Argument to getExtra must be a string");
- return;
- }
-
- std::string str = args[0].ToString();
- std::map<string16, string16>::const_iterator iter =
- extra_data_.find(UTF8ToUTF16(str));
- if (iter == extra_data_.end()) {
- result->SetNull();
- return;
- }
- std::string val = UTF16ToUTF8(iter->second);
- result->Set(val);
+ virtual void destroy() OVERRIDE {
}
private:
- // Intent data suitable for surfacing to Javascript callers.
- WebCString action_;
- WebCString type_;
- std::map<string16, string16> extra_data_;
- WebBlob web_blob_;
- scoped_ptr<CppVariant> data_val_;
-
- // The dispatcher object, for forwarding postResult/postFailure calls.
- WebIntentsHost* parent_;
+ WebIntentsHost* host_;
};
WebIntentsHost::WebIntentsHost(RenderViewImpl* render_view)
@@ -230,14 +116,51 @@ void WebIntentsHost::OnFailure(const WebKit::WebString& data) {
// We set the intent payload into all top-level frame window objects. This
// should persist the data through redirects, and not deliver it to any
-// sub-frames. TODO(gbillock): This policy needs to be fine-tuned and
-// documented.
+// sub-frames.
+// TODO(gbillock): match to spec to double-check registration match before
+// delivery.
void WebIntentsHost::DidClearWindowObject(WebFrame* frame) {
if (intent_.get() == NULL || frame->top() != frame)
return;
- if (!delivered_intent_.get()) {
- delivered_intent_.reset(
- new BoundDeliveredIntent(*(intent_.get()), this, frame));
+
+ if (!delivered_intent_client_.get()) {
+ delivered_intent_client_.reset(new DeliveredIntentClientImpl(this));
}
- delivered_intent_->BindToJavascript(frame, "webkitIntent");
+
+ WebKit::WebVector<WebKit::WebString> extras_keys(
darin (slow to review) 2012/06/05 18:22:18 nit: no WebKit:: in front of WebString
Greg Billock 2012/06/05 19:55:45 Done.
+ intent_->extra_data.size());
+ WebKit::WebVector<WebKit::WebString> extras_values(
+ intent_->extra_data.size());
+ std::map<string16, string16>::iterator iter;
+ int i;
+ for (i = 0, iter = intent_->extra_data.begin();
+ iter != intent_->extra_data.end();
+ ++i, ++iter) {
+ extras_keys[i] = iter->first;
+ extras_values[i] = iter->second;
+ }
+
+ v8::HandleScope scope;
+ v8::Local<v8::Context> ctx = frame->mainWorldScriptContext();
+ v8::Context::Scope cscope(ctx);
+ scoped_ptr<WebIntent> web_intent;
+
+ if (intent_->data_type == webkit_glue::WebIntentData::SERIALIZED) {
+ web_intent.reset(new WebIntent(intent_->action,
darin (slow to review) 2012/06/05 18:22:18 does some of this code need to be updated?
Greg Billock 2012/06/05 19:55:45 Yes. Didn't push the new version. Now done.
+ intent_->type,
+ intent_->data));
+ } else if (intent_->data_type == webkit_glue::WebIntentData::UNSERIALIZED) {
+ web_intent.reset(new WebIntent(intent_->action, intent_->type,
+ intent_->unserialized_data,
+ extras_keys, extras_values));
+ } else {
+ DCHECK(intent_->data_type == webkit_glue::WebIntentData::BLOB);
+ web_blob_ = WebBlob::createFromFile(
+ WebString::fromUTF8(intent_->blob_file.AsUTF8Unsafe()),
+ intent_->blob_length);
+ web_intent.reset(new WebIntent(intent_->action, intent_->type, &web_blob_,
+ extras_keys, extras_values));
+ }
+
+ frame->deliverIntent(*(web_intent.get()), delivered_intent_client_.get());
}
« no previous file with comments | « content/renderer/web_intents_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698