blob: 1673f2e8ee03bb3451d52df578dc2edaa7901243 [file] [log] [blame]
[email protected]c50008512011-02-03 01:17:271// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]9a2051d2008-08-15 20:12:424
[email protected]18cb2572008-08-21 20:34:455#ifndef CHROME_RENDERER_EXTERNAL_HOST_BINDINGS_H_
6#define CHROME_RENDERER_EXTERNAL_HOST_BINDINGS_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]9a2051d2008-08-15 20:12:428
[email protected]921f1592011-03-18 00:41:029#include "content/renderer/web_ui_bindings.h"
[email protected]946d1b22009-07-22 23:57:2110#include "ipc/ipc_message.h"
[email protected]9a2051d2008-08-15 20:12:4211
12// ExternalHostBindings is the class backing the "externalHost" object
13// accessible from Javascript
14//
15// We expose one function, for sending a message to the external host:
[email protected]28790922009-03-09 19:48:3716// postMessage(String message[, String target]);
[email protected]18cb2572008-08-21 20:34:4517class ExternalHostBindings : public DOMBoundBrowserObject {
[email protected]9a2051d2008-08-15 20:12:4218 public:
[email protected]81e63782009-02-27 19:35:0919 ExternalHostBindings();
[email protected]dec76e802010-09-23 22:43:5320 virtual ~ExternalHostBindings();
[email protected]9a2051d2008-08-15 20:12:4221
[email protected]28790922009-03-09 19:48:3722 // The postMessage() function provided to Javascript.
23 void postMessage(const CppArgumentList& args, CppVariant* result);
[email protected]1b44bb92009-03-03 00:39:1724
25 // Invokes the registered onmessage handler.
26 // Returns true on successful invocation.
[email protected]28790922009-03-09 19:48:3727 bool ForwardMessageFromExternalHost(const std::string& message,
28 const std::string& origin,
29 const std::string& target);
30
31 // Overridden to hold onto a pointer back to the web frame.
[email protected]906690b2010-12-03 18:11:2532 void BindToJavascript(WebKit::WebFrame* frame, const std::string& classname) {
[email protected]28790922009-03-09 19:48:3733 frame_ = frame;
34 DOMBoundBrowserObject::BindToJavascript(frame, classname);
35 }
36
37 protected:
38 // Creates an uninitialized instance of a MessageEvent object.
39 // This is equivalent to calling window.document.createEvent("MessageEvent")
40 // in javascript.
41 bool CreateMessageEvent(NPObject** message_event);
[email protected]1b44bb92009-03-03 00:39:1742
[email protected]9a2051d2008-08-15 20:12:4243 private:
[email protected]1b44bb92009-03-03 00:39:1744 CppVariant on_message_handler_;
[email protected]dd7daa82009-08-10 05:46:4545 WebKit::WebFrame* frame_;
[email protected]1b44bb92009-03-03 00:39:1746
[email protected]18cb2572008-08-21 20:34:4547 DISALLOW_COPY_AND_ASSIGN(ExternalHostBindings);
[email protected]9a2051d2008-08-15 20:12:4248};
49
[email protected]18cb2572008-08-21 20:34:4550#endif // CHROME_RENDERER_EXTERNAL_HOST_BINDINGS_H_