- add sources.
[platform/framework/web/crosswalk.git] / src / chrome_frame / test / perf / silverlight.cc
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.
4
5 #include <atlbase.h>
6 #include <atlwin.h>
7 #include <atlhost.h>
8
9 #include "base/test/perf_time_logger.h"
10 #include "base/win/scoped_comptr.h"
11 #include "chrome_frame/test/perf/chrome_frame_perftest.h"
12
13 interface IXcpControlDownloadCallback;
14 interface __declspec(uuid("1B36028E-B491-4bb2-8584-8A9E0A677D6E"))
15 IXcpControlHost : public IUnknown {
16   typedef enum {
17     XcpHostOption_FreezeOnInitialFrame       = 0x001,
18     XcpHostOption_DisableFullScreen          = 0x002,
19     XcpHostOption_DisableManagedExecution    = 0x008,
20     XcpHostOption_EnableCrossDomainDownloads = 0x010,
21     XcpHostOption_UseCustomAppDomain         = 0x020,
22     XcpHostOption_DisableNetworking          = 0x040,
23     XcpHostOption_DisableScriptCallouts      = 0x080,
24     XcpHostOption_EnableHtmlDomAccess        = 0x100,
25     XcpHostOption_EnableScriptableObjectAccess = 0x200,
26   } XcpHostOptions;
27
28   STDMETHOD(GetHostOptions)(DWORD* pdwOptions) PURE;
29   STDMETHOD(NotifyLoaded()) PURE;
30   STDMETHOD(NotifyError)(BSTR bstrError, BSTR bstrSource,
31       long nLine, long nColumn) PURE;
32   STDMETHOD(InvokeHandler)(BSTR bstrName, VARIANT varArg1, VARIANT varArg2,
33       VARIANT* pvarResult) PURE;
34   STDMETHOD(GetBaseUrl)(BSTR* pbstrUrl) PURE;
35   STDMETHOD(GetNamedSource)(BSTR bstrSourceName, BSTR* pbstrSource) PURE;
36   STDMETHOD(DownloadUrl)(BSTR bstrUrl, IXcpControlDownloadCallback* pCallback,
37       IStream** ppStream) PURE;
38 };
39
40 // Not templatized, to trade execution speed vs typing
41 class IXcpControlHostImpl : public IXcpControlHost {
42  public:
43   STDMETHOD(GetHostOptions)(DWORD* pdwOptions) {
44     return E_NOTIMPL;
45   }
46
47   STDMETHOD(NotifyLoaded()) {
48     return E_NOTIMPL;
49   }
50
51   STDMETHOD(NotifyError)(BSTR bstrError, BSTR bstrSource,
52                          long nLine, long nColumn) {
53     return E_NOTIMPL;
54   }
55
56   STDMETHOD(InvokeHandler)(BSTR bstrName, VARIANT varArg1, VARIANT varArg2,
57                            VARIANT* pvarResult) {
58     return E_NOTIMPL;
59   }
60
61   STDMETHOD(GetBaseUrl)(BSTR* pbstrUrl) {
62     return E_NOTIMPL;
63   }
64
65   STDMETHOD(GetNamedSource)(BSTR bstrSourceName, BSTR* pbstrSource) {
66     return E_NOTIMPL;
67   }
68
69   STDMETHOD(DownloadUrl)(BSTR bstrUrl, IXcpControlDownloadCallback* pCallback,
70                          IStream** ppStream) {
71     return E_NOTIMPL;
72   }
73 };
74
75 // Silverlight container. Supports do-nothing implementation of IXcpControlHost.
76 // Should be extended to do some real movie-or-something download.
77 class SilverlightContainer
78     : public IServiceProviderImpl<SilverlightContainer>,
79       public IXcpControlHostImpl,
80       public CWindowImpl<
81           SilverlightContainer,
82           CWindow,
83           CWinTraits<WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN |
84                          WS_CLIPSIBLINGS,
85                      WS_EX_APPWINDOW | WS_EX_WINDOWEDGE> >,
86       public CComObjectRootEx<CComSingleThreadModel> {
87  public:
88   DECLARE_WND_CLASS_EX(L"Silverlight_container", 0, 0)
89   BEGIN_COM_MAP(SilverlightContainer)
90     COM_INTERFACE_ENTRY(IServiceProvider)
91     COM_INTERFACE_ENTRY(IXcpControlHost)
92   END_COM_MAP()
93
94   BEGIN_SERVICE_MAP(SilverlightContainer)
95     SERVICE_ENTRY(__uuidof(IXcpControlHost))
96   END_SERVICE_MAP()
97
98   BEGIN_MSG_MAP(ChromeFrameActiveXContainer)
99     MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
100   END_MSG_MAP()
101
102   LRESULT OnDestroy(UINT, WPARAM, LPARAM, BOOL& handled) {
103     host_.Release();
104     return 0;
105   }
106
107   virtual void OnFinalMessage(HWND ) {
108   }
109
110   static const wchar_t* GetWndCaption() {
111     return L"Silverlight Container";
112   }
113
114   HRESULT CreateWndAndHost(RECT* r) {
115     Create(NULL, r);
116     ShowWindow(SW_SHOWDEFAULT);
117
118     CComPtr<IUnknown> spUnkContainer;
119     HRESULT hr = CAxHostWindow::_CreatorClass::CreateInstance(NULL,
120         __uuidof(IAxWinHostWindow), reinterpret_cast<void**>(&host_));
121     if (SUCCEEDED(hr)) {
122       CComPtr<IObjectWithSite> p;
123       hr = host_.QueryInterface(&p);
124       if (SUCCEEDED(hr)) {
125         p->SetSite(GetUnknown());
126       }
127     }
128     return hr;
129   }
130
131   HRESULT CreateControl() {
132     HRESULT hr = host_->CreateControl(L"AgControl.AgControl", m_hWnd, NULL);
133     EXPECT_HRESULT_SUCCEEDED(hr);
134     return hr;
135   }
136
137   base::win::ScopedComPtr<IAxWinHostWindow> host_;
138 };
139
140 // Create and in-place Silverlight control. Should be extended to do something
141 // more meaningful.
142 TEST(ChromeFramePerf, DISABLED_HostSilverlight2) {
143   SimpleModule module;
144   AtlAxWinInit();
145   CComObjectStackEx<SilverlightContainer> wnd;
146   RECT rc = {0, 0, 800, 600};
147   wnd.CreateWndAndHost(&rc);
148   base::PerfTimeLogger perf_create("Create Silverlight Control2");
149   wnd.CreateControl();
150   perf_create.Done();
151   wnd.DestroyWindow();
152 }
153
154 // Simplest test - creates in-place Silverlight control.
155 TEST(ChromeFramePerf, DISABLED_HostSilverlight) {
156   SimpleModule module;
157   AtlAxWinInit();
158   CAxWindow host;
159   RECT rc = {0, 0, 800, 600};
160   base::PerfTimeLogger perf_create("Create Silverlight Control");
161   host.Create(NULL, rc, L"AgControl.AgControl",
162       WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
163       WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
164   EXPECT_TRUE(host.m_hWnd != NULL);
165   base::win::ScopedComPtr<IDispatch> disp;
166   HRESULT hr = host.QueryControl(disp.Receive());
167   EXPECT_HRESULT_SUCCEEDED(hr);
168   disp.Release();
169   perf_create.Done();
170 }
171