| LEFT | RIGHT | 
 |     1 /* | 
 |     2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 
 |     3  * Copyright (C) 2006-2015 Eyeo GmbH | 
 |     4  * | 
 |     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 | 
 |     7  * published by the Free Software Foundation. | 
 |     8  * | 
 |     9  * Adblock Plus is distributed in the hope that it will be useful, | 
 |    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 |    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 |    12  * GNU General Public License for more details. | 
 |    13  * | 
 |    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/>. | 
 |    16  */ | 
 |    17  | 
|     1 #include "PluginStdAfx.h" |    18 #include "PluginStdAfx.h" | 
|     2  |    19  | 
|     3 #include "PluginClass.h" |    20 #include "PluginClass.h" | 
|     4 #include "PluginSettings.h" |    21 #include "PluginSettings.h" | 
|     5 #include "PluginSystem.h" |    22 #include "PluginSystem.h" | 
|     6 #include "PluginFilter.h" |    23 #include "PluginFilter.h" | 
|     7 #include "PluginMimeFilterClient.h" |    24 #include "PluginMimeFilterClient.h" | 
|     8 #include "PluginClient.h" |    25 #include "PluginClient.h" | 
|     9 #include "PluginClientFactory.h" |    26 #include "PluginClientFactory.h" | 
|    10 #include "PluginMutex.h" |    27 #include "PluginMutex.h" | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|    68       return right - left; |    85       return right - left; | 
|    69     } |    86     } | 
|    70   }; |    87   }; | 
|    71 } |    88 } | 
|    72  |    89  | 
|    73 CPluginClass::CPluginClass() |    90 CPluginClass::CPluginClass() | 
|    74 { |    91 { | 
|    75   //Use this line to debug memory leaks |    92   //Use this line to debug memory leaks | 
|    76   //    _CrtDumpMemoryLeaks(); |    93   //    _CrtDumpMemoryLeaks(); | 
|    77  |    94  | 
|    78   m_isAdvised = false; |    95   m_isAdviced = false; | 
 |    96   m_nConnectionID = 0; | 
|    79   m_hTabWnd = NULL; |    97   m_hTabWnd = NULL; | 
|    80   m_hStatusBarWnd = NULL; |    98   m_hStatusBarWnd = NULL; | 
|    81   m_hPaneWnd = NULL; |    99   m_hPaneWnd = NULL; | 
|    82   m_nPaneWidth = 0; |   100   m_nPaneWidth = 0; | 
|    83   m_pWndProcStatus = NULL; |   101   m_pWndProcStatus = NULL; | 
|    84   m_hTheme = NULL; |   102   m_hTheme = NULL; | 
|    85   m_isInitializedOk = false; |   103   m_isInitializedOk = false; | 
|    86  |   104  | 
|    87  |   105  | 
|    88   m_tab = new CPluginTab(this); |   106   m_tab = new CPluginTab(this); | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
|   106  |   124  | 
|   107 void CPluginClass::FinalRelease() |   125 void CPluginClass::FinalRelease() | 
|   108 { |   126 { | 
|   109   s_criticalSectionBrowser.Lock(); |   127   s_criticalSectionBrowser.Lock(); | 
|   110   { |   128   { | 
|   111     m_webBrowser2.Release(); |   129     m_webBrowser2.Release(); | 
|   112   } |   130   } | 
|   113   s_criticalSectionBrowser.Unlock(); |   131   s_criticalSectionBrowser.Unlock(); | 
|   114 } |   132 } | 
|   115  |   133  | 
 |   134  | 
 |   135 // This method tries to get a 'connection point' from the stored browser, which 
      can be | 
 |   136 // used to attach or detach from the stream of browser events | 
 |   137 CComPtr<IConnectionPoint> CPluginClass::GetConnectionPoint() | 
 |   138 { | 
 |   139   CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pContaine
      r(GetBrowser()); | 
 |   140   if (!pContainer) | 
 |   141   { | 
 |   142     return NULL; | 
 |   143   } | 
 |   144  | 
 |   145   CComPtr<IConnectionPoint> pPoint; | 
 |   146   HRESULT hr = pContainer->FindConnectionPoint(DIID_DWebBrowserEvents2, &pPoint)
      ; | 
 |   147   if (FAILED(hr)) | 
 |   148   { | 
 |   149     DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_FIND_CONNEC
      TION_POINT, "Class::GetConnectionPoint - FindConnectionPoint") | 
 |   150       return NULL; | 
 |   151   } | 
 |   152  | 
 |   153   return pPoint; | 
 |   154 } | 
 |   155  | 
|   116 HWND CPluginClass::GetBrowserHWND() const |   156 HWND CPluginClass::GetBrowserHWND() const | 
|   117 { |   157 { | 
|   118   SHANDLE_PTR hBrowserWndHandle = NULL; |   158   SHANDLE_PTR hBrowserWndHandle = NULL; | 
|   119  |   159  | 
|   120   CComQIPtr<IWebBrowser2> browser = GetBrowser(); |   160   CComQIPtr<IWebBrowser2> browser = GetBrowser(); | 
|   121   if (browser) |   161   if (browser) | 
|   122   { |   162   { | 
|   123     HRESULT hr = browser->get_HWND(&hBrowserWndHandle); |   163     HRESULT hr = browser->get_HWND(&hBrowserWndHandle); | 
|   124     if (FAILED(hr)) |   164     if (FAILED(hr)) | 
|   125     { |   165     { | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|   151  |   191  | 
|   152   s_criticalSectionLocal.Lock(); |   192   s_criticalSectionLocal.Lock(); | 
|   153   { |   193   { | 
|   154     browser = s_asyncWebBrowser2; |   194     browser = s_asyncWebBrowser2; | 
|   155   } |   195   } | 
|   156   s_criticalSectionLocal.Unlock(); |   196   s_criticalSectionLocal.Unlock(); | 
|   157  |   197  | 
|   158   return browser; |   198   return browser; | 
|   159 } |   199 } | 
|   160  |   200  | 
|   161 CString CPluginClass::GetBrowserUrl() const |   201 std::wstring CPluginClass::GetBrowserUrl() const | 
|   162 { |   202 { | 
|   163   CString url; |   203   std::wstring url; | 
|   164  |  | 
|   165   CComQIPtr<IWebBrowser2> browser = GetBrowser(); |   204   CComQIPtr<IWebBrowser2> browser = GetBrowser(); | 
|   166   if (browser) |   205   if (browser) | 
|   167   { |   206   { | 
|   168     CComBSTR bstrURL; |   207     CComBSTR bstrURL; | 
|   169  |   208     if (SUCCEEDED(browser->get_LocationURL(&bstrURL)) && bstrURL) | 
|   170     if (SUCCEEDED(browser->get_LocationURL(&bstrURL))) |   209     { | 
|   171     { |   210       url = std::wstring(bstrURL, SysStringLen(bstrURL)); | 
|   172       url = bstrURL; |   211       UnescapeUrl(url); | 
|   173       CPluginClient::UnescapeUrl(url); |  | 
|   174     } |   212     } | 
|   175   } |   213   } | 
|   176   else |   214   else | 
|   177   { |   215   { | 
|   178     url = m_tab->GetDocumentUrl(); |   216     url = m_tab->GetDocumentUrl(); | 
|   179   } |   217   } | 
|   180  |  | 
|   181   return url; |   218   return url; | 
|   182 } |   219 } | 
|   183  |   220  | 
|   184 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) |   221 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) | 
|   185 { |   222 { | 
|   186   if (thisPtr == NULL) |   223   if (thisPtr == NULL) | 
|   187     return 0; |   224     return 0; | 
|   188   if (!((CPluginClass*)thisPtr)->InitObject(true)) |   225   if (!((CPluginClass*)thisPtr)->InitObject(true)) | 
|   189   { |   226   { | 
|   190     ((CPluginClass*)thisPtr)->Unadvise(); |   227     ((CPluginClass*)thisPtr)->Unadvice(); | 
|   191   } |   228   } | 
|   192  |   229  | 
|   193   return 0; |   230   return 0; | 
|   194 } |   231 } | 
|   195  |   232  | 
|   196  |   233  | 
|   197  |   234  | 
|   198 // This gets called when a new browser window is created (which also triggers th
      e |   235 // This gets called when a new browser window is created (which also triggers th
      e | 
|   199 // creation of this object). The pointer passed in should be to a IWebBrowser2 |   236 // creation of this object). The pointer passed in should be to a IWebBrowser2 | 
|   200 // interface that represents the browser for the window. |   237 // interface that represents the browser for the window. | 
|   201 // it is also called when a tab is closed, this unknownSite will be null |   238 // it is also called when a tab is closed, this unknownSite will be null | 
|   202 // 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 | 
|   203 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) |   240 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) | 
|   204 { |   241 { | 
|   205   return EntryPointWithHResult([&]()->HRESULT |   242   return EntryPointWithHResult([&]()->HRESULT | 
|   206   { |   243   { | 
|   207     CPluginSettings* settings = CPluginSettings::GetInstance(); |   244     CPluginSettings* settings = CPluginSettings::GetInstance(); | 
|   208      |   245  | 
|   209     MULTIPLE_VERSIONS_CHECK(); |   246     MULTIPLE_VERSIONS_CHECK(); | 
|   210      |   247  | 
|   211     if (unknownSite) |   248     if (unknownSite) | 
|   212     { |   249     { | 
|   213      |   250  | 
|   214       DEBUG_GENERAL(L"==========================================================
      ======================\nNEW TAB UI\n============================================
      ====================================") |   251       DEBUG_GENERAL(L"==========================================================
      ======================\nNEW TAB UI\n============================================
      ====================================") | 
|   215      |   252  | 
|   216       HRESULT hr = ::CoInitialize(NULL); |   253       HRESULT hr = ::CoInitialize(NULL); | 
|   217       if (FAILED(hr)) |   254       if (FAILED(hr)) | 
|   218       { |   255       { | 
|   219         DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT,
       "Class::SetSite - CoInitialize"); |   256         DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT,
       "Class::SetSite - CoInitialize"); | 
|   220       } |   257       } | 
|   221      |   258  | 
|   222       s_criticalSectionBrowser.Lock(); |   259       s_criticalSectionBrowser.Lock(); | 
|   223       { |   260       { | 
|   224         m_webBrowser2 = unknownSite; |   261         m_webBrowser2 = unknownSite; | 
|   225       } |   262       } | 
|   226       s_criticalSectionBrowser.Unlock(); |   263       s_criticalSectionBrowser.Unlock(); | 
|   227      |   264  | 
|   228       //register the mimefilter |   265       //register the mimefilter | 
|   229       //and only mimefilter |   266       //and only mimefilter | 
|   230       //on some few computers the mimefilter does not get properly registered wh
      en it is done on another thread |   267       //on some few computers the mimefilter does not get properly registered wh
      en it is done on another thread | 
|   231      |   268  | 
|   232       s_criticalSectionLocal.Lock(); |   269       s_criticalSectionLocal.Lock(); | 
|   233       { |   270       { | 
|   234         // Always register on startup, then check if we need to unregister in a 
      separate thread |   271         // Always register on startup, then check if we need to unregister in a 
      separate thread | 
|   235         s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |   272         s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | 
|   236         s_asyncWebBrowser2 = unknownSite; |   273         s_asyncWebBrowser2 = unknownSite; | 
|   237         s_instances.insert(this); |   274         s_instances.insert(this); | 
|   238       } |   275       } | 
|   239       s_criticalSectionLocal.Unlock(); |   276       s_criticalSectionLocal.Unlock(); | 
|   240      |   277  | 
|   241       try |   278       try | 
|   242       { |   279       { | 
|   243         // Check if loaded as BHO |   280         // Check if loaded as BHO | 
|   244         auto webBrowser = GetBrowser(); |   281         if (GetBrowser()) | 
|   245         if (webBrowser) |  | 
|   246         { |   282         { | 
|   247           DEBUG_GENERAL("Loaded as BHO"); |   283           DEBUG_GENERAL("Loaded as BHO"); | 
|   248           HRESULT hr = DispEventAdvise(webBrowser); |   284           CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); | 
|   249           if (SUCCEEDED(hr)) |   285           if (pPoint) | 
|   250           { |   286           { | 
|   251             m_isAdvised = true; |   287             HRESULT hr = pPoint->Advise((IDispatch*)this, &m_nConnectionID); | 
|   252             try |   288             if (SUCCEEDED(hr)) | 
|   253             { |   289             { | 
|   254               std::thread startInitObjectThread(StartInitObject, this); |   290               m_isAdviced = true; | 
|   255               startInitObjectThread.detach(); // TODO: but actually we should wa
      it for the thread in the dtr. |   291  | 
 |   292               try | 
 |   293               { | 
 |   294                 std::thread startInitObjectThread(StartInitObject, this); | 
 |   295                 startInitObjectThread.detach(); // TODO: but actually we should 
      wait for the thread in the dtr. | 
 |   296               } | 
 |   297               catch (const std::system_error& ex) | 
 |   298               { | 
 |   299                 auto errDescription = std::string("Class::Thread - Failed to cre
      ate StartInitObject thread, ") + | 
 |   300                   ex.code().message() + ex.what(); | 
 |   301                 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_E
      RROR_MAIN_THREAD_CREATE_PROCESS, errDescription.c_str()); | 
 |   302               } | 
|   256             } |   303             } | 
|   257             catch (const std::system_error& ex) |   304             else | 
|   258             { |   305             { | 
|   259               auto errDescription = std::string("Class::Thread - Failed to creat
      e StartInitObject thread, ") + |   306               DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_A
      DVICE, "Class::SetSite - Advice"); | 
|   260                 ex.code().message() + ex.what(); |  | 
|   261               DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERR
      OR_MAIN_THREAD_CREATE_PROCESS, errDescription.c_str()); |  | 
|   262             } |   307             } | 
|   263           } |   308           } | 
|   264           else |  | 
|   265           { |  | 
|   266             DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV
      ICE, "Class::SetSite - Advice"); |  | 
|   267           } |  | 
|   268         } |   309         } | 
|   269         else // Check if loaded as toolbar handler |   310         else // Check if loaded as toolbar handler | 
|   270         { |   311         { | 
|   271           DEBUG_GENERAL("Loaded as toolbar handler"); |   312           DEBUG_GENERAL("Loaded as toolbar handler"); | 
|   272           CComPtr<IServiceProvider> pServiceProvider; |   313           CComPtr<IServiceProvider> pServiceProvider; | 
|   273      |   314  | 
|   274           HRESULT hr = unknownSite->QueryInterface(&pServiceProvider); |   315           HRESULT hr = unknownSite->QueryInterface(&pServiceProvider); | 
|   275           if (SUCCEEDED(hr)) |   316           if (SUCCEEDED(hr)) | 
|   276           { |   317           { | 
|   277             if (pServiceProvider) |   318             if (pServiceProvider) | 
|   278             { |   319             { | 
|   279               s_criticalSectionBrowser.Lock(); |   320               s_criticalSectionBrowser.Lock(); | 
|   280               { |   321               { | 
|   281                 HRESULT hr = pServiceProvider->QueryService(IID_IWebBrowserApp, 
      &m_webBrowser2); |   322                 HRESULT hr = pServiceProvider->QueryService(IID_IWebBrowserApp, 
      &m_webBrowser2); | 
|   282                 if (SUCCEEDED(hr)) |   323                 if (SUCCEEDED(hr)) | 
|   283                 { |   324                 { | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|   296           } |   337           } | 
|   297           else |   338           else | 
|   298           { |   339           { | 
|   299             DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUE
      RY_SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)"); |   340             DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_QUE
      RY_SERVICE_PROVIDER, "Class::SetSite - QueryInterface (service provider)"); | 
|   300           } |   341           } | 
|   301         } |   342         } | 
|   302       } |   343       } | 
|   303       catch (std::runtime_error e) |   344       catch (std::runtime_error e) | 
|   304       { |   345       { | 
|   305         DEBUG_ERROR(e.what()); |   346         DEBUG_ERROR(e.what()); | 
|   306         Unadvise(); |   347         Unadvice(); | 
|   307       } |   348       } | 
|   308     } |   349     } | 
|   309     else |   350     else | 
|   310     { |   351     { | 
|   311       Unadvise(); |   352       // Unadvice | 
|   312      |   353       Unadvice(); | 
 |   354  | 
|   313       // Destroy window |   355       // Destroy window | 
|   314       if (m_pWndProcStatus) |   356       if (m_pWndProcStatus) | 
|   315       { |   357       { | 
|   316         ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn
      dProcStatus); |   358         ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn
      dProcStatus); | 
|   317      |   359  | 
|   318         m_pWndProcStatus = NULL; |   360         m_pWndProcStatus = NULL; | 
|   319       } |   361       } | 
|   320      |   362  | 
|   321       if (m_hPaneWnd) |   363       if (m_hPaneWnd) | 
|   322       { |   364       { | 
|   323         DestroyWindow(m_hPaneWnd); |   365         DestroyWindow(m_hPaneWnd); | 
|   324         m_hPaneWnd = NULL; |   366         m_hPaneWnd = NULL; | 
|   325       } |   367       } | 
|   326      |   368  | 
|   327       m_hTabWnd = NULL; |   369       m_hTabWnd = NULL; | 
|   328       m_hStatusBarWnd = NULL; |   370       m_hStatusBarWnd = NULL; | 
|   329      |   371  | 
|   330       // Remove instance from the list, shutdown threads |   372       // Remove instance from the list, shutdown threads | 
|   331       HANDLE hMainThread = NULL; |   373       HANDLE hMainThread = NULL; | 
|   332       HANDLE hTabThread = NULL; |   374       HANDLE hTabThread = NULL; | 
|   333      |   375  | 
|   334       s_criticalSectionLocal.Lock(); |   376       s_criticalSectionLocal.Lock(); | 
|   335       { |   377       { | 
|   336         s_instances.erase(this); |   378         s_instances.erase(this); | 
|   337      |   379  | 
|   338         std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::Ge
      tCurrentThreadId()); |   380         std::map<DWORD,CPluginClass*>::iterator it = s_threadInstances.find(::Ge
      tCurrentThreadId()); | 
|   339         if (it != s_threadInstances.end()) |   381         if (it != s_threadInstances.end()) | 
|   340         { |   382         { | 
|   341           s_threadInstances.erase(it); |   383           s_threadInstances.erase(it); | 
|   342         } |   384         } | 
|   343         if (s_instances.empty()) |   385         if (s_instances.empty()) | 
|   344         { |   386         { | 
|   345           // TODO: Explicitly releasing a resource when a container becomes empt
      y looks like a job better suited for shared_ptr |   387           // TODO: Explicitly releasing a resource when a container becomes empt
      y looks like a job better suited for shared_ptr | 
|   346           CPluginClientFactory::ReleaseMimeFilterClientInstance(); |   388           CPluginClientFactory::ReleaseMimeFilterClientInstance(); | 
|   347         } |   389         } | 
|   348       } |   390       } | 
|   349       s_criticalSectionLocal.Unlock(); |   391       s_criticalSectionLocal.Unlock(); | 
|   350      |   392  | 
|   351       // Release browser interface |   393       // Release browser interface | 
|   352       s_criticalSectionBrowser.Lock(); |   394       s_criticalSectionBrowser.Lock(); | 
|   353       { |   395       { | 
|   354         m_webBrowser2.Release(); |   396         m_webBrowser2.Release(); | 
|   355       } |   397       } | 
|   356       s_criticalSectionBrowser.Unlock(); |   398       s_criticalSectionBrowser.Unlock(); | 
|   357      |   399  | 
|   358       DEBUG_GENERAL("===========================================================
      =====================\nNEW TAB UI - END\n=======================================
      =========================================") |   400       DEBUG_GENERAL("===========================================================
      =====================\nNEW TAB UI - END\n=======================================
      =========================================") | 
|   359      |   401  | 
|   360       ::CoUninitialize(); |   402       ::CoUninitialize(); | 
|   361     } |   403     } | 
|   362      |   404  | 
|   363     return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); |   405     return IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite); | 
|   364   }); |   406   }); | 
|   365 } |   407 } | 
|   366  |   408  | 
|   367 bool CPluginClass::IsStatusBarEnabled() |   409 bool CPluginClass::IsStatusBarEnabled() | 
|   368 { |   410 { | 
|   369   DEBUG_GENERAL("IsStatusBarEnabled start"); |   411   DEBUG_GENERAL("IsStatusBarEnabled start"); | 
|   370   HKEY pHkey; |   412   HKEY pHkey; | 
|   371   HKEY pHkeySub; |   413   HKEY pHkeySub; | 
|   372   RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); |   414   RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   470       } |   512       } | 
|   471     } |   513     } | 
|   472     else |   514     else | 
|   473     { |   515     { | 
|   474       DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class
      ::Get statusbar state"); |   516       DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_STATUSBAR, "Class
      ::Get statusbar state"); | 
|   475     } |   517     } | 
|   476   } |   518   } | 
|   477   DEBUG_GENERAL("ShowStatusBar end"); |   519   DEBUG_GENERAL("ShowStatusBar end"); | 
|   478 } |   520 } | 
|   479  |   521  | 
|   480 void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2( |   522 /* | 
|   481                         /* [in] */ IDispatch* frameBrowserDisp, |   523  * #1163 This class is the implementation for method DISPID_BEFORENAVIGATE2 in C
      PluginClass::Invoke. | 
|   482                         /* [in] */ VARIANT* urlVariant, |   524  * - It validates and convertes its own arguments, rather than unifying them in 
      the Invoke body. | 
|   483                         /* [in] */ VARIANT* /*Flags*/, |   525  * - It's declared void and not HRESULT, so DISPID_BEFORENAVIGATE2 can only retu
      rn S_OK. | 
|   484                         /* [in] */ VARIANT* /*TargetFrameName*/, |   526  */ | 
|   485                         /* [in] */ VARIANT* /*PostData*/, |   527 void CPluginClass::BeforeNavigate2(DISPPARAMS* pDispParams) | 
|   486                         /* [in] */ VARIANT* /*Headers*/, |   528 { | 
|   487                         /* [in, out] */ VARIANT_BOOL* /*Cancel*/) |   529  | 
|   488 { |   530   if (pDispParams->cArgs < 7) | 
|   489   EntryPoint([&] |   531   { | 
|   490   { |   532     return; | 
|   491     ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; |   533   } | 
|   492     if (!webBrowser) |   534   //Register a mime filter if it's not registered yet | 
|   493     { |   535   if (s_mimeFilter == NULL) | 
|   494       return; |   536   { | 
|   495     } |   537     s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); | 
|   496      |   538   } | 
|   497     if (!urlVariant || urlVariant->vt != VT_BSTR) |   539  | 
|   498     { |   540   // Get the IWebBrowser2 interface | 
|   499       return; |   541   CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> WebBrowser2Ptr; | 
|   500     } |   542   VARTYPE vt = pDispParams->rgvarg[6].vt; | 
|   501     std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); |   543   if (vt == VT_DISPATCH) | 
|   502     UnescapeUrl(url); |   544   { | 
|   503      |   545     WebBrowser2Ptr = pDispParams->rgvarg[6].pdispVal; | 
|   504     //Register a mime filter if it's not registered yet |   546   } | 
|   505     if (s_mimeFilter == NULL) |   547   else | 
|   506     { |   548   { | 
|   507       s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); |   549     // Wrong type, return. | 
|   508     } |   550     return; | 
|   509      |   551   } | 
|   510     CString urlCString = ToCString(url); |   552  | 
|   511      |   553   // Get the URL | 
|   512     // If webbrowser2 is equal to top level browser (as set in SetSite), we are 
      navigating new page |   554   std::wstring url; | 
|   513     CPluginClient* client = CPluginClient::GetInstance(); |   555   const auto& arg = pDispParams->rgvarg[5]; | 
|   514      |   556   vt = arg.vt; | 
|   515     if (urlCString.Find(L"javascript") == 0) |   557   if (vt == (VT_BYREF | VT_VARIANT) && arg.pvarVal->vt == VT_BSTR) | 
|   516     { |   558   { | 
|   517     } |   559     BSTR b = arg.pvarVal->bstrVal; | 
|   518     else if (GetBrowser().IsEqualObject(webBrowser)) |   560     if (b) { | 
|   519     { |   561       url = std::wstring(b, SysStringLen(b)); | 
|   520       m_tab->OnNavigate(urlCString); |   562       UnescapeUrl(url); | 
|   521      |   563     } | 
|   522       DEBUG_GENERAL(L"==========================================================
      ======================\nBegin main navigation url:" + urlCString + "\n==========
      ======================================================================") |   564   } | 
|   523      |   565   else | 
 |   566   { | 
 |   567     // Wrong type, return. | 
 |   568     return; | 
 |   569   } | 
 |   570  | 
 |   571   // If webbrowser2 is equal to top level browser (as set in SetSite), we are na
      vigating new page | 
 |   572   CPluginClient* client = CPluginClient::GetInstance(); | 
 |   573   CString urlLegacy = ToCString(url); | 
 |   574   if (urlLegacy.Find(L"javascript") == 0) | 
 |   575   { | 
 |   576   } | 
 |   577   else if (GetBrowser().IsEqualObject(WebBrowser2Ptr)) | 
 |   578   { | 
 |   579     m_tab->OnNavigate(url); | 
 |   580  | 
 |   581     DEBUG_GENERAL(L"============================================================
      ====================\nBegin main navigation url:" + urlLegacy + "\n=============
      ===================================================================") | 
 |   582  | 
|   524 #ifdef ENABLE_DEBUG_RESULT |   583 #ifdef ENABLE_DEBUG_RESULT | 
|   525         CPluginDebug::DebugResultDomain(urlCString); |   584       CPluginDebug::DebugResultDomain(urlLegacy); | 
|   526 #endif |   585 #endif | 
|   527      |   586  | 
|   528       UpdateStatusBar(); |   587     UpdateStatusBar(); | 
|   529     } |   588   } | 
|   530     else |   589   else | 
|   531     { |   590   { | 
|   532       DEBUG_NAVI(L"Navi::Begin navigation url:" + urlCString) |   591     DEBUG_NAVI(L"Navi::Begin navigation url:" + urlLegacy) | 
|   533       m_tab->CacheFrame(urlCString); |   592     m_tab->CacheFrame(url); | 
|   534     } |   593   } | 
|   535   }); |   594 } | 
|   536 } |   595  | 
|   537  |   596 /* | 
|   538 void STDMETHODCALLTYPE CPluginClass::OnDownloadBegin() |   597  * #1163 implements behavior for method DISPID_WINDOWSTATECHANGED in CPluginClas
      s::Invoke | 
|   539 { |   598  * - should validate and convert arguments in Invoke, not here | 
|   540   EntryPoint([&] |   599  * - does not validate number of arguments before indexing into 'rgvarg' | 
|   541   { |   600  * - does not validate type of argument before using its value | 
|   542     DEBUG_NAVI("Navi::Download Begin") |   601  */ | 
|   543   }); |   602 STDMETHODIMP CPluginClass::OnTabChanged(DISPPARAMS* pDispParams, WORD wFlags) | 
|   544 } |   603 { | 
|   545  |   604   DEBUG_GENERAL("Tab changed"); | 
|   546 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() |   605   bool newtabshown = pDispParams->rgvarg[1].intVal==3; | 
|   547 { |   606   if (newtabshown) | 
|   548   EntryPoint([&] |   607   { | 
|   549   { |   608     std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(Ge
      tCurrentThreadId()); | 
|   550     DEBUG_NAVI("Navi::Download Complete") |   609     if (it == s_threadInstances.end()) | 
|   551     ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); |   610     { | 
|   552     if (browser) |   611       s_threadInstances[::GetCurrentThreadId()] = this; | 
|   553     { |   612       if (!m_isInitializedOk) | 
|   554       m_tab->OnDownloadComplete(browser); |   613       { | 
|   555     } |   614         m_isInitializedOk = true; | 
|   556   }); |   615         InitObject(true); | 
|   557 } |   616         UpdateStatusBar(); | 
|   558  |   617       } | 
|   559 void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserD
      isp, VARIANT* /*urlOrPidl*/) |   618     } | 
