Index: chrome_frame/bho.cc |
=================================================================== |
--- chrome_frame/bho.cc (revision 29317) |
+++ chrome_frame/bho.cc (working copy) |
@@ -17,10 +17,14 @@ |
#include "chrome_frame/protocol_sink_wrap.h" |
#include "chrome_frame/utils.h" |
#include "chrome_frame/vtable_patch_manager.h" |
+#include "net/http/http_util.h" |
const wchar_t kPatchProtocols[] = L"PatchProtocols"; |
static const int kIBrowserServiceOnHttpEquivIndex = 30; |
+base::LazyInstance<base::ThreadLocalPointer<Bho> > |
+ Bho::bho_current_thread_instance_(base::LINKER_INITIALIZED); |
+ |
PatchHelper g_patch_helper; |
BEGIN_VTABLE_PATCHES(IBrowserService) |
@@ -63,6 +67,14 @@ |
<< " Site: " << site << " Error: " << hr; |
} |
} |
+ // Save away our BHO instance in TLS which enables it to be referenced by |
+ // our active document/activex instances to query referrer and other |
+ // information for a URL. |
+ AddRef(); |
+ bho_current_thread_instance_.Pointer()->Set(this); |
+ } else { |
+ bho_current_thread_instance_.Pointer()->Set(NULL); |
+ Release(); |
} |
return IObjectWithSiteImpl<Bho>::SetSite(site); |
@@ -112,6 +124,25 @@ |
} |
} |
} |
+ |
+ referrer_.clear(); |
+ |
+ // Save away the referrer in case our active document needs it to initiate |
+ // navigation in chrome. |
+ if (headers && V_VT(headers) == VT_BSTR && headers->bstrVal != NULL) { |
+ std::string raw_headers_utf8 = WideToUTF8(headers->bstrVal); |
+ std::string http_headers = |
+ net::HttpUtil::AssembleRawHeaders(raw_headers_utf8.c_str(), |
+ raw_headers_utf8.length()); |
+ net::HttpUtil::HeadersIterator it(http_headers.begin(), http_headers.end(), |
+ "\r\n"); |
+ while (it.GetNext()) { |
+ if (LowerCaseEqualsASCII(it.name(), "referer")) { |
+ referrer_ = it.values(); |
+ break; |
+ } |
+ } |
+ } |
return S_OK; |
} |
@@ -210,6 +241,11 @@ |
return S_OK; |
} |
+Bho* Bho::GetCurrentThreadBhoInstance() { |
+ DCHECK(bho_current_thread_instance_.Pointer()->Get() != NULL); |
+ return bho_current_thread_instance_.Pointer()->Get(); |
+} |
+ |
void PatchHelper::InitializeAndPatchProtocolsIfNeeded() { |
if (state_ != UNKNOWN) |
return; |