LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
19 | 19 |
20 #include "PluginClass.h" | 20 #include "PluginClass.h" |
21 #include "PluginSettings.h" | 21 #include "PluginSettings.h" |
22 #include "PluginSystem.h" | 22 #include "PluginSystem.h" |
23 #include "PluginFilter.h" | 23 #include "PluginFilter.h" |
24 #include "PluginMimeFilterClient.h" | 24 #include "PluginMimeFilterClient.h" |
25 #include "AdblockPlusClient.h" | 25 #include "AdblockPlusClient.h" |
26 #include "PluginClientBase.h" | 26 #include "PluginClientBase.h" |
27 #include "PluginClientFactory.h" | 27 #include "PluginClientFactory.h" |
28 #include "PluginUtil.h" | 28 #include "PluginUtil.h" |
29 #include "../shared/Utils.h" | 29 #include "../shared/Utils.h" |
30 #include "../shared/Dictionary.h" | 30 #include "../shared/Dictionary.h" |
31 #include "IeVersion.h" | 31 #include "IeVersion.h" |
32 #include "../shared/Version.h" | 32 #include "../shared/Version.h" |
| 33 #include "Instances.h" |
33 #include <thread> | 34 #include <thread> |
34 #include <array> | 35 #include <array> |
35 | 36 |
36 #ifdef DEBUG_HIDE_EL | 37 #ifdef DEBUG_HIDE_EL |
37 DWORD profileTime = 0; | 38 DWORD profileTime = 0; |
38 #endif | 39 #endif |
39 | 40 |
40 extern CComModule _Module; | 41 extern CComModule _Module; |
41 | 42 |
42 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); | 43 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); |
43 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR
ECT); | 44 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR
ECT); |
44 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); | 45 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); |
45 | 46 |
46 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; | 47 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; |
47 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL
ED, IDI_ICON_DEACTIVATED }; | 48 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL
ED, IDI_ICON_DEACTIVATED }; |
48 uint32_t iconHeight = 32; | 49 uint32_t iconHeight = 32; |
49 uint32_t iconWidth = 32; | 50 uint32_t iconWidth = 32; |
50 | 51 |
51 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; | 52 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; |
52 | 53 |
53 CLOSETHEMEDATA pfnClose = NULL; | 54 CLOSETHEMEDATA pfnClose = NULL; |
54 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; | 55 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; |
55 OPENTHEMEDATA pfnOpenThemeData = NULL; | 56 OPENTHEMEDATA pfnOpenThemeData = NULL; |
56 | 57 |
57 ATOM CPluginClass::s_atomPaneClass = NULL; | 58 ATOM CPluginClass::s_atomPaneClass = NULL; |
58 HINSTANCE CPluginClass::s_hUxtheme = NULL; | 59 HINSTANCE CPluginClass::s_hUxtheme = NULL; |
59 std::set<CPluginClass*> CPluginClass::s_instances; | 60 std::set<CPluginClass*> CPluginClass::s_instances; |
60 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances; | |
61 | 61 |
62 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; | 62 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; |
63 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; | 63 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; |
64 | 64 |
65 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; | 65 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; |
| 66 |
| 67 namespace |
| 68 { |
| 69 /** |
| 70 * A synchronized map whose key is always the current thread ID. |
| 71 */ |
| 72 class CurrentThreadMap |
| 73 : public SyncMap<DWORD, CPluginClass*, nullptr> |
| 74 { |
| 75 typedef SyncMap<DWORD, CPluginClass*, nullptr> Base; |
| 76 |
| 77 public: |
| 78 bool AddIfAbsent(CPluginClass* p) |
| 79 { |
| 80 return Base::AddIfAbsent(::GetCurrentThreadId(), p); |
| 81 } |
| 82 |
| 83 bool RemoveAndCheck() |
| 84 { |
| 85 return Base::RemoveIfPresent(::GetCurrentThreadId()); |
| 86 } |
| 87 |
| 88 CPluginClass* Locate() |
| 89 { |
| 90 return Base::Locate(::GetCurrentThreadId()); |
| 91 } |
| 92 }; |
| 93 |
| 94 /** |
| 95 * Map from thread ID's to CPluginClass instances |
| 96 */ |
| 97 CurrentThreadMap threadMap; |
| 98 } |
66 | 99 |
67 /* | 100 /* |
68 * Without namespace declaration, the identifier "Rectangle" is ambiguous | 101 * Without namespace declaration, the identifier "Rectangle" is ambiguous |
69 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85)
.aspx | 102 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85)
.aspx |
70 */ | 103 */ |
71 namespace AdblockPlus | 104 namespace AdblockPlus |
72 { | 105 { |
73 /** | 106 /** |
74 * Replacement for ATL type CRect. | 107 * Replacement for ATL type CRect. |
75 */ | 108 */ |
76 class Rectangle | 109 class Rectangle |
77 : public RECT | 110 : public RECT |
78 { | 111 { |
79 public: | 112 public: |
80 int Height() const | 113 unsigned long Height() const |
81 { | 114 { |
82 return bottom - top; | 115 if (bottom < top) |
83 } | 116 { |
84 | 117 throw std::runtime_error("invariant violation: rectangle bottom < top"); |
85 int Width() const | 118 } |
86 { | 119 return static_cast<unsigned long>(bottom - top); |
87 return right - left; | 120 } |
| 121 |
| 122 unsigned long Width() const |
| 123 { |
| 124 if (right < left) |
| 125 { |
| 126 throw std::runtime_error("invariant violation: rectangle right < left"); |
| 127 } |
| 128 return static_cast<unsigned long>(right - left); |
88 } | 129 } |
89 }; | 130 }; |
90 } | 131 } |
91 | 132 |
92 CPluginClass::CPluginClass() | 133 CPluginClass::CPluginClass() |
93 : m_webBrowser2(nullptr), | 134 : m_webBrowser2(nullptr), |
94 detachedInitializationFailed(false) | 135 detachedInitializationFailed(false) |
95 { | 136 { |
96 DEBUG_GENERAL([this]() -> std::wstring | 137 DEBUG_GENERAL([this]() -> std::wstring |
97 { | 138 { |
98 std::wstring s = L"CPluginClass::<constructor>, this = "; | 139 std::wstring s = L"CPluginClass::<constructor>, this = "; |
99 s += ToHexLiteral(this); | 140 s += ToHexLiteral(this); |
100 return s; | 141 return s; |
101 }()); | 142 }()); |
102 | 143 |
103 //Use this line to debug memory leaks | 144 //Use this line to debug memory leaks |
104 // _CrtDumpMemoryLeaks(); | 145 // _CrtDumpMemoryLeaks(); |
105 | 146 |
106 m_hTabWnd = NULL; | 147 m_hTabWnd = NULL; |
107 m_hStatusBarWnd = NULL; | 148 m_hStatusBarWnd = NULL; |
108 m_hPaneWnd = NULL; | 149 m_hPaneWnd = NULL; |
109 m_nPaneWidth = 0; | 150 m_nPaneWidth = 0; |
110 m_pWndProcStatus = NULL; | 151 m_pWndProcStatus = NULL; |
111 m_hTheme = NULL; | 152 m_hTheme = NULL; |
112 m_isInitializedOk = false; | 153 m_isInitializedOk = false; |
113 | |
114 | |
115 m_tab = new CPluginTab(); | 154 m_tab = new CPluginTab(); |
116 | |
117 Dictionary::Create(GetBrowserLanguage()); | 155 Dictionary::Create(GetBrowserLanguage()); |
118 } | 156 } |
119 | 157 |
120 CPluginClass::~CPluginClass() | 158 CPluginClass::~CPluginClass() |
121 { | 159 { |
122 DEBUG_GENERAL([this]() -> std::wstring | 160 DEBUG_GENERAL([this]() -> std::wstring |
123 { | 161 { |
124 std::wstring s = L"CPluginClass::<destructor>, this = "; | 162 std::wstring s = L"CPluginClass::<destructor>, this = "; |
125 s += ToHexLiteral(this); | 163 s += ToHexLiteral(this); |
126 return s; | 164 return s; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 201 |
164 return browser; | 202 return browser; |
165 } | 203 } |
166 | 204 |
167 std::wstring CPluginClass::GetBrowserUrl() const | 205 std::wstring CPluginClass::GetBrowserUrl() const |
168 { | 206 { |
169 std::wstring url; | 207 std::wstring url; |
170 if (m_webBrowser2) | 208 if (m_webBrowser2) |
171 { | 209 { |
172 CComBSTR bstrURL; | 210 CComBSTR bstrURL; |
173 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL)) && bstrURL) | 211 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL))) |
174 { | 212 { |
175 url = std::wstring(bstrURL, SysStringLen(bstrURL)); | 213 url = ToWstring(bstrURL); |
176 } | 214 } |
177 } | 215 } |
178 else | 216 else |
179 { | 217 { |
180 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserUrl - Reached with m_webBr
owser2 == nullptr"); | 218 DEBUG_GENERAL(L"CPluginClass::GetBrowserUrl - Reached with m_webBrowser2 ==
nullptr (probable invariant violation)"); |
| 219 } |
| 220 if (url.empty()) |
| 221 { |
181 url = m_tab->GetDocumentUrl(); | 222 url = m_tab->GetDocumentUrl(); |
182 } | 223 } |
183 return url; | 224 return url; |
184 } | 225 } |
185 | 226 |
186 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) | 227 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) |
187 { | 228 { |
188 if (thisPtr == NULL) | 229 if (thisPtr == NULL) |
189 return 0; | 230 return 0; |
190 auto self = static_cast<CPluginClass*>(thisPtr); | 231 auto self = static_cast<CPluginClass*>(thisPtr); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p
ointer to IWebBrowser2*"); | 268 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p
ointer to IWebBrowser2*"); |
228 } | 269 } |
229 DEBUG_GENERAL([this]() -> std::wstring | 270 DEBUG_GENERAL([this]() -> std::wstring |
230 { | 271 { |
231 std::wstringstream ss; | 272 std::wstringstream ss; |
232 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); | 273 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this); |
233 ss << L", browser = " << ToHexLiteral(m_webBrowser2); | 274 ss << L", browser = " << ToHexLiteral(m_webBrowser2); |
234 return ss.str(); | 275 return ss.str(); |
235 }()); | 276 }()); |
236 | 277 |
| 278 /* |
| 279 * Add ourselves to the thread map. |
| 280 */ |
| 281 if (!threadMap.AddIfAbsent(this)) |
| 282 { |
| 283 throw std::logic_error("CPluginClass::SetSite - May not overwrite existi
ng entry in thread map"); |
| 284 } |
| 285 |
237 //register the mimefilter | 286 //register the mimefilter |
238 //and only mimefilter | 287 //and only mimefilter |
239 //on some few computers the mimefilter does not get properly registered wh
en it is done on another thread | 288 //on some few computers the mimefilter does not get properly registered wh
en it is done on another thread |
240 s_criticalSectionLocal.Lock(); | 289 s_criticalSectionLocal.Lock(); |
241 { | 290 { |
242 // Always register on startup, then check if we need to unregister in a
separate thread | 291 // Always register on startup, then check if we need to unregister in a
separate thread |
243 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | 292 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |
244 s_asyncWebBrowser2 = unknownSite; | 293 s_asyncWebBrowser2 = unknownSite; |
245 s_instances.insert(this); | 294 s_instances.insert(this); |
246 } | 295 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 m_hPaneWnd = NULL; | 336 m_hPaneWnd = NULL; |
288 } | 337 } |
289 | 338 |
290 m_hTabWnd = NULL; | 339 m_hTabWnd = NULL; |
291 m_hStatusBarWnd = NULL; | 340 m_hStatusBarWnd = NULL; |
292 | 341 |
293 // Remove instance from the list, shutdown threads | 342 // Remove instance from the list, shutdown threads |
294 HANDLE hMainThread = NULL; | 343 HANDLE hMainThread = NULL; |
295 HANDLE hTabThread = NULL; | 344 HANDLE hTabThread = NULL; |
296 | 345 |
| 346 if (!threadMap.RemoveAndCheck()) |
| 347 { |
| 348 throw std::logic_error("CPluginClass::SetSite - Missing entry in thread
map"); |
| 349 } |
| 350 |
297 s_criticalSectionLocal.Lock(); | 351 s_criticalSectionLocal.Lock(); |
298 { | 352 { |
299 s_instances.erase(this); | 353 s_instances.erase(this); |
300 | |
301 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::Ge
tCurrentThreadId()); | |
302 if (it != s_threadInstances.end()) | |
303 { | |
304 s_threadInstances.erase(it); | |
305 } | |
306 if (s_instances.empty()) | 354 if (s_instances.empty()) |
307 { | 355 { |
308 // TODO: Explicitly releasing a resource when a container becomes empt
y looks like a job better suited for shared_ptr | 356 // TODO: Explicitly releasing a resource when a container becomes empt
y looks like a job better suited for shared_ptr |
309 CPluginClientFactory::ReleaseMimeFilterClientInstance(); | 357 CPluginClientFactory::ReleaseMimeFilterClientInstance(); |
310 } | 358 } |
311 } | 359 } |
312 s_criticalSectionLocal.Unlock(); | 360 s_criticalSectionLocal.Unlock(); |
313 | 361 |
314 m_webBrowser2 = nullptr; | 362 m_webBrowser2 = nullptr; |
315 | 363 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 503 |
456 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; | 504 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; |
457 if (!webBrowser) | 505 if (!webBrowser) |
458 { | 506 { |
459 return; | 507 return; |
460 } | 508 } |
461 if (!urlVariant || urlVariant->vt != VT_BSTR) | 509 if (!urlVariant || urlVariant->vt != VT_BSTR) |
462 { | 510 { |
463 return; | 511 return; |
464 } | 512 } |
465 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); | 513 std::wstring url = ToWstring(urlVariant->bstrVal); |
466 | 514 |
467 // If webbrowser2 is equal to top level browser (as set in SetSite), we are | 515 // If webbrowser2 is equal to top level browser (as set in SetSite), we are |
468 // navigating new page | 516 // navigating new page |
469 CPluginClient* client = CPluginClient::GetInstance(); | 517 CPluginClient* client = CPluginClient::GetInstance(); |
470 if (url.find(L"javascript") == 0) | 518 if (url.find(L"javascript") == 0) |
471 { | 519 { |
472 } | 520 } |
473 else if (IsRootBrowser(webBrowser)) | 521 else if (IsRootBrowser(webBrowser)) |
474 { | 522 { |
475 m_tab->OnNavigate(url); | 523 m_tab->OnNavigate(url); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
nsigned long validFlagsMask) | 585 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
nsigned long validFlagsMask) |
538 { | 586 { |
539 if (detachedInitializationFailed) return; | 587 if (detachedInitializationFailed) return; |
540 try | 588 try |
541 { | 589 { |
542 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)"); | 590 DEBUG_GENERAL(L"WindowStateChanged (check tab changed)"); |
543 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL
ECMDIDF_WINDOWSTATE_ENABLED) | 591 bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL
ECMDIDF_WINDOWSTATE_ENABLED) |
544 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA
BLED); | 592 && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_WINDOWSTATE_ENA
BLED); |
545 if (newtabshown) | 593 if (newtabshown) |
546 { | 594 { |
547 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(
GetCurrentThreadId()); | 595 if (!m_isInitializedOk) |
548 if (it == s_threadInstances.end()) | 596 { |
549 { | 597 m_isInitializedOk = true; |
550 s_threadInstances[::GetCurrentThreadId()] = this; | 598 InitObject(); |
551 if (!m_isInitializedOk) | 599 UpdateStatusBar(); |
552 { | |
553 m_isInitializedOk = true; | |
554 InitObject(); | |
555 UpdateStatusBar(); | |
556 } | |
557 } | 600 } |
558 } | 601 } |
559 notificationMessage.Hide(); | 602 notificationMessage.Hide(); |
560 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end"); | 603 DEBUG_GENERAL(L"WindowStateChanged (check tab changed) end"); |
561 } | 604 } |
562 catch (...) | 605 catch (...) |
563 { | 606 { |
564 } | 607 } |
565 } | 608 } |
566 | 609 |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 s_criticalSectionLocal.Unlock(); | 997 s_criticalSectionLocal.Unlock(); |
955 | 998 |
956 return result; | 999 return result; |
957 } | 1000 } |
958 | 1001 |
959 CPluginTab* CPluginClass::GetTab() | 1002 CPluginTab* CPluginClass::GetTab() |
960 { | 1003 { |
961 return m_tab; | 1004 return m_tab; |
962 } | 1005 } |
963 | 1006 |
964 CPluginTab* CPluginClass::GetTab(DWORD dwThreadId) | 1007 CPluginTab* CPluginClass::GetTabForCurrentThread() |
965 { | 1008 { |
966 CPluginTab* tab = NULL; | 1009 auto p = threadMap.Locate(); |
967 | 1010 return p ? p->m_tab : nullptr; |
968 s_criticalSectionLocal.Lock(); | |
969 { | |
970 std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(dw
ThreadId); | |
971 if (it != s_threadInstances.end()) | |
972 { | |
973 tab = it->second->m_tab; | |
974 } | |
975 } | |
976 s_criticalSectionLocal.Unlock(); | |
977 | |
978 return tab; | |
979 } | 1011 } |
980 | 1012 |
981 // Entry point | 1013 // Entry point |
982 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) | 1014 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) |
983 { | 1015 { |
984 if (detachedInitializationFailed) return S_OK; | 1016 if (detachedInitializationFailed) return S_OK; |
985 try | 1017 try |
986 { | 1018 { |
987 if (cCmds == 0) return E_INVALIDARG; | 1019 if (cCmds == 0) return E_INVALIDARG; |
988 if (prgCmds == 0) return E_POINTER; | 1020 if (prgCmds == 0) return E_POINTER; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 | 1168 |
1137 MENUITEMINFOW miiSep = {}; | 1169 MENUITEMINFOW miiSep = {}; |
1138 miiSep.cbSize = sizeof(miiSep); | 1170 miiSep.cbSize = sizeof(miiSep); |
1139 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; | 1171 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; |
1140 miiSep.fType = MFT_SEPARATOR; | 1172 miiSep.fType = MFT_SEPARATOR; |
1141 | 1173 |
1142 CPluginClient* client = CPluginClient::GetInstance(); | 1174 CPluginClient* client = CPluginClient::GetInstance(); |
1143 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1175 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1144 { | 1176 { |
1145 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); | 1177 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); |
1146 // Is domain in white list? | |
1147 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); | 1178 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); |
1148 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) | 1179 /* |
1149 { | 1180 * The display state of the "disable on this site" menu item depends upon ta
b content |
| 1181 */ |
| 1182 if (!GetTab()->IsPossibleToDisableOnSite()) |
| 1183 { |
| 1184 // Since we can't disable the present content, |
| 1185 // it makes no sense to offer the user an option to block it. |
| 1186 fmii.fState = MFS_UNCHECKED | MFS_DISABLED; |
| 1187 } |
| 1188 else if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) |
| 1189 { |
| 1190 // Domain is in white list, indicated by a check mark |
1150 fmii.fState = MFS_CHECKED | MFS_ENABLED; | 1191 fmii.fState = MFS_CHECKED | MFS_ENABLED; |
1151 } | 1192 } |
1152 else | 1193 else |
1153 { | 1194 { |
1154 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; | 1195 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; |
1155 } | 1196 } |
1156 fmii.fMask = MIIM_STRING | MIIM_STATE; | 1197 fmii.fMask = MIIM_STRING | MIIM_STATE; |
1157 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1198 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1158 fmii.cch = static_cast<UINT>(ctext.size()); | 1199 fmii.cch = static_cast<UINT>(ctext.size()); |
1159 | 1200 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 } | 1413 } |
1373 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara
m); | 1414 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara
m); |
1374 } | 1415 } |
1375 | 1416 |
1376 | 1417 |
1377 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) | 1418 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) |
1378 { | 1419 { |
1379 // use the disable icon as defualt, if the client doesn't exists | 1420 // use the disable icon as defualt, if the client doesn't exists |
1380 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); | 1421 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); |
1381 | 1422 |
1382 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | 1423 CPluginTab* tab = GetTabForCurrentThread(); |
1383 if (tab) | 1424 if (tab) |
1384 { | 1425 { |
1385 CPluginClient* client = CPluginClient::GetInstance(); | 1426 CPluginClient* client = CPluginClient::GetInstance(); |
1386 if (CPluginSettings::GetInstance()->IsPluginEnabled()) | 1427 if (CPluginSettings::GetInstance()->IsPluginEnabled()) |
1387 { | 1428 { |
1388 if (client->IsWhitelistedUrl(url)) | 1429 if (client->IsWhitelistedUrl(url)) |
1389 { | 1430 { |
1390 hIcon = GetIcon(ICON_PLUGIN_DISABLED); | 1431 hIcon = GetIcon(ICON_PLUGIN_DISABLED); |
1391 } | 1432 } |
1392 else | 1433 else |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN
); | 1577 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN
); |
1537 break; | 1578 break; |
1538 } | 1579 } |
1539 case WM_DESTROY: | 1580 case WM_DESTROY: |
1540 break; | 1581 break; |
1541 case SC_CLOSE: | 1582 case SC_CLOSE: |
1542 break; | 1583 break; |
1543 | 1584 |
1544 case WM_UPDATEUISTATE: | 1585 case WM_UPDATEUISTATE: |
1545 { | 1586 { |
1546 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | 1587 CPluginTab* tab = GetTabForCurrentThread(); |
1547 if (tab) | 1588 if (tab) |
1548 { | 1589 { |
1549 tab->OnActivate(); | 1590 tab->OnActivate(); |
1550 RECT rect; | 1591 RECT rect; |
1551 GetWindowRect(pClass->m_hPaneWnd, &rect); | 1592 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1552 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left)
/ 2, rect.top + (rect.bottom - rect.top) / 2); | 1593 pClass->notificationMessage.MoveToCenter(rect); |
1553 } | 1594 } |
1554 if (LOWORD(wParam) == UIS_CLEAR) | 1595 if (LOWORD(wParam) == UIS_CLEAR) |
1555 { | 1596 { |
1556 pClass->notificationMessage.Hide(); | 1597 pClass->notificationMessage.Hide(); |
1557 } | 1598 } |
1558 break; | 1599 break; |
1559 } | 1600 } |
1560 case WM_WINDOWPOSCHANGING: | 1601 case WM_WINDOWPOSCHANGING: |
1561 { | 1602 { |
1562 RECT rect; | 1603 RECT rect; |
1563 GetWindowRect(pClass->m_hPaneWnd, &rect); | 1604 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1564 if (pClass->notificationMessage.IsVisible()) | 1605 if (pClass->notificationMessage.IsVisible()) |
1565 { | 1606 { |
1566 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left)
/ 2, rect.top + (rect.bottom - rect.top) / 2); | 1607 pClass->notificationMessage.MoveToCenter(rect); |
1567 } | 1608 } |
1568 break; | 1609 break; |
1569 } | 1610 } |
1570 case WM_WINDOWPOSCHANGED: | 1611 case WM_WINDOWPOSCHANGED: |
1571 { | 1612 { |
1572 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); | 1613 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); |
1573 if (wndPos->flags & SWP_HIDEWINDOW) | 1614 if (wndPos->flags & SWP_HIDEWINDOW) |
1574 { | 1615 { |
1575 pClass->notificationMessage.Hide(); | 1616 pClass->notificationMessage.Hide(); |
1576 } | 1617 } |
1577 break; | 1618 break; |
1578 } | 1619 } |
1579 case WM_ALREADY_UP_TO_DATE: | 1620 case WM_ALREADY_UP_TO_DATE: |
1580 { | 1621 { |
1581 Dictionary* dictionary = Dictionary::GetInstance(); | 1622 Dictionary* dictionary = Dictionary::GetInstance(); |
1582 std::wstring upToDateText = dictionary->Lookup("updater", "update-alread
y-up-to-date-text"); | 1623 std::wstring upToDateText = dictionary->Lookup("updater", "update-alread
y-up-to-date-text"); |
1583 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-alrea
dy-up-to-date-title"); | 1624 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-alrea
dy-up-to-date-title"); |
1584 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle,
TTI_INFO); | 1625 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle,
TTI_INFO); |
1585 break; | 1626 break; |
1586 } | 1627 } |
1587 case WM_UPDATE_CHECK_ERROR: | 1628 case WM_UPDATE_CHECK_ERROR: |
1588 { | 1629 { |
1589 Dictionary* dictionary = Dictionary::GetInstance(); | 1630 Dictionary* dictionary = Dictionary::GetInstance(); |
1590 std::wstring errorText = dictionary->Lookup("updater", "update-error-tex
t"); | 1631 std::wstring errorText = dictionary->Lookup("updater", "update-error-tex
t"); |
1591 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-ti
tle"); | 1632 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-ti
tle"); |
1592 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERR
OR); | 1633 pClass->notificationMessage.SetTextAndIcon(errorText, errorTitle, TTI_ER
ROR); |
1593 break; | 1634 break; |
1594 } | 1635 } |
1595 case WM_DOWNLOADING_UPDATE: | 1636 case WM_DOWNLOADING_UPDATE: |
1596 { | 1637 { |
1597 Dictionary* dictionary = Dictionary::GetInstance(); | 1638 Dictionary* dictionary = Dictionary::GetInstance(); |
1598 std::wstring downloadingText = dictionary->Lookup("updater", "downloadin
g-update-text"); | 1639 std::wstring downloadingText = dictionary->Lookup("updater", "downloadin
g-update-text"); |
1599 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloadi
ng-update-title"); | 1640 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloadi
ng-update-title"); |
1600 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingT
itle, TTI_INFO); | 1641 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingT
itle, TTI_INFO); |
1601 break; | 1642 break; |
1602 } | 1643 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 s_criticalSectionLocal.Unlock(); | 1687 s_criticalSectionLocal.Unlock(); |
1647 | 1688 |
1648 return icon; | 1689 return icon; |
1649 } | 1690 } |
1650 | 1691 |
1651 ATOM CPluginClass::GetAtomPaneClass() | 1692 ATOM CPluginClass::GetAtomPaneClass() |
1652 { | 1693 { |
1653 return s_atomPaneClass; | 1694 return s_atomPaneClass; |
1654 } | 1695 } |
1655 | 1696 |
LEFT | RIGHT |