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

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

Issue 11043057: First run page triggering (Closed)
Left Patch Set: Injecting an object for localization Created July 20, 2013, 10:41 p.m.
Right Patch Set: Minor refactoring. Renaming and a small cleanup. Created July 26, 2013, 12:05 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginClass.h ('k') | src/plugin/PluginSettings.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 216
217 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 217 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
218 { 218 {
219 if (thisPtr == NULL) 219 if (thisPtr == NULL)
220 return 0; 220 return 0;
221 if (!((CPluginClass*)thisPtr)->InitObject(true)) 221 if (!((CPluginClass*)thisPtr)->InitObject(true))
222 { 222 {
223 ((CPluginClass*)thisPtr)->Unadvice(); 223 ((CPluginClass*)thisPtr)->Unadvice();
224 } 224 }
225 225
226 if ((((CPluginClass*)thisPtr)->m_hPaneWnd == NULL) || (!((CPluginClass*)thisPt r)->IsStatusBarEnabled()))
227 {
228 ((CPluginClass*)thisPtr)->ShowStatusBar();
229 }
230 return 0; 226 return 0;
231 } 227 }
232 228
233 229
234 230
235 // This gets called when a new browser window is created (which also triggers th e 231 // This gets called when a new browser window is created (which also triggers th e
236 // creation of this object). The pointer passed in should be to a IWebBrowser2 232 // creation of this object). The pointer passed in should be to a IWebBrowser2
237 // interface that represents the browser for the window. 233 // interface that represents the browser for the window.
238 // it is also called when a tab is closed, this unknownSite will be null 234 // it is also called when a tab is closed, this unknownSite will be null
239 // so we should handle that it is called this way several times during a session 235 // so we should handle that it is called this way several times during a session
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 416 }
421 } 417 }
422 } 418 }
423 return trueth == 1; 419 return trueth == 1;
424 } 420 }
425 421
426 void CPluginClass::ShowStatusBar() 422 void CPluginClass::ShowStatusBar()
427 { 423 {
428 VARIANT_BOOL isVisible; 424 VARIANT_BOOL isVisible;
429 425
430 CPluginSettings* settings = CPluginSettings::GetInstance();
431 426
432 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); 427 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
433 if (browser) 428 if (browser)
434 { 429 {
435 HRESULT hr = S_OK; 430 HRESULT hr = S_OK;
436 hr = browser->get_StatusBar(&isVisible); 431 hr = browser->get_StatusBar(&isVisible);
437 if (SUCCEEDED(hr)) 432 if (SUCCEEDED(hr))
438 { 433 {
439 if (!isVisible) 434 if (!isVisible)
440 { 435 {
441 if (!settings->GetStatusBarAsked()) 436 SHANDLE_PTR pBrowserHWnd;
437 browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd);
438 Dictionary* dictionary = Dictionary::GetInstance();
439
440 HKEY pHkey;
441 HKEY pHkeySub;
442 LSTATUS regRes = 0;
443 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey);
444
445 // Do we have enough rights to enable a status bar?
446 if (regRes != 0)
442 { 447 {
443 SHANDLE_PTR pBrowserHWnd; 448 // We use the tab window here and in the next few calls, since the bro wser window may still not be available
444 browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd); 449 LRESULT res = MessageBox((HWND)m_hTabWnd,
445 Dictionary* dictionary = Dictionary::GetInstance(); 450 dictionary->Lookup("status-bar", "error-text").c_str(),
446 settings->SetStatusBarAsked(); 451 dictionary->Lookup("status-bar", "error-title").c_str(),
447 452 MB_OK);
448 HKEY pHkey; 453 return;
449 HKEY pHkeySub; 454 }
450 LSTATUS regRes = 0; 455 // Ask if a user wants to enable a status bar automatically
451 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey); 456 LRESULT res = MessageBox((HWND)m_hTabWnd,
452 457 dictionary->Lookup("status-bar", "question").c_str(),
453 // Do we have enough rights to enable a status bar? 458 dictionary->Lookup("status-bar", "title").c_str(),
454 if (regRes != 0) 459 MB_YESNO);
460 if (res == IDYES)
461 {
462 DWORD trueth = 1;
463 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M INIE", &pHkeySub);
464 regRes = RegSetValueEx(pHkeySub, L"ShowStatusBar", 0, REG_DWORD, (BYTE *)&trueth, sizeof(DWORD));
465 regRes = RegCloseKey(pHkeySub);
466 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\\M ain", &pHkeySub);
467 regRes = RegSetValueEx(pHkeySub, L"StatusBarWeb", 0, REG_DWORD, (BYTE* )&trueth, sizeof(DWORD));
468 regRes = RegCloseKey(pHkeySub);
469 hr = browser->put_StatusBar(TRUE);
470 if (FAILED(hr))
455 { 471 {
456 // We use the tab window here and in the next few calls, since the b rowser window may still not be available 472 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_PUT_STATUSBAR, "Class::Enable statusbar");
457 LRESULT res = MessageBox((HWND)m_hTabWnd,
458 dictionary->Lookup("status-bar", "error-text").c_str(),
459 dictionary->Lookup("status-bar", "error-title").c_str(),
460 MB_OK);
461 return;
462 } 473 }
463 // Ask if a user wants to enable a status bar automatically 474 CreateStatusBarPane();
464 LRESULT res = MessageBox((HWND)m_hTabWnd, 475
465 dictionary->Lookup("status-bar", "question").c_str(), 476 // We need to restart the tab now, to enable the status bar properly
466 dictionary->Lookup("status-bar", "title").c_str(), 477 VARIANT vFlags;
467 MB_YESNO); 478 vFlags.vt = VT_I4;
468 if (res == IDYES) 479 vFlags.intVal = navOpenInNewTab;
480
481 CComBSTR curLoc;
482 browser->get_LocationURL(&curLoc);
483 HRESULT hr = browser->Navigate(curLoc, &vFlags, NULL, NULL, NULL);
484 if (FAILED(hr))
469 { 485 {
470 DWORD trueth = 1; 486 vFlags.intVal = navOpenInNewWindow;
471 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\ \MINIE", &pHkeySub); 487
472 regRes = RegSetValueEx(pHkeySub, L"ShowStatusBar", 0, REG_DWORD, (BY TE*)&trueth, sizeof(DWORD)); 488 hr = browser->Navigate(CComBSTR(curLoc), &vFlags, NULL, NULL, NULL);
473 regRes = RegCloseKey(pHkeySub);
474 regRes = RegOpenKey(pHkey, L"Software\\Microsoft\\Internet Explorer\ \Main", &pHkeySub);
475 regRes = RegSetValueEx(pHkeySub, L"StatusBarWeb", 0, REG_DWORD, (BYT E*)&trueth, sizeof(DWORD));
476 regRes = RegCloseKey(pHkeySub);
477 hr = browser->put_StatusBar(TRUE);
478 if (FAILED(hr)) 489 if (FAILED(hr))
479 { 490 {
480 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_PUT_STATUSBAR , "Class::Enable statusbar"); 491 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATI ON, "Navigation::Failed")
481 } 492 }
482 CreateStatusBarPane();
483
484 // We need to restart the tab now, to enable the status bar properly
485 VARIANT vFlags;
486 vFlags.vt = VT_I4;
487 vFlags.intVal = navOpenInNewTab;
488
489 CComBSTR curLoc;
490 browser->get_LocationURL(&curLoc);
491 HRESULT hr = browser->Navigate(curLoc, &vFlags, NULL, NULL, NULL);
492 if (FAILED(hr))
493 {
494 vFlags.intVal = navOpenInNewWindow;
495
496 hr = browser->Navigate(CComBSTR(curLoc), &vFlags, NULL, NULL, NULL );
497 if (FAILED(hr))
498 {
499 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGA TION, "Navigation::Failed")
500 }
501 }
502 browser->Quit();
503
504 } 493 }
494 browser->Quit();
505 } 495 }
506 } 496 }
507 } 497 }
508 else 498 else
509 { 499 {
510 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state"); 500 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class ::Get statusbar state");
511 } 501 }
512 } 502 }
513 } 503 }
514 504
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 805
816 // Create status pane 806 // Create status pane
817 if (bBHO) 807 if (bBHO)
818 { 808 {
819 if (!CreateStatusBarPane()) 809 if (!CreateStatusBarPane())
820 { 810 {
821 return false; 811 return false;
822 } 812 }
823 } 813 }
824 814
815 if (CPluginClient::GetInstance()->IsFirstRun())
816 {
817 CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)CPluginClass::FirstRunThrea d, NULL, NULL, NULL);
818 if ((m_hPaneWnd == NULL) || (!IsStatusBarEnabled()))
819 {
820 ShowStatusBar();
821 }
822
823 }
824
825 CPluginSettings* settings = CPluginSettings::GetInstance(); 825 CPluginSettings* settings = CPluginSettings::GetInstance();
826 return true; 826 return true;
827 } 827 }
828 828
829 bool CPluginClass::CreateStatusBarPane() 829 bool CPluginClass::CreateStatusBarPane()
830 { 830 {
831 DEBUG_GENERAL(L"Getting client"); 831 DEBUG_GENERAL(L"Getting client");
832 832
833 CPluginClient* client = CPluginClient::GetInstance(); 833 CPluginClient* client = CPluginClient::GetInstance();
834 834
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 INT *pData = new INT[nPartCount]; 991 INT *pData = new INT[nPartCount];
992 992
993 ::SendMessage(m_hStatusBarWnd, SB_GETPARTS, nPartCount, (LPARAM)pData); 993 ::SendMessage(m_hStatusBarWnd, SB_GETPARTS, nPartCount, (LPARAM)pData);
994 ::SendMessage(m_hStatusBarWnd, SB_SETPARTS, nPartCount, (LPARAM)pData); 994 ::SendMessage(m_hStatusBarWnd, SB_SETPARTS, nPartCount, (LPARAM)pData);
995 995
996 delete[] pData; 996 delete[] pData;
997 } 997 }
998 HDC hdc = GetWindowDC(m_hStatusBarWnd); 998 HDC hdc = GetWindowDC(m_hStatusBarWnd);
999 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0); 999 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0);
1000 ReleaseDC(m_hStatusBarWnd, hdc); 1000 ReleaseDC(m_hStatusBarWnd, hdc);
1001
1001 return true; 1002 return true;
1002 } 1003 }
1003 1004
1005 void CPluginClass::FirstRunThread()
1006 {
1007 CoInitialize(NULL);
1008 VARIANT vFlags;
1009 vFlags.vt = VT_I4;
1010 vFlags.intVal = navOpenInNewTab;
1011
1012 CComBSTR navigatePath = CComBSTR(FirstRunPageFileUrl().c_str());
1013
1014 HRESULT hr = GetAsyncBrowser()->Navigate(navigatePath, &vFlags, NULL, NULL, NU LL);
1015 if (FAILED(hr))
1016 {
1017 vFlags.intVal = navOpenInNewWindow;
1018 hr = GetAsyncBrowser()->Navigate(navigatePath, &vFlags, NULL, NULL, NULL);
1019 }
1020
1021 if (FAILED(hr))
1022 {
1023 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION_WELCOME , "Navigation::Welcome page failed")
1024 }
1025 }
1004 void CPluginClass::CloseTheme() 1026 void CPluginClass::CloseTheme()
1005 { 1027 {
1006 if (m_hTheme) 1028 if (m_hTheme)
1007 { 1029 {
1008 if (pfnClose) 1030 if (pfnClose)
1009 { 1031 {
1010 pfnClose(m_hTheme); 1032 pfnClose(m_hTheme);
1011 } 1033 }
1012 1034
1013 m_hTheme = NULL; 1035 m_hTheme = NULL;
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 hr = browser->Navigate(BString(UserSettingsFileUrl()), &vFlags, NULL, NULL, NULL); 1746 hr = browser->Navigate(BString(UserSettingsFileUrl()), &vFlags, NULL, NULL, NULL);
1725 if (FAILED(hr)) 1747 if (FAILED(hr))
1726 { 1748 {
1727 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") 1749 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1728 } 1750 }
1729 } 1751 }
1730 } 1752 }
1731 #endif 1753 #endif
1732 } 1754 }
1733 break; 1755 break;
1734
1735
1736 // First run page
1737 case WM_LAUNCH_INFO:
1738 {
1739 // Set the status bar visible, if it isn't
1740 // Otherwise the user won't see the icon the first time
1741
1742 if (wParam == 1)
1743 {
1744 // Redirect to welcome page
1745 VARIANT_BOOL isVisible;
1746 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
1747 if (browser)
1748 {
1749 HRESULT hr = S_OK;
1750
1751 hr = browser->get_StatusBar(&isVisible);
1752 if (SUCCEEDED(hr))
1753 {
1754 if (!isVisible)
1755 {
1756 Dictionary* dictionary = Dictionary::GetInstance();
1757
1758 LRESULT res = MessageBox(NULL,
1759 dictionary->Lookup("status-bar", "question").c_str(),
1760 dictionary->Lookup("status-bar", "title").c_str(),
1761 MB_YESNO);
1762 if (res == IDYES)
1763 {
1764 hr = browser->put_StatusBar(TRUE);
1765 if (FAILED(hr))
1766 {
1767 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_PUT_STATU SBAR, "Class::Enable statusbar");
1768 }
1769 }
1770 }
1771 }
1772 else
1773 {
1774 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class::Get statusbar state");
1775 }
1776
1777 CPluginSettings* settings = CPluginSettings::GetInstance();
1778
1779 //TODO: Navigate to first run page here
1780 /* hr = browser->Navigate(CComBSTR("FIRST_RUN_PAGE_URL"), NULL, NULL, NUL L, NULL);
1781 if (FAILED(hr))
1782 {
1783 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _WELCOME, "Navigation::Welcome page failed")
1784 }
1785 */
1786 }
1787 }
1788 else
1789 {
1790 // Redirect to info page
1791 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
1792 if (browser)
1793 {
1794 VARIANT vFlags;
1795 vFlags.vt = VT_I4;
1796 vFlags.intVal = navOpenInNewTab;
1797
1798 // TODO: Navigate to info page here or remove this clause
1799 /* HRESULT hr = browser->Navigate(CComBSTR(INFO_PAGE_URL), &vFlags, NUL L, NULL, NULL);
1800 if (FAILED(hr))
1801 {
1802 vFlags.intVal = navOpenInNewWindow;
1803
1804 hr = browser->Navigate(CComBSTR(httpRequest.GetUrl()), &vFlags, NULL , NULL, NULL);
1805 if (FAILED(hr))
1806 {
1807 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATI ON_INFO, "Navigation::Info page failed")
1808 }
1809 }
1810 */
1811 }
1812 }
1813 }
1814 break;
1815
1816 case WM_DESTROY: 1756 case WM_DESTROY:
1817 break; 1757 break;
1818 case SC_CLOSE: 1758 case SC_CLOSE:
1819 break; 1759 break;
1820 1760
1821 case WM_UPDATEUISTATE: 1761 case WM_UPDATEUISTATE:
1822 { 1762 {
1823 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1763 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1824 if (tab) 1764 if (tab)
1825 { 1765 {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 } 1903 }
1964 } 1904 }
1965 } 1905 }
1966 1906
1967 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 1907 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1968 } 1908 }
1969 1909
1970 return hTabWnd; 1910 return hTabWnd;
1971 1911
1972 } 1912 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld