blob: 39900e93b150e13eb7e76ab4dddc89cd21c9d728 [file] [log] [blame]
[email protected]8ee65ba2011-04-12 20:53:231// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]f7817822009-09-24 05:11:582// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_FRAME_COM_MESSAGE_EVENT_H_
6#define CHROME_FRAME_COM_MESSAGE_EVENT_H_
7
8#include <atlbase.h>
9#include <atlcom.h>
10#include <mshtml.h> // IHTMLEventObj
[email protected]8ee65ba2011-04-12 20:53:2311
[email protected]f7817822009-09-24 05:11:5812#include "base/basictypes.h"
[email protected]8ee65ba2011-04-12 20:53:2313#include "base/win/scoped_comptr.h"
[email protected]f7817822009-09-24 05:11:5814
15// Implements a MessageEvent compliant event object by providing MessageEvent
16// specific properties itself and inherited properties from a browser provided
17// event implementation.
18// NOTE: The messagePort and source properties will always be NULL.
19// See the HTML 5 spec for further details on a MessageEvent object:
20// http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#messageevent
21class ComMessageEvent
22 : public CComObjectRootEx<CComSingleThreadModel>,
23 public IDispatch {
24 public:
25 ComMessageEvent();
26 ~ComMessageEvent();
27
28BEGIN_COM_MAP(ComMessageEvent)
29 COM_INTERFACE_ENTRY(IDispatch)
30END_COM_MAP()
31
32 // The dispids we support. These are based on HTML5 and not IHTMLEventObj5
33 // (there are a couple of differences).
34 // http://dev.w3.org/html5/spec/Overview.html#messageevent
35 // vs http://msdn.microsoft.com/en-us/library/cc288548(VS.85).aspx
36 typedef enum {
37 DISPID_MESSAGE_EVENT_DATA = 201,
38 DISPID_MESSAGE_EVENT_ORIGIN,
39 DISPID_MESSAGE_EVENT_LAST_EVENT_ID,
40 DISPID_MESSAGE_EVENT_SOURCE,
41 DISPID_MESSAGE_EVENT_MESSAGE_PORT,
42 DISPID_MESSAGE_EVENT_TYPE
43 } MessageEventDispIds;
44
45 // Utility function for checking Invoke flags and assigning a BSTR to the
46 // result variable.
47 HRESULT GetStringProperty(WORD flags, const wchar_t* value, VARIANT* result);
48
49 STDMETHOD(GetTypeInfoCount)(UINT* info);
50 STDMETHOD(GetTypeInfo)(UINT which_info, LCID lcid, ITypeInfo** type_info);
51 STDMETHOD(GetIDsOfNames)(REFIID iid, LPOLESTR* names, UINT count_names,
52 LCID lcid, DISPID* dispids);
53 STDMETHOD(Invoke)(DISPID dispid, REFIID iid, LCID lcid, WORD flags,
54 DISPPARAMS* params, VARIANT* result, EXCEPINFO* excepinfo,
55 UINT* arg_err);
56
57 // Initializes this object. The container pointer is used to find the
58 // container's IHTMLEventObj implementation if available.
59 bool Initialize(IOleContainer* container, const std::string& message,
60 const std::string& origin, const std::string& event_type);
61
62 protected:
63 // HTML Event object to which we delegate property and method
64 // calls that we do not directly support. This may not be initialized
65 // if our container does not require the properties/methods exposed by
66 // the basic event object.
[email protected]8ee65ba2011-04-12 20:53:2367 base::win::ScopedComPtr<IHTMLEventObj> basic_event_;
[email protected]f7817822009-09-24 05:11:5868 std::string message_;
69 std::string origin_;
70 std::string type_;
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(ComMessageEvent);
74};
75
76#endif // CHROME_FRAME_COM_MESSAGE_EVENT_H_