Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/plugin/PluginWbPassThrough.cpp

Issue 4912420225024000: Issue #1234 - Convert strings associated with URL's (Closed)
Patch Set: Rebased Created Oct. 21, 2014, 6:26 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginWbPassThrough.h" 3 #include "PluginWbPassThrough.h"
4 #include "PluginClient.h" 4 #include "PluginClient.h"
5 #include "PluginClientFactory.h" 5 #include "PluginClientFactory.h"
6 #include "PluginFilter.h" 6 #include "PluginFilter.h"
7 #include "PluginSettings.h" 7 #include "PluginSettings.h"
8 #include "PluginClass.h" 8 #include "PluginClass.h"
9 #include "PluginSystem.h" 9 #include "PluginSystem.h"
10 #include <WinInet.h> 10 #include <WinInet.h>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 // It is important to have this check last, since it is rather generic, and mi ght overlay text/html, for example 52 // It is important to have this check last, since it is rather generic, and mi ght overlay text/html, for example
53 if (mimeType.Find(L"xml") >= 0) 53 if (mimeType.Find(L"xml") >= 0)
54 { 54 {
55 return CFilter::contentTypeXmlHttpRequest; 55 return CFilter::contentTypeXmlHttpRequest;
56 } 56 }
57 57
58 return CFilter::contentTypeAny; 58 return CFilter::contentTypeAny;
59 } 59 }
60 60
61 int WBPassthruSink::GetContentTypeFromURL(const CString& src) 61 int WBPassthruSink::GetContentTypeFromURL(const std::wstring& src)
62 { 62 {
63 CString srcExt = src; 63 CString srcLegacy = ToCString(src);
64 CString srcExt = srcLegacy;
64 65
65 int pos = 0; 66 int pos = 0;
66 if ((pos = src.Find('?')) > 0) 67 if ((pos = srcLegacy.Find('?')) > 0)
67 { 68 {
68 srcExt = src.Left(pos); 69 srcExt = srcLegacy.Left(pos);
69 } 70 }
70 71
71 int lastDotIndex = srcExt.ReverseFind('.'); 72 int lastDotIndex = srcExt.ReverseFind('.');
72 if (lastDotIndex < 0) 73 if (lastDotIndex < 0)
73 return CFilter::contentTypeAny; 74 return CFilter::contentTypeAny;
74 CString ext = srcExt.Mid(lastDotIndex); 75 CString ext = srcExt.Mid(lastDotIndex);
75 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg") 76 if (ext == L".jpg" || ext == L".gif" || ext == L".png" || ext == L".jpeg")
76 { 77 {
77 return CFilter::contentTypeImage; 78 return CFilter::contentTypeImage;
78 } 79 }
(...skipping 13 matching lines...) Expand all
92 { 93 {
93 return CFilter::contentTypeObject; 94 return CFilter::contentTypeObject;
94 } 95 }
95 else if (ext == L".jsp" || ext == L".php" || ext == L".html") 96 else if (ext == L".jsp" || ext == L".php" || ext == L".html")
96 { 97 {
97 return CFilter::contentTypeSubdocument; 98 return CFilter::contentTypeSubdocument;
98 } 99 }
99 return CFilter::contentTypeAny; 100 return CFilter::contentTypeAny;
100 } 101 }
101 102
102 int WBPassthruSink::GetContentType(const CString& mimeType, const std::wstring& domain, const CString& src) 103 int WBPassthruSink::GetContentType(const CString& mimeType, const std::wstring& domain, const std::wstring& src)
103 { 104 {
104 // No referer or mime type 105 // No referer or mime type
105 // BINDSTRING_XDR_ORIGIN works only for IE v8+ 106 // BINDSTRING_XDR_ORIGIN works only for IE v8+
106 if (mimeType.IsEmpty() && domain.empty() && CPluginClient::GetInstance()->GetI EVersion() >= 8) 107 if (mimeType.IsEmpty() && domain.empty() && CPluginClient::GetInstance()->GetI EVersion() >= 8)
107 { 108 {
108 return CFilter::contentTypeXmlHttpRequest; 109 return CFilter::contentTypeXmlHttpRequest;
109 } 110 }
110 int contentType = GetContentTypeFromMimeType(mimeType); 111 int contentType = GetContentTypeFromMimeType(mimeType);
111 if (contentType == CFilter::contentTypeAny) 112 if (contentType == CFilter::contentTypeAny)
112 { 113 {
113 contentType = GetContentTypeFromURL(src); 114 contentType = GetContentTypeFromURL(src);
114 } 115 }
115 return contentType; 116 return contentType;
116 } 117 }
117 118
118 //////////////////////////////////////////////////////////////////////////////// //////// 119 //////////////////////////////////////////////////////////////////////////////// ////////
119 //WBPassthruSink 120 //WBPassthruSink
120 //Monitor and/or cancel every request and responde 121 //Monitor and/or cancel every request and responde
121 //WB makes, including images, sounds, scripts, etc 122 //WB makes, including images, sounds, scripts, etc
122 //////////////////////////////////////////////////////////////////////////////// //////// 123 //////////////////////////////////////////////////////////////////////////////// ////////
123 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin k, 124 HRESULT WBPassthruSink::OnStart(LPCWSTR szUrl, IInternetProtocolSink *pOIProtSin k,
124 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN DLE_PTR dwReserved, 125 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HAN DLE_PTR dwReserved,
125 IInternetProtocol* pTargetProtocol, bool& handle d) 126 IInternetProtocol* pTargetProtocol, bool& handle d)
126 { 127 {
127 m_pTargetProtocol = pTargetProtocol; 128 m_pTargetProtocol = pTargetProtocol;
128 bool isBlocked = false; 129 bool isBlocked = false;
129 CString src = szUrl; 130 std::wstring src(szUrl);
130 DEBUG_GENERAL(src); 131 DEBUG_GENERAL(ToCString(src));
131 CPluginClient::UnescapeUrl(src); 132 UnescapeUrl(src);
132 133
133 // call the impl of the base class as soon as possible because it initializes the base class 134 // call the impl of the base class as soon as possible because it initializes the base class
134 // members, used by this method. It queries for the required interfaces. 135 // members, used by this method. It queries for the required interfaces.
135 HRESULT hr = BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwRese rved, pTargetProtocol); 136 HRESULT hr = BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, dwRese rved, pTargetProtocol);
136 if (FAILED(hr)) 137 if (FAILED(hr))
137 { 138 {
138 return hr; 139 return hr;
139 } 140 }
140 141
141 CString mimeType; 142 CString mimeType;
(...skipping 26 matching lines...) Expand all
168 169
169 CString cookie; 170 CString cookie;
170 ULONG len1 = 2048; 171 ULONG len1 = 2048;
171 ULONG len2 = 2048; 172 ULONG len2 = 2048;
172 173
173 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId()); 174 CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId());
174 CPluginClient* client = CPluginClient::GetInstance(); 175 CPluginClient* client = CPluginClient::GetInstance();
175 176
176 if (tab && client) 177 if (tab && client)
177 { 178 {
178 CString documentUrl = tab->GetDocumentUrl(); 179 std::wstring documentUrl = tab->GetDocumentUrl();
179 // Page is identical to document => don't block 180 // Page is identical to document => don't block
180 if (documentUrl == src) 181 if (documentUrl == src)
181 { 182 {
182 // fall through 183 // fall through
183 } 184 }
184 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi telistedUrl(std::wstring(documentUrl))) 185 else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhi telistedUrl(documentUrl))
185 { 186 {
186 m_boundDomain = tab->GetDocumentUrl(); 187 m_boundDomain = tab->GetDocumentUrl();
187 m_contentType = CFilter::contentTypeAny; 188 m_contentType = CFilter::contentTypeAny;
188 if (tab != nullptr && tab->IsFrameCached(src)) 189 if (tab != nullptr && tab->IsFrameCached(src))
189 { 190 {
190 m_contentType = CFilter::contentTypeSubdocument; 191 m_contentType = CFilter::contentTypeSubdocument;
191 } 192 }
192 else 193 else
193 { 194 {
194 m_contentType = GetContentType(mimeType, m_boundDomain, src); 195 m_contentType = GetContentType(mimeType, m_boundDomain, src);
(...skipping 27 matching lines...) Expand all
222 } 223 }
223 } 224 }
224 } 225 }
225 226
226 // The descision about EContentType::contentTypeAny is made later in 227 // The descision about EContentType::contentTypeAny is made later in
227 // WBPassthruSink::BeginningTransaction. Sometimes here we cannot detect the r equest type, but 228 // WBPassthruSink::BeginningTransaction. Sometimes here we cannot detect the r equest type, but
228 // in WBPassthruSink::BeginningTransaction the header Accept is available whic h allows to 229 // in WBPassthruSink::BeginningTransaction the header Accept is available whic h allows to
229 // obtain the "request type" in our terminology. 230 // obtain the "request type" in our terminology.
230 if (nullptr != client 231 if (nullptr != client
231 && CFilter::EContentType::contentTypeAny != m_contentType 232 && CFilter::EContentType::contentTypeAny != m_contentType
232 && client->ShouldBlock(static_cast<const wchar_t*>(src), m_contentType, m_bo undDomain, true)) 233 && client->ShouldBlock(src, m_contentType, m_boundDomain, true))
233 { 234 {
234 isBlocked = true; 235 isBlocked = true;
235 } 236 }
236 237
237 // For IE6 and earlier there is iframe back button issue, so avoid it. 238 // For IE6 and earlier there is iframe back button issue, so avoid it.
238 if (isBlocked && client->GetIEVersion() > 6) 239 if (isBlocked && client->GetIEVersion() > 6)
239 { 240 {
240 handled = true; 241 handled = true;
241 if (CFilter::EContentType::contentTypeImage == m_contentType) 242 if (CFilter::EContentType::contentTypeImage == m_contentType)
242 { 243 {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } 464 }
464 465
465 STDMETHODIMP WBPassthru::UnlockRequest() 466 STDMETHODIMP WBPassthru::UnlockRequest()
466 { 467 {
467 if (!m_hasOriginalStartCalled) 468 if (!m_hasOriginalStartCalled)
468 { 469 {
469 return S_OK; 470 return S_OK;
470 } 471 }
471 return BaseClass::UnlockRequest(); 472 return BaseClass::UnlockRequest();
472 } 473 }
OLDNEW
« src/plugin/PluginFilter.cpp ('K') | « src/plugin/PluginWbPassThrough.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld