Roll leveldb to r76.
[chromium-blink-merge.git] / chrome_frame / test / perf / silverlight.cc
blob6ce7a0ebc56f291493a8af6284b17d6e249f14e1
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.
5 #include <atlbase.h>
6 #include <atlwin.h>
7 #include <atlhost.h>
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 {
15 typedef enum {
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,
25 } XcpHostOptions;
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 {
41 public:
42 STDMETHOD(GetHostOptions)(DWORD* pdwOptions) {
43 return E_NOTIMPL;
46 STDMETHOD(NotifyLoaded()) {
47 return E_NOTIMPL;
50 STDMETHOD(NotifyError)(BSTR bstrError, BSTR bstrSource,
51 long nLine, long nColumn) {
52 return E_NOTIMPL;
55 STDMETHOD(InvokeHandler)(BSTR bstrName, VARIANT varArg1, VARIANT varArg2,
56 VARIANT* pvarResult) {
57 return E_NOTIMPL;
60 STDMETHOD(GetBaseUrl)(BSTR* pbstrUrl) {
61 return E_NOTIMPL;
64 STDMETHOD(GetNamedSource)(BSTR bstrSourceName, BSTR* pbstrSource) {
65 return E_NOTIMPL;
68 STDMETHOD(DownloadUrl)(BSTR bstrUrl, IXcpControlDownloadCallback* pCallback,
69 IStream** ppStream) {
70 return E_NOTIMPL;
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> {
83 public:
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)
88 END_COM_MAP()
90 BEGIN_SERVICE_MAP(SilverlightContainer)
91 SERVICE_ENTRY(__uuidof(IXcpControlHost))
92 END_SERVICE_MAP()
94 BEGIN_MSG_MAP(ChromeFrameActiveXContainer)
95 MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
96 END_MSG_MAP()
98 LRESULT OnDestroy(UINT, WPARAM, LPARAM, BOOL& handled) {
99 host_.Release();
100 return 0;
103 virtual void OnFinalMessage(HWND ) {
106 static const wchar_t* GetWndCaption() {
107 return L"Silverlight Container";
110 HRESULT CreateWndAndHost(RECT* r) {
111 Create(NULL, r);
112 ShowWindow(SW_SHOWDEFAULT);
114 CComPtr<IUnknown> spUnkContainer;
115 HRESULT hr = CAxHostWindow::_CreatorClass::CreateInstance(NULL,
116 __uuidof(IAxWinHostWindow), reinterpret_cast<void**>(&host_));
117 if (SUCCEEDED(hr)) {
118 CComPtr<IObjectWithSite> p;
119 hr = host_.QueryInterface(&p);
120 if (SUCCEEDED(hr)) {
121 p->SetSite(GetUnknown());
124 return hr;
127 HRESULT CreateControl() {
128 HRESULT hr = host_->CreateControl(L"AgControl.AgControl", m_hWnd, NULL);
129 EXPECT_HRESULT_SUCCEEDED(hr);
130 return hr;
133 base::win::ScopedComPtr<IAxWinHostWindow> host_;
136 // Create and in-place Silverlight control. Should be extended to do something
137 // more meaningful.
138 TEST(ChromeFramePerf, DISABLED_HostSilverlight2) {
139 SimpleModule module;
140 AtlAxWinInit();
141 CComObjectStackEx<SilverlightContainer> wnd;
142 RECT rc = {0, 0, 800, 600};
143 wnd.CreateWndAndHost(&rc);
144 PerfTimeLogger perf_create("Create Silverlight Control2");
145 wnd.CreateControl();
146 perf_create.Done();
147 wnd.DestroyWindow();
150 // Simplest test - creates in-place Silverlight control.
151 TEST(ChromeFramePerf, DISABLED_HostSilverlight) {
152 SimpleModule module;
153 AtlAxWinInit();
154 CAxWindow host;
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);
164 disp.Release();
165 perf_create.Done();