|   560 { |   619   } | 
|   561   EntryPoint([&] |   620   notificationMessage.Hide(); | 
|   562   { |   621   DEBUG_GENERAL("Tab change end"); | 
|   563     ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp; |   622   return S_OK; | 
|   564     if (!webBrowser2) |   623 } | 
|   565     { |   624  | 
|   566       return; |   625 STDMETHODIMP CPluginClass::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, W
      ORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo,
       UINT* puArgErr) | 
|   567     } |   626 { | 
|   568     ATL::CString frameSrc; |   627   return EntryPointWithHResult([&]()->HRESULT | 
|   569     ATL::CComBSTR locationUrl; |   628   { | 
|   570     if (FAILED(webBrowser2->get_LocationURL(&locationUrl)) && !!locationUrl) |   629     WCHAR tmp[256]; | 
|   571     { |   630     wsprintf(tmp, L"Invoke: %d\n", dispidMember); | 
|   572       return; |   631     DEBUG_GENERAL(tmp); | 
|   573     } |   632     switch (dispidMember) | 
|   574     frameSrc = locationUrl; |   633     { | 
|   575     CPluginClient::UnescapeUrl(frameSrc); |   634     case DISPID_WINDOWSTATECHANGED: | 
|   576     bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2); |   635       { | 
|   577     m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser); |   636         // #1163 should validate and convert arguments here | 
|   578   }); |   637         return OnTabChanged(pDispParams, wFlags); | 
|   579 } |   638       } | 
|   580  |   639  | 
|   581 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u
      nsigned long validFlagsMask) |   640     case DISPID_HTMLDOCUMENTEVENTS2_ONBEFOREUPDATE: | 
