OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome_frame/test/ie_event_sink.h" | 5 #include "chrome_frame/test/ie_event_sink.h" |
6 | 6 |
7 #include <shlguid.h> | 7 #include <shlguid.h> |
8 #include <shobjidl.h> | 8 #include <shobjidl.h> |
9 | 9 |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 chrome_frame_test::KillProcesses(chrome_frame_test::kIEImageName, 0, | 167 chrome_frame_test::KillProcesses(chrome_frame_test::kIEImageName, 0, |
168 !abnormal_shutdown_); | 168 !abnormal_shutdown_); |
169 chrome_frame_test::KillProcesses(chrome_frame_test::kIEBrokerImageName, 0, | 169 chrome_frame_test::KillProcesses(chrome_frame_test::kIEBrokerImageName, 0, |
170 !abnormal_shutdown_); | 170 !abnormal_shutdown_); |
171 } | 171 } |
172 | 172 |
173 bool IEEventSink::IsCFRendering() { | 173 bool IEEventSink::IsCFRendering() { |
174 DCHECK(web_browser2_); | 174 DCHECK(web_browser2_); |
175 | 175 |
176 if (web_browser2_) { | 176 if (web_browser2_) { |
177 ScopedComPtr<IDispatch> doc; | 177 base::win::ScopedComPtr<IDispatch> doc; |
178 web_browser2_->get_Document(doc.Receive()); | 178 web_browser2_->get_Document(doc.Receive()); |
179 if (doc) { | 179 if (doc) { |
180 // Detect if CF is rendering based on whether the document is a | 180 // Detect if CF is rendering based on whether the document is a |
181 // ChromeActiveDocument. Detecting based on hwnd is problematic as | 181 // ChromeActiveDocument. Detecting based on hwnd is problematic as |
182 // the CF Active Document window may not have been created yet. | 182 // the CF Active Document window may not have been created yet. |
183 ScopedComPtr<IChromeFrame> chrome_frame; | 183 base::win::ScopedComPtr<IChromeFrame> chrome_frame; |
184 chrome_frame.QueryFrom(doc); | 184 chrome_frame.QueryFrom(doc); |
185 return chrome_frame.get(); | 185 return chrome_frame.get(); |
186 } | 186 } |
187 } | 187 } |
188 return false; | 188 return false; |
189 } | 189 } |
190 | 190 |
191 void IEEventSink::PostMessageToCF(const std::wstring& message, | 191 void IEEventSink::PostMessageToCF(const std::wstring& message, |
192 const std::wstring& target) { | 192 const std::wstring& target) { |
193 EXPECT_TRUE(chrome_frame_ != NULL); | 193 EXPECT_TRUE(chrome_frame_ != NULL); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 if (web_browser2_) { | 234 if (web_browser2_) { |
235 ScopedBstr address_bar_url; | 235 ScopedBstr address_bar_url; |
236 EXPECT_EQ(S_OK, web_browser2_->get_LocationURL(address_bar_url.Receive())); | 236 EXPECT_EQ(S_OK, web_browser2_->get_LocationURL(address_bar_url.Receive())); |
237 EXPECT_EQ(expected_url, std::wstring(address_bar_url)); | 237 EXPECT_EQ(expected_url, std::wstring(address_bar_url)); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 void IEEventSink::Exec(const GUID* cmd_group_guid, DWORD command_id, | 241 void IEEventSink::Exec(const GUID* cmd_group_guid, DWORD command_id, |
242 DWORD cmd_exec_opt, VARIANT* in_args, | 242 DWORD cmd_exec_opt, VARIANT* in_args, |
243 VARIANT* out_args) { | 243 VARIANT* out_args) { |
244 ScopedComPtr<IOleCommandTarget> shell_browser_cmd_target; | 244 base::win::ScopedComPtr<IOleCommandTarget> shell_browser_cmd_target; |
245 DoQueryService(SID_STopLevelBrowser, web_browser2_, | 245 DoQueryService(SID_STopLevelBrowser, web_browser2_, |
246 shell_browser_cmd_target.Receive()); | 246 shell_browser_cmd_target.Receive()); |
247 ASSERT_TRUE(NULL != shell_browser_cmd_target); | 247 ASSERT_TRUE(NULL != shell_browser_cmd_target); |
248 EXPECT_HRESULT_SUCCEEDED(shell_browser_cmd_target->Exec(cmd_group_guid, | 248 EXPECT_HRESULT_SUCCEEDED(shell_browser_cmd_target->Exec(cmd_group_guid, |
249 command_id, cmd_exec_opt, in_args, out_args)); | 249 command_id, cmd_exec_opt, in_args, out_args)); |
250 } | 250 } |
251 | 251 |
252 HWND IEEventSink::GetBrowserWindow() { | 252 HWND IEEventSink::GetBrowserWindow() { |
253 HWND browser_window = NULL; | 253 HWND browser_window = NULL; |
254 web_browser2_->get_HWND(reinterpret_cast<SHANDLE_PTR*>(&browser_window)); | 254 web_browser2_->get_HWND(reinterpret_cast<SHANDLE_PTR*>(&browser_window)); |
255 EXPECT_TRUE(::IsWindow(browser_window)); | 255 EXPECT_TRUE(::IsWindow(browser_window)); |
256 return browser_window; | 256 return browser_window; |
257 } | 257 } |
258 | 258 |
259 HWND IEEventSink::GetRendererWindow() { | 259 HWND IEEventSink::GetRendererWindow() { |
260 HWND renderer_window = NULL; | 260 HWND renderer_window = NULL; |
261 if (IsCFRendering()) { | 261 if (IsCFRendering()) { |
262 DCHECK(chrome_frame_); | 262 DCHECK(chrome_frame_); |
263 ScopedComPtr<IOleWindow> ole_window; | 263 base::win::ScopedComPtr<IOleWindow> ole_window; |
264 ole_window.QueryFrom(chrome_frame_); | 264 ole_window.QueryFrom(chrome_frame_); |
265 EXPECT_TRUE(ole_window.get()); | 265 EXPECT_TRUE(ole_window.get()); |
266 | 266 |
267 if (ole_window) { | 267 if (ole_window) { |
268 HWND activex_window = NULL; | 268 HWND activex_window = NULL; |
269 ole_window->GetWindow(&activex_window); | 269 ole_window->GetWindow(&activex_window); |
270 EXPECT_TRUE(IsWindow(activex_window)); | 270 EXPECT_TRUE(IsWindow(activex_window)); |
271 | 271 |
272 wchar_t class_name[MAX_PATH] = {0}; | 272 wchar_t class_name[MAX_PATH] = {0}; |
273 HWND child_window = NULL; | 273 HWND child_window = NULL; |
274 // chrome tab window is the first (and the only) child of activex | 274 // chrome tab window is the first (and the only) child of activex |
275 for (HWND first_child = activex_window; ::IsWindow(first_child); | 275 for (HWND first_child = activex_window; ::IsWindow(first_child); |
276 first_child = ::GetWindow(first_child, GW_CHILD)) { | 276 first_child = ::GetWindow(first_child, GW_CHILD)) { |
277 child_window = first_child; | 277 child_window = first_child; |
278 GetClassName(child_window, class_name, arraysize(class_name)); | 278 GetClassName(child_window, class_name, arraysize(class_name)); |
279 if (!_wcsicmp(class_name, L"Chrome_RenderWidgetHostHWND")) { | 279 if (!_wcsicmp(class_name, L"Chrome_RenderWidgetHostHWND")) { |
280 renderer_window = child_window; | 280 renderer_window = child_window; |
281 break; | 281 break; |
282 } | 282 } |
283 } | 283 } |
284 } | 284 } |
285 } else { | 285 } else { |
286 DCHECK(web_browser2_); | 286 DCHECK(web_browser2_); |
287 ScopedComPtr<IDispatch> doc; | 287 base::win::ScopedComPtr<IDispatch> doc; |
288 HRESULT hr = web_browser2_->get_Document(doc.Receive()); | 288 HRESULT hr = web_browser2_->get_Document(doc.Receive()); |
289 EXPECT_HRESULT_SUCCEEDED(hr); | 289 EXPECT_HRESULT_SUCCEEDED(hr); |
290 EXPECT_TRUE(doc); | 290 EXPECT_TRUE(doc); |
291 if (doc) { | 291 if (doc) { |
292 ScopedComPtr<IOleWindow> ole_window; | 292 base::win::ScopedComPtr<IOleWindow> ole_window; |
293 ole_window.QueryFrom(doc); | 293 ole_window.QueryFrom(doc); |
294 EXPECT_TRUE(ole_window); | 294 EXPECT_TRUE(ole_window); |
295 if (ole_window) { | 295 if (ole_window) { |
296 ole_window->GetWindow(&renderer_window); | 296 ole_window->GetWindow(&renderer_window); |
297 } | 297 } |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 EXPECT_TRUE(::IsWindow(renderer_window)); | 301 EXPECT_TRUE(::IsWindow(renderer_window)); |
302 return renderer_window; | 302 return renderer_window; |
303 } | 303 } |
304 | 304 |
305 HWND IEEventSink::GetRendererWindowSafe() { | 305 HWND IEEventSink::GetRendererWindowSafe() { |
306 HWND renderer_window = NULL; | 306 HWND renderer_window = NULL; |
307 if (IsCFRendering()) { | 307 if (IsCFRendering()) { |
308 DCHECK(chrome_frame_); | 308 DCHECK(chrome_frame_); |
309 ScopedComPtr<IOleWindow> ole_window; | 309 base::win::ScopedComPtr<IOleWindow> ole_window; |
310 ole_window.QueryFrom(chrome_frame_); | 310 ole_window.QueryFrom(chrome_frame_); |
311 | 311 |
312 if (ole_window) { | 312 if (ole_window) { |
313 HWND activex_window = NULL; | 313 HWND activex_window = NULL; |
314 ole_window->GetWindow(&activex_window); | 314 ole_window->GetWindow(&activex_window); |
315 | 315 |
316 // chrome tab window is the first (and the only) child of activex | 316 // chrome tab window is the first (and the only) child of activex |
317 for (HWND first_child = activex_window; ::IsWindow(first_child); | 317 for (HWND first_child = activex_window; ::IsWindow(first_child); |
318 first_child = ::GetWindow(first_child, GW_CHILD)) { | 318 first_child = ::GetWindow(first_child, GW_CHILD)) { |
319 renderer_window = first_child; | 319 renderer_window = first_child; |
320 } | 320 } |
321 wchar_t class_name[MAX_PATH] = {0}; | 321 wchar_t class_name[MAX_PATH] = {0}; |
322 GetClassName(renderer_window, class_name, arraysize(class_name)); | 322 GetClassName(renderer_window, class_name, arraysize(class_name)); |
323 if (_wcsicmp(class_name, L"Chrome_RenderWidgetHostHWND") != 0) | 323 if (_wcsicmp(class_name, L"Chrome_RenderWidgetHostHWND") != 0) |
324 renderer_window = NULL; | 324 renderer_window = NULL; |
325 } | 325 } |
326 } else { | 326 } else { |
327 DCHECK(web_browser2_); | 327 DCHECK(web_browser2_); |
328 ScopedComPtr<IDispatch> doc; | 328 base::win::ScopedComPtr<IDispatch> doc; |
329 web_browser2_->get_Document(doc.Receive()); | 329 web_browser2_->get_Document(doc.Receive()); |
330 if (doc) { | 330 if (doc) { |
331 ScopedComPtr<IOleWindow> ole_window; | 331 base::win::ScopedComPtr<IOleWindow> ole_window; |
332 ole_window.QueryFrom(doc); | 332 ole_window.QueryFrom(doc); |
333 if (ole_window) { | 333 if (ole_window) { |
334 ole_window->GetWindow(&renderer_window); | 334 ole_window->GetWindow(&renderer_window); |
335 } | 335 } |
336 } | 336 } |
337 } | 337 } |
338 if (!::IsWindow(renderer_window)) | 338 if (!::IsWindow(renderer_window)) |
339 renderer_window = NULL; | 339 renderer_window = NULL; |
340 return renderer_window; | 340 return renderer_window; |
341 } | 341 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 void IEEventSink::Refresh() { | 375 void IEEventSink::Refresh() { |
376 base::win::ScopedVariant refresh_level(REFRESH_COMPLETELY); | 376 base::win::ScopedVariant refresh_level(REFRESH_COMPLETELY); |
377 web_browser2_->Refresh2(refresh_level.AsInput()); | 377 web_browser2_->Refresh2(refresh_level.AsInput()); |
378 } | 378 } |
379 | 379 |
380 // private methods | 380 // private methods |
381 void IEEventSink::ConnectToChromeFrame() { | 381 void IEEventSink::ConnectToChromeFrame() { |
382 DCHECK(web_browser2_); | 382 DCHECK(web_browser2_); |
383 if (chrome_frame_.get()) | 383 if (chrome_frame_.get()) |
384 return; | 384 return; |
385 ScopedComPtr<IShellBrowser> shell_browser; | 385 base::win::ScopedComPtr<IShellBrowser> shell_browser; |
386 DoQueryService(SID_STopLevelBrowser, web_browser2_, | 386 DoQueryService(SID_STopLevelBrowser, web_browser2_, |
387 shell_browser.Receive()); | 387 shell_browser.Receive()); |
388 | 388 |
389 if (shell_browser) { | 389 if (shell_browser) { |
390 ScopedComPtr<IShellView> shell_view; | 390 base::win::ScopedComPtr<IShellView> shell_view; |
391 shell_browser->QueryActiveShellView(shell_view.Receive()); | 391 shell_browser->QueryActiveShellView(shell_view.Receive()); |
392 if (shell_view) { | 392 if (shell_view) { |
393 shell_view->GetItemObject(SVGIO_BACKGROUND, __uuidof(IChromeFrame), | 393 shell_view->GetItemObject(SVGIO_BACKGROUND, __uuidof(IChromeFrame), |
394 reinterpret_cast<void**>(chrome_frame_.Receive())); | 394 reinterpret_cast<void**>(chrome_frame_.Receive())); |
395 } | 395 } |
396 | 396 |
397 if (chrome_frame_) { | 397 if (chrome_frame_) { |
398 base::win::ScopedVariant onmessage(onmessage_.ToDispatch()); | 398 base::win::ScopedVariant onmessage(onmessage_.ToDispatch()); |
399 base::win::ScopedVariant onloaderror(onloaderror_.ToDispatch()); | 399 base::win::ScopedVariant onloaderror(onloaderror_.ToDispatch()); |
400 base::win::ScopedVariant onload(onload_.ToDispatch()); | 400 base::win::ScopedVariant onload(onload_.ToDispatch()); |
401 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onmessage(onmessage)); | 401 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onmessage(onmessage)); |
402 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onloaderror(onloaderror)); | 402 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onloaderror(onloaderror)); |
403 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onload(onload)); | 403 EXPECT_HRESULT_SUCCEEDED(chrome_frame_->put_onload(onload)); |
404 } | 404 } |
405 } | 405 } |
406 } | 406 } |
407 | 407 |
408 void IEEventSink::DisconnectFromChromeFrame() { | 408 void IEEventSink::DisconnectFromChromeFrame() { |
409 if (chrome_frame_) { | 409 if (chrome_frame_) { |
410 // Use a local ref counted copy of the IChromeFrame interface as the | 410 // Use a local ref counted copy of the IChromeFrame interface as the |
411 // outgoing calls could cause the interface to be deleted due to a message | 411 // outgoing calls could cause the interface to be deleted due to a message |
412 // pump running in the context of the outgoing call. | 412 // pump running in the context of the outgoing call. |
413 ScopedComPtr<IChromeFrame> chrome_frame(chrome_frame_); | 413 base::win::ScopedComPtr<IChromeFrame> chrome_frame(chrome_frame_); |
414 chrome_frame_.Release(); | 414 chrome_frame_.Release(); |
415 base::win::ScopedVariant dummy(static_cast<IDispatch*>(NULL)); | 415 base::win::ScopedVariant dummy(static_cast<IDispatch*>(NULL)); |
416 chrome_frame->put_onmessage(dummy); | 416 chrome_frame->put_onmessage(dummy); |
417 chrome_frame->put_onload(dummy); | 417 chrome_frame->put_onload(dummy); |
418 chrome_frame->put_onloaderror(dummy); | 418 chrome_frame->put_onloaderror(dummy); |
419 } | 419 } |
420 } | 420 } |
421 | 421 |
422 void IEEventSink::FindIEProcessId() { | 422 void IEEventSink::FindIEProcessId() { |
423 HWND hwnd = NULL; | 423 HWND hwnd = NULL; |
(...skipping 19 matching lines...) Expand all Loading... |
443 return; | 443 return; |
444 | 444 |
445 if (listener_) | 445 if (listener_) |
446 listener_->OnNewWindow2(dispatch, s); | 446 listener_->OnNewWindow2(dispatch, s); |
447 | 447 |
448 // Note that |dispatch| is an [in/out] argument. IE is asking listeners if | 448 // Note that |dispatch| is an [in/out] argument. IE is asking listeners if |
449 // they want to use a IWebBrowser2 of their choice for the new window. | 449 // they want to use a IWebBrowser2 of their choice for the new window. |
450 // Since we need to listen on events on the new browser, we create one | 450 // Since we need to listen on events on the new browser, we create one |
451 // if needed. | 451 // if needed. |
452 if (!*dispatch) { | 452 if (!*dispatch) { |
453 ScopedComPtr<IDispatch> new_browser; | 453 base::win::ScopedComPtr<IDispatch> new_browser; |
454 HRESULT hr = new_browser.CreateInstance(CLSID_InternetExplorer, NULL, | 454 HRESULT hr = new_browser.CreateInstance(CLSID_InternetExplorer, NULL, |
455 CLSCTX_LOCAL_SERVER); | 455 CLSCTX_LOCAL_SERVER); |
456 DCHECK(SUCCEEDED(hr) && new_browser); | 456 DCHECK(SUCCEEDED(hr) && new_browser); |
457 *dispatch = new_browser.Detach(); | 457 *dispatch = new_browser.Detach(); |
458 } | 458 } |
459 | 459 |
460 if (*dispatch && listener_) | 460 if (*dispatch && listener_) |
461 listener_->OnNewBrowserWindow(*dispatch, ScopedBstr()); | 461 listener_->OnNewBrowserWindow(*dispatch, ScopedBstr()); |
462 } | 462 } |
463 | 463 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 return; | 521 return; |
522 | 522 |
523 if (listener_) | 523 if (listener_) |
524 listener_->OnNewWindow3(dispatch, cancel, flags, url_context, url); | 524 listener_->OnNewWindow3(dispatch, cancel, flags, url_context, url); |
525 | 525 |
526 // Note that |dispatch| is an [in/out] argument. IE is asking listeners if | 526 // Note that |dispatch| is an [in/out] argument. IE is asking listeners if |
527 // they want to use a IWebBrowser2 of their choice for the new window. | 527 // they want to use a IWebBrowser2 of their choice for the new window. |
528 // Since we need to listen on events on the new browser, we create one | 528 // Since we need to listen on events on the new browser, we create one |
529 // if needed. | 529 // if needed. |
530 if (!*dispatch) { | 530 if (!*dispatch) { |
531 ScopedComPtr<IDispatch> new_browser; | 531 base::win::ScopedComPtr<IDispatch> new_browser; |
532 HRESULT hr = new_browser.CreateInstance(CLSID_InternetExplorer, NULL, | 532 HRESULT hr = new_browser.CreateInstance(CLSID_InternetExplorer, NULL, |
533 CLSCTX_LOCAL_SERVER); | 533 CLSCTX_LOCAL_SERVER); |
534 DCHECK(SUCCEEDED(hr) && new_browser); | 534 DCHECK(SUCCEEDED(hr) && new_browser); |
535 *dispatch = new_browser.Detach(); | 535 *dispatch = new_browser.Detach(); |
536 } | 536 } |
537 | 537 |
538 if (*dispatch && listener_) | 538 if (*dispatch && listener_) |
539 listener_->OnNewBrowserWindow(*dispatch, url); | 539 listener_->OnNewBrowserWindow(*dispatch, url); |
540 } | 540 } |
541 | 541 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 source.Receive(), NULL, NULL)); | 602 source.Receive(), NULL, NULL)); |
603 } | 603 } |
604 } | 604 } |
605 | 605 |
606 if (listener_) | 606 if (listener_) |
607 listener_->OnMessage(V_BSTR(&data), V_BSTR(&origin), V_BSTR(&source)); | 607 listener_->OnMessage(V_BSTR(&data), V_BSTR(&origin), V_BSTR(&source)); |
608 return S_OK; | 608 return S_OK; |
609 } | 609 } |
610 | 610 |
611 } // namespace chrome_frame_test | 611 } // namespace chrome_frame_test |
OLD | NEW |