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