|   582 { |   641       break; | 
|   583   EntryPoint([&] |   642  | 
|   584   { |   643     case DISPID_HTMLDOCUMENTEVENTS2_ONCLICK: | 
|   585     DEBUG_GENERAL("Tab changed"); |   644       break; | 
|   586     bool newtabshown = validFlagsMask == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OL
      ECMDIDF_WINDOWSTATE_ENABLED) |   645  | 
|   587                     && flags == (OLECMDIDF_WINDOWSTATE_USERVISIBLE | OLECMDIDF_W
      INDOWSTATE_ENABLED); |   646     case DISPID_EVMETH_ONLOAD: | 
|   588     if (newtabshown) |   647       DEBUG_NAVI("Navi::OnLoad") | 
|   589     { |   648       break; | 
|   590       std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(
      GetCurrentThreadId()); |   649  | 
|   591       if (it == s_threadInstances.end()) |   650     case DISPID_EVMETH_ONCHANGE: | 
|   592       { |   651       break; | 
|   593         s_threadInstances[::GetCurrentThreadId()] = this; |   652  | 
|   594         if (!m_isInitializedOk) |   653     case DISPID_EVMETH_ONMOUSEDOWN: | 
|   595         { |   654       break; | 
|   596           m_isInitializedOk = true; |   655  | 
|   597           InitObject(true); |   656     case DISPID_EVMETH_ONMOUSEENTER: | 
|   598           UpdateStatusBar(); |   657       break; | 
|   599         } |   658  | 
|   600       } |   659     case DISPID_IHTMLIMGELEMENT_START: | 
|   601     } |   660       break; | 
|   602     notificationMessage.Hide(); |   661  | 
|   603     DEBUG_GENERAL("Tab change end"); |   662     case STDDISPID_XOBJ_ERRORUPDATE: | 
|   604   }); |   663       break; | 
|   605 } |   664  | 
|   606  |   665     case STDDISPID_XOBJ_ONPROPERTYCHANGE: | 
|   607 void STDMETHODCALLTYPE CPluginClass::OnCommandStateChange(long /*command*/, VARI
      ANT_BOOL /*enable*/) |   666       break; | 
|   608 { |   667  | 
|   609   EntryPoint([&] |   668     case DISPID_READYSTATECHANGE: | 
|   610   { |   669       DEBUG_NAVI("Navi::ReadyStateChange"); | 
|   611     if (m_hPaneWnd == NULL) |   670       break; | 
|   612     { |   671  | 
|   613       CreateStatusBarPane(); |   672     case DISPID_BEFORENAVIGATE: | 
|   614     } |   673       DEBUG_NAVI("Navi::BeforeNavigate"); | 
|   615     else |   674       break; | 
|   616     { |   675  | 
 |   676     case DISPID_COMMANDSTATECHANGE: | 
 |   677       if (m_hPaneWnd == NULL) | 
 |   678       { | 
 |   679         CreateStatusBarPane(); | 
 |   680       } | 
 |   681       else | 
 |   682       { | 
|   617       if (AdblockPlus::IE::InstalledMajorVersion() > 6) |   683       if (AdblockPlus::IE::InstalledMajorVersion() > 6) | 
|   618       { |   684         { | 
|   619         RECT rect; |   685           RECT rect; | 
|   620         BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); |   686           BOOL rectRes = GetClientRect(m_hStatusBarWnd, &rect); | 
|   621         if (rectRes == TRUE) |   687           if (rectRes == TRUE) | 
|   622         { |   688           { | 
|   623           MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.bottom 
      - rect.top, TRUE); |   689             MoveWindow(m_hPaneWnd, rect.right - 200, 0, m_nPaneWidth, rect.botto
      m - rect.top, TRUE); | 
|   624         } |   690           } | 
|   625       } |   691         }       | 
 |   692       } | 
 |   693       break; | 
 |   694  | 
 |   695     case DISPID_STATUSTEXTCHANGE: | 
 |   696       break; | 
 |   697  | 
 |   698     case DISPID_BEFORENAVIGATE2: | 
 |   699       { | 
 |   700         // #1163 should validate and convert parameters here | 
 |   701         BeforeNavigate2(pDispParams); | 
 |   702       } | 
 |   703       break; | 
 |   704  | 
 |   705     case DISPID_DOWNLOADBEGIN: | 
 |   706       { | 
 |   707         DEBUG_NAVI("Navi::Download Begin") | 
 |   708       } | 
 |   709       break; | 
 |   710  | 
 |   711     case DISPID_DOWNLOADCOMPLETE: | 
 |   712       { | 
 |   713         DEBUG_NAVI("Navi::Download Complete"); | 
 |   714         CComQIPtr<IWebBrowser2> browser = GetBrowser(); | 
 |   715         if (browser) | 
 |   716         { | 
 |   717           m_tab->OnDownloadComplete(browser); | 
 |   718         } | 
 |   719       } | 
 |   720       break; | 
 |   721  | 
 |   722     case DISPID_DOCUMENTCOMPLETE: | 
 |   723       { | 
 |   724         DEBUG_NAVI("Navi::Document Complete"); | 
 |   725         CComQIPtr<IWebBrowser2> browser = GetBrowser(); | 
 |   726         if (browser && pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == V
      T_DISPATCH) | 
 |   727         { | 
 |   728           CComQIPtr<IWebBrowser2> pBrowser = pDispParams->rgvarg[1].pdispVal; | 
 |   729           if (pBrowser) | 
 |   730           { | 
 |   731             CComBSTR bstrUrl; | 
 |   732             if (SUCCEEDED(pBrowser->get_LocationURL(&bstrUrl)) && bstrUrl && ::S
      ysStringLen(bstrUrl) > 0) | 
 |   733             { | 
 |   734               std::wstring url = std::wstring(bstrUrl, SysStringLen(bstrUrl)); | 
 |   735               UnescapeUrl(url); | 
 |   736               m_tab->OnDocumentComplete(browser, url, browser.IsEqualObject(pBro
      wser)); | 
 |   737             } | 
 |   738           } | 
 |   739         } | 
 |   740       } | 
 |   741       break; | 
 |   742  | 
 |   743     case DISPID_ONQUIT: | 
 |   744     case DISPID_QUIT: | 
 |   745       { | 
 |   746         Unadvice(); | 
 |   747       } | 
 |   748       break; | 
 |   749  | 
 |   750     default: | 
 |   751       { | 
 |   752         CString did; | 
 |   753         did.Format(L"DispId:%u", dispidMember); | 
 |   754  | 
 |   755         DEBUG_NAVI(L"Navi::Default " + did) | 
 |   756       } | 
 |   757       /* | 
 |   758        * Ordinarily a method not dispatched should return DISP_E_MEMBERNOTFOUND. | 
 |   759        * As a conservative initial change, we leave it behaving as before, | 
 |   760        *   which is to do nothing and return S_OK. | 
 |   761        */ | 
 |   762       // do nothing | 
 |   763       break; | 
|   626     } |   764     } | 
|   627   }); |   765   }); | 
|   628 } |   766 } | 
|   629  |   767  | 
|   630 bool CPluginClass::InitObject(bool bBHO) |   768 bool CPluginClass::InitObject(bool bBHO) | 
|   631 { |   769 { | 
|   632   DEBUG_GENERAL("InitObject"); |   770   DEBUG_GENERAL("InitObject"); | 
|   633   CPluginSettings* settings = CPluginSettings::GetInstance(); |   771   CPluginSettings* settings = CPluginSettings::GetInstance(); | 
|   634  |   772  | 
|   635   if (!settings->GetPluginEnabled()) |   773   if (!settings->GetPluginEnabled()) | 
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1000   return tab; |  1138   return tab; | 
|  1001 } |  1139 } | 
|  1002  |  1140  | 
|  1003  |  1141  | 
|  1004 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
      LECMD prgCmds[], OLECMDTEXT* pCmdText) |  1142 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
      LECMD prgCmds[], OLECMDTEXT* pCmdText) | 
