diff options
author | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-09 19:48:37 +0000 |
---|---|---|
committer | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-09 19:48:37 +0000 |
commit | 2879092e01ea4ebb93c1b80925c81e059b24607b (patch) | |
tree | 53638b170c3c9c3146d13238d1ed20993cdb4257 /chrome/renderer/external_host_bindings.h | |
parent | 12a6f036f3859f88b439dba009172f5c1dd03dc9 (diff) | |
download | chromium_src-2879092e01ea4ebb93c1b80925c81e059b24607b.zip chromium_src-2879092e01ea4ebb93c1b80925c81e059b24607b.tar.gz chromium_src-2879092e01ea4ebb93c1b80925c81e059b24607b.tar.bz2 |
Changing ForwardMessageToExternalHost to postMessage and passing a proper
MessageEvent object to the onmessage handler.
Also adding support for origin and target parameters. The origin parameter is
implicit but target can be specified when calling postMessage. If no target
is specified we default to "*".
At the moment I'm only allowing target == "*" messages to pass through since
I haven't implemented support for matching more complicated patterns :)
Review URL: http://codereview.chromium.org/40128
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11275 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/external_host_bindings.h')
-rw-r--r-- | chrome/renderer/external_host_bindings.h | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/chrome/renderer/external_host_bindings.h b/chrome/renderer/external_host_bindings.h index b4c46ad..62caac6 100644 --- a/chrome/renderer/external_host_bindings.h +++ b/chrome/renderer/external_host_bindings.h @@ -12,22 +12,37 @@ // accessible from Javascript // // We expose one function, for sending a message to the external host: -// ForwardMessageToExternalHost(String receiver, String message); +// postMessage(String message[, String target]); class ExternalHostBindings : public DOMBoundBrowserObject { public: ExternalHostBindings(); - virtual ~ExternalHostBindings() {}; + virtual ~ExternalHostBindings() { + } - // The ForwardMessageToExternalHost() function provided to Javascript. - void ForwardMessageToExternalHost(const CppArgumentList& args, - CppVariant* result); + // The postMessage() function provided to Javascript. + void postMessage(const CppArgumentList& args, CppVariant* result); // Invokes the registered onmessage handler. // Returns true on successful invocation. - bool ForwardMessageFromExternalHost(const std::string& message); + bool ForwardMessageFromExternalHost(const std::string& message, + const std::string& origin, + const std::string& target); + + // Overridden to hold onto a pointer back to the web frame. + void BindToJavascript(WebFrame* frame, const std::wstring& classname) { + frame_ = frame; + DOMBoundBrowserObject::BindToJavascript(frame, classname); + } + + protected: + // Creates an uninitialized instance of a MessageEvent object. + // This is equivalent to calling window.document.createEvent("MessageEvent") + // in javascript. + bool CreateMessageEvent(NPObject** message_event); private: CppVariant on_message_handler_; + WebFrame* frame_; DISALLOW_COPY_AND_ASSIGN(ExternalHostBindings); }; |