1 // Copyright (c) 2009 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_FRAME_CHROME_FRAME_ACTIVEX_H_
6 #define CHROME_FRAME_CHROME_FRAME_ACTIVEX_H_
15 #include "base/scoped_bstr_win.h"
16 #include "base/scoped_comptr_win.h"
17 #include "base/scoped_variant_win.h"
18 #include "chrome_frame/chrome_frame_activex_base.h"
19 #include "chrome_frame/com_type_info_holder.h"
20 #include "grit/chrome_frame_resources.h"
22 // Include without path to make GYP build see it.
23 #include "chrome_tab.h" // NOLINT
25 #define WM_HOST_MOVED_NOTIFICATION (WM_APP + 1)
27 // ChromeFrameActivex: Implementation of the ActiveX control that is
28 // responsible for hosting a chrome frame, i.e. an iframe like widget which
29 // hosts the the chrome window. This object delegates to Chrome.exe
30 // (via the Chrome IPC-based automation mechanism) for the actual rendering.
31 class ATL_NO_VTABLE ChromeFrameActivex
32 : public ChromeFrameActivexBase
<ChromeFrameActivex
, CLSID_ChromeFrame
>,
33 public IObjectSafetyImpl
<ChromeFrameActivex
,
34 INTERFACESAFE_FOR_UNTRUSTED_CALLER
|
35 INTERFACESAFE_FOR_UNTRUSTED_DATA
>,
36 public IPersistPropertyBag
{
38 typedef ChromeFrameActivexBase
<ChromeFrameActivex
, CLSID_ChromeFrame
> Base
;
40 ~ChromeFrameActivex();
42 DECLARE_REGISTRY_RESOURCEID(IDR_CHROMEFRAME
)
44 BEGIN_COM_MAP(ChromeFrameActivex
)
45 COM_INTERFACE_ENTRY(IObjectSafety
)
46 COM_INTERFACE_ENTRY(IPersistPropertyBag
)
47 COM_INTERFACE_ENTRY(IConnectionPointContainer
)
48 COM_INTERFACE_ENTRY_CHAIN(Base
)
51 BEGIN_MSG_MAP(ChromeFrameActivex
)
52 MESSAGE_HANDLER(WM_CREATE
, OnCreate
)
53 MESSAGE_HANDLER(WM_HOST_MOVED_NOTIFICATION
, OnHostMoved
)
57 HRESULT
FinalConstruct();
59 virtual HRESULT
OnDraw(ATL_DRAWINFO
& draw_info
);
61 // IPersistPropertyBag implementation
62 STDMETHOD(GetClassID
)(CLSID
* class_id
) {
64 *class_id
= GetObjectCLSID();
68 STDMETHOD(InitNew
)() {
72 STDMETHOD(Load
)(IPropertyBag
* bag
, IErrorLog
* error_log
);
74 STDMETHOD(Save
)(IPropertyBag
* bag
, BOOL clear_dirty
, BOOL save_all
) {
78 // Used to setup the document_url_ member needed for completing navigation.
79 // Create external tab (possibly in incognito mode).
80 HRESULT
IOleObject_SetClientSite(IOleClientSite
* client_site
);
82 // Overridden to perform security checks.
83 STDMETHOD(put_src
)(BSTR src
);
86 // ChromeFrameDelegate overrides
87 virtual void OnLoad(int tab_handle
, const GURL
& url
);
88 virtual void OnMessageFromChromeFrame(int tab_handle
,
89 const std::string
& message
,
90 const std::string
& origin
,
91 const std::string
& target
);
92 virtual void OnLoadFailed(int error_code
, const std::string
& url
);
93 virtual void OnAutomationServerLaunchFailed(
94 AutomationLaunchResult reason
, const std::string
& server_version
);
95 virtual void OnExtensionInstalled(const FilePath
& path
,
96 void* user_data
, AutomationMsg_ExtensionResponseValues response
);
99 LRESULT
OnCreate(UINT message
, WPARAM wparam
, LPARAM lparam
,
100 BOOL
& handled
); // NO_LINT
101 LRESULT
OnHostMoved(UINT message
, WPARAM wparam
, LPARAM lparam
,
102 BOOL
& handled
); // NO_LINT
104 HRESULT
GetContainingDocument(IHTMLDocument2
** doc
);
105 HRESULT
GetDocumentWindow(IHTMLWindow2
** window
);
107 // Gets the value of the 'id' attribute of the object element.
108 HRESULT
GetObjectScriptId(IHTMLObjectElement
* object_elem
, BSTR
* id
);
110 // Returns the object element in the HTML page.
111 // Note that if we're not being hosted inside an HTML
112 // document, then this call will fail.
113 HRESULT
GetObjectElement(IHTMLObjectElement
** element
);
115 HRESULT
CreateScriptBlockForEvent(IHTMLElement2
* insert_after
,
116 BSTR instance_id
, BSTR script
,
119 // Utility function that checks the size of the vector and if > 0 creates
120 // a variant for the string argument and forwards the call to the other
122 void FireEvent(const EventHandlers
& handlers
, const std::string
& arg
);
124 // Invokes all registered handlers in a vector of event handlers.
125 void FireEvent(const EventHandlers
& handlers
, IDispatch
* event
);
127 // This variant is used for the privatemessage handler only.
128 void FireEvent(const EventHandlers
& handlers
, IDispatch
* event
,
131 // Installs a hook on the top-level window hosting the control.
132 HRESULT
InstallTopLevelHook(IOleClientSite
* client_site
);
134 // A hook attached to the top-level window containing the ActiveX control.
135 HHOOK chrome_wndproc_hook_
;
138 #endif // CHROME_FRAME_CHROME_FRAME_ACTIVEX_H_