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

Delta Between Two Patch Sets: src/plugin/PluginClass.cpp

Issue 11013110: Cleanup (Closed)
Left Patch Set: Created July 5, 2013, 3:28 a.m.
Right Patch Set: More beautification and addressing comments Created July 29, 2013, 12:13 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginClass.h ('k') | src/plugin/PluginClassThread.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
74 CPluginSettings* settings = CPluginSettings::GetInstance();
75
76 CPluginSystem* system = CPluginSystem::GetInstance(); 73 CPluginSystem* system = CPluginSystem::GetInstance();
77 74
78 std::wstring locale((LPCWSTR)system->GetBrowserLanguage()); 75 std::wstring locale((LPCWSTR)system->GetBrowserLanguage());
79 Dictionary::Create(locale); 76 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 } 77 }
93 78
94 CPluginClass::~CPluginClass() 79 CPluginClass::~CPluginClass()
95 { 80 {
96 delete m_tab; 81 delete m_tab;
97
98 CPluginSettings* settings = CPluginSettings::GetInstance();
99
100 settings->DecrementTabCount();
101 } 82 }
102 83
103 84
104 ///////////////////////////////////////////////////////////////////////////// 85 /////////////////////////////////////////////////////////////////////////////
105 // Initialization 86 // Initialization
106 87
107 HRESULT CPluginClass::FinalConstruct() 88 HRESULT CPluginClass::FinalConstruct()
108 { 89 {
109 return S_OK; 90 return S_OK;
110 } 91 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 url = bstrURL; 202 url = bstrURL;
222 CPluginClient::UnescapeUrl(url); 203 CPluginClient::UnescapeUrl(url);
223 } 204 }
224 } 205 }
225 else 206 else
226 { 207 {
227 url = m_tab->GetDocumentUrl(); 208 url = m_tab->GetDocumentUrl();
228 } 209 }
229 210
230 return url; 211 return url;
231 }
232
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 } 212 }
267 213
268 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 214 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
269 { 215 {
270 if (thisPtr == NULL) 216 if (thisPtr == NULL)
271 return 0; 217 return 0;
272 if (!((CPluginClass*)thisPtr)->InitObject(true)) 218 if (!((CPluginClass*)thisPtr)->InitObject(true))
273 { 219 {
274 ((CPluginClass*)thisPtr)->Unadvice(); 220 ((CPluginClass*)thisPtr)->Unadvice();
275 } 221 }
(...skipping 14 matching lines...) Expand all
290 // so we should handle that it is called this way several times during a session 236 // so we should handle that it is called this way several times during a session
291 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) 237 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
292 { 238 {
293 CPluginSettings* settings = CPluginSettings::GetInstance(); 239 CPluginSettings* settings = CPluginSettings::GetInstance();
294 CPluginSystem* system = CPluginSystem::GetInstance(); 240 CPluginSystem* system = CPluginSystem::GetInstance();
295 241
296 MULTIPLE_VERSIONS_CHECK(); 242 MULTIPLE_VERSIONS_CHECK();
297 243
298 if (unknownSite) 244 if (unknownSite)
299 { 245 {
300 if (settings->IsMainProcess() && settings->IsMainUiThread()) 246 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 247
309 HRESULT hr = ::CoInitialize(NULL); 248 HRESULT hr = ::CoInitialize(NULL);
310 if (FAILED(hr)) 249 if (FAILED(hr))
311 { 250 {
312 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, " Class::SetSite - CoInitialize"); 251 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, " Class::SetSite - CoInitialize");
313 } 252 }
314 253
315 s_criticalSectionBrowser.Lock(); 254 s_criticalSectionBrowser.Lock();
316 { 255 {
317 m_webBrowser2 = unknownSite; 256 m_webBrowser2 = unknownSite;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 m_hStatusBarWnd = NULL; 361 m_hStatusBarWnd = NULL;
423 362
424 // Remove instance from the list, shutdown threads 363 // Remove instance from the list, shutdown threads
425 HANDLE hMainThread = NULL; 364 HANDLE hMainThread = NULL;
426 HANDLE hTabThread = NULL; 365 HANDLE hTabThread = NULL;
427 366
428 s_criticalSectionLocal.Lock(); 367 s_criticalSectionLocal.Lock();
429 { 368 {
430 s_instances.Remove(this); 369 s_instances.Remove(this);
431 370
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()); 371 std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::GetC urrentThreadId());
442 if (it != s_threadInstances.end()) 372 if (it != s_threadInstances.end())
443 { 373 {
444 s_threadInstances.erase(it); 374 s_threadInstances.erase(it);
445 } 375 }
446 if (s_instances.GetSize() == 0) 376 if (s_instances.GetSize() == 0)
447 { 377 {
448 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 378 CPluginClientFactory::ReleaseMimeFilterClientInstance();
449 } 379 }
450 } 380 }
451 s_criticalSectionLocal.Unlock(); 381 s_criticalSectionLocal.Unlock();
452 382
453 if (hMainThread != NULL)
454 {
455 s_isMainThreadDone = true;
456
457 ::WaitForSingleObject(hMainThread, INFINITE);
458 ::CloseHandle(hMainThread);
459 }
460
461 // Release browser interface 383 // Release browser interface
462 s_criticalSectionBrowser.Lock(); 384 s_criticalSectionBrowser.Lock();
463 { 385 {
464 m_webBrowser2.Release(); 386 m_webBrowser2.Release();
465 } 387 }
466 s_criticalSectionBrowser.Unlock(); 388 s_criticalSectionBrowser.Unlock();
467 389
468 if (settings->IsMainProcess() && settings->IsMainUiThread()) 390 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 391
477 ::CoUninitialize(); 392 ::CoUninitialize();
478 } 393 }
479 394
480 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); 395 return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
481 } 396 }
482 397
483 bool CPluginClass::IsStatusBarEnabled() 398 bool CPluginClass::IsStatusBarEnabled()
484 { 399 {
485 HKEY pHkey; 400 HKEY pHkey;
(...skipping 27 matching lines...) Expand all
513 428
514 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); 429 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
515 if (browser) 430 if (browser)
516 { 431 {
517 HRESULT hr = S_OK; 432 HRESULT hr = S_OK;
518 hr = browser->get_StatusBar(&isVisible); 433 hr = browser->get_StatusBar(&isVisible);
519 if (SUCCEEDED(hr)) 434 if (SUCCEEDED(hr))
520 { 435 {
521 if (!isVisible) 436 if (!isVisible)
522 { 437 {
523 if (!settings->GetStatusBarAsked()) 438 if (!settings->GetStatusBarAsked())
Oleksandr 2013/07/05 03:33:55 This is the only case where we might have still ne
Wladimir Palant 2013/07/05 09:26:45 I suggest storing it in prefs.json instead - via t
524 { 439 {
525 SHANDLE_PTR pBrowserHWnd; 440 SHANDLE_PTR pBrowserHWnd;
526 browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd); 441 browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd);
527 Dictionary* dictionary = Dictionary::GetInstance(); 442 Dictionary* dictionary = Dictionary::GetInstance();
528 settings->SetStatusBarAsked(true); 443 settings->SetStatusBarAsked();
529 444
530 HKEY pHkey; 445 HKEY pHkey;
531 HKEY pHkeySub; 446 HKEY pHkeySub;
532 LSTATUS regRes = 0; 447 LSTATUS regRes = 0;
533 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey); 448 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey);
534 449
535 // Do we have enough rights to enable a status bar? 450 // Do we have enough rights to enable a status bar?
536 if (regRes != 0) 451 if (regRes != 0)
537 { 452 {
538 // We use the tab window here and in the next few calls, since the b rowser window may still not be available 453 // 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 813 // Create status pane
899 if (bBHO) 814 if (bBHO)
900 { 815 {
901 if (!CreateStatusBarPane()) 816 if (!CreateStatusBarPane())
902 { 817 {
903 return false; 818 return false;
904 } 819 }
905 } 820 }
906 821
907 CPluginSettings* settings = CPluginSettings::GetInstance(); 822 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; 823 return true;
925 } 824 }
926 825
927 bool CPluginClass::CreateStatusBarPane() 826 bool CPluginClass::CreateStatusBarPane()
928 { 827 {
929 DEBUG_GENERAL(L"Getting client"); 828 DEBUG_GENERAL(L"Getting client");
930 829
931 CPluginClient* client = CPluginClient::GetInstance(); 830 CPluginClient* client = CPluginClient::GetInstance();
932 831
933 DEBUG_GENERAL(L"Getting ieversion"); 832 DEBUG_GENERAL(L"Getting ieversion");
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 989
1091 ::SendMessage(m_hStatusBarWnd, SB_GETPARTS, nPartCount, (LPARAM)pData); 990 ::SendMessage(m_hStatusBarWnd, SB_GETPARTS, nPartCount, (LPARAM)pData);
1092 ::SendMessage(m_hStatusBarWnd, SB_SETPARTS, nPartCount, (LPARAM)pData); 991 ::SendMessage(m_hStatusBarWnd, SB_SETPARTS, nPartCount, (LPARAM)pData);
1093 992
1094 delete[] pData; 993 delete[] pData;
1095 } 994 }
1096 HDC hdc = GetWindowDC(m_hStatusBarWnd); 995 HDC hdc = GetWindowDC(m_hStatusBarWnd);
1097 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0); 996 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0);
1098 ReleaseDC(m_hStatusBarWnd, hdc); 997 ReleaseDC(m_hStatusBarWnd, hdc);
1099 return true; 998 return true;
1100 }///////////////////////////////////////////////////////////////////////////// 999 }
1101 // Implementation
1102 1000
1103 void CPluginClass::CloseTheme() 1001 void CPluginClass::CloseTheme()
1104 { 1002 {
1105 if (m_hTheme) 1003 if (m_hTheme)
1106 { 1004 {
1107 if (pfnClose) 1005 if (pfnClose)
1108 { 1006 {
1109 pfnClose(m_hTheme); 1007 pfnClose(m_hTheme);
1110 } 1008 }
1111 1009
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 } 1960 }
2063 } 1961 }
2064 } 1962 }
2065 1963
2066 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1964 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
2067 } 1965 }
2068 1966
2069 return hTabWnd; 1967 return hTabWnd;
2070 1968
2071 } 1969 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld