1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_RENDERER_EXTERNAL_HOST_BINDINGS_H_
6 #define CHROME_RENDERER_EXTERNAL_HOST_BINDINGS_H_
8 #include "ipc/ipc_sender.h"
9 #include "webkit/renderer/cpp_bound_class.h"
11 // ExternalHostBindings is the class backing the "externalHost" object
12 // accessible from Javascript
14 // We expose one function, for sending a message to the external host:
15 // postMessage(String message[, String target]);
16 class ExternalHostBindings
: public webkit_glue::CppBoundClass
{
18 ExternalHostBindings(IPC::Sender
* sender
, int routing_id
);
19 virtual ~ExternalHostBindings();
21 // Invokes the registered onmessage handler.
22 // Returns true on successful invocation.
23 bool ForwardMessageFromExternalHost(const std::string
& message
,
24 const std::string
& origin
,
25 const std::string
& target
);
27 // Overridden to hold onto a pointer back to the web frame.
28 void BindToJavascript(WebKit::WebFrame
* frame
, const std::string
& classname
);
31 // Creates an uninitialized instance of a MessageEvent object.
32 // This is equivalent to calling window.document.createEvent("MessageEvent")
34 bool CreateMessageEvent(NPObject
** message_event
);
36 // The postMessage() function provided to Javascript.
37 void PostMessage(const webkit_glue::CppArgumentList
& args
,
38 webkit_glue::CppVariant
* result
);
40 webkit_glue::CppVariant on_message_handler_
;
41 WebKit::WebFrame
* frame_
;
45 DISALLOW_COPY_AND_ASSIGN(ExternalHostBindings
);
48 #endif // CHROME_RENDERER_EXTERNAL_HOST_BINDINGS_H_