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