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

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

Issue 11013110: Cleanup (Closed)
Patch Set: More refactoring. Removing main thread, tab counting. Implementing SetPref and GetPref. Addressing … Created July 9, 2013, 12:59 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 "PluginClass.h" 3 #include "PluginClass.h"
4 #include "PluginSettings.h" 4 #include "PluginSettings.h"
5 #include "PluginSystem.h" 5 #include "PluginSystem.h"
6 #ifdef SUPPORT_FILTER 6 #ifdef SUPPORT_FILTER
7 #include "PluginFilter.h" 7 #include "PluginFilter.h"
8 #endif 8 #endif
9 #include "PluginMimeFilterClient.h" 9 #include "PluginMimeFilterClient.h"
10 #include "PluginClient.h" 10 #include "PluginClient.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 m_hStatusBarWnd = NULL; 63 m_hStatusBarWnd = NULL;
64 m_hPaneWnd = NULL; 64 m_hPaneWnd = NULL;
65 m_nPaneWidth = 0; 65 m_nPaneWidth = 0;
66 m_pWndProcStatus = NULL; 66 m_pWndProcStatus = NULL;
67 m_hTheme = NULL; 67 m_hTheme = NULL;
68 m_isInitializedOk = false; 68 m_isInitializedOk = false;
69 69
70 70
71 m_tab = new CPluginTab(this); 71 m_tab = new CPluginTab(this);
72 72
73 // Load / create settings 73 // Load settings (fetch the available subscriptions, if still not fetched)
74 CPluginSettings* settings = CPluginSettings::GetInstance(); 74 CPluginSettings* settings = CPluginSettings::GetInstance();
75 75
76 CPluginSystem* system = CPluginSystem::GetInstance(); 76 CPluginSystem* system = CPluginSystem::GetInstance();
77 77
78 std::wstring locale((LPCWSTR)system->GetBrowserLanguage()); 78 std::wstring locale((LPCWSTR)system->GetBrowserLanguage());
79 Dictionary::Create(locale); 79 Dictionary::Create(locale);
80
81 bool isMainTab = settings->IncrementTabCount();
82
83 if (isMainTab)
84 {
85 // Prepare settings
86 settings->SetMainProcessId();
87 settings->SetMainUiThreadId();
88 #ifdef ENABLE_DEBUG_RESULT
89 CPluginDebug::DebugResultClear();
90 #endif
91 }
92 } 80 }
93 81
94 CPluginClass::~CPluginClass() 82 CPluginClass::~CPluginClass()
95 { 83 {
96 delete m_tab; 84 delete m_tab;
97
98 CPluginSettings* settings = CPluginSettings::GetInstance();
99
100 settings->DecrementTabCount();
101 } 85 }
102 86
103 87
104 ///////////////////////////////////////////////////////////////////////////// 88 /////////////////////////////////////////////////////////////////////////////
105 // Initialization 89 // Initialization
106 90
107 HRESULT CPluginClass::FinalConstruct() 91 HRESULT CPluginClass::FinalConstruct()
108 { 92 {
109 return S_OK; 93 return S_OK;
110 } 94 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 207 }
224 } 208 }
225 else 209 else
226 { 210 {
227 url = m_tab->GetDocumentUrl(); 211 url = m_tab->GetDocumentUrl();
228 } 212 }
229 213
230 return url; 214 return url;
231 } 215 }
232 216
233 void CPluginClass::LaunchUpdater(const CString& strPath)
234 {
235 PROCESS_INFORMATION pi;
236 ::ZeroMemory(&pi, sizeof(pi));
237
238 STARTUPINFO si;
239 ::ZeroMemory(&si, sizeof(si));
240 si.cb = sizeof(si);
241 si.wShowWindow = FALSE;
242 CString cpath;
243 if (strPath.Find(L".exe") == strPath.GetLength() - 4)
244 {
245 cpath = strPath;
246 }
247 else
248 {
249 cpath = _T("\"msiexec.exe\" /i \"") + strPath + _T("\" UPDATEPLUGIN=\"True\" ");
250 }
251
252 if (!::CreateProcess(NULL, cpath.GetBuffer(), NULL, NULL, FALSE, CREATE_BREAKA WAY_FROM_JOB, NULL, NULL, &si, &pi))
253 {
254 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UPDATER, PLUGIN_ERROR_UPDATER _CREATE_PROCESS, "Class::Updater - Failed to start process");
255 return;
256 }
257 #ifndef AUTOMATIC_SHUTDOWN
258 else
259 {
260 ::WaitForSingleObject(pi.hProcess, INFINITE);
261 }
262 #endif // not AUTOMATIC_SHUTDOWN
263
264 ::CloseHandle(pi.hProcess);
265 ::CloseHandle(pi.hThread);
266 }
267
268 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 217 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
269 { 218 {
270 if (thisPtr == NULL) 219 if (thisPtr == NULL)
271 return 0; 220 return 0;
272 if (!((CPluginClass*)thisPtr)->InitObject(true)) 221 if (!((CPluginClass*)thisPtr)->InitObject(true))
273 { 222 {
274 ((CPluginClass*)thisPtr)->Unadvice(); 223 ((CPluginClass*)thisPtr)->Unadvice();
275 } 224 }
276 225
277 if ((((CPluginClass*)thisPtr)->m_hPaneWnd == NULL) || (!((CPluginClass*)thisPt r)->IsStatusBarEnabled())) 226 if ((((CPluginClass*)thisPtr)->m_hPaneWnd == NULL) || (!((CPluginClass*)thisPt r)->IsStatusBarEnabled()))
(...skipping 12 matching lines...) Expand all
290 // so we should handle that it is called this way several times during a session 239 // so we should handle that it is called this way several times during a session
291 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) 240 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
292 { 241 {
293 CPluginSettings* settings = CPluginSettings::GetInstance(); 242 CPluginSettings* settings = CPluginSettings::GetInstance();
294 CPluginSystem* system = CPluginSystem::GetInstance(); 243 CPluginSystem* system = CPluginSystem::GetInstance();
295 244
296 MULTIPLE_VERSIONS_CHECK(); 245 MULTIPLE_VERSIONS_CHECK();
297 246
298 if (unknownSite) 247 if (unknownSite)
299 { 248 {
300 if (settings->IsMainProcess() && settings->IsMainUiThread()) 249 DEBUG_GENERAL(L"============================================================ ====================\nNEW TAB UI\n============================================== ==================================")
301 {
302 DEBUG_GENERAL(L"========================================================== ======================\nMAIN TAB UI\n=========================================== =====================================")
303 }
304 else
305 {
306 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================")
307 }
308 250
309 HRESULT hr = ::CoInitialize(NULL); 251 HRESULT hr = ::CoInitialize(NULL);
310 if (FAILED(hr)) 252 if (FAILED(hr))
311 { 253 {
312 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, " Class::SetSite - CoInitialize"); 254 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, " Class::SetSite - CoInitialize");
313 } 255 }
314 256
315 s_criticalSectionBrowser.Lock(); 257 s_criticalSectionBrowser.Lock();
316 { 258 {
317 m_webBrowser2 = unknownSite; 259 m_webBrowser2 = unknownSite;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 m_hStatusBarWnd = NULL; 364 m_hStatusBarWnd = NULL;
423 365
424 // Remove instance from the list, shutdown threads 366 // Remove instance from the list, shutdown threads
425 HANDLE hMainThread = NULL; 367 HANDLE hMainThread = NULL;
426 HANDLE hTabThread = NULL; 368 HANDLE hTabThread = NULL;
427 369
428 s_criticalSectionLocal.Lock(); 370 s_criticalSectionLocal.Lock();
429 { 371 {
430 s_instances.Remove(this); 372 s_instances.Remove(this);
431 373
432 if (s_instances.GetSize() == 0)
433 {
434 if (settings->IsMainProcess() && settings->IsMainUiThread())
435 {
436 hMainThread = s_hMainThread;
437 s_hMainThread = NULL;
438 }
439 }
440
441 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC urrentThreadId()); 374 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC urrentThreadId());
442 if (it != s_threadInstances.end()) 375 if (it != s_threadInstances.end())
443 { 376 {
444 s_threadInstances.erase(it); 377 s_threadInstances.erase(it);
445 } 378 }
446 if (s_instances.GetSize() == 0) 379 if (s_instances.GetSize() == 0)
447 { 380 {
448 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 381 CPluginClientFactory::ReleaseMimeFilterClientInstance();
449 } 382 }
450 } 383 }
451 s_criticalSectionLocal.Unlock(); 384 s_criticalSectionLocal.Unlock();
452 385
453 if (hMainThread != NULL)
454 {
455 s_isMainThreadDone = true;
456
457 ::WaitForSingleObject(hMainThread, INFINITE);
458 ::CloseHandle(hMainThread);
459 }
460
461 // Release browser interface 386 // Release browser interface
462 s_criticalSectionBrowser.Lock(); 387 s_criticalSectionBrowser.Lock();
463 { 388 {
464 m_webBrowser2.Release(); 389 m_webBrowser2.Release();
465 } 390 }
466 s_criticalSectionBrowser.Unlock(); 391 s_criticalSectionBrowser.Unlock();
467 392
468 if (settings->IsMainProcess() && settings->IsMainUiThread()) 393 DEBUG_GENERAL("============================================================= ===================\nNEW TAB UI - END\n========================================= =======================================")
469 {
470 DEBUG_GENERAL("=========================================================== =====================\nMAIN TAB UI - END\n====================================== ==========================================")
471 }
472 else
473 {
474 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================")
475 }
476 394
477 ::CoUninitialize(); 395 ::CoUninitialize();
478 } 396 }
479 397
480 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); 398 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
481 } 399 }
482 400
483 bool CPluginClass::IsStatusBarEnabled() 401 bool CPluginClass::IsStatusBarEnabled()
484 { 402 {
485 HKEY pHkey; 403 HKEY pHkey;
(...skipping 18 matching lines...) Expand all
504 } 422 }
505 return trueth == 1; 423 return trueth == 1;
506 } 424 }
507 425
508 void CPluginClass::ShowStatusBar() 426 void CPluginClass::ShowStatusBar()
509 { 427 {
510 VARIANT_BOOL isVisible; 428 VARIANT_BOOL isVisible;
511 429
512 CPluginSettings* settings = CPluginSettings::GetInstance(); 430 CPluginSettings* settings = CPluginSettings::GetInstance();
513 431
432 //TODO: Remove the message box
433 MessageBox(NULL, L"", L"", MB_OK);
Wladimir Palant 2013/07/11 12:53:10 Please address that TODO comment ;)
434
514 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); 435 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
515 if (browser) 436 if (browser)
516 { 437 {
517 HRESULT hr = S_OK; 438 HRESULT hr = S_OK;
518 hr = browser->get_StatusBar(&isVisible); 439 hr = browser->get_StatusBar(&isVisible);
519 if (SUCCEEDED(hr)) 440 if (SUCCEEDED(hr))
520 { 441 {
521 if (!isVisible) 442 if (!isVisible)
522 { 443 {
523 if (!settings->GetStatusBarAsked()) 444 if (!settings->GetStatusBarAsked())
524 { 445 {
525 SHANDLE_PTR pBrowserHWnd; 446 SHANDLE_PTR pBrowserHWnd;
526 browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd); 447 browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd);
527 Dictionary* dictionary = Dictionary::GetInstance(); 448 Dictionary* dictionary = Dictionary::GetInstance();
528 settings->SetStatusBarAsked(true); 449 settings->SetStatusBarAsked();
529 450
530 HKEY pHkey; 451 HKEY pHkey;
531 HKEY pHkeySub; 452 HKEY pHkeySub;
532 LSTATUS regRes = 0; 453 LSTATUS regRes = 0;
533 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey); 454 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey);
534 455
535 // Do we have enough rights to enable a status bar? 456 // Do we have enough rights to enable a status bar?
536 if (regRes != 0) 457 if (regRes != 0)
537 { 458 {
538 // We use the tab window here and in the next few calls, since the b rowser window may still not be available 459 // We use the tab window here and in the next few calls, since the b rowser window may still not be available
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 // Create status pane 819 // Create status pane
899 if (bBHO) 820 if (bBHO)
900 { 821 {
901 if (!CreateStatusBarPane()) 822 if (!CreateStatusBarPane())
902 { 823 {
903 return false; 824 return false;
904 } 825 }
905 } 826 }
906 827
907 CPluginSettings* settings = CPluginSettings::GetInstance(); 828 CPluginSettings* settings = CPluginSettings::GetInstance();
908
909 // Create main thread
910 if (GetMainThreadHandle() == NULL && settings->IsMainProcess() && settings->Is MainUiThread())
911 {
912 DWORD id;
913 HANDLE handle = ::CreateThread(NULL, 0, MainThreadProc, (LPVOID)m_tab, CREAT E_SUSPENDED, &id);
914 if (handle == NULL)
915 {
916 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_T HREAD_CREATE_PROCESS, "Class::Thread - Failed to create main thread");
917 }
918
919 s_hMainThread = handle;
920
921 ::ResumeThread(handle);
922 }
923
924 return true; 829 return true;
925 } 830 }
926 831
927 bool CPluginClass::CreateStatusBarPane() 832 bool CPluginClass::CreateStatusBarPane()
928 { 833 {
929 DEBUG_GENERAL(L"Getting client"); 834 DEBUG_GENERAL(L"Getting client");
930 835
931 CPluginClient* client = CPluginClient::GetInstance(); 836 CPluginClient* client = CPluginClient::GetInstance();
932 837
933 DEBUG_GENERAL(L"Getting ieversion"); 838 DEBUG_GENERAL(L"Getting ieversion");
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 995
1091 ::SendMessage(m_hStatusBarWnd, SB_GETPARTS, nPartCount, (LPARAM)pData); 996 ::SendMessage(m_hStatusBarWnd, SB_GETPARTS, nPartCount, (LPARAM)pData);
1092 ::SendMessage(m_hStatusBarWnd, SB_SETPARTS, nPartCount, (LPARAM)pData); 997 ::SendMessage(m_hStatusBarWnd, SB_SETPARTS, nPartCount, (LPARAM)pData);
1093 998
1094 delete[] pData; 999 delete[] pData;
1095 } 1000 }
1096 HDC hdc = GetWindowDC(m_hStatusBarWnd); 1001 HDC hdc = GetWindowDC(m_hStatusBarWnd);
1097 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0); 1002 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0);
1098 ReleaseDC(m_hStatusBarWnd, hdc); 1003 ReleaseDC(m_hStatusBarWnd, hdc);
1099 return true; 1004 return true;
1100 }///////////////////////////////////////////////////////////////////////////// 1005 }
1101 // Implementation
1102 1006
1103 void CPluginClass::CloseTheme() 1007 void CPluginClass::CloseTheme()
1104 { 1008 {
1105 if (m_hTheme) 1009 if (m_hTheme)
1106 { 1010 {
1107 if (pfnClose) 1011 if (pfnClose)
1108 { 1012 {
1109 pfnClose(m_hTheme); 1013 pfnClose(m_hTheme);
1110 } 1014 }
1111 1015
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 } 1966 }
2063 } 1967 }
2064 } 1968 }
2065 1969
2066 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1970 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
2067 } 1971 }
2068 1972
2069 return hTabWnd; 1973 return hTabWnd;
2070 1974
2071 } 1975 }
OLDNEW

Powered by Google App Engine
This is Rietveld