|  1005 { |  1143 { | 
|  1006   return EntryPointWithHResult([&]()->HRESULT |  1144   return EntryPointWithHResult([&]()->HRESULT | 
|  1007   { |  1145   { | 
|  1008     if (cCmds == 0) return E_INVALIDARG; |  1146     if (cCmds == 0) return E_INVALIDARG; | 
|  1009     if (prgCmds == 0) return E_POINTER; |  1147     if (prgCmds == 0) return E_POINTER; | 
|  1010      |  1148  | 
|  1011     prgCmds[0].cmdf = OLECMDF_ENABLED; |  1149     prgCmds[0].cmdf = OLECMDF_ENABLED; | 
|  1012      |  1150  | 
|  1013     return S_OK; |  1151     return S_OK; | 
|  1014   }); |  1152   }); | 
|  1015 } |  1153 } | 
|  1016  |  1154  | 
|  1017 HMENU CPluginClass::CreatePluginMenu(const CString& url) |  1155 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) | 
|  1018 { |  1156 { | 
|  1019   DEBUG_GENERAL("CreatePluginMenu"); |  1157   DEBUG_GENERAL("CreatePluginMenu"); | 
|  1020   HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); |  1158   HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); | 
|  1021  |  1159  | 
|  1022   HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); |  1160   HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); | 
|  1023  |  1161  | 
|  1024   HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); |  1162   HMENU hMenuTrackPopup = GetSubMenu(hMenu, 0); | 
|  1025  |  1163  | 
|  1026   SetMenuBar(hMenuTrackPopup, url); |  1164   SetMenuBar(hMenuTrackPopup, url); | 
|  1027  |  1165  | 
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1115           { |  1253           { | 
|  1116             DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION
      _SETTINGS, "Navigation::Failed") |  1254             DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION
      _SETTINGS, "Navigation::Failed") | 
