[email protected] | c5000851 | 2011-02-03 01:17:27 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
[email protected] | 9a2051d | 2008-08-15 20:12:42 | [diff] [blame] | 4 | |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 5 | #ifndef CHROME_RENDERER_EXTERNAL_HOST_BINDINGS_H_ |
6 | #define CHROME_RENDERER_EXTERNAL_HOST_BINDINGS_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 9a2051d | 2008-08-15 20:12:42 | [diff] [blame] | 8 | |
[email protected] | 921f159 | 2011-03-18 00:41:02 | [diff] [blame] | 9 | #include "content/renderer/web_ui_bindings.h" |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 10 | #include "ipc/ipc_message.h" |
[email protected] | 9a2051d | 2008-08-15 20:12:42 | [diff] [blame] | 11 | |
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] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 16 | // postMessage(String message[, String target]); |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 17 | class ExternalHostBindings : public DOMBoundBrowserObject { |
[email protected] | 9a2051d | 2008-08-15 20:12:42 | [diff] [blame] | 18 | public: |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 19 | ExternalHostBindings(); |
[email protected] | dec76e80 | 2010-09-23 22:43:53 | [diff] [blame] | 20 | virtual ~ExternalHostBindings(); |
[email protected] | 9a2051d | 2008-08-15 20:12:42 | [diff] [blame] | 21 | |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 22 | // The postMessage() function provided to Javascript. |
23 | void postMessage(const CppArgumentList& args, CppVariant* result); | ||||
[email protected] | 1b44bb9 | 2009-03-03 00:39:17 | [diff] [blame] | 24 | |
25 | // Invokes the registered onmessage handler. | ||||
26 | // Returns true on successful invocation. | ||||
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 27 | 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] | 906690b | 2010-12-03 18:11:25 | [diff] [blame] | 32 | void BindToJavascript(WebKit::WebFrame* frame, const std::string& classname) { |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 33 | 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] | 1b44bb9 | 2009-03-03 00:39:17 | [diff] [blame] | 42 | |
[email protected] | 9a2051d | 2008-08-15 20:12:42 | [diff] [blame] | 43 | private: |
[email protected] | 1b44bb9 | 2009-03-03 00:39:17 | [diff] [blame] | 44 | CppVariant on_message_handler_; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 45 | WebKit::WebFrame* frame_; |
[email protected] | 1b44bb9 | 2009-03-03 00:39:17 | [diff] [blame] | 46 | |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 47 | DISALLOW_COPY_AND_ASSIGN(ExternalHostBindings); |
[email protected] | 9a2051d | 2008-08-15 20:12:42 | [diff] [blame] | 48 | }; |
49 | |||||
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 50 | #endif // CHROME_RENDERER_EXTERNAL_HOST_BINDINGS_H_ |