| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // IE browser helper object implementation. | 5 // IE browser helper object implementation. |
| 6 #include "ceee/ie/plugin/bho/browser_helper_object.h" | 6 #include "ceee/ie/plugin/bho/browser_helper_object.h" |
| 7 | 7 |
| 8 #include <atlsafe.h> | 8 #include <atlsafe.h> |
| 9 #include <shlguid.h> | 9 #include <shlguid.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 | 12 |
| 13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
| 14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
| 15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/string_split.h" | |
| 18 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 19 #include "base/tuple.h" | 18 #include "base/tuple.h" |
| 20 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 21 #include "ceee/common/com_utils.h" | 20 #include "ceee/common/com_utils.h" |
| 22 #include "ceee/common/window_utils.h" | 21 #include "ceee/common/window_utils.h" |
| 23 #include "ceee/common/windows_constants.h" | 22 #include "ceee/common/windows_constants.h" |
| 24 #include "ceee/ie/broker/tab_api_module.h" | 23 #include "ceee/ie/broker/tab_api_module.h" |
| 25 #include "ceee/ie/common/constants.h" | 24 #include "ceee/ie/common/constants.h" |
| 26 #include "ceee/ie/common/extension_manifest.h" | 25 #include "ceee/ie/common/extension_manifest.h" |
| 27 #include "ceee/ie/common/ie_util.h" | 26 #include "ceee/ie/common/ie_util.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 TRACE_EVENT_END("ceee.bho", this, ""); | 113 TRACE_EVENT_END("ceee.bho", this, ""); |
| 115 } | 114 } |
| 116 | 115 |
| 117 HRESULT BrowserHelperObject::FinalConstruct() { | 116 HRESULT BrowserHelperObject::FinalConstruct() { |
| 118 if (ceee_module_util::GetOptionToolbandIsHidden()) { | 117 if (ceee_module_util::GetOptionToolbandIsHidden()) { |
| 119 // Patching wininet when BHO could not be created considered pointless. | 118 // Patching wininet when BHO could not be created considered pointless. |
| 120 LOG(INFO) << | 119 LOG(INFO) << |
| 121 "Refused to instantiate the BHO when the visual component is hidden."; | 120 "Refused to instantiate the BHO when the visual component is hidden."; |
| 122 return E_FAIL; | 121 return E_FAIL; |
| 123 } | 122 } |
| 124 | |
| 125 const wchar_t* bho_list = NULL; | |
| 126 ::LoadString(_pModule->m_hInstResource, IDS_CEEE_NESTED_BHO_LIST, | |
| 127 reinterpret_cast<wchar_t*>(&bho_list), 0); | |
| 128 if (bho_list == NULL) { | |
| 129 LOG(ERROR) << "Failed to load string: " << GetLastError(); | |
| 130 } else { | |
| 131 std::vector<std::wstring> guids; | |
| 132 base::SplitString(bho_list, ',', &guids); | |
| 133 for (size_t i = 0; i < guids.size(); ++i) { | |
| 134 CLSID clsid; | |
| 135 base::win::ScopedComPtr<IObjectWithSite> factory; | |
| 136 HRESULT hr = ::CLSIDFromString(guids[i].c_str(), &clsid); | |
| 137 if (SUCCEEDED(hr)) { | |
| 138 hr = factory.CreateInstance(clsid); | |
| 139 if (SUCCEEDED(hr)) { | |
| 140 nested_bho_.push_back(factory); | |
| 141 } else { | |
| 142 LOG(ERROR) << "Failed to load " << guids[i] << " " << com::LogWe(hr); | |
| 143 } | |
| 144 } else { | |
| 145 LOG(ERROR) << "Invalid CLSID " << guids[i] << " " << com::LogWe(hr); | |
| 146 } | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 return S_OK; | 123 return S_OK; |
| 151 } | 124 } |
| 152 | 125 |
| 153 void BrowserHelperObject::FinalRelease() { | 126 void BrowserHelperObject::FinalRelease() { |
| 154 // Need to disconnect outside of destructor, because we use a virtual method | 127 // Need to disconnect outside of destructor, because we use a virtual method |
| 155 // for unit testing. | 128 // for unit testing. |
| 156 broker_rpc().Disconnect(); | 129 broker_rpc().Disconnect(); |
| 157 web_browser_.Release(); | 130 web_browser_.Release(); |
| 158 nested_bho_.clear(); | |
| 159 } | 131 } |
| 160 | 132 |
| 161 void BrowserHelperObject::ReportAddonTimes(const char* name, | 133 void BrowserHelperObject::ReportAddonTimes(const char* name, |
| 162 const CLSID& clsid) { | 134 const CLSID& clsid) { |
| 163 ReportSingleAddonTime(name, clsid, "LoadTime"); | 135 ReportSingleAddonTime(name, clsid, "LoadTime"); |
| 164 ReportSingleAddonTime(name, clsid, "NavTime"); | 136 ReportSingleAddonTime(name, clsid, "NavTime"); |
| 165 } | 137 } |
| 166 | 138 |
| 167 void BrowserHelperObject::ReportSingleAddonTime(const char* name, | 139 void BrowserHelperObject::ReportSingleAddonTime(const char* name, |
| 168 const CLSID& clsid, | 140 const CLSID& clsid, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 186 break; | 158 break; |
| 187 default: | 159 default: |
| 188 counter_name += 'x'; | 160 counter_name += 'x'; |
| 189 break; | 161 break; |
| 190 } | 162 } |
| 191 VLOG(1) << counter_name << "=" << time; | 163 VLOG(1) << counter_name << "=" << time; |
| 192 broker_rpc().SendUmaHistogramTimes(counter_name.c_str(), time); | 164 broker_rpc().SendUmaHistogramTimes(counter_name.c_str(), time); |
| 193 } | 165 } |
| 194 | 166 |
| 195 STDMETHODIMP BrowserHelperObject::SetSite(IUnknown* site) { | 167 STDMETHODIMP BrowserHelperObject::SetSite(IUnknown* site) { |
| 196 for (size_t i = 0; i < nested_bho_.size(); ++i) { | 168 typedef IObjectWithSiteImpl<BrowserHelperObject> SuperSite; |
| 197 HRESULT hr = nested_bho_[i]->SetSite(site); | |
| 198 LOG_IF(ERROR, FAILED(hr)) << "Failed to set site of nested BHO" << | |
| 199 com::LogWe(hr); | |
| 200 } | |
| 201 | 169 |
| 202 // From experience, we know the site may be set multiple times. | 170 // From experience, we know the site may be set multiple times. |
| 203 // Let's ignore second and subsequent set or unset. | 171 // Let's ignore second and subsequent set or unset. |
| 204 if (site != NULL && m_spUnkSite.p != NULL || | 172 if (site != NULL && m_spUnkSite.p != NULL || |
| 205 site == NULL && m_spUnkSite.p == NULL ) { | 173 site == NULL && m_spUnkSite.p == NULL ) { |
| 206 LOG(WARNING) << "Duplicate call to SetSite, previous site " | 174 LOG(WARNING) << "Duplicate call to SetSite, previous site " |
| 207 << m_spUnkSite.p << " new site " << site; | 175 << m_spUnkSite.p << " new site " << site; |
| 208 return S_OK; | 176 return S_OK; |
| 209 } | 177 } |
| 210 | 178 |
| 211 if (NULL == site) { | 179 if (NULL == site) { |
| 212 mu::ScopedTimer metrics_timer("ceee/BHO.TearDown", &broker_rpc()); | 180 mu::ScopedTimer metrics_timer("ceee/BHO.TearDown", &broker_rpc()); |
| 213 | 181 |
| 214 // TODO(vitalybuka@chromium.org): switch to sampling when we have enough | 182 // TODO(vitalybuka@chromium.org): switch to sampling when we have enough |
| 215 // users. | 183 // users. |
| 216 ReportAddonTimes("BHO", CLSID_BrowserHelperObject); | 184 ReportAddonTimes("BHO", CLSID_BrowserHelperObject); |
| 217 ReportAddonTimes("ChromeFrameBHO", CLSID_ChromeFrameBHO); | 185 ReportAddonTimes("ChromeFrameBHO", CLSID_ChromeFrameBHO); |
| 218 ReportAddonTimes("Toolband", CLSID_ToolBand); | 186 ReportAddonTimes("Toolband", CLSID_ToolBand); |
| 219 | 187 |
| 220 // We're being torn down. | 188 // We're being torn down. |
| 221 TearDown(); | 189 TearDown(); |
| 222 | 190 |
| 223 FireOnRemovedEvent(); | 191 FireOnRemovedEvent(); |
| 224 // This call should be the last thing we send to the broker. | 192 // This call should be the last thing we send to the broker. |
| 225 FireOnUnmappedEvent(); | 193 FireOnUnmappedEvent(); |
| 226 } | 194 } |
| 227 | 195 |
| 228 typedef IObjectWithSiteImpl<BrowserHelperObject> SuperSite; | |
| 229 HRESULT hr = SuperSite::SetSite(site); | 196 HRESULT hr = SuperSite::SetSite(site); |
| 230 if (FAILED(hr)) | 197 if (FAILED(hr)) |
| 231 return hr; | 198 return hr; |
| 232 | 199 |
| 233 if (NULL != site) { | 200 if (NULL != site) { |
| 234 // We're being initialized. | 201 // We're being initialized. |
| 235 hr = Initialize(site); | 202 hr = Initialize(site); |
| 236 | 203 |
| 237 // Release the site, and tear down our own state in case of failure. | 204 // Release the site, and tear down our own state in case of failure. |
| 238 if (FAILED(hr)) { | 205 if (FAILED(hr)) { |
| (...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 return S_FALSE; | 1634 return S_FALSE; |
| 1668 } else { | 1635 } else { |
| 1669 return SendEventToBrokerImpl(event_name, event_args); | 1636 return SendEventToBrokerImpl(event_name, event_args); |
| 1670 } | 1637 } |
| 1671 } | 1638 } |
| 1672 | 1639 |
| 1673 HRESULT BrowserHelperObject::SendEventToBrokerImpl( | 1640 HRESULT BrowserHelperObject::SendEventToBrokerImpl( |
| 1674 const std::string& event_name, const std::string& event_args) { | 1641 const std::string& event_name, const std::string& event_args) { |
| 1675 return broker_rpc().FireEvent(event_name.c_str(), event_args.c_str()); | 1642 return broker_rpc().FireEvent(event_name.c_str(), event_args.c_str()); |
| 1676 } | 1643 } |
| OLD | NEW |