|  1117           } |  1255           } | 
|  1118         } |  1256         } | 
|  1119       } |  1257       } | 
|  1120       break; |  1258       break; | 
|  1121     } |  1259     } | 
|  1122   case ID_MENU_DISABLE_ON_SITE: |  1260   case ID_MENU_DISABLE_ON_SITE: | 
|  1123     { |  1261     { | 
|  1124       CPluginSettings* settings = CPluginSettings::GetInstance(); |  1262       CPluginSettings* settings = CPluginSettings::GetInstance(); | 
|  1125       CString urlString = GetTab()->GetDocumentUrl(); |  1263       std::wstring urlString = GetTab()->GetDocumentUrl(); | 
|  1126       if (client->IsWhitelistedUrl(to_wstring(urlString))) |  1264       if (client->IsWhitelistedUrl(urlString)) | 
|  1127       { |  1265       { | 
|  1128         settings->RemoveWhiteListedDomain(to_CString(client->GetHostFromUrl(to_w
      string(urlString)))); |  1266         settings->RemoveWhiteListedDomain(ToCString(client->GetHostFromUrl(urlSt
      ring))); | 
|  1129       } |  1267       } | 
|  1130       else |  1268       else | 
|  1131       { |  1269       { | 
|  1132         settings->AddWhiteListedDomain(to_CString(client->GetHostFromUrl(to_wstr
      ing(urlString)))); |  1270         settings->AddWhiteListedDomain(ToCString(client->GetHostFromUrl(urlStrin
      g))); | 
|  1133       } |  1271       } | 
|  1134       GetBrowser()->Refresh(); |  1272       GetBrowser()->Refresh(); | 
|  1135     } |  1273     } | 
|  1136   default: |  1274   default: | 
|  1137     break; |  1275     break; | 
|  1138   } |  1276   } | 
|  1139  |  1277  | 
|  1140   // Invalidate and redraw the control |  1278   // Invalidate and redraw the control | 
|  1141   UpdateStatusBar(); |  1279   UpdateStatusBar(); | 
|  1142 } |  1280 } | 
|  1143  |  1281  | 
|  1144  |  1282  | 
|  1145 bool CPluginClass::SetMenuBar(HMENU hMenu, const CString& url) |  1283 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring& url) | 
|  1146 { |  1284 { | 
|  1147   DEBUG_GENERAL("SetMenuBar"); |  1285   DEBUG_GENERAL("SetMenuBar"); | 
|  1148  |  1286  | 
|  1149   std::wstring ctext; |  1287   std::wstring ctext; | 
|  1150   Dictionary* dictionary = Dictionary::GetInstance(); |  1288   Dictionary* dictionary = Dictionary::GetInstance(); | 
|  1151  |  1289  | 
|  1152   MENUITEMINFOW fmii = {}; |  1290   MENUITEMINFOW fmii = {}; | 
|  1153   fmii.cbSize = sizeof(fmii); |  1291   fmii.cbSize = sizeof(fmii); | 
|  1154  |  1292  | 
|  1155   MENUITEMINFOW miiSep = {}; |  1293   MENUITEMINFOW miiSep = {}; | 
|  1156   miiSep.cbSize = sizeof(miiSep); |  1294   miiSep.cbSize = sizeof(miiSep); | 
|  1157   miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; |  1295   miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; | 
|  1158   miiSep.fType = MFT_SEPARATOR; |  1296   miiSep.fType = MFT_SEPARATOR; | 
|  1159  |  1297  | 
|  1160   CPluginClient* client = CPluginClient::GetInstance(); |  1298   CPluginClient* client = CPluginClient::GetInstance(); | 
|  1161   CPluginSettings* settings = CPluginSettings::GetInstance(); |  1299   CPluginSettings* settings = CPluginSettings::GetInstance(); | 
|  1162   { |  1300   { | 
|  1163     ctext = dictionary->Lookup("menu", "menu-disable-on-site"); |  1301     ctext = dictionary->Lookup("menu", "menu-disable-on-site"); | 
|  1164     // Is domain in white list? |  1302     // Is domain in white list? | 
|  1165     ReplaceString(ctext, L"?1?", client->GetHostFromUrl(to_wstring(url))); |  1303     ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); | 
|  1166     if (client->IsWhitelistedUrl(to_wstring(GetTab()->GetDocumentUrl()))) |  1304     if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) | 
|  1167     { |  1305     { | 
|  1168       fmii.fState = MFS_CHECKED | MFS_ENABLED; |  1306       fmii.fState = MFS_CHECKED | MFS_ENABLED; | 
|  1169     } |  1307     } | 
|  1170     else |  1308     else | 
|  1171     { |  1309     { | 
|  1172       fmii.fState = MFS_UNCHECKED | MFS_ENABLED; |  1310       fmii.fState = MFS_UNCHECKED | MFS_ENABLED; | 
|  1173     } |  1311     } | 
|  1174     fmii.fMask = MIIM_STRING | MIIM_STATE; |  1312     fmii.fMask = MIIM_STRING | MIIM_STATE; | 
|  1175     fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |  1313     fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 
|  1176     fmii.cch = static_cast<UINT>(ctext.size()); |  1314     fmii.cch = static_cast<UINT>(ctext.size()); | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1216  |  1354  | 
|  1217 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
      ARIANTARG*) |  1355 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
      ARIANTARG*) | 
