1 // Copyright (c) 2011 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.
9 #include "base/win/scoped_comptr.h"
10 #include "chrome_frame/test/perf/chrome_frame_perftest.h"
12 interface IXcpControlDownloadCallback
;
13 interface
__declspec(uuid("1B36028E-B491-4bb2-8584-8A9E0A677D6E"))
14 IXcpControlHost
: public IUnknown
{
16 XcpHostOption_FreezeOnInitialFrame
= 0x001,
17 XcpHostOption_DisableFullScreen
= 0x002,
18 XcpHostOption_DisableManagedExecution
= 0x008,
19 XcpHostOption_EnableCrossDomainDownloads
= 0x010,
20 XcpHostOption_UseCustomAppDomain
= 0x020,
21 XcpHostOption_DisableNetworking
= 0x040,
22 XcpHostOption_DisableScriptCallouts
= 0x080,
23 XcpHostOption_EnableHtmlDomAccess
= 0x100,
24 XcpHostOption_EnableScriptableObjectAccess
= 0x200,
27 STDMETHOD(GetHostOptions
)(DWORD
* pdwOptions
) PURE
;
28 STDMETHOD(NotifyLoaded()) PURE
;
29 STDMETHOD(NotifyError
)(BSTR bstrError
, BSTR bstrSource
,
30 long nLine
, long nColumn
) PURE
;
31 STDMETHOD(InvokeHandler
)(BSTR bstrName
, VARIANT varArg1
, VARIANT varArg2
,
32 VARIANT
* pvarResult
) PURE
;
33 STDMETHOD(GetBaseUrl
)(BSTR
* pbstrUrl
) PURE
;
34 STDMETHOD(GetNamedSource
)(BSTR bstrSourceName
, BSTR
* pbstrSource
) PURE
;
35 STDMETHOD(DownloadUrl
)(BSTR bstrUrl
, IXcpControlDownloadCallback
* pCallback
,
36 IStream
** ppStream
) PURE
;
39 // Not templatized, to trade execution speed vs typing
40 class IXcpControlHostImpl
: public IXcpControlHost
{
42 STDMETHOD(GetHostOptions
)(DWORD
* pdwOptions
) {
46 STDMETHOD(NotifyLoaded()) {
50 STDMETHOD(NotifyError
)(BSTR bstrError
, BSTR bstrSource
,
51 long nLine
, long nColumn
) {
55 STDMETHOD(InvokeHandler
)(BSTR bstrName
, VARIANT varArg1
, VARIANT varArg2
,
56 VARIANT
* pvarResult
) {
60 STDMETHOD(GetBaseUrl
)(BSTR
* pbstrUrl
) {
64 STDMETHOD(GetNamedSource
)(BSTR bstrSourceName
, BSTR
* pbstrSource
) {
68 STDMETHOD(DownloadUrl
)(BSTR bstrUrl
, IXcpControlDownloadCallback
* pCallback
,
74 // Silverlight container. Supports do-nothing implementation of IXcpControlHost.
75 // Should be extended to do some real movie-or-something download.
76 class SilverlightContainer
:
77 public IServiceProviderImpl
<SilverlightContainer
>,
78 public IXcpControlHostImpl
,
79 public CWindowImpl
<SilverlightContainer
, CWindow
, CWinTraits
<
80 WS_OVERLAPPEDWINDOW
| WS_VISIBLE
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
,
81 WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
> >,
82 public CComObjectRootEx
<CComSingleThreadModel
> {
84 DECLARE_WND_CLASS_EX(L
"Silverlight_container", 0, 0)
85 BEGIN_COM_MAP(SilverlightContainer
)
86 COM_INTERFACE_ENTRY(IServiceProvider
)
87 COM_INTERFACE_ENTRY(IXcpControlHost
)
90 BEGIN_SERVICE_MAP(SilverlightContainer
)
91 SERVICE_ENTRY(__uuidof(IXcpControlHost
))
94 BEGIN_MSG_MAP(ChromeFrameActiveXContainer
)
95 MESSAGE_HANDLER(WM_DESTROY
, OnDestroy
)
98 LRESULT
OnDestroy(UINT
, WPARAM
, LPARAM
, BOOL
& handled
) {
103 virtual void OnFinalMessage(HWND
) {
106 static const wchar_t* GetWndCaption() {
107 return L
"Silverlight Container";
110 HRESULT
CreateWndAndHost(RECT
* r
) {
112 ShowWindow(SW_SHOWDEFAULT
);
114 CComPtr
<IUnknown
> spUnkContainer
;
115 HRESULT hr
= CAxHostWindow::_CreatorClass::CreateInstance(NULL
,
116 __uuidof(IAxWinHostWindow
), reinterpret_cast<void**>(&host_
));
118 CComPtr
<IObjectWithSite
> p
;
119 hr
= host_
.QueryInterface(&p
);
121 p
->SetSite(GetUnknown());
127 HRESULT
CreateControl() {
128 HRESULT hr
= host_
->CreateControl(L
"AgControl.AgControl", m_hWnd
, NULL
);
129 EXPECT_HRESULT_SUCCEEDED(hr
);
133 base::win::ScopedComPtr
<IAxWinHostWindow
> host_
;
136 // Create and in-place Silverlight control. Should be extended to do something
138 TEST(ChromeFramePerf
, DISABLED_HostSilverlight2
) {
141 CComObjectStackEx
<SilverlightContainer
> wnd
;
142 RECT rc
= {0, 0, 800, 600};
143 wnd
.CreateWndAndHost(&rc
);
144 PerfTimeLogger
perf_create("Create Silverlight Control2");
150 // Simplest test - creates in-place Silverlight control.
151 TEST(ChromeFramePerf
, DISABLED_HostSilverlight
) {
155 RECT rc
= {0, 0, 800, 600};
156 PerfTimeLogger
perf_create("Create Silverlight Control");
157 host
.Create(NULL
, rc
, L
"AgControl.AgControl",
158 WS_OVERLAPPEDWINDOW
| WS_VISIBLE
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
,
159 WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
160 EXPECT_TRUE(host
.m_hWnd
!= NULL
);
161 base::win::ScopedComPtr
<IDispatch
> disp
;
162 HRESULT hr
= host
.QueryControl(disp
.Receive());
163 EXPECT_HRESULT_SUCCEEDED(hr
);