OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 <htiframe.h> | 5 #include <htiframe.h> |
| 6 #include <mshtml.h> |
6 | 7 |
7 #include "chrome_frame/protocol_sink_wrap.h" | 8 #include "chrome_frame/protocol_sink_wrap.h" |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/registry.h" | 11 #include "base/registry.h" |
11 #include "base/scoped_bstr_win.h" | 12 #include "base/scoped_bstr_win.h" |
12 #include "base/singleton.h" | 13 #include "base/singleton.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 | 15 |
15 #include "chrome_frame/utils.h" | 16 #include "chrome_frame/utils.h" |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 scoped_refptr<ProtocolSinkWrap> ProtocolSinkWrap::InstanceFromProtocol( | 603 scoped_refptr<ProtocolSinkWrap> ProtocolSinkWrap::InstanceFromProtocol( |
603 IInternetProtocol* protocol) { | 604 IInternetProtocol* protocol) { |
604 CComCritSecLock<CComAutoCriticalSection> lock(sink_map_lock_); | 605 CComCritSecLock<CComAutoCriticalSection> lock(sink_map_lock_); |
605 scoped_refptr<ProtocolSinkWrap> instance; | 606 scoped_refptr<ProtocolSinkWrap> instance; |
606 ProtocolSinkMap::iterator it = sink_map_.find(protocol); | 607 ProtocolSinkMap::iterator it = sink_map_.find(protocol); |
607 if (sink_map_.end() != it) | 608 if (sink_map_.end() != it) |
608 instance = it->second; | 609 instance = it->second; |
609 return instance; | 610 return instance; |
610 } | 611 } |
611 | 612 |
612 HRESULT ProtocolSinkWrap::WebBrowserFromProtocolSink( | |
613 IInternetProtocolSink* sink, IWebBrowser2** web_browser) { | |
614 // TODO(tommi): GUID_NULL doesn't work when loading from history. | |
615 // asking for IID_IHttpNegotiate as the service id works, but | |
616 // getting the IWebBrowser2 interface still doesn't work. | |
617 ScopedComPtr<IHttpNegotiate> http_negotiate; | |
618 HRESULT hr = DoQueryService(GUID_NULL, sink, http_negotiate.Receive()); | |
619 if (http_negotiate) | |
620 hr = DoQueryService(IID_ITargetFrame2, http_negotiate, web_browser); | |
621 | |
622 return hr; | |
623 } | |
624 | |
625 ScopedComPtr<IInternetProtocolSink> ProtocolSinkWrap::MaybeWrapSink( | 613 ScopedComPtr<IInternetProtocolSink> ProtocolSinkWrap::MaybeWrapSink( |
626 IInternetProtocol* protocol, IInternetProtocolSink* prot_sink, | 614 IInternetProtocol* protocol, IInternetProtocolSink* prot_sink, |
627 const wchar_t* url) { | 615 const wchar_t* url) { |
628 ScopedComPtr<IInternetProtocolSink> sink_to_use(prot_sink); | 616 ScopedComPtr<IInternetProtocolSink> sink_to_use(prot_sink); |
629 ScopedComPtr<IWebBrowser2> web_browser; | 617 ScopedComPtr<IWebBrowser2> web_browser; |
630 WebBrowserFromProtocolSink(prot_sink, web_browser.Receive()); | 618 |
| 619 // FYI: GUID_NULL doesn't work when the URL is being loaded from history. |
| 620 // asking for IID_IHttpNegotiate as the service id works, but |
| 621 // getting the IWebBrowser2 interface still doesn't work. |
| 622 ScopedComPtr<IHttpNegotiate> http_negotiate; |
| 623 HRESULT hr = DoQueryService(GUID_NULL, prot_sink, http_negotiate.Receive()); |
| 624 if (http_negotiate) { |
| 625 hr = DoQueryService(IID_ITargetFrame2, http_negotiate, |
| 626 web_browser.Receive()); |
| 627 } |
| 628 |
631 if (web_browser) { | 629 if (web_browser) { |
632 CComObject<ProtocolSinkWrap>* wrap = NULL; | 630 // Do one more check to make sure we don't wrap requests that are |
633 CComObject<ProtocolSinkWrap>::CreateInstance(&wrap); | 631 // targeted to sub frames. |
634 DCHECK(wrap); | 632 // For a use case, see FullTabModeIE_SubIFrame and FullTabModeIE_SubFrame |
635 if (wrap->Initialize(protocol, prot_sink, url)) { | 633 // unit tests. |
636 sink_to_use = wrap; | 634 |
| 635 // Default should_wrap to true in case no window is available. |
| 636 // In that case this request is a top level request. |
| 637 bool should_wrap = true; |
| 638 |
| 639 ScopedComPtr<IHTMLWindow2> current_frame, parent_frame; |
| 640 hr = DoQueryService(IID_IHTMLWindow2, http_negotiate, |
| 641 current_frame.Receive()); |
| 642 if (current_frame) { |
| 643 // Only the top level window will return self when get_parent is called. |
| 644 current_frame->get_parent(parent_frame.Receive()); |
| 645 if (parent_frame != current_frame) { |
| 646 DLOG(INFO) << "Sub frame detected"; |
| 647 should_wrap = false; |
| 648 } |
| 649 } |
| 650 |
| 651 if (should_wrap) { |
| 652 CComObject<ProtocolSinkWrap>* wrap = NULL; |
| 653 CComObject<ProtocolSinkWrap>::CreateInstance(&wrap); |
| 654 DCHECK(wrap); |
| 655 if (wrap->Initialize(protocol, prot_sink, url)) { |
| 656 sink_to_use = wrap; |
| 657 } |
637 } | 658 } |
638 } | 659 } |
639 | 660 |
640 return sink_to_use; | 661 return sink_to_use; |
641 } | 662 } |
OLD | NEW |