summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-21 01:23:15 +0000
committergbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-21 01:23:15 +0000
commitffc8bed530d482be34801701a13540156ddf6939 (patch)
tree3d29ec3caa4bbf39c557b08dc05e920b54d06ba5
parent7bb26e20e23e564be350f6adb27a6226a0a0116b (diff)
downloadchromium_src-ffc8bed530d482be34801701a13540156ddf6939.zip
chromium_src-ffc8bed530d482be34801701a13540156ddf6939.tar.gz
chromium_src-ffc8bed530d482be34801701a13540156ddf6939.tar.bz2
Update chromium code to use WebIntentRequest.
R=darin@chromium.org,jhawkins@chromium.org BUG=None TEST=None Review URL: http://codereview.chromium.org/9186021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118577 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/renderer/render_view_impl.cc14
-rw-r--r--content/renderer/render_view_impl.h2
-rw-r--r--content/renderer/web_intents_host.cc64
-rw-r--r--content/renderer/web_intents_host.h16
4 files changed, 64 insertions, 32 deletions
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index 54dd53e..3504f40 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -208,6 +208,8 @@ using WebKit::WebHistoryItem;
using WebKit::WebIconURL;
using WebKit::WebImage;
using WebKit::WebInputElement;
+using WebKit::WebIntentRequest;
+using WebKit::WebIntentServiceInfo;
using WebKit::WebMediaPlayer;
using WebKit::WebMediaPlayerAction;
using WebKit::WebMediaPlayerClient;
@@ -3185,7 +3187,7 @@ void RenderViewImpl::requestStorageQuota(
}
void RenderViewImpl::registerIntentService(
- WebKit::WebFrame* frame, const WebKit::WebIntentServiceInfo& service) {
+ WebFrame* frame, const WebIntentServiceInfo& service) {
string16 title = service.title();
if (title.empty())
title = webview()->mainFrame()->document().title();
@@ -3198,12 +3200,12 @@ void RenderViewImpl::registerIntentService(
service.disposition()));
}
-void RenderViewImpl::dispatchIntent(WebKit::WebFrame* frame,
- const WebKit::WebIntentRequest& request) {
- WebKit::WebIntent intent(request.intent());
- webkit_glue::WebIntentData intent_data(intent);
+void RenderViewImpl::dispatchIntent(
+ WebFrame* frame, const WebIntentRequest& intentRequest) {
+ webkit_glue::WebIntentData intent_data(intentRequest.intent());
+ int id = intents_host_->RegisterWebIntent(intentRequest);
Send(new IntentsHostMsg_WebIntentDispatch(
- routing_id_, intent_data, intent.identifier()));
+ routing_id_, intent_data, id));
}
// WebKit::WebPageSerializerClient implementation ------------------------------
diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
index 3add4d7..cf82759 100644
--- a/content/renderer/render_view_impl.h
+++ b/content/renderer/render_view_impl.h
@@ -549,7 +549,7 @@ class RenderViewImpl : public RenderWidget,
WebKit::WebFrame* frame,
const WebKit::WebIntentServiceInfo& service);
virtual void dispatchIntent(WebKit::WebFrame* frame,
- const WebKit::WebIntentRequest& request);
+ const WebKit::WebIntentRequest& intentRequest);
// WebKit::WebPageSerializerClient implementation ----------------------------
diff --git a/content/renderer/web_intents_host.cc b/content/renderer/web_intents_host.cc
index 7d96f3d..6f2e05a 100644
--- a/content/renderer/web_intents_host.cc
+++ b/content/renderer/web_intents_host.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,15 +10,20 @@
#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/platform/WebCString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.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 "v8/include/v8.h"
#include "webkit/glue/cpp_bound_class.h"
+using WebKit::WebBindings;
using WebKit::WebCString;
+using WebKit::WebFrame;
+using WebKit::WebIntentRequest;
using WebKit::WebString;
+using WebKit::WebSerializedScriptValue;
// 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
@@ -30,7 +35,7 @@ class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
const string16& type,
const string16& data,
WebIntentsHost* parent,
- WebKit::WebFrame* frame) {
+ WebFrame* frame) {
action_ = WebString(action).utf8();
type_ = WebString(type).utf8();
parent_ = parent;
@@ -38,8 +43,8 @@ class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
v8::HandleScope scope;
v8::Local<v8::Context> ctx = frame->mainWorldScriptContext();
v8::Context::Scope cscope(ctx);
- WebKit::WebSerializedScriptValue ssv =
- WebKit::WebSerializedScriptValue::fromString(WebString(data));
+ WebSerializedScriptValue ssv =
+ WebSerializedScriptValue::fromString(WebString(data));
// TODO(gbillock): use an exception handler instead? Need to
// pass back error state to caller? This is a pretty unexpected
// internal error...
@@ -48,9 +53,7 @@ class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
v8::Local<v8::Value>::New(ssv.deserialize());
data_val_.reset(new CppVariant);
- WebKit::WebBindings::toNPVariant(data_obj,
- frame->windowObject(),
- data_val_.get());
+ WebBindings::toNPVariant(data_obj, frame->windowObject(), data_val_.get());
BindGetterCallback("action", base::Bind(&BoundDeliveredIntent::getAction,
base::Unretained(this)));
@@ -67,12 +70,12 @@ class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
virtual ~BoundDeliveredIntent() {
}
- WebKit::WebString SerializeCppVariant(const CppVariant& val) {
+ WebString SerializeCppVariant(const CppVariant& val) {
v8::HandleScope scope;
- v8::Handle<v8::Value> v8obj = WebKit::WebBindings::toV8Value(&val);
+ v8::Handle<v8::Value> v8obj = WebBindings::toV8Value(&val);
- WebKit::WebSerializedScriptValue ssv =
- WebKit::WebSerializedScriptValue::serialize(v8obj);
+ WebSerializedScriptValue ssv =
+ WebSerializedScriptValue::serialize(v8obj);
if (ssv.isNull())
return WebKit::WebString();
@@ -81,8 +84,7 @@ class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
void postResult(const CppArgumentList& args, CppVariant* retval) {
if (args.size() != 1) {
- WebKit::WebBindings::setException(
- NULL, "Must pass one argument to postResult");
+ WebBindings::setException(NULL, "Must pass one argument to postResult");
return;
}
@@ -92,8 +94,7 @@ class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
void postFailure(const CppArgumentList& args, CppVariant* retval) {
if (args.size() != 1) {
- WebKit::WebBindings::setException(
- NULL, "Must pass one argument to postFailure");
+ WebBindings::setException(NULL, "Must pass one argument to postFailure");
return;
}
@@ -128,10 +129,19 @@ class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
};
WebIntentsHost::WebIntentsHost(RenderViewImpl* render_view)
- : content::RenderViewObserver(render_view) {
+ : content::RenderViewObserver(render_view),
+ id_counter_(0) {
}
-WebIntentsHost::~WebIntentsHost() {}
+WebIntentsHost::~WebIntentsHost() {
+}
+
+int WebIntentsHost::RegisterWebIntent(
+ const WebIntentRequest& request) {
+ int id = id_counter_++;
+ intent_requests_[id] = request;
+ return id;
+}
bool WebIntentsHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
@@ -151,13 +161,19 @@ void WebIntentsHost::OnWebIntentReply(
webkit_glue::WebIntentReplyType reply_type,
const WebKit::WebString& data,
int intent_id) {
+ std::map<int, WebIntentRequest>::iterator request =
+ intent_requests_.find(intent_id);
+ if (request == intent_requests_.end())
+ return;
+ WebIntentRequest intent_request = request->second;
+ intent_requests_.erase(request);
+ WebSerializedScriptValue value =
+ WebSerializedScriptValue::fromString(data);
if (reply_type == webkit_glue::WEB_INTENT_REPLY_SUCCESS) {
- render_view()->GetWebView()->mainFrame()->handleIntentResult(
- intent_id, data);
+ intent_request.postResult(value);
} else {
- render_view()->GetWebView()->mainFrame()->handleIntentFailure(
- intent_id, data);
+ intent_request.postFailure(value);
}
}
@@ -175,7 +191,7 @@ void WebIntentsHost::OnFailure(const WebKit::WebString& data) {
// 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.
-void WebIntentsHost::DidClearWindowObject(WebKit::WebFrame* frame) {
+void WebIntentsHost::DidClearWindowObject(WebFrame* frame) {
if (intent_.get() == NULL || frame->top() != frame)
return;
diff --git a/content/renderer/web_intents_host.h b/content/renderer/web_intents_host.h
index 4567dcd..a90fa52 100644
--- a/content/renderer/web_intents_host.h
+++ b/content/renderer/web_intents_host.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,8 @@
#define CONTENT_RENDERER_WEB_INTENTS_HOST_H_
#pragma once
+#include <map>
+
#include "base/memory/scoped_ptr.h"
#include "content/public/renderer/render_view_observer.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
@@ -15,6 +17,7 @@
class RenderViewImpl;
namespace WebKit {
+class WebIntentRequest;
class WebFrame;
}
@@ -31,6 +34,9 @@ class WebIntentsHost : public content::RenderViewObserver {
explicit WebIntentsHost(RenderViewImpl* render_view);
virtual ~WebIntentsHost();
+ // Called by the RenderView to register a new Web Intent invocation.
+ int RegisterWebIntent(const WebKit::WebIntentRequest& request);
+
// Called by the bound intent object to register the result from the service
// page.
void OnResult(const WebKit::WebString& data);
@@ -39,6 +45,14 @@ class WebIntentsHost : public content::RenderViewObserver {
private:
class BoundDeliveredIntent;
+ // A counter used to assign unique IDs to web intents invocations in this
+ // renderer.
+ int id_counter_;
+
+ // Map tracking registered Web Intent requests by assigned ID numbers to
+ // correctly route any return data.
+ std::map<int, WebKit::WebIntentRequest> intent_requests_;
+
// RenderView::Observer implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void DidClearWindowObject(WebKit::WebFrame* frame) OVERRIDE;