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

Unified Diff: content/renderer/introducer_dispatcher.cc

Issue 6880275: Web Introducer overview Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 years, 8 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/introducer_dispatcher.h ('k') | content/renderer/render_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/introducer_dispatcher.cc
===================================================================
--- content/renderer/introducer_dispatcher.cc (revision 0)
+++ content/renderer/introducer_dispatcher.cc (revision 0)
@@ -0,0 +1,221 @@
+// Copyright (c) 2011 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.
+
+#include "content/renderer/introducer_dispatcher.h"
+
+#include "base/id_map.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/common/introducer_messages.h"
+#include "content/common/webmessageportchannel_impl.h"
+#include "content/renderer/render_view_observer.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMStringList.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntroducer.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntroducerAcceptCallback.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntroducerCallback.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntroducerConnectCallback.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntroducerInstallCallback.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
+
+class ConnectCallback : public WebKit::WebIntroducerCallback {
+public:
+ ConnectCallback(WebKit::WebMessagePortChannel* service,
+ const WebKit::WebElement& anchor,
+ WebKit::WebIntroducerConnectCallback* callback) :
+ service_(service),
+ anchor_(anchor),
+ callback_(callback),
+ navigated_(false) {}
+ virtual ~ConnectCallback() {}
+
+ void handleEvent(const WebKit::WebDOMStringList& agreed) {
+ if (0 == agreed.length()) {
+ service_->destroy();
+ service_ = NULL;
+ }
+ callback_->handleEvent(service_, agreed, navigated_);
+ }
+
+ void navigate(const GURL& src) {
+ WebKit::WebFrame* frame = WebKit::WebFrame::fromFrameOwnerElement(anchor_);
+ if (frame) {
+ frame->loadRequest(WebKit::WebURLRequest(src));
+ navigated_ = true;
+ }
+ }
+
+private:
+ WebKit::WebMessagePortChannel* service_;
+ WebKit::WebElement anchor_;
+ scoped_ptr<WebKit::WebIntroducerConnectCallback> callback_;
+ bool navigated_;
+
+ DISALLOW_COPY_AND_ASSIGN(ConnectCallback);
+};
+
+class AcceptCallback : public WebKit::WebIntroducerCallback {
+public:
+ AcceptCallback(WebKit::WebMessagePortChannel* customer,
+ WebKit::WebIntroducerAcceptCallback* callback) :
+ customer_(customer),
+ callback_(callback) {}
+ virtual ~AcceptCallback() {}
+
+ void handleEvent(const WebKit::WebString& origin,
+ const WebKit::WebDOMStringList& wanted) {
+ if (0 == wanted.length()) {
+ customer_->destroy();
+ customer_ = NULL;
+ } else {
+ callback_->handleEvent(customer_, origin, wanted);
+ }
+ }
+
+private:
+ WebKit::WebMessagePortChannel* customer_;
+ scoped_ptr<WebKit::WebIntroducerAcceptCallback> callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(AcceptCallback);
+};
+
+class IntroducerDispatcher : public RenderViewObserver,
+ public WebKit::WebIntroducer {
+ public:
+ explicit IntroducerDispatcher(RenderView* render_view)
+ : RenderViewObserver(render_view) {}
+ virtual ~IntroducerDispatcher() {}
+
+ virtual void install(const WebKit::WebSecurityOrigin& origin,
+ const WebKit::WebURL& icon,
+ const WebKit::WebString& name,
+ const WebKit::WebURL& home,
+ WebKit::WebIntroducerInstallCallback* callback) {
+ Send(new IntroducerHostMsg_Install(routing_id(), pending_.Add(callback),
+ origin.toString().utf8(),
+ icon, name, home));
+ }
+ void OnInstallReturn(int request_id, bool done) {
+ WebKit::WebIntroducerCallback* cb = pending_.Lookup(request_id);
+ if (cb) {
+ static_cast<WebKit::WebIntroducerInstallCallback*>(cb)->handleEvent(done);
+ }
+ pending_.Remove(request_id);
+ }
+ virtual void uninstall(const WebKit::WebSecurityOrigin& origin) {
+ Send(new IntroducerHostMsg_Uninstall(routing_id(), pending_.Add(NULL),
+ origin.toString().utf8()));
+ }
+ virtual void offer(const WebKit::WebSecurityOrigin& origin,
+ const WebKit::WebString& id,
+ const WebKit::WebString& label,
+ const WebKit::WebDOMStringList& supports,
+ const WebKit::WebURL& window,
+ const WebKit::WebURL& frame) {
+ IntroducerHostMsg_Offer_Params args;
+ args.id = id.utf8();
+ args.label = label;
+ args.supports.reserve(supports.length());
+ for (unsigned i = 0, end = supports.length(); i != end; ++i) {
+ args.supports.push_back(supports.item(i).utf8());
+ }
+ args.window = window;
+ args.frame = frame;
+ Send(new IntroducerHostMsg_Offer(routing_id(), pending_.Add(NULL),
+ origin.toString().utf8(), args));
+ }
+ virtual void rescind(const WebKit::WebSecurityOrigin& origin,
+ const WebKit::WebString& id) {
+ Send(new IntroducerHostMsg_Rescind(routing_id(), pending_.Add(NULL),
+ origin.toString().utf8(), id.utf8()));
+ }
+ virtual void connect(const WebKit::WebSecurityOrigin& origin,
+ const WebKit::WebElement& anchor,
+ const WebKit::WebDOMStringList& wanted,
+ WebKit::WebIntroducerConnectCallback* callback) {
+ std::vector<std::string> wanted_arg;
+ wanted_arg.reserve(wanted.length());
+ for (unsigned i = 0, end = wanted.length(); i != end; ++i) {
+ wanted_arg.push_back(wanted.item(i).utf8());
+ }
+ WebMessagePortChannelImpl* service = new WebMessagePortChannelImpl();
+ WebKit::WebFrame* frame = WebKit::WebFrame::fromFrameOwnerElement(anchor);
+ Send(new IntroducerHostMsg_Connect(routing_id(),
+ pending_.Add(new ConnectCallback(service, anchor, callback)),
+ origin.toString().utf8(),
+ frame ? frame->identifier() : 0,
+ wanted_arg,
+ service->message_port_id()));
+ }
+ void OnConnectNavigation(int request_id, const GURL& src) {
+ WebKit::WebIntroducerCallback* cb = pending_.Lookup(request_id);
+ if (cb) {
+ static_cast<ConnectCallback*>(cb)->navigate(src);
+ }
+ }
+ void OnConnectReturn(int request_id, const std::vector<std::string>& agreed) {
+ WebKit::WebIntroducerCallback* cb = pending_.Lookup(request_id);
+ if (cb) {
+ WebKit::WebDOMStringList web_agreed;
+ for (std::vector<std::string>::const_iterator i = agreed.begin(),
+ end = agreed.end();
+ i != end; ++i) {
+ web_agreed.append(WebKit::WebString::fromUTF8(*i));
+ }
+ static_cast<ConnectCallback*>(cb)->handleEvent(web_agreed);
+ }
+ pending_.Remove(request_id);
+ }
+ virtual void accept(const WebKit::WebSecurityOrigin& origin,
+ const WebKit::WebString& registrant,
+ WebKit::WebIntroducerAcceptCallback* callback) {
+ WebMessagePortChannelImpl* customer = new WebMessagePortChannelImpl();
+ WebKit::WebFrame* frame = WebKit::WebFrame::frameForCurrentContext();
+ Send(new IntroducerHostMsg_Accept(routing_id(),
+ pending_.Add(new AcceptCallback(customer, callback)),
+ frame->parent() ? frame->identifier() : 0,
+ registrant.utf8(),
+ customer->message_port_id()));
+ }
+ void OnAcceptReturn(int request_id,
+ const std::string& origin,
+ const std::vector<std::string>& wanted) {
+ WebKit::WebIntroducerCallback* cb = pending_.Lookup(request_id);
+ if (cb) {
+ WebKit::WebDOMStringList web_wanted;
+ for (std::vector<std::string>::const_iterator i = wanted.begin(),
+ end = wanted.end();
+ i != end; ++i) {
+ web_wanted.append(WebKit::WebString::fromUTF8(*i));
+ }
+ static_cast<AcceptCallback*>(cb)->handleEvent(
+ WebKit::WebString::fromUTF8(origin), web_wanted);
+ }
+ pending_.Remove(request_id);
+ }
+
+ virtual bool OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(IntroducerDispatcher, message)
+ IPC_MESSAGE_HANDLER(IntroducerMsg_AcceptReturn, OnAcceptReturn);
+ IPC_MESSAGE_HANDLER(IntroducerMsg_ConnectNavigation, OnConnectNavigation);
+ IPC_MESSAGE_HANDLER(IntroducerMsg_ConnectReturn, OnConnectReturn);
+ IPC_MESSAGE_HANDLER(IntroducerMsg_InstallReturn, OnInstallReturn);
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+ }
+
+ private:
+ IDMap<WebKit::WebIntroducerCallback,IDMapOwnPointer> pending_;
+
+ DISALLOW_COPY_AND_ASSIGN(IntroducerDispatcher);
+};
+
+WebKit::WebIntroducer* makeIntroducerDispatcher(RenderView* render_view) {
+ return new IntroducerDispatcher(render_view);
+}
Property changes on: content/renderer/introducer_dispatcher.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « content/renderer/introducer_dispatcher.h ('k') | content/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698