|  1218 { |  1356 { | 
|  1219   return EntryPointWithHResult([&]()->HRESULT |  1357   return EntryPointWithHResult([&]()->HRESULT | 
|  1220   { |  1358   { | 
|  1221     HWND hBrowserWnd = GetBrowserHWND(); |  1359     HWND hBrowserWnd = GetBrowserHWND(); | 
|  1222     if (!hBrowserWnd) |  1360     if (!hBrowserWnd) | 
|  1223     { |  1361     { | 
|  1224       return E_FAIL; |  1362       return E_FAIL; | 
|  1225     } |  1363     } | 
|  1226      |  1364  | 
|  1227     // Create menu |  1365     // Create menu | 
|  1228     HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); |  1366     HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); | 
|  1229     if (!hMenu) |  1367     if (!hMenu) | 
|  1230     { |  1368     { | 
|  1231       return E_FAIL; |  1369       return E_FAIL; | 
|  1232     } |  1370     } | 
|  1233      |  1371  | 
|  1234     // Check if button in toolbar was pressed |  1372     // Check if button in toolbar was pressed | 
|  1235     int nIDCommand = -1; |  1373     int nIDCommand = -1; | 
|  1236     BOOL bRightAlign = FALSE; |  1374     BOOL bRightAlign = FALSE; | 
|  1237      |  1375  | 
|  1238     POINT pt; |  1376     POINT pt; | 
|  1239     GetCursorPos(&pt); |  1377     GetCursorPos(&pt); | 
|  1240      |  1378  | 
|  1241     HWND hWndToolBar = ::WindowFromPoint(pt); |  1379     HWND hWndToolBar = ::WindowFromPoint(pt); | 
|  1242      |  1380  | 
|  1243     DWORD nProcessId; |  1381     DWORD nProcessId; | 
|  1244     ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); |  1382     ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); | 
|  1245      |  1383  | 
|  1246     if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) |  1384     if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) | 
|  1247     { |  1385     { | 
|  1248       ::ScreenToClient(hWndToolBar, &pt); |  1386       ::ScreenToClient(hWndToolBar, &pt); | 
|  1249       int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); |  1387       int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); | 
|  1250      |  1388  | 
|  1251       if (nButton > 0) |  1389       if (nButton > 0) | 
|  1252       { |  1390       { | 
|  1253         TBBUTTON pTBBtn = {}; |  1391         TBBUTTON pTBBtn = {}; | 
|  1254      |  1392  | 
|  1255         if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) |  1393         if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) | 
|  1256         { |  1394         { | 
|  1257           RECT rcButton; |  1395           RECT rcButton; | 
|  1258           nIDCommand = pTBBtn.idCommand; |  1396           nIDCommand = pTBBtn.idCommand; | 
|  1259      |  1397  | 
|  1260           if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton
      )) |  1398           if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton
      )) | 
|  1261           { |  1399           { | 
|  1262             pt.x = rcButton.left; |  1400             pt.x = rcButton.left; | 
|  1263             pt.y = rcButton.bottom; |  1401             pt.y = rcButton.bottom; | 
|  1264             ClientToScreen(hWndToolBar, &pt); |  1402             ClientToScreen(hWndToolBar, &pt); | 
|  1265      |  1403  | 
|  1266             RECT rcWorkArea; |  1404             RECT rcWorkArea; | 
|  1267             SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); |  1405             SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); | 
|  1268             if (rcWorkArea.right - pt.x < 150) |  1406             if (rcWorkArea.right - pt.x < 150) | 
|  1269             { |  1407             { | 
|  1270               bRightAlign = TRUE; |  1408               bRightAlign = TRUE; | 
|  1271               pt.x = rcButton.right; |  1409               pt.x = rcButton.right; | 
|  1272               pt.y = rcButton.bottom; |  1410               pt.y = rcButton.bottom; | 
|  1273               ClientToScreen(hWndToolBar, &pt); |  1411               ClientToScreen(hWndToolBar, &pt); | 
|  1274             } |  1412             } | 
|  1275           } |  1413           } | 
|  1276         } |  1414         } | 
|  1277       } |  1415       } | 
|  1278       else |  1416       else | 
|  1279       { |  1417       { | 
|  1280         GetCursorPos(&pt); |  1418         GetCursorPos(&pt); | 
|  1281       } |  1419       } | 
|  1282     } |  1420     } | 
|  1283      |  1421  | 
|  1284     // Display menu |  1422     // Display menu | 
|  1285     UINT nFlags = 0; |  1423     UINT nFlags = 0; | 
|  1286     if (bRightAlign) |  1424     if (bRightAlign) | 
|  1287     { |  1425     { | 
|  1288       nFlags |= TPM_RIGHTALIGN; |  1426       nFlags |= TPM_RIGHTALIGN; | 
|  1289     } |  1427     } | 
|  1290     else |  1428     else | 
|  1291     { |  1429     { | 
|  1292       nFlags |= TPM_LEFTALIGN; |  1430       nFlags |= TPM_LEFTALIGN; | 
|  1293     } |  1431     } | 
|  1294      |  1432  | 
|  1295     DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); |  1433     DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); | 
|  1296      |  1434  | 
|  1297     return S_OK; |  1435     return S_OK; | 
|  1298   }); |  1436   }); | 
|  1299 } |  1437 } | 
|  1300  |  1438  | 
|  1301 ///////////////////////////////////////////////////////////////////////////// |  1439 ///////////////////////////////////////////////////////////////////////////// | 
|  1302 // Window procedures |  1440 // Window procedures | 
|  1303  |  1441  | 
|  1304 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa
      ram, LPARAM lParam) |  1442 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa
      ram, LPARAM lParam) | 
|  1305 { |  1443 { | 
|  1306   // Find tab |  1444   // Find tab | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1373   } |  1511   } | 
|  1374  |  1512  | 
|  1375   LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara
      m, lParam); |  1513   LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara
      m, lParam); | 
