|
1 /* |
|
2 * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * |
|
8 * 1. Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * 2. Redistributions in binary form must reproduce the above copyright |
|
11 * notice, this list of conditions and the following disclaimer in the |
|
12 * documentation and/or other materials provided with the distribution. |
|
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
14 * its contributors may be used to endorse or promote products derived |
|
15 * from this software without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #include "DumpRenderTree.h" |
|
30 #include "FrameLoaderDelegate.h" |
|
31 |
|
32 #include "EventSender.h" |
|
33 #include "GCController.h" |
|
34 #include "LayoutTestController.h" |
|
35 #include "WorkQueueItem.h" |
|
36 #include "WorkQueue.h" |
|
37 #include <WebCore/COMPtr.h> |
|
38 #include <JavaScriptCore/Assertions.h> |
|
39 #include <JavaScriptCore/JavaScriptCore.h> |
|
40 #include <WebKit/IWebFramePrivate.h> |
|
41 #include <WebKit/IWebViewPrivate.h> |
|
42 #include <stdio.h> |
|
43 |
|
44 static FrameLoadDelegate* g_delegateWaitingOnTimer; |
|
45 |
|
46 FrameLoadDelegate::FrameLoadDelegate() |
|
47 : m_refCount(1) |
|
48 , m_gcController(new GCController) |
|
49 { |
|
50 } |
|
51 |
|
52 FrameLoadDelegate::~FrameLoadDelegate() |
|
53 { |
|
54 } |
|
55 |
|
56 HRESULT STDMETHODCALLTYPE FrameLoadDelegate::QueryInterface(REFIID riid, void** ppvObject) |
|
57 { |
|
58 *ppvObject = 0; |
|
59 if (IsEqualGUID(riid, IID_IUnknown)) |
|
60 *ppvObject = static_cast<IWebFrameLoadDelegate*>(this); |
|
61 else if (IsEqualGUID(riid, IID_IWebFrameLoadDelegate)) |
|
62 *ppvObject = static_cast<IWebFrameLoadDelegate*>(this); |
|
63 else |
|
64 return E_NOINTERFACE; |
|
65 |
|
66 AddRef(); |
|
67 return S_OK; |
|
68 } |
|
69 |
|
70 ULONG STDMETHODCALLTYPE FrameLoadDelegate::AddRef(void) |
|
71 { |
|
72 return ++m_refCount; |
|
73 } |
|
74 |
|
75 ULONG STDMETHODCALLTYPE FrameLoadDelegate::Release(void) |
|
76 { |
|
77 ULONG newRef = --m_refCount; |
|
78 if (!newRef) |
|
79 delete(this); |
|
80 |
|
81 return newRef; |
|
82 } |
|
83 |
|
84 |
|
85 HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didStartProvisionalLoadForFrame( |
|
86 /* [in] */ IWebView* webView, |
|
87 /* [in] */ IWebFrame* frame) |
|
88 { |
|
89 // Make sure we only set this once per test. If it gets cleared, and then set again, we might |
|
90 // end up doing two dumps for one test. |
|
91 if (!topLoadingFrame && !done) |
|
92 topLoadingFrame = frame; |
|
93 |
|
94 return S_OK; |
|
95 } |
|
96 |
|
97 HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didCommitLoadForFrame( |
|
98 /* [in] */ IWebView *webView, |
|
99 /* [in] */ IWebFrame *frame) |
|
100 { |
|
101 COMPtr<IWebViewPrivate> webViewPrivate; |
|
102 HRESULT hr = webView->QueryInterface(&webViewPrivate); |
|
103 if (FAILED(hr)) |
|
104 return hr; |
|
105 webViewPrivate->updateActiveState(); |
|
106 return S_OK; |
|
107 } |
|
108 |
|
109 HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didReceiveTitle( |
|
110 /* [in] */ IWebView *webView, |
|
111 /* [in] */ BSTR title, |
|
112 /* [in] */ IWebFrame *frame) |
|
113 { |
|
114 if (::layoutTestController->dumpTitleChanges() && !done) |
|
115 printf("TITLE CHANGED: %S\n", title ? title : L""); |
|
116 return S_OK; |
|
117 } |
|
118 |
|
119 void FrameLoadDelegate::processWork() |
|
120 { |
|
121 // quit doing work once a load is in progress |
|
122 while (!topLoadingFrame && WorkQueue::shared()->count()) { |
|
123 WorkQueueItem* item = WorkQueue::shared()->dequeue(); |
|
124 ASSERT(item); |
|
125 item->invoke(); |
|
126 } |
|
127 |
|
128 // if we didn't start a new load, then we finished all the commands, so we're ready to dump state |
|
129 if (!topLoadingFrame && !::layoutTestController->waitToDump()) |
|
130 dump(); |
|
131 } |
|
132 |
|
133 static void CALLBACK processWorkTimer(HWND, UINT, UINT_PTR id, DWORD) |
|
134 { |
|
135 ::KillTimer(0, id); |
|
136 FrameLoadDelegate* d = g_delegateWaitingOnTimer; |
|
137 g_delegateWaitingOnTimer = 0; |
|
138 d->processWork(); |
|
139 } |
|
140 |
|
141 void FrameLoadDelegate::locationChangeDone(IWebError*, IWebFrame* frame) |
|
142 { |
|
143 if (frame != topLoadingFrame) |
|
144 return; |
|
145 |
|
146 topLoadingFrame = 0; |
|
147 WorkQueue::shared()->setFrozen(true); |
|
148 |
|
149 if (::layoutTestController->waitToDump()) |
|
150 return; |
|
151 |
|
152 if (WorkQueue::shared()->count()) { |
|
153 ASSERT(!g_delegateWaitingOnTimer); |
|
154 g_delegateWaitingOnTimer = this; |
|
155 ::SetTimer(0, 0, 0, processWorkTimer); |
|
156 return; |
|
157 } |
|
158 |
|
159 dump(); |
|
160 } |
|
161 |
|
162 HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didFinishLoadForFrame( |
|
163 /* [in] */ IWebView* webView, |
|
164 /* [in] */ IWebFrame* frame) |
|
165 { |
|
166 locationChangeDone(0, frame); |
|
167 return S_OK; |
|
168 } |
|
169 |
|
170 HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didFailLoadWithError( |
|
171 /* [in] */ IWebView* webView, |
|
172 /* [in] */ IWebError* error, |
|
173 /* [in] */ IWebFrame* forFrame) |
|
174 { |
|
175 locationChangeDone(error, forFrame); |
|
176 return S_OK; |
|
177 } |
|
178 |
|
179 HRESULT STDMETHODCALLTYPE FrameLoadDelegate::windowScriptObjectAvailable( |
|
180 /* [in] */ IWebView *sender, |
|
181 /* [in] */ JSContextRef context, |
|
182 /* [in] */ JSObjectRef windowObject) |
|
183 { |
|
184 JSValueRef exception = 0; |
|
185 |
|
186 ::layoutTestController->makeWindowObject(context, windowObject, &exception); |
|
187 ASSERT(!exception); |
|
188 |
|
189 m_gcController->makeWindowObject(context, windowObject, &exception); |
|
190 ASSERT(!exception); |
|
191 |
|
192 JSStringRef eventSenderStr = JSStringCreateWithUTF8CString("eventSender"); |
|
193 JSValueRef eventSender = makeEventSender(context); |
|
194 JSObjectSetProperty(context, windowObject, eventSenderStr, eventSender, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, 0); |
|
195 JSStringRelease(eventSenderStr); |
|
196 |
|
197 return S_OK; |
|
198 } |