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: Created July 5, 2013, 3:28 a.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"
11 #include "PluginClientFactory.h" 11 #include "PluginClientFactory.h"
12 #include "PluginHttpRequest.h"
13 #include "PluginMutex.h" 12 #include "PluginMutex.h"
14 #include "DownloadSource.h"
15 #include "sddl.h" 13 #include "sddl.h"
16 #include "PluginUtil.h" 14 #include "PluginUtil.h"
17 #include "PluginUserSettings.h" 15 #include "PluginUserSettings.h"
18 16
19 #include "../shared/Dictionary.h" 17 #include "../shared/Dictionary.h"
20 18
21 #ifdef DEBUG_HIDE_EL 19 #ifdef DEBUG_HIDE_EL
22 DWORD profileTime = 0; 20 DWORD profileTime = 0;
23 #endif 21 #endif
24 22
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 std::wstring locale((LPCWSTR)system->GetBrowserLanguage()); 78 std::wstring locale((LPCWSTR)system->GetBrowserLanguage());
81 Dictionary::Create(locale); 79 Dictionary::Create(locale);
82 80
83 bool isMainTab = settings->IncrementTabCount(); 81 bool isMainTab = settings->IncrementTabCount();
84 82
85 if (isMainTab) 83 if (isMainTab)
86 { 84 {
87 // Prepare settings 85 // Prepare settings
88 settings->SetMainProcessId(); 86 settings->SetMainProcessId();
89 settings->SetMainUiThreadId(); 87 settings->SetMainUiThreadId();
90
91 // Ensure plugin version
92 if (!settings->Has(SETTING_PLUGIN_VERSION))
93 {
94 settings->SetString(SETTING_PLUGIN_VERSION, IEPLUGIN_VERSION);
95 settings->SetFirstRunUpdate();
96 }
97
98 // First run or deleted settings file (dictionary version = 1)
99 if (settings->GetString(SETTING_DICTIONARY_VERSION, L"1").Compare(L"1") == 0 )
100 {
101 settings->SetFirstRun();
102 }
103
104 // Update?
105 CString oldVersion = settings->GetString(SETTING_PLUGIN_VERSION);
106 if (settings->IsFirstRunUpdate() || settings->GetString(SETTING_PLUGIN_UPDAT E_VERSION) == IEPLUGIN_VERSION || oldVersion != IEPLUGIN_VERSION)
107 {
108 settings->SetString(SETTING_PLUGIN_VERSION, IEPLUGIN_VERSION);
109
110 settings->SetFirstRunUpdate();
111 }
112
113 int info = settings->GetValue(SETTING_PLUGIN_INFO_PANEL, 0);
114
115 #ifdef ENABLE_DEBUG_RESULT 88 #ifdef ENABLE_DEBUG_RESULT
116 CPluginDebug::DebugResultClear(); 89 CPluginDebug::DebugResultClear();
117 #endif 90 #endif
118
119 #ifdef ENABLE_DEBUG_INFO
120 if (info == 0 || info > 2)
121 {
122 CPluginDebug::DebugClear();
123 }
124 #endif // ENABLE_DEBUG_INFO
125
126 settings->Write(false);
127 } 91 }
128 } 92 }
129 93
130 CPluginClass::~CPluginClass() 94 CPluginClass::~CPluginClass()
131 { 95 {
132 delete m_tab; 96 delete m_tab;
133 97
134 CPluginSettings* settings = CPluginSettings::GetInstance(); 98 CPluginSettings* settings = CPluginSettings::GetInstance();
135 99
136 settings->DecrementTabCount(); 100 settings->DecrementTabCount();
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 513
550 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); 514 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
551 if (browser) 515 if (browser)
552 { 516 {
553 HRESULT hr = S_OK; 517 HRESULT hr = S_OK;
554 hr = browser->get_StatusBar(&isVisible); 518 hr = browser->get_StatusBar(&isVisible);
555 if (SUCCEEDED(hr)) 519 if (SUCCEEDED(hr))
556 { 520 {
557 if (!isVisible) 521 if (!isVisible)
558 { 522 {
559 if (!settings->GetBool("statusbarasked", false)) 523 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
560 { 524 {
561 SHANDLE_PTR pBrowserHWnd; 525 SHANDLE_PTR pBrowserHWnd;
562 browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd); 526 browser->get_HWND((SHANDLE_PTR*)&pBrowserHWnd);
563 Dictionary* dictionary = Dictionary::GetInstance(); 527 Dictionary* dictionary = Dictionary::GetInstance();
564 settings->SetBool("statusbarasked", true); 528 settings->SetStatusBarAsked(true);
565 settings->Write();
566 529
567 HKEY pHkey; 530 HKEY pHkey;
568 HKEY pHkeySub; 531 HKEY pHkeySub;
569 LSTATUS regRes = 0; 532 LSTATUS regRes = 0;
570 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey); 533 regRes = RegOpenCurrentUser(KEY_WRITE, &pHkey);
571 534
572 // Do we have enough rights to enable a status bar? 535 // Do we have enough rights to enable a status bar?
573 if (regRes != 0) 536 if (regRes != 0)
574 { 537 {
575 // We use the tab window here and in the next few calls, since the b rowser window may still not be available 538 // We use the tab window here and in the next few calls, since the b rowser window may still not be available
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 else 1356 else
1394 { 1357 {
1395 s_mimeFilter = NULL; 1358 s_mimeFilter = NULL;
1396 1359
1397 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 1360 CPluginClientFactory::ReleaseMimeFilterClientInstance();
1398 } 1361 }
1399 } 1362 }
1400 s_criticalSectionLocal.Unlock(); 1363 s_criticalSectionLocal.Unlock();
1401 } 1364 }
1402 break; 1365 break;
1403 #ifndef ENTERPRISE
1404 case ID_SETTINGS:
1405 {
1406 url = CString(UserSettingsFileUrl().c_str());
1407 }
1408 break;
1409 #endif
1410 case ID_INVITEFRIENDS:
1411 {
1412 url = CPluginHttpRequest::GetStandardUrl(USERS_SCRIPT_INVITATION);
1413 navigationErrorId = PLUGIN_ERROR_NAVIGATION_INVITATION;
1414 }
1415 break;
1416
1417 case ID_FAQ:
1418 {
1419 url = CPluginHttpRequest::GetStandardUrl(USERS_SCRIPT_FAQ);
1420 navigationErrorId = PLUGIN_ERROR_NAVIGATION_FAQ;
1421 }
1422 break;
1423
1424 case ID_FEEDBACK:
1425 {
1426 CPluginHttpRequest httpRequest(USERS_SCRIPT_FEEDBACK);
1427
1428 httpRequest.AddPluginId();
1429 httpRequest.Add("reason", 0);
1430 httpRequest.Add(L"url", m_tab->GetDocumentUrl(), false);
1431
1432 url = httpRequest.GetUrl();
1433 navigationErrorId = PLUGIN_ERROR_NAVIGATION_FEEDBACK;
1434 }
1435 break;
1436
1437 case ID_ABOUT:
1438 {
1439 url = CPluginHttpRequest::GetStandardUrl(USERS_SCRIPT_ABOUT);
1440 navigationErrorId = PLUGIN_ERROR_NAVIGATION_ABOUT;
1441 }
1442 break;
1443
1444 default: 1366 default:
1445
1446 break; 1367 break;
1447 } 1368 }
1448 1369
1449 // Invalidate and redraw the control 1370 // Invalidate and redraw the control
1450 UpdateStatusBar(); 1371 UpdateStatusBar();
1451 1372
1452 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 1373 CComQIPtr<IWebBrowser2> browser = GetBrowser();
1453 if (!url.IsEmpty() && browser) 1374 if (!url.IsEmpty() && browser)
1454 { 1375 {
1455 VARIANT vFlags; 1376 VARIANT vFlags;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 MENUITEMINFOW miiSep; 1419 MENUITEMINFOW miiSep;
1499 memset(&miiSep, 0, sizeof(MENUITEMINFO)); 1420 memset(&miiSep, 0, sizeof(MENUITEMINFO));
1500 miiSep.cbSize = sizeof(MENUITEMINFO); 1421 miiSep.cbSize = sizeof(MENUITEMINFO);
1501 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; 1422 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE;
1502 miiSep.fType = MFT_SEPARATOR; 1423 miiSep.fType = MFT_SEPARATOR;
1503 1424
1504 CPluginClient* client = CPluginClient::GetInstance(); 1425 CPluginClient* client = CPluginClient::GetInstance();
1505 1426
1506 CPluginSettings* settings = CPluginSettings::GetInstance(); 1427 CPluginSettings* settings = CPluginSettings::GetInstance();
1507 1428
1508 settings->RefreshTab();
1509
1510 // Update settings
1511 m_tab->OnUpdateSettings(false);
1512
1513 #ifdef SUPPORT_WHITELIST 1429 #ifdef SUPPORT_WHITELIST
1514 { 1430 {
1515 // White list domain 1431 // White list domain
1516 ctext = dictionary->Lookup("menu", "disable-on-site"); 1432 ctext = dictionary->Lookup("menu", "disable-on-site");
1517 fmii.fMask = MIIM_STRING | MIIM_STATE; 1433 fmii.fMask = MIIM_STRING | MIIM_STATE;
1518 fmii.fState = MFS_DISABLED; 1434 fmii.fState = MFS_DISABLED;
1519 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1435 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1520 fmii.cch = ctext.size(); 1436 fmii.cch = ctext.size();
1521 1437
1522 UINT index = WM_WHITELIST_DOMAIN; 1438 UINT index = WM_WHITELIST_DOMAIN;
1523 1439
1524 ::SetMenuItemInfoW(hMenu, ID_WHITELISTDOMAIN, FALSE, &fmii); 1440 ::SetMenuItemInfoW(hMenu, ID_WHITELISTDOMAIN, FALSE, &fmii);
1525 } 1441 }
1526 #else 1442 #else
1527 { 1443 {
1528 ::DeleteMenu(hMenu, ID_WHITELISTDOMAIN, FALSE); 1444 ::DeleteMenu(hMenu, ID_WHITELISTDOMAIN, FALSE);
1529 } 1445 }
1530 #endif // SUPPORT_WHITELIST 1446 #endif // SUPPORT_WHITELIST
1531 1447
1532 // Invite friends
1533 ctext = dictionary->Lookup("menu", "invite");
1534 fmii.fMask = MIIM_STATE | MIIM_STRING;
1535 fmii.fState = MFS_ENABLED;
1536 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1537 fmii.cch = ctext.size();
1538 ::SetMenuItemInfoW(hMenu, ID_INVITEFRIENDS, FALSE, &fmii);
1539
1540 // FAQ
1541 ctext = dictionary->Lookup("menu", "faq");
1542 fmii.fMask = MIIM_STATE | MIIM_STRING;
1543 fmii.fState = MFS_ENABLED;
1544 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1545 fmii.cch = ctext.size();
1546 ::SetMenuItemInfoW(hMenu, ID_FAQ, FALSE, &fmii);
1547
1548 // About
1549 ctext = dictionary->Lookup("menu", "about");
1550 fmii.fMask = MIIM_STATE | MIIM_STRING;
1551 fmii.fState = MFS_ENABLED;
1552 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1553 fmii.cch = ctext.size();
1554 ::SetMenuItemInfoW(hMenu, ID_ABOUT, FALSE, &fmii);
1555
1556 // Feedback
1557 ctext = dictionary->Lookup("menu", "feedback");
1558 fmii.fMask = MIIM_STATE | MIIM_STRING;
1559 fmii.fState = MFS_ENABLED;
1560 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1561 fmii.cch = ctext.size();
1562 ::SetMenuItemInfoW(hMenu, ID_FEEDBACK, FALSE, &fmii);
1563
1564 // Plugin enable 1448 // Plugin enable
1565 if (settings->GetPluginEnabled()) 1449 if (settings->GetPluginEnabled())
1566 { 1450 {
1567 ctext = dictionary->Lookup("menu", "disable"); 1451 ctext = dictionary->Lookup("menu", "disable");
1568 } 1452 }
1569 else 1453 else
1570 { 1454 {
1571 ctext = dictionary->Lookup("menu", "enable"); 1455 ctext = dictionary->Lookup("menu", "enable");
1572 } 1456 }
1573 fmii.fMask = MIIM_STATE | MIIM_STRING; 1457 fmii.fMask = MIIM_STATE | MIIM_STRING;
1574 fmii.fState = client ? MFS_ENABLED : MFS_DISABLED; 1458 fmii.fState = client ? MFS_ENABLED : MFS_DISABLED;
1575 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1459 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1576 fmii.cch = ctext.size(); 1460 fmii.cch = ctext.size();
1577 ::SetMenuItemInfoW(hMenu, ID_PLUGIN_ENABLE, FALSE, &fmii); 1461 ::SetMenuItemInfoW(hMenu, ID_PLUGIN_ENABLE, FALSE, &fmii);
1578 1462
1579 // Settings 1463 // Settings
1580 #ifndef ENTERPRISE
1581 ctext = dictionary->Lookup("menu", "settings"); 1464 ctext = dictionary->Lookup("menu", "settings");
1582 fmii.fMask = MIIM_STATE | MIIM_STRING; 1465 fmii.fMask = MIIM_STATE | MIIM_STRING;
1583 fmii.fState = MFS_ENABLED; 1466 fmii.fState = MFS_ENABLED;
1584 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1467 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1585 fmii.cch = ctext.size(); 1468 fmii.cch = ctext.size();
1586 ::SetMenuItemInfoW(hMenu, ID_SETTINGS, FALSE, &fmii); 1469 ::SetMenuItemInfoW(hMenu, ID_SETTINGS, FALSE, &fmii);
1587 #else
1588 RemoveMenu(hMenu, ID_SETTINGS, MF_BYCOMMAND);
1589 RemoveMenu(hMenu, 5, MF_BYPOSITION);
1590 #endif
1591 1470
1592 return true; 1471 return true;
1593 } 1472 }
1594 1473
1595 1474
1596 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*) 1475 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*)
1597 { 1476 {
1598 HWND hBrowserWnd = GetBrowserHWND(); 1477 HWND hBrowserWnd = GetBrowserHWND();
1599 if (!hBrowserWnd) 1478 if (!hBrowserWnd)
1600 { 1479 {
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 if (FAILED(hr)) 1824 if (FAILED(hr))
1946 { 1825 {
1947 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") 1826 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1948 } 1827 }
1949 } 1828 }
1950 } 1829 }
1951 #endif 1830 #endif
1952 } 1831 }
1953 break; 1832 break;
1954 1833
1955 #ifndef ENTERPRISE
1956 1834
1957 case WM_LAUNCH_INFO: 1835 // First run page
1836 case WM_LAUNCH_INFO:
1958 { 1837 {
1959 // Set the status bar visible, if it isn't 1838 // Set the status bar visible, if it isn't
1960 // Otherwise the user won't see the icon the first time 1839 // Otherwise the user won't see the icon the first time
1961 1840
1962 if (wParam == 1) 1841 if (wParam == 1)
1963 { 1842 {
1964 // Redirect to welcome page 1843 // Redirect to welcome page
1965 VARIANT_BOOL isVisible; 1844 VARIANT_BOOL isVisible;
1966 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); 1845 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
1967 if (browser) 1846 if (browser)
(...skipping 21 matching lines...) Expand all
1989 } 1868 }
1990 } 1869 }
1991 } 1870 }
1992 else 1871 else
1993 { 1872 {
1994 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class::Get statusbar state"); 1873 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class::Get statusbar state");
1995 } 1874 }
1996 1875
1997 CPluginSettings* settings = CPluginSettings::GetInstance(); 1876 CPluginSettings* settings = CPluginSettings::GetInstance();
1998 1877
1999 CPluginHttpRequest httpRequest(USERS_SCRIPT_WELCOME); 1878 //TODO: Navigate to first run page here
2000 1879 /* hr = browser->Navigate(CComBSTR("FIRST_RUN_PAGE_URL"), NULL, NULL, NUL L, NULL);
2001 httpRequest.Add("errors", settings->GetErrorList());
2002
2003
2004 hr = browser->Navigate(CComBSTR(httpRequest.GetUrl() + "&src=" + DOWNL OAD_SOURCE), NULL, NULL, NULL, NULL);
2005 if (FAILED(hr)) 1880 if (FAILED(hr))
2006 { 1881 {
2007 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _WELCOME, "Navigation::Welcome page failed") 1882 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _WELCOME, "Navigation::Welcome page failed")
2008 } 1883 }
2009 1884 */
2010 // Update settings server side on next IE start, as they have possibly changed
2011 settings->ForceConfigurationUpdateOnStart();
2012 } 1885 }
2013 } 1886 }
2014 else 1887 else
2015 { 1888 {
2016 // Redirect to info page 1889 // Redirect to info page
2017 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser(); 1890 CComQIPtr<IWebBrowser2> browser = GetAsyncBrowser();
2018 if (browser) 1891 if (browser)
2019 { 1892 {
2020 CPluginHttpRequest httpRequest(USERS_SCRIPT_INFO);
2021
2022 httpRequest.Add("info", wParam);
2023
2024 VARIANT vFlags; 1893 VARIANT vFlags;
2025 vFlags.vt = VT_I4; 1894 vFlags.vt = VT_I4;
2026 vFlags.intVal = navOpenInNewTab; 1895 vFlags.intVal = navOpenInNewTab;
2027 1896
2028 HRESULT hr = browser->Navigate(CComBSTR(httpRequest.GetUrl()), &vFlags , NULL, NULL, NULL); 1897 // TODO: Navigate to info page here or remove this clause
1898 /* HRESULT hr = browser->Navigate(CComBSTR(INFO_PAGE_URL), &vFlags, NUL L, NULL, NULL);
2029 if (FAILED(hr)) 1899 if (FAILED(hr))
2030 { 1900 {
2031 vFlags.intVal = navOpenInNewWindow; 1901 vFlags.intVal = navOpenInNewWindow;
2032 1902
2033 hr = browser->Navigate(CComBSTR(httpRequest.GetUrl()), &vFlags, NULL , NULL, NULL); 1903 hr = browser->Navigate(CComBSTR(httpRequest.GetUrl()), &vFlags, NULL , NULL, NULL);
2034 if (FAILED(hr)) 1904 if (FAILED(hr))
2035 { 1905 {
2036 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATI ON_INFO, "Navigation::Info page failed") 1906 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATI ON_INFO, "Navigation::Info page failed")
2037 } 1907 }
2038 } 1908 }
1909 */
2039 } 1910 }
2040 } 1911 }
2041 } 1912 }
2042 break; 1913 break;
2043 #endif
2044 1914
2045 case WM_DESTROY: 1915 case WM_DESTROY:
2046 break; 1916 break;
2047 case SC_CLOSE: 1917 case SC_CLOSE:
2048 break; 1918 break;
2049 1919
2050 case WM_UPDATEUISTATE: 1920 case WM_UPDATEUISTATE:
2051 { 1921 {
2052 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1922 CPluginTab* tab = GetTab(::GetCurrentThreadId());
2053 if (tab) 1923 if (tab)
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2192 } 2062 }
2193 } 2063 }
2194 } 2064 }
2195 2065
2196 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); 2066 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
2197 } 2067 }
2198 2068
2199 return hTabWnd; 2069 return hTabWnd;
2200 2070
2201 } 2071 }
OLDNEW

Powered by Google App Engine
This is Rietveld