|  1376  |  1514  | 
|  1377  |  1515  | 
|  1378   return result; |  1516   return result; | 
|  1379  |  1517  | 
|  1380 } |  1518 } | 
|  1381  |  1519  | 
|  1382  |  1520  | 
|  1383 HICON CPluginClass::GetStatusBarIcon(const CString& url) |  1521 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) | 
|  1384 { |  1522 { | 
|  1385   // use the disable icon as defualt, if the client doesn't exists |  1523   // use the disable icon as defualt, if the client doesn't exists | 
|  1386   HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); |  1524   HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); | 
|  1387  |  1525  | 
|  1388   CPluginTab* tab = GetTab(::GetCurrentThreadId()); |  1526   CPluginTab* tab = GetTab(::GetCurrentThreadId()); | 
|  1389   if (tab) |  1527   if (tab) | 
|  1390   { |  1528   { | 
|  1391     CPluginClient* client = CPluginClient::GetInstance(); |  1529     CPluginClient* client = CPluginClient::GetInstance(); | 
|  1392     if (CPluginSettings::GetInstance()->IsPluginEnabled()) |  1530     if (CPluginSettings::GetInstance()->IsPluginEnabled()) | 
|  1393     { |  1531     { | 
|  1394       if (client->IsWhitelistedUrl(ToWstring(url))) |  1532       if (client->IsWhitelistedUrl(url)) | 
|  1395       { |  1533       { | 
|  1396         hIcon = GetIcon(ICON_PLUGIN_DISABLED); |  1534         hIcon = GetIcon(ICON_PLUGIN_DISABLED); | 
|  1397       } |  1535       } | 
|  1398       else |  1536       else | 
|  1399       { |  1537       { | 
|  1400         CPluginSettings* settings = CPluginSettings::GetInstance(); |  1538         CPluginSettings* settings = CPluginSettings::GetInstance(); | 
|  1401         hIcon = GetIcon(ICON_PLUGIN_ENABLED); |  1539         hIcon = GetIcon(ICON_PLUGIN_ENABLED); | 
|  1402       } |  1540       } | 
|  1403     } |  1541     } | 
|  1404   } |  1542   } | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1502  |  1640  | 
|  1503       // Done! |  1641       // Done! | 
|  1504       EndPaint(hWnd, &ps); |  1642       EndPaint(hWnd, &ps); | 
|  1505  |  1643  | 
|  1506       return 0; |  1644       return 0; | 
|  1507     } |  1645     } | 
|  1508  |  1646  | 
|  1509   case WM_LBUTTONUP: |  1647   case WM_LBUTTONUP: | 
|  1510   case WM_RBUTTONUP: |  1648   case WM_RBUTTONUP: | 
|  1511     { |  1649     { | 
|  1512       CString strURL = pClass->GetBrowserUrl(); |  1650       std::wstring url = pClass->GetBrowserUrl(); | 
|  1513       if (strURL != pClass->GetTab()->GetDocumentUrl()) |  1651       if (url != pClass->GetTab()->GetDocumentUrl()) | 
|  1514       { |  1652       { | 
|  1515         pClass->GetTab()->SetDocumentUrl(strURL); |  1653         pClass->GetTab()->SetDocumentUrl(url); | 
|  1516       } |  1654       } | 
|  1517  |  1655  | 
|  1518       // Create menu |  1656       // Create menu | 
|  1519       HMENU hMenu = pClass->CreatePluginMenu(strURL); |  1657       HMENU hMenu = pClass->CreatePluginMenu(url); | 
|  1520       if (!hMenu) |  1658       if (!hMenu) | 
|  1521       { |  1659       { | 
|  1522         return 0; |  1660         return 0; | 
|  1523       } |  1661       } | 
|  1524  |  1662  | 
|  1525       // Display menu |  1663       // Display menu | 
|  1526       POINT pt; |  1664       POINT pt; | 
|  1527       ::GetCursorPos(&pt); |  1665       ::GetCursorPos(&pt); | 
|  1528  |  1666  | 
|  1529       RECT rc; |  1667       RECT rc; | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1614   if (m_hPaneWnd == NULL) |  1752   if (m_hPaneWnd == NULL) | 
|  1615   { |  1753   { | 
|  1616     CreateStatusBarPane(); |  1754     CreateStatusBarPane(); | 
|  1617   } |  1755   } | 
|  1618   if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) |  1756   if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) | 
|  1619   { |  1757   { | 
|  1620       DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID
      ATE_STATUSBAR, "Class::Invalidate statusbar"); |  1758       DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID
      ATE_STATUSBAR, "Class::Invalidate statusbar"); | 
|  1621   } |  1759   } | 
|  1622 } |  1760 } | 
|  1623  |  1761  | 
|  1624 void STDMETHODCALLTYPE CPluginClass::OnOnQuit() |  1762  | 
|  1625 { |  1763 void CPluginClass::Unadvice() | 
|  1626   EntryPoint([&] |  | 
|  1627   { |  | 
|  1628     Unadvise(); |  | 
|  1629   }); |  | 
|  1630 } |  | 
|  1631  |  | 
|  1632 void CPluginClass::Unadvise() |  | 
|  1633 { |  1764 { | 
|  1634   s_criticalSectionLocal.Lock(); |  1765   s_criticalSectionLocal.Lock(); | 
|  1635   { |  1766   { | 
|  1636     if (m_isAdvised) |  1767     if (m_isAdviced) | 
|  1637     { |  1768     { | 
|  1638       HRESULT hr = DispEventUnadvise(GetBrowser()); |  1769       CComPtr<IConnectionPoint> pPoint = GetConnectionPoint(); | 
|  1639       if (FAILED(hr)) |  1770       if (pPoint) | 
|  1640       { |  1771       { | 
|  1641         DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS
      E, "Class::Unadvise - Unadvise"); |  1772         HRESULT hr = pPoint->Unadvise(m_nConnectionID); | 
|  1642       } |  1773         if (FAILED(hr)) | 
|  1643       m_isAdvised = false; |  1774         { | 
 |  1775           DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADV
      ICE, "Class::Unadvice - Unadvise"); | 
 |  1776         } | 
 |  1777       } | 
 |  1778  | 
 |  1779       m_isAdviced = false; | 
|  1644     } |  1780     } | 
|  1645   } |  1781   } | 
|  1646   s_criticalSectionLocal.Unlock(); |  1782   s_criticalSectionLocal.Unlock(); | 
|  1647 } |  1783 } | 
|  1648  |  1784  | 
|  1649 HICON CPluginClass::GetIcon(int type) |  1785 HICON CPluginClass::GetIcon(int type) | 
|  1650 { |  1786 { | 
|  1651   HICON icon = NULL; |  1787   HICON icon = NULL; | 
|  1652  |  1788  | 
|  1653   s_criticalSectionLocal.Lock(); |  1789   s_criticalSectionLocal.Lock(); | 
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1735         } |  1871         } | 
|  1736       } |  1872       } | 
|  1737     } |  1873     } | 
|  1738  |  1874  | 
|  1739     hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); |  1875     hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT); | 
|  1740   } |  1876   } | 
|  1741  |  1877  | 
|  1742   return hTabWnd; |  1878   return hTabWnd; | 
|  1743  |  1879  | 
|  1744 } |  1880 } | 
| LEFT | RIGHT |