| 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 <htiframe.h> | 5 #include <htiframe.h> |
| 6 #include <mshtml.h> | 6 #include <mshtml.h> |
| 7 | 7 |
| 8 #include "chrome_frame/protocol_sink_wrap.h" | 8 #include "chrome_frame/protocol_sink_wrap.h" |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 bool ProtocolSinkWrap::ignore_xua_ = false; | 31 bool ProtocolSinkWrap::ignore_xua_ = false; |
| 32 | 32 |
| 33 static const char kTextHtmlMimeType[] = "text/html"; | 33 static const char kTextHtmlMimeType[] = "text/html"; |
| 34 const wchar_t kUrlMonDllName[] = L"urlmon.dll"; | 34 const wchar_t kUrlMonDllName[] = L"urlmon.dll"; |
| 35 | 35 |
| 36 static const int kInternetProtocolStartIndex = 3; | 36 static const int kInternetProtocolStartIndex = 3; |
| 37 static const int kInternetProtocolReadIndex = 9; | 37 static const int kInternetProtocolReadIndex = 9; |
| 38 static const int kInternetProtocolStartExIndex = 13; | 38 static const int kInternetProtocolStartExIndex = 13; |
| 39 static const int kInternetProtocolLockRequestIndex = 11; | 39 static const int kInternetProtocolLockRequestIndex = 11; |
| 40 static const int kInternetProtocolUnlockRequestIndex = 12; | 40 static const int kInternetProtocolUnlockRequestIndex = 12; |
| 41 static const int kInternetProtocolAbortIndex = 5; | |
| 42 static const int kInternetProtocolTerminateIndex = 6; | |
| 43 | 41 |
| 44 | 42 |
| 45 // IInternetProtocol/Ex patches. | 43 // IInternetProtocol/Ex patches. |
| 46 STDMETHODIMP Hook_Start(InternetProtocol_Start_Fn orig_start, | 44 STDMETHODIMP Hook_Start(InternetProtocol_Start_Fn orig_start, |
| 47 IInternetProtocol* protocol, | 45 IInternetProtocol* protocol, |
| 48 LPCWSTR url, | 46 LPCWSTR url, |
| 49 IInternetProtocolSink* prot_sink, | 47 IInternetProtocolSink* prot_sink, |
| 50 IInternetBindInfo* bind_info, | 48 IInternetBindInfo* bind_info, |
| 51 DWORD flags, | 49 DWORD flags, |
| 52 HANDLE_PTR reserved); | 50 HANDLE_PTR reserved); |
| 53 | 51 |
| 54 STDMETHODIMP Hook_StartEx(InternetProtocol_StartEx_Fn orig_start_ex, | 52 STDMETHODIMP Hook_StartEx(InternetProtocol_StartEx_Fn orig_start_ex, |
| 55 IInternetProtocolEx* protocol, | 53 IInternetProtocolEx* protocol, |
| 56 IUri* uri, | 54 IUri* uri, |
| 57 IInternetProtocolSink* prot_sink, | 55 IInternetProtocolSink* prot_sink, |
| 58 IInternetBindInfo* bind_info, | 56 IInternetBindInfo* bind_info, |
| 59 DWORD flags, | 57 DWORD flags, |
| 60 HANDLE_PTR reserved); | 58 HANDLE_PTR reserved); |
| 61 | 59 |
| 62 STDMETHODIMP Hook_Read(InternetProtocol_Read_Fn orig_read, | 60 STDMETHODIMP Hook_Read(InternetProtocol_Read_Fn orig_read, |
| 63 IInternetProtocol* protocol, | 61 IInternetProtocol* protocol, |
| 64 void* buffer, | 62 void* buffer, |
| 65 ULONG size, | 63 ULONG size, |
| 66 ULONG* size_read); | 64 ULONG* size_read); |
| 67 | 65 |
| 68 STDMETHODIMP Hook_LockRequest(InternetProtocol_LockRequest_Fn orig_req, | 66 STDMETHODIMP Hook_LockRequest(InternetProtocol_LockRequest_Fn orig_req, |
| 69 IInternetProtocol* protocol, | 67 IInternetProtocol* protocol, DWORD dwOptions); |
| 70 DWORD options); | |
| 71 | 68 |
| 72 STDMETHODIMP Hook_UnlockRequest(InternetProtocol_UnlockRequest_Fn orig_req, | 69 STDMETHODIMP Hook_UnlockRequest(InternetProtocol_UnlockRequest_Fn orig_req, |
| 73 IInternetProtocol* protocol); | 70 IInternetProtocol* protocol); |
| 74 | 71 |
| 75 STDMETHODIMP Hook_Abort(InternetProtocol_Abort_Fn orig_req, | |
| 76 IInternetProtocol* protocol, | |
| 77 HRESULT hr, | |
| 78 DWORD options); | |
| 79 | |
| 80 STDMETHODIMP Hook_Terminate(InternetProtocol_Terminate_Fn orig_req, | |
| 81 IInternetProtocol* protocol, | |
| 82 DWORD options); | |
| 83 | |
| 84 ///////////////////////////////////////////////////////////////////////////// | 72 ///////////////////////////////////////////////////////////////////////////// |
| 85 BEGIN_VTABLE_PATCHES(CTransaction) | 73 BEGIN_VTABLE_PATCHES(CTransaction) |
| 86 VTABLE_PATCH_ENTRY(kInternetProtocolStartIndex, Hook_Start) | 74 VTABLE_PATCH_ENTRY(kInternetProtocolStartIndex, Hook_Start) |
| 87 VTABLE_PATCH_ENTRY(kInternetProtocolReadIndex, Hook_Read) | 75 VTABLE_PATCH_ENTRY(kInternetProtocolReadIndex, Hook_Read) |
| 88 VTABLE_PATCH_ENTRY(kInternetProtocolLockRequestIndex, Hook_LockRequest) | 76 VTABLE_PATCH_ENTRY(kInternetProtocolLockRequestIndex, Hook_LockRequest) |
| 89 VTABLE_PATCH_ENTRY(kInternetProtocolUnlockRequestIndex, Hook_UnlockRequest) | 77 VTABLE_PATCH_ENTRY(kInternetProtocolUnlockRequestIndex, Hook_UnlockRequest) |
| 90 VTABLE_PATCH_ENTRY(kInternetProtocolAbortIndex, Hook_Abort) | |
| 91 VTABLE_PATCH_ENTRY(kInternetProtocolTerminateIndex, Hook_Terminate) | |
| 92 END_VTABLE_PATCHES() | 78 END_VTABLE_PATCHES() |
| 93 | 79 |
| 94 BEGIN_VTABLE_PATCHES(CTransaction2) | 80 BEGIN_VTABLE_PATCHES(CTransaction2) |
| 95 VTABLE_PATCH_ENTRY(kInternetProtocolStartExIndex, Hook_StartEx) | 81 VTABLE_PATCH_ENTRY(kInternetProtocolStartExIndex, Hook_StartEx) |
| 96 END_VTABLE_PATCHES() | 82 END_VTABLE_PATCHES() |
| 97 | 83 |
| 98 // | 84 // |
| 99 // ProtocolSinkWrap implementation | 85 // ProtocolSinkWrap implementation |
| 100 | 86 |
| 101 // Static map initialization | 87 // Static map initialization |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 if (size_read) | 800 if (size_read) |
| 815 *size_read = 0; | 801 *size_read = 0; |
| 816 return S_FALSE; | 802 return S_FALSE; |
| 817 } | 803 } |
| 818 | 804 |
| 819 hr = prot_data->Read(buffer, size, size_read); | 805 hr = prot_data->Read(buffer, size, size_read); |
| 820 return hr; | 806 return hr; |
| 821 } | 807 } |
| 822 | 808 |
| 823 STDMETHODIMP Hook_LockRequest(InternetProtocol_LockRequest_Fn orig_req, | 809 STDMETHODIMP Hook_LockRequest(InternetProtocol_LockRequest_Fn orig_req, |
| 824 IInternetProtocol* protocol, | 810 IInternetProtocol* protocol, DWORD options) { |
| 825 DWORD options) { | |
| 826 DCHECK(orig_req); | 811 DCHECK(orig_req); |
| 827 | 812 |
| 828 scoped_refptr<ProtData> prot_data = ProtData::DataFromProtocol(protocol); | 813 scoped_refptr<ProtData> prot_data = ProtData::DataFromProtocol(protocol); |
| 829 if (prot_data && prot_data->is_attach_external_tab_request()) { | 814 if (prot_data && prot_data->is_attach_external_tab_request()) { |
| 830 prot_data->AddRef(); | 815 prot_data->AddRef(); |
| 831 return S_OK; | 816 return S_OK; |
| 832 } | 817 } |
| 833 | 818 |
| 834 // We are just pass through at this point, avoid false positive crash | 819 // We are just pass through at this point, avoid false positive crash |
| 835 // reports. | 820 // reports. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 846 prot_data->Release(); | 831 prot_data->Release(); |
| 847 return S_OK; | 832 return S_OK; |
| 848 } | 833 } |
| 849 | 834 |
| 850 // We are just pass through at this point, avoid false positive crash | 835 // We are just pass through at this point, avoid false positive crash |
| 851 // reports. | 836 // reports. |
| 852 ExceptionBarrierReportOnlyModule barrier; | 837 ExceptionBarrierReportOnlyModule barrier; |
| 853 return orig_req(protocol); | 838 return orig_req(protocol); |
| 854 } | 839 } |
| 855 | 840 |
| 856 STDMETHODIMP Hook_Abort(InternetProtocol_Abort_Fn orig_req, | |
| 857 IInternetProtocol* protocol, | |
| 858 HRESULT hr, | |
| 859 DWORD options) { | |
| 860 scoped_refptr<ProtData> prot_data = ProtData::DataFromProtocol(protocol); | |
| 861 if (prot_data) | |
| 862 prot_data->Invalidate(); | |
| 863 | |
| 864 // We are just pass through at this point, avoid false positive crash | |
| 865 // reports. | |
| 866 ExceptionBarrierReportOnlyModule barrier; | |
| 867 return orig_req(protocol, hr, options); | |
| 868 } | |
| 869 | |
| 870 STDMETHODIMP Hook_Terminate(InternetProtocol_Terminate_Fn orig_req, | |
| 871 IInternetProtocol* protocol, | |
| 872 DWORD options) { | |
| 873 scoped_refptr<ProtData> prot_data = ProtData::DataFromProtocol(protocol); | |
| 874 if (prot_data) | |
| 875 prot_data->Invalidate(); | |
| 876 | |
| 877 // We are just pass through at this point, avoid false positive crash | |
| 878 // reports. | |
| 879 ExceptionBarrierReportOnlyModule barrier; | |
| 880 return orig_req(protocol, options); | |
| 881 } | |
| 882 | |
| 883 // Patching / Hooking code. | 841 // Patching / Hooking code. |
| 884 class FakeProtocol : public CComObjectRootEx<CComSingleThreadModel>, | 842 class FakeProtocol : public CComObjectRootEx<CComSingleThreadModel>, |
| 885 public IInternetProtocol { | 843 public IInternetProtocol { |
| 886 public: | 844 public: |
| 887 BEGIN_COM_MAP(FakeProtocol) | 845 BEGIN_COM_MAP(FakeProtocol) |
| 888 COM_INTERFACE_ENTRY(IInternetProtocol) | 846 COM_INTERFACE_ENTRY(IInternetProtocol) |
| 889 COM_INTERFACE_ENTRY(IInternetProtocolRoot) | 847 COM_INTERFACE_ENTRY(IInternetProtocolRoot) |
| 890 END_COM_MAP() | 848 END_COM_MAP() |
| 891 | 849 |
| 892 STDMETHOD(Start)(LPCWSTR url, IInternetProtocolSink *protocol_sink, | 850 STDMETHOD(Start)(LPCWSTR url, IInternetProtocolSink *protocol_sink, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 // Explicit release, otherwise ~CComObjectStackEx will complain about | 940 // Explicit release, otherwise ~CComObjectStackEx will complain about |
| 983 // outstanding reference to us, because it runs before ~FakeProtocol | 941 // outstanding reference to us, because it runs before ~FakeProtocol |
| 984 prot.transaction_.Release(); | 942 prot.transaction_.Release(); |
| 985 } | 943 } |
| 986 } | 944 } |
| 987 | 945 |
| 988 void TransactionHooks::RevertHooks() { | 946 void TransactionHooks::RevertHooks() { |
| 989 vtable_patch::UnpatchInterfaceMethods(CTransaction_PatchInfo); | 947 vtable_patch::UnpatchInterfaceMethods(CTransaction_PatchInfo); |
| 990 vtable_patch::UnpatchInterfaceMethods(CTransaction2_PatchInfo); | 948 vtable_patch::UnpatchInterfaceMethods(CTransaction2_PatchInfo); |
| 991 } | 949 } |
| OLD | NEW |