• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得windowscocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

OpenTweenのfork


Commit MetaInfo

修訂7d2cb3f40e1332635e60125f6cbb76bef6c1509c (tree)
時間2012-02-22 19:46:14
作者Egtra <yusuke.ichinohe@gmai...>
CommiterKimura Youichi

Log Message

Port WebBrowsercontroller.vb to C#

Change Summary

差異

--- a/Tween/Tween.vbproj
+++ b/Tween/Tween.vbproj
@@ -294,7 +294,6 @@
294294 <Compile Include="FavoriteQueue.vb" />
295295 <Compile Include="Twitter.vb" />
296296 <Compile Include="UserInfo.vb" />
297- <Compile Include="WebBrowserController.vb" />
298297 </ItemGroup>
299298 <ItemGroup>
300299 <EmbeddedResource Include="AppendSettingDialog.en.resx">
--- a/Tween/WebBrowserController.vb
+++ /dev/null
@@ -1,419 +0,0 @@
1-' Tween - Client of Twitter
2-' Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3-' (c) 2008-2011 Moz (@syo68k)
4-' (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5-' (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6-' (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7-' All rights reserved.
8-'
9-' This file is part of Tween.
10-'
11-' This program is free software; you can redistribute it and/or modify it
12-' under the terms of the GNU General Public License as published by the Free
13-' Software Foundation; either version 3 of the License, or (at your option)
14-' any later version.
15-'
16-' This program is distributed in the hope that it will be useful, but
17-' WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18-' or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19-' for more details.
20-'
21-' You should have received a copy of the GNU General Public License along
22-' with this program. If not, see <http://www.gnu.org/licenses/>, or write to
23-' the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
24-' Boston, MA 02110-1301, USA.
25-
26-Imports System.Runtime.InteropServices
27-Imports System.Threading
28-Imports System.Text.RegularExpressions
29-
30-Public Class InternetSecurityManager
31- Implements WebBrowserAPI.IServiceProvider
32- Implements WebBrowserAPI.IInternetSecurityManager
33-
34-#Region "HRESULT"
35- Private Class HRESULT
36- Public Shared S_OK As Integer = &H0
37- Public Shared S_FALSE As Integer = &H1
38- Public Shared E_NOTIMPL As Integer = &H80004001
39- Public Shared E_NOINTERFACE As Integer = &H80004002
40- End Class
41-#End Region
42-
43-#Region "WebBrowserAPI"
44- Private Class WebBrowserAPI
45- Public Shared INET_E_DEFAULT_ACTION As Integer = &H800C0011
46-
47- Public Enum URLZONE
48- URLZONE_LOCAL_MACHINE = 0
49- URLZONE_INTRANET = URLZONE_LOCAL_MACHINE + 1
50- URLZONE_TRUSTED = URLZONE_INTRANET + 1
51- URLZONE_INTERNET = URLZONE_TRUSTED + 1
52- URLZONE_UNTRUSTED = URLZONE_INTERNET + 1
53- End Enum
54-
55- Public Shared URLACTION_MIN As Integer = &H1000
56-
57- Public Shared URLACTION_DOWNLOAD_MIN As Integer = &H1000
58- Public Shared URLACTION_DOWNLOAD_SIGNED_ACTIVEX As Integer = &H1001
59- Public Shared URLACTION_DOWNLOAD_UNSIGNED_ACTIVEX As Integer = &H1004
60- Public Shared URLACTION_DOWNLOAD_CURR_MAX As Integer = &H1004
61- Public Shared URLACTION_DOWNLOAD_MAX As Integer = &H11FF
62-
63- Public Shared URLACTION_ACTIVEX_MIN As Integer = &H1200
64- Public Shared URLACTION_ACTIVEX_RUN As Integer = &H1200
65- Public Shared URLPOLICY_ACTIVEX_CHECK_LIST As Integer = &H10000
66- Public Shared URLACTION_ACTIVEX_OVERRIDE_OBJECT_SAFETY As Integer = &H1201
67- Public Shared URLACTION_ACTIVEX_OVERRIDE_DATA_SAFETY As Integer = &H1202
68- Public Shared URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY As Integer = &H1203
69- Public Shared URLACTION_SCRIPT_OVERRIDE_SAFETY As Integer = &H1401
70- Public Shared URLACTION_ACTIVEX_CONFIRM_NOOBJECTSAFETY As Integer = &H1204
71- Public Shared URLACTION_ACTIVEX_TREATASUNTRUSTED As Integer = &H1205
72- Public Shared URLACTION_ACTIVEX_NO_WEBOC_SCRIPT As Integer = &H1206
73- Public Shared URLACTION_ACTIVEX_CURR_MAX As Integer = &H1206
74- Public Shared URLACTION_ACTIVEX_MAX As Integer = &H13FF
75-
76- Public Shared URLACTION_SCRIPT_MIN As Integer = &H1400
77- Public Shared URLACTION_SCRIPT_RUN As Integer = &H1400
78- Public Shared URLACTION_SCRIPT_JAVA_USE As Integer = &H1402
79- Public Shared URLACTION_SCRIPT_SAFE_ACTIVEX As Integer = &H1405
80- Public Shared URLACTION_CROSS_DOMAIN_DATA As Integer = &H1406
81- Public Shared URLACTION_SCRIPT_PASTE As Integer = &H1407
82- Public Shared URLACTION_SCRIPT_CURR_MAX As Integer = &H1407
83- Public Shared URLACTION_SCRIPT_MAX As Integer = &H15FF
84-
85- Public Shared URLACTION_HTML_MIN As Integer = &H1600
86- Public Shared URLACTION_HTML_SUBMIT_FORMS As Integer = &H1601 ' aggregate next two
87- Public Shared URLACTION_HTML_SUBMIT_FORMS_FROM As Integer = &H1602 '
88- Public Shared URLACTION_HTML_SUBMIT_FORMS_TO As Integer = &H1603 '
89- Public Shared URLACTION_HTML_FONT_DOWNLOAD As Integer = &H1604
90- Public Shared URLACTION_HTML_JAVA_RUN As Integer = &H1605 ' derive from Java custom policy
91- Public Shared URLACTION_HTML_USERDATA_SAVE As Integer = &H1606
92- Public Shared URLACTION_HTML_SUBFRAME_NAVIGATE As Integer = &H1607
93- Public Shared URLACTION_HTML_META_REFRESH As Integer = &H1608
94- Public Shared URLACTION_HTML_MIXED_CONTENT As Integer = &H1609
95- Public Shared URLACTION_HTML_MAX As Integer = &H17FF
96-
97- Public Shared URLACTION_SHELL_MIN As Integer = &H1800
98- Public Shared URLACTION_SHELL_INSTALL_DTITEMS As Integer = &H1800
99- Public Shared URLACTION_SHELL_MOVE_OR_COPY As Integer = &H1802
100- Public Shared URLACTION_SHELL_FILE_DOWNLOAD As Integer = &H1803
101- Public Shared URLACTION_SHELL_VERB As Integer = &H1804
102- Public Shared URLACTION_SHELL_WEBVIEW_VERB As Integer = &H1805
103- Public Shared URLACTION_SHELL_SHELLEXECUTE As Integer = &H1806
104- Public Shared URLACTION_SHELL_CURR_MAX As Integer = &H1806
105- Public Shared URLACTION_SHELL_MAX As Integer = &H19FF
106-
107- Public Shared URLACTION_NETWORK_MIN As Integer = &H1A00
108-
109- Public Shared URLACTION_CREDENTIALS_USE As Integer = &H1A00
110- Public Shared URLPOLICY_CREDENTIALS_SILENT_LOGON_OK As Integer = &H0
111- Public Shared URLPOLICY_CREDENTIALS_MUST_PROMPT_USER As Integer = &H10000
112- Public Shared URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT As Integer = &H20000
113- Public Shared URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY As Integer = &H30000
114-
115- Public Shared URLACTION_AUTHENTICATE_CLIENT As Integer = &H1A01
116- Public Shared URLPOLICY_AUTHENTICATE_CLEARTEXT_OK As Integer = &H0
117- Public Shared URLPOLICY_AUTHENTICATE_CHALLENGE_RESPONSE As Integer = &H10000
118- Public Shared URLPOLICY_AUTHENTICATE_MUTUAL_ONLY As Integer = &H30000
119-
120-
121- Public Shared URLACTION_COOKIES As Integer = &H1A02
122- Public Shared URLACTION_COOKIES_SESSION As Integer = &H1A03
123-
124- Public Shared URLACTION_CLIENT_CERT_PROMPT As Integer = &H1A04
125-
126- Public Shared URLACTION_COOKIES_THIRD_PARTY As Integer = &H1A05
127- Public Shared URLACTION_COOKIES_SESSION_THIRD_PARTY As Integer = &H1A06
128-
129- Public Shared URLACTION_COOKIES_ENABLED As Integer = &H1A10
130-
131- Public Shared URLACTION_NETWORK_CURR_MAX As Integer = &H1A10
132- Public Shared URLACTION_NETWORK_MAX As Integer = &H1BFF
133-
134-
135- Public Shared URLACTION_JAVA_MIN As Integer = &H1C00
136- Public Shared URLACTION_JAVA_PERMISSIONS As Integer = &H1C00
137- Public Shared URLPOLICY_JAVA_PROHIBIT As Integer = &H0
138- Public Shared URLPOLICY_JAVA_HIGH As Integer = &H10000
139- Public Shared URLPOLICY_JAVA_MEDIUM As Integer = &H20000
140- Public Shared URLPOLICY_JAVA_LOW As Integer = &H30000
141- Public Shared URLPOLICY_JAVA_CUSTOM As Integer = &H800000
142- Public Shared URLACTION_JAVA_CURR_MAX As Integer = &H1C00
143- Public Shared URLACTION_JAVA_MAX As Integer = &H1CFF
144-
145-
146- ' The following Infodelivery actions should have no default policies
147- ' in the registry. They assume that no default policy means fall
148- ' back to the global restriction. If an admin sets a policy per
149- ' zone, then it overrides the global restriction.
150-
151- Public Shared URLACTION_INFODELIVERY_MIN As Integer = &H1D00
152- Public Shared URLACTION_INFODELIVERY_NO_ADDING_CHANNELS As Integer = &H1D00
153- Public Shared URLACTION_INFODELIVERY_NO_EDITING_CHANNELS As Integer = &H1D01
154- Public Shared URLACTION_INFODELIVERY_NO_REMOVING_CHANNELS As Integer = &H1D02
155- Public Shared URLACTION_INFODELIVERY_NO_ADDING_SUBSCRIPTIONS As Integer = &H1D03
156- Public Shared URLACTION_INFODELIVERY_NO_EDITING_SUBSCRIPTIONS As Integer = &H1D04
157- Public Shared URLACTION_INFODELIVERY_NO_REMOVING_SUBSCRIPTIONS As Integer = &H1D05
158- Public Shared URLACTION_INFODELIVERY_NO_CHANNEL_LOGGING As Integer = &H1D06
159- Public Shared URLACTION_INFODELIVERY_CURR_MAX As Integer = &H1D06
160- Public Shared URLACTION_INFODELIVERY_MAX As Integer = &H1DFF
161- Public Shared URLACTION_CHANNEL_SOFTDIST_MIN As Integer = &H1E00
162- Public Shared URLACTION_CHANNEL_SOFTDIST_PERMISSIONS As Integer = &H1E05
163- Public Shared URLPOLICY_CHANNEL_SOFTDIST_PROHIBIT As Integer = &H10000
164- Public Shared URLPOLICY_CHANNEL_SOFTDIST_PRECACHE As Integer = &H20000
165- Public Shared URLPOLICY_CHANNEL_SOFTDIST_AUTOINSTALL As Integer = &H30000
166- Public Shared URLACTION_CHANNEL_SOFTDIST_MAX As Integer = &H1EFF
167-
168- ' For each action specified above the system maintains
169- ' a set of policies for the action.
170- ' The only policies supported currently are permissions (i.e. is something allowed)
171- ' and logging status.
172- ' IMPORTANT: If you are defining your own policies don't overload the meaning of the
173- ' loword of the policy. You can use the hiword to store any policy bits which are only
174- ' meaningful to your action.
175- ' For an example of how to do this look at the URLPOLICY_JAVA above
176-
177- ' Permissions
178- Public Shared URLPOLICY_ALLOW As Byte = &H0
179- Public Shared URLPOLICY_QUERY As Byte = &H1
180- Public Shared URLPOLICY_DISALLOW As Byte = &H3
181-
182- ' Notifications are not done when user already queried.
183- Public Shared URLPOLICY_NOTIFY_ON_ALLOW As Integer = &H10
184- Public Shared URLPOLICY_NOTIFY_ON_DISALLOW As Integer = &H20
185-
186- ' Logging is done regardless of whether user was queried.
187- Public Shared URLPOLICY_LOG_ON_ALLOW As Integer = &H40
188- Public Shared URLPOLICY_LOG_ON_DISALLOW As Integer = &H80
189-
190- Public Shared URLPOLICY_MASK_PERMISSIONS As Integer = &HF
191-
192-
193- Public Shared URLPOLICY_DONTCHECKDLGBOX As Integer = &H100
194-
195-
196- ' ----------------------------------------------------------------------
197- ' ここ以下は COM Interface の宣言です。
198- Public Shared IID_IProfferService As Guid = New Guid("cb728b20-f786-11ce-92ad-00aa00a74cd0")
199- Public Shared SID_SProfferService As Guid = New Guid("cb728b20-f786-11ce-92ad-00aa00a74cd0")
200- Public Shared IID_IInternetSecurityManager As Guid = New Guid("79eac9ee-baf9-11ce-8c82-00aa004ba90b")
201-
202- <ComImport(), _
203- Guid("6d5140c1-7436-11ce-8034-00aa006009fa"), _
204- InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
205- Public Interface IServiceProvider
206- <PreserveSig()> _
207- Function QueryService(<[In]()> ByRef guidService As Guid, <[In]()> ByRef riid As Guid, <Out()> ByRef ppvObject As IntPtr) As Integer
208- End Interface
209-
210- <ComImport(), _
211- Guid("cb728b20-f786-11ce-92ad-00aa00a74cd0"), _
212- InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
213- Public Interface IProfferService
214- <PreserveSig()> _
215- Function ProfferService(<[In]()> ByRef guidService As Guid, <[In]()> ByVal psp As IServiceProvider, <Out()> ByRef cookie As Integer) As Integer
216-
217- <PreserveSig()> _
218- Function RevokeService(<[In]()> ByVal cookie As Integer) As Integer
219- End Interface
220-
221- <ComImport(), _
222- Guid("79eac9ed-baf9-11ce-8c82-00aa004ba90b"), _
223- InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
224- Public Interface IInternetSecurityMgrSite
225- <PreserveSig()> _
226- Function GetWindow(<[Out]()> ByRef hwnd As IntPtr) As Integer
227-
228- <PreserveSig()> _
229- Function EnableModeless(<[In](), MarshalAs(UnmanagedType.Bool)> ByVal fEnable As Boolean) As Integer
230- End Interface
231-
232- <ComImport(), _
233- Guid("79eac9ee-baf9-11ce-8c82-00aa004ba90b"), _
234- InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
235- Public Interface IInternetSecurityManager
236- <PreserveSig()> _
237- Function SetSecuritySite(<[In]()> ByVal pSite As IInternetSecurityMgrSite) As Integer
238-
239- <PreserveSig()> _
240- Function GetSecuritySite(<Out()> ByRef pSite As IInternetSecurityMgrSite) As Integer
241-
242- <PreserveSig()> _
243- Function MapUrlToZone(<[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal pwszUrl As String, <Out()> ByRef pdwZone As Integer, ByVal dwFlags As Integer) As Integer
244-
245- <PreserveSig()> _
246- Function GetSecurityId(<MarshalAs(UnmanagedType.LPWStr)> ByVal pwszUrl As String, <MarshalAs(UnmanagedType.LPArray)> ByVal pbSecurityId As Byte(), ByRef pcbSecurityId As UInt32, ByVal dwReserved As UInt32) As Integer
247-
248- <PreserveSig()> _
249- Function ProcessUrlAction(<[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal pwszUrl As String, ByVal dwAction As Integer, <Out()> ByRef pPolicy As Byte, ByVal cbPolicy As Integer, ByVal pContext As Byte, ByVal cbContext As Integer, ByVal dwFlags As Integer, ByVal dwReserved As Integer) As Integer
250-
251- <PreserveSig()> _
252- Function QueryCustomPolicy(<[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal pwszUrl As String, ByRef guidKey As Guid, ByVal ppPolicy As Byte, ByVal pcbPolicy As Integer, ByVal pContext As Byte, ByVal cbContext As Integer, ByVal dwReserved As Integer) As Integer
253-
254- <PreserveSig()> _
255- Function SetZoneMapping(ByVal dwZone As Integer, <[In](), MarshalAs(UnmanagedType.LPWStr)> ByVal lpszPattern As String, ByVal dwFlags As Integer) As Integer
256-
257- <PreserveSig()> _
258- Function GetZoneMappings(ByVal dwZone As Integer, ByRef ppenumString As ComTypes.IEnumString, ByVal dwFlags As Integer) As Integer
259- End Interface
260- End Class
261-#End Region
262-
263- <Flags()> Public Enum POLICY As Integer
264- ALLOW_ACTIVEX = &H1
265- ALLOW_SCRIPT = &H2
266- End Enum
267-
268- Private ocx As New Object
269- Private ocxServiceProvider As WebBrowserAPI.IServiceProvider
270- Private profferServicePtr As New IntPtr
271- Private profferService As WebBrowserAPI.IProfferService
272-
273- Private _Policy As POLICY = 0 ' DefaultですべてDisAllow
274-
275- Public Sub New(ByVal _WebBrowser As System.Windows.Forms.WebBrowser)
276- ' ActiveXコントロール取得
277- _WebBrowser.DocumentText = "about:blank" 'ActiveXを初期化する
278- Dim hresult As Integer = 0
279-
280- Do
281- Thread.Sleep(100)
282- Application.DoEvents()
283- Loop Until _WebBrowser.ReadyState = WebBrowserReadyState.Complete
284-
285- ocx = _WebBrowser.ActiveXInstance
286-
287- ' IServiceProvider.QueryService() を使って IProfferService を取得
288- ocxServiceProvider = DirectCast(ocx, WebBrowserAPI.IServiceProvider)
289-
290- Try
291- hresult = ocxServiceProvider.QueryService( _
292- WebBrowserAPI.SID_SProfferService, _
293- WebBrowserAPI.IID_IProfferService, profferServicePtr)
294- Catch ex As SEHException
295- Catch ex As ExternalException
296- TraceOut(ex, "ocxServiceProvider.QueryService() HRESULT:" + ex.ErrorCode.ToString("X8") + Environment.NewLine)
297- Exit Sub
298- End Try
299-
300-
301- profferService = DirectCast(Marshal.GetObjectForIUnknown(profferServicePtr), _
302- WebBrowserAPI.IProfferService)
303-
304- ' IProfferService.ProfferService() を使って
305- ' 自分を IInternetSecurityManager として提供
306- Try
307- hresult = profferService.ProfferService( _
308- WebBrowserAPI.IID_IInternetSecurityManager, Me, cookie:=0)
309- Catch ex As SEHException
310- Catch ex As ExternalException
311- TraceOut(ex, "IProfferSerive.ProfferService() HRESULT:" + ex.ErrorCode.ToString("X8") + Environment.NewLine)
312- Exit Sub
313- End Try
314-
315- End Sub
316-
317- Private Function QueryService(ByRef guidService As System.Guid, _
318- ByRef riid As System.Guid, ByRef ppvObject As System.IntPtr) _
319- As Integer Implements WebBrowserAPI.IServiceProvider.QueryService
320-
321- ppvObject = IntPtr.Zero
322- If guidService.CompareTo( _
323- WebBrowserAPI.IID_IInternetSecurityManager) = 0 Then
324- ' 自分から IID_IInternetSecurityManager を
325- ' QueryInterface して返す
326- Dim punk As IntPtr = Marshal.GetIUnknownForObject(Me)
327- Return Marshal.QueryInterface(punk, riid, ppvObject)
328- End If
329- Return HRESULT.E_NOINTERFACE
330- End Function
331-
332- Private Function GetSecurityId(ByVal pwszUrl As String, ByVal pbSecurityId() As Byte, ByRef pcbSecurityId As UInteger, ByVal dwReserved As UInteger) As Integer _
333- Implements WebBrowserAPI.IInternetSecurityManager.GetSecurityId
334- Return WebBrowserAPI.INET_E_DEFAULT_ACTION
335- End Function
336-
337- Private Function GetSecuritySite(ByRef pSite As WebBrowserAPI.IInternetSecurityMgrSite) As Integer _
338- Implements WebBrowserAPI.IInternetSecurityManager.GetSecuritySite
339- Return WebBrowserAPI.INET_E_DEFAULT_ACTION
340- End Function
341-
342- Private Function GetZoneMappings(ByVal dwZone As Integer, ByRef ppenumString As System.Runtime.InteropServices.ComTypes.IEnumString, ByVal dwFlags As Integer) As Integer _
343- Implements WebBrowserAPI.IInternetSecurityManager.GetZoneMappings
344- ppenumString = Nothing
345- Return WebBrowserAPI.INET_E_DEFAULT_ACTION
346- End Function
347-
348- Private Function MapUrlToZone(ByVal pwszUrl As String, ByRef pdwZone As Integer, ByVal dwFlags As Integer) As Integer _
349- Implements WebBrowserAPI.IInternetSecurityManager.MapUrlToZone
350- pdwZone = 0
351- If pwszUrl = "about:blank" Then Return WebBrowserAPI.INET_E_DEFAULT_ACTION
352- Try
353- Dim urlStr As String = IDNDecode(pwszUrl)
354- If urlStr Is Nothing Then Return WebBrowserAPI.URLPOLICY_DISALLOW
355- Dim url As New Uri(urlStr)
356- If url.Scheme = "data" Then
357- Return WebBrowserAPI.URLPOLICY_DISALLOW
358- End If
359- Catch ex As Exception
360- Return WebBrowserAPI.URLPOLICY_DISALLOW
361- End Try
362- Return WebBrowserAPI.INET_E_DEFAULT_ACTION
363- End Function
364-
365- Private Function ProcessUrlAction(ByVal pwszUrl As String, ByVal dwAction As Integer, ByRef pPolicy As Byte, ByVal cbPolicy As Integer, ByVal pContext As Byte, ByVal cbContext As Integer, ByVal dwFlags As Integer, ByVal dwReserved As Integer) As Integer _
366- Implements WebBrowserAPI.IInternetSecurityManager.ProcessUrlAction
367- 'スクリプト実行状態かを検査しポリシー設定
368- If WebBrowserAPI.URLACTION_SCRIPT_MIN <= dwAction And _
369- dwAction <= WebBrowserAPI.URLACTION_SCRIPT_MAX Then
370- ' スクリプト実行状態
371- If (_Policy And POLICY.ALLOW_SCRIPT) = POLICY.ALLOW_SCRIPT Then
372- pPolicy = WebBrowserAPI.URLPOLICY_ALLOW
373- Else
374- pPolicy = WebBrowserAPI.URLPOLICY_DISALLOW
375- End If
376- If Regex.IsMatch(pwszUrl, "^https?://((api\.)?twitter\.com/|([a-zA-Z0-9]+\.)?twimg\.com/|ssl\.google-analytics\.com/)") Then pPolicy = WebBrowserAPI.URLPOLICY_ALLOW
377- Return HRESULT.S_OK
378- End If
379- ' ActiveX実行状態かを検査しポリシー設定
380- If WebBrowserAPI.URLACTION_ACTIVEX_MIN <= dwAction And _
381- dwAction <= WebBrowserAPI.URLACTION_ACTIVEX_MAX Then
382- ' ActiveX実行状態
383- If (_Policy And POLICY.ALLOW_ACTIVEX) = POLICY.ALLOW_ACTIVEX Then
384- pPolicy = WebBrowserAPI.URLPOLICY_ALLOW
385- Else
386- pPolicy = WebBrowserAPI.URLPOLICY_DISALLOW
387- End If
388- Return HRESULT.S_OK
389- End If
390- '他のものについてはデフォルト処理
391- Return WebBrowserAPI.INET_E_DEFAULT_ACTION
392- End Function
393-
394- Private Function QueryCustomPolicy(ByVal pwszUrl As String, ByRef guidKey As System.Guid, ByVal ppPolicy As Byte, ByVal pcbPolicy As Integer, ByVal pContext As Byte, ByVal cbContext As Integer, ByVal dwReserved As Integer) As Integer _
395- Implements WebBrowserAPI.IInternetSecurityManager.QueryCustomPolicy
396- Return WebBrowserAPI.INET_E_DEFAULT_ACTION
397- End Function
398-
399- Private Function SetSecuritySite(ByVal pSite As WebBrowserAPI.IInternetSecurityMgrSite) As Integer _
400- Implements WebBrowserAPI.IInternetSecurityManager.SetSecuritySite
401- Return WebBrowserAPI.INET_E_DEFAULT_ACTION
402- End Function
403-
404- Private Function SetZoneMapping(ByVal dwZone As Integer, ByVal lpszPattern As String, ByVal dwFlags As Integer) As Integer _
405- Implements WebBrowserAPI.IInternetSecurityManager.SetZoneMapping
406- Return WebBrowserAPI.INET_E_DEFAULT_ACTION
407- End Function
408-
409-
410- Public Property SecurityPolicy() As POLICY
411- Get
412- Return _Policy
413- End Get
414- Set(ByVal value As POLICY)
415- _Policy = value
416- End Set
417- End Property
418-
419-End Class
\ No newline at end of file
--- a/TweenCS/TweenCS.csproj
+++ b/TweenCS/TweenCS.csproj
@@ -60,6 +60,7 @@
6060 <Compile Include="TweenAboutBox.Designer.cs">
6161 <DependentUpon>TweenAboutBox.cs</DependentUpon>
6262 </Compile>
63+ <Compile Include="WebBrowserController.cs" />
6364 <Compile Include="Win32Api.cs" />
6465 </ItemGroup>
6566 <ItemGroup>
@@ -106,7 +107,7 @@
106107 <Content Include="Resources\S9.ico" />
107108 </ItemGroup>
108109 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
109- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
110+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
110111 Other similar extension points exist, see Microsoft.Common.targets.
111112 <Target Name="BeforeBuild">
112113 </Target>
--- /dev/null
+++ b/TweenCS/WebBrowserController.cs
@@ -0,0 +1,469 @@
1+// Tween - Client of Twitter
2+// Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3+// (c) 2008-2011 Moz (@syo68k)
4+// (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5+// (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6+// (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7+// (c) 2011 Egtra (@egtra) <http://dev.activebasic.com/egtra/>
8+// All rights reserved.
9+//
10+// This file is part of Tween.
11+//
12+// This program is free software; you can redistribute it and/or modify it
13+// under the terms of the GNU General Public License as published by the Free
14+// Software Foundation; either version 3 of the License, or (at your option)
15+// any later version.
16+//
17+// This program is distributed in the hope that it will be useful, but
18+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20+// for more details.
21+//
22+// You should have received a copy of the GNU General Public License along
23+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25+// Boston, MA 02110-1301, USA.
26+
27+using System;
28+using System.Collections.Generic;
29+using System.Linq;
30+using System.Text;
31+using System.Runtime.InteropServices;
32+using System.Threading;
33+using System.Text.RegularExpressions;
34+using System.Runtime.InteropServices.ComTypes;
35+using System.Windows.Forms;
36+
37+namespace Tween
38+{
39+ #region "WebBrowserAPI"
40+ internal class WebBrowserAPI
41+ {
42+ public static int INET_E_DEFAULT_ACTION = unchecked((int)0x800C0011);
43+
44+ public enum URLZONE
45+ {
46+ URLZONE_LOCAL_MACHINE = 0,
47+ URLZONE_INTRANET = URLZONE_LOCAL_MACHINE + 1,
48+ URLZONE_TRUSTED = URLZONE_INTRANET + 1,
49+ URLZONE_INTERNET = URLZONE_TRUSTED + 1,
50+ URLZONE_UNTRUSTED = URLZONE_INTERNET + 1,
51+ }
52+
53+ public static int URLACTION_MIN = 0x1000;
54+
55+ public static int URLACTION_DOWNLOAD_MIN = 0x1000;
56+ public static int URLACTION_DOWNLOAD_SIGNED_ACTIVEX = 0x1001;
57+ public static int URLACTION_DOWNLOAD_UNSIGNED_ACTIVEX = 0x1004;
58+ public static int URLACTION_DOWNLOAD_CURR_MAX = 0x1004;
59+ public static int URLACTION_DOWNLOAD_MAX = 0x11FF;
60+
61+ public static int URLACTION_ACTIVEX_MIN = 0x1200;
62+ public static int URLACTION_ACTIVEX_RUN = 0x1200;
63+ public static int URLPOLICY_ACTIVEX_CHECK_LIST = 0x10000;
64+ public static int URLACTION_ACTIVEX_OVERRIDE_OBJECT_SAFETY = 0x1201;
65+ public static int URLACTION_ACTIVEX_OVERRIDE_DATA_SAFETY = 0x1202;
66+ public static int URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY = 0x1203;
67+ public static int URLACTION_SCRIPT_OVERRIDE_SAFETY = 0x1401;
68+ public static int URLACTION_ACTIVEX_CONFIRM_NOOBJECTSAFETY = 0x1204;
69+ public static int URLACTION_ACTIVEX_TREATASUNTRUSTED = 0x1205;
70+ public static int URLACTION_ACTIVEX_NO_WEBOC_SCRIPT = 0x1206;
71+ public static int URLACTION_ACTIVEX_CURR_MAX = 0x1206;
72+ public static int URLACTION_ACTIVEX_MAX = 0x13FF;
73+
74+ public static int URLACTION_SCRIPT_MIN = 0x1400;
75+ public static int URLACTION_SCRIPT_RUN = 0x1400;
76+ public static int URLACTION_SCRIPT_JAVA_USE = 0x1402;
77+ public static int URLACTION_SCRIPT_SAFE_ACTIVEX = 0x1405;
78+ public static int URLACTION_CROSS_DOMAIN_DATA = 0x1406;
79+ public static int URLACTION_SCRIPT_PASTE = 0x1407;
80+ public static int URLACTION_SCRIPT_CURR_MAX = 0x1407;
81+ public static int URLACTION_SCRIPT_MAX = 0x15FF;
82+
83+ public static int URLACTION_HTML_MIN = 0x1600;
84+ public static int URLACTION_HTML_SUBMIT_FORMS = 0x1601; // aggregate next two
85+ public static int URLACTION_HTML_SUBMIT_FORMS_FROM = 0x1602; //
86+ public static int URLACTION_HTML_SUBMIT_FORMS_TO = 0x1603; //
87+ public static int URLACTION_HTML_FONT_DOWNLOAD = 0x1604;
88+ public static int URLACTION_HTML_JAVA_RUN = 0x1605; // derive from Java custom policy
89+ public static int URLACTION_HTML_USERDATA_SAVE = 0x1606;
90+ public static int URLACTION_HTML_SUBFRAME_NAVIGATE = 0x1607;
91+ public static int URLACTION_HTML_META_REFRESH = 0x1608;
92+ public static int URLACTION_HTML_MIXED_CONTENT = 0x1609;
93+ public static int URLACTION_HTML_MAX = 0x17FF;
94+
95+ public static int URLACTION_SHELL_MIN = 0x1800;
96+ public static int URLACTION_SHELL_INSTALL_DTITEMS = 0x1800;
97+ public static int URLACTION_SHELL_MOVE_OR_COPY = 0x1802;
98+ public static int URLACTION_SHELL_FILE_DOWNLOAD = 0x1803;
99+ public static int URLACTION_SHELL_VERB = 0x1804;
100+ public static int URLACTION_SHELL_WEBVIEW_VERB = 0x1805;
101+ public static int URLACTION_SHELL_SHELLEXECUTE = 0x1806;
102+ public static int URLACTION_SHELL_CURR_MAX = 0x1806;
103+ public static int URLACTION_SHELL_MAX = 0x19FF;
104+
105+ public static int URLACTION_NETWORK_MIN = 0x1A00;
106+
107+ public static int URLACTION_CREDENTIALS_USE = 0x1A00;
108+ public static int URLPOLICY_CREDENTIALS_SILENT_LOGON_OK = 0x0;
109+ public static int URLPOLICY_CREDENTIALS_MUST_PROMPT_USER = 0x10000;
110+ public static int URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT = 0x20000;
111+ public static int URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY = 0x30000;
112+
113+ public static int URLACTION_AUTHENTICATE_CLIENT = 0x1A01;
114+ public static int URLPOLICY_AUTHENTICATE_CLEARTEXT_OK = 0x0;
115+ public static int URLPOLICY_AUTHENTICATE_CHALLENGE_RESPONSE = 0x10000;
116+ public static int URLPOLICY_AUTHENTICATE_MUTUAL_ONLY = 0x30000;
117+
118+
119+ public static int URLACTION_COOKIES = 0x1A02;
120+ public static int URLACTION_COOKIES_SESSION = 0x1A03;
121+
122+ public static int URLACTION_CLIENT_CERT_PROMPT = 0x1A04;
123+
124+ public static int URLACTION_COOKIES_THIRD_PARTY = 0x1A05;
125+ public static int URLACTION_COOKIES_SESSION_THIRD_PARTY = 0x1A06;
126+
127+ public static int URLACTION_COOKIES_ENABLED = 0x1A10;
128+
129+ public static int URLACTION_NETWORK_CURR_MAX = 0x1A10;
130+ public static int URLACTION_NETWORK_MAX = 0x1BFF;
131+
132+
133+ public static int URLACTION_JAVA_MIN = 0x1C00;
134+ public static int URLACTION_JAVA_PERMISSIONS = 0x1C00;
135+ public static int URLPOLICY_JAVA_PROHIBIT = 0x0;
136+ public static int URLPOLICY_JAVA_HIGH = 0x10000;
137+ public static int URLPOLICY_JAVA_MEDIUM = 0x20000;
138+ public static int URLPOLICY_JAVA_LOW = 0x30000;
139+ public static int URLPOLICY_JAVA_CUSTOM = 0x800000;
140+ public static int URLACTION_JAVA_CURR_MAX = 0x1C00;
141+ public static int URLACTION_JAVA_MAX = 0x1CFF;
142+
143+
144+ // The following Infodelivery actions should have no default policies
145+ // in the registry. They assume that no default policy means fall
146+ // back to the global restriction. If an admin sets a policy per
147+ // zone, then it overrides the global restriction.
148+
149+ public static int URLACTION_INFODELIVERY_MIN = 0x1D00;
150+ public static int URLACTION_INFODELIVERY_NO_ADDING_CHANNELS = 0x1D00;
151+ public static int URLACTION_INFODELIVERY_NO_EDITING_CHANNELS = 0x1D01;
152+ public static int URLACTION_INFODELIVERY_NO_REMOVING_CHANNELS = 0x1D02;
153+ public static int URLACTION_INFODELIVERY_NO_ADDING_SUBSCRIPTIONS = 0x1D03;
154+ public static int URLACTION_INFODELIVERY_NO_EDITING_SUBSCRIPTIONS = 0x1D04;
155+ public static int URLACTION_INFODELIVERY_NO_REMOVING_SUBSCRIPTIONS = 0x1D05;
156+ public static int URLACTION_INFODELIVERY_NO_CHANNEL_LOGGING = 0x1D06;
157+ public static int URLACTION_INFODELIVERY_CURR_MAX = 0x1D06;
158+ public static int URLACTION_INFODELIVERY_MAX = 0x1DFF;
159+ public static int URLACTION_CHANNEL_SOFTDIST_MIN = 0x1E00;
160+ public static int URLACTION_CHANNEL_SOFTDIST_PERMISSIONS = 0x1E05;
161+ public static int URLPOLICY_CHANNEL_SOFTDIST_PROHIBIT = 0x10000;
162+ public static int URLPOLICY_CHANNEL_SOFTDIST_PRECACHE = 0x20000;
163+ public static int URLPOLICY_CHANNEL_SOFTDIST_AUTOINSTALL = 0x30000;
164+ public static int URLACTION_CHANNEL_SOFTDIST_MAX = 0x1EFF;
165+
166+ // For each action specified above the system maintains
167+ // a set of policies for the action.
168+ // The only policies supported currently are permissions (i.e. is something allowed)
169+ // and logging status.
170+ // IMPORTANT: If you are defining your own policies don//t overload the meaning of the
171+ // loword of the policy. You can use the hiword to store any policy bits which are only
172+ // meaningful to your action.
173+ // For an example of how to do this look at the URLPOLICY_JAVA above
174+
175+ // Permissions
176+ public static byte URLPOLICY_ALLOW = 0x0;
177+ public static byte URLPOLICY_QUERY = 0x1;
178+ public static byte URLPOLICY_DISALLOW = 0x3;
179+
180+ // Notifications are not done when user already queried.
181+ public static int URLPOLICY_NOTIFY_ON_ALLOW = 0x10;
182+ public static int URLPOLICY_NOTIFY_ON_DISALLOW = 0x20;
183+
184+ // Logging is done regardless of whether user was queried.
185+ public static int URLPOLICY_LOG_ON_ALLOW = 0x40;
186+ public static int URLPOLICY_LOG_ON_DISALLOW = 0x80;
187+
188+ public static int URLPOLICY_MASK_PERMISSIONS = 0xF;
189+
190+
191+ public static int URLPOLICY_DONTCHECKDLGBOX = 0x100;
192+
193+
194+ // ----------------------------------------------------------------------
195+ // ここ以下は COM Interface の宣言です。
196+ public static Guid IID_IProfferService = new Guid("cb728b20-f786-11ce-92ad-00aa00a74cd0");
197+ public static Guid SID_SProfferService = new Guid("cb728b20-f786-11ce-92ad-00aa00a74cd0");
198+ public static Guid IID_IInternetSecurityManager = new Guid("79eac9ee-baf9-11ce-8c82-00aa004ba90b");
199+
200+ [ComImport,
201+ Guid("6d5140c1-7436-11ce-8034-00aa006009fa"),
202+ InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
203+ public interface IServiceProvider
204+ {
205+ [PreserveSig]
206+ int QueryService([In] ref Guid guidService, [In] ref Guid riid, out IntPtr ppvObject);
207+ }
208+
209+ [ComImport,
210+ Guid("cb728b20-f786-11ce-92ad-00aa00a74cd0"),
211+ InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
212+ public interface IProfferService
213+ {
214+ [PreserveSig]
215+ int ProfferService([In] ref Guid guidService, [In] IServiceProvider psp, out int cookie);
216+
217+ [PreserveSig]
218+ int RevokeService([In] int cookie);
219+ }
220+
221+ [ComImport,
222+ Guid("79eac9ed-baf9-11ce-8c82-00aa004ba90b"),
223+ InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
224+ public interface IInternetSecurityMgrSite
225+ {
226+ [PreserveSig]
227+ int GetWindow(out IntPtr hwnd);
228+
229+ [PreserveSig]
230+ int EnableModeless([In, MarshalAs(UnmanagedType.Bool)] bool fEnable);
231+ }
232+
233+ [ComImport,
234+ Guid("79eac9ee-baf9-11ce-8c82-00aa004ba90b"),
235+ InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
236+ public interface IInternetSecurityManager
237+ {
238+ [PreserveSig]
239+ int SetSecuritySite([In] IInternetSecurityMgrSite pSite);
240+
241+ [PreserveSig]
242+ int GetSecuritySite(out IInternetSecurityMgrSite pSite);
243+
244+ [PreserveSig]
245+ int MapUrlToZone([In, MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, out int pdwZone, int dwFlags);
246+
247+ [PreserveSig]
248+ int GetSecurityId([MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, [MarshalAs(UnmanagedType.LPArray)] byte[] pbSecurityId, ref UInt32 pcbSecurityId, UInt32 dwReserved);
249+
250+ [PreserveSig]
251+ int ProcessUrlAction([In, MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, int dwAction, out byte pPolicy, int cbPolicy, byte pContext, int cbContext, int dwFlags, int dwReserved);
252+
253+ [PreserveSig]
254+ int QueryCustomPolicy([In, MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, ref Guid guidKey, byte ppPolicy, int pcbPolicy, byte pContext, int cbContext, int dwReserved);
255+
256+ [PreserveSig]
257+ int SetZoneMapping(int dwZone, [In, MarshalAs(UnmanagedType.LPWStr)] string lpszPattern, int dwFlags);
258+
259+ [PreserveSig]
260+ int GetZoneMappings(int dwZone, ref IEnumString ppenumstring, int dwFlags);
261+ }
262+ }
263+ #endregion
264+
265+ public class InternetSecurityManager : WebBrowserAPI.IServiceProvider, WebBrowserAPI.IInternetSecurityManager
266+ {
267+ #region "HRESULT"
268+ private class HRESULT
269+ {
270+ public static int S_OK = 0x0;
271+ public static int S_FALSE = 0x1;
272+ public static int E_NOTIMPL = unchecked((int)0x80004001);
273+ public static int E_NOINTERFACE = unchecked((int)0x80004002);
274+ }
275+ #endregion
276+
277+ [Flags] public enum POLICY : int
278+ {
279+ ALLOW_ACTIVEX = 0x1,
280+ ALLOW_SCRIPT = 0x2,
281+ }
282+
283+ private object ocx = new object();
284+ private WebBrowserAPI.IServiceProvider ocxServiceProvider;
285+ private IntPtr profferServicePtr = new IntPtr();
286+ private WebBrowserAPI.IProfferService profferService;
287+
288+ private POLICY _Policy = 0; // DefaultですべてDisAllow
289+
290+ public InternetSecurityManager(WebBrowser _WebBrowser)
291+ {
292+ // ActiveXコントロール取得
293+ _WebBrowser.DocumentText = "about:blank"; //ActiveXを初期化する
294+ int hresult = 0;
295+
296+ do
297+ {
298+ Thread.Sleep(100);
299+ Application.DoEvents();
300+ } while (_WebBrowser.ReadyState != WebBrowserReadyState.Complete);
301+
302+ ocx = _WebBrowser.ActiveXInstance;
303+
304+ // IServiceProvider.QueryService() を使って IProfferService を取得
305+ ocxServiceProvider = (WebBrowserAPI.IServiceProvider)ocx;
306+
307+ try
308+ {
309+ hresult = ocxServiceProvider.QueryService(
310+ ref WebBrowserAPI.SID_SProfferService,
311+ ref WebBrowserAPI.IID_IProfferService, out profferServicePtr);
312+ }
313+ catch (SEHException ex)
314+ {
315+ MyCommon.TraceOut(ex, "ocxServiceProvider.QueryService() HRESULT:" + ex.ErrorCode.ToString("X8") + Environment.NewLine);
316+ return;
317+ }
318+ catch (ExternalException ex)
319+ {
320+ MyCommon.TraceOut(ex, "ocxServiceProvider.QueryService() HRESULT:" + ex.ErrorCode.ToString("X8") + Environment.NewLine);
321+ return;
322+ }
323+
324+
325+ profferService = (WebBrowserAPI.IProfferService)Marshal.GetObjectForIUnknown(profferServicePtr);
326+
327+ // IProfferService.ProfferService() を使って
328+ // 自分を IInternetSecurityManager として提供
329+ try
330+ {
331+ int cookie = 0;
332+ hresult = profferService.ProfferService(
333+ ref WebBrowserAPI.IID_IInternetSecurityManager, this, out cookie);
334+ }
335+ catch (SEHException ex)
336+ {
337+ MyCommon.TraceOut(ex, "IProfferSerive.ProfferService() HRESULT:" + ex.ErrorCode.ToString("X8") + Environment.NewLine);
338+ return;
339+ }
340+ catch (ExternalException ex)
341+ {
342+ MyCommon.TraceOut(ex, "IProfferSerive.ProfferService() HRESULT:" + ex.ErrorCode.ToString("X8") + Environment.NewLine);
343+ return;
344+ }
345+ }
346+
347+ int WebBrowserAPI.IServiceProvider.QueryService(ref Guid guidService,
348+ ref Guid riid, out IntPtr ppvObject)
349+ {
350+
351+ ppvObject = IntPtr.Zero;
352+ if (guidService.CompareTo(
353+ WebBrowserAPI.IID_IInternetSecurityManager) == 0)
354+ {
355+ // 自分から IID_IInternetSecurityManager を
356+ // QueryInterface して返す
357+ var punk = Marshal.GetIUnknownForObject(this);
358+ return Marshal.QueryInterface(punk, ref riid, out ppvObject);
359+ }
360+ return HRESULT.E_NOINTERFACE;
361+ }
362+
363+ int WebBrowserAPI.IInternetSecurityManager.GetSecurityId(string pwszUrl, byte[] pbSecurityId, ref uint pcbSecurityId, uint dwReserved)
364+ {
365+ return WebBrowserAPI.INET_E_DEFAULT_ACTION;
366+ }
367+
368+ int WebBrowserAPI.IInternetSecurityManager.GetSecuritySite(out WebBrowserAPI.IInternetSecurityMgrSite pSite)
369+ {
370+ pSite = null;
371+ return WebBrowserAPI.INET_E_DEFAULT_ACTION;
372+ }
373+
374+ int WebBrowserAPI.IInternetSecurityManager.GetZoneMappings(int dwZone, ref IEnumString ppenumstring, int dwFlags)
375+ {
376+ ppenumstring = null;
377+ return WebBrowserAPI.INET_E_DEFAULT_ACTION;
378+ }
379+
380+ int WebBrowserAPI.IInternetSecurityManager.MapUrlToZone(string pwszUrl, out int pdwZone, int dwFlags)
381+ {
382+ pdwZone = 0;
383+ if (pwszUrl == "about:blank") return WebBrowserAPI.INET_E_DEFAULT_ACTION;
384+ try
385+ {
386+ var urlStr = MyCommon.IDNDecode(pwszUrl);
387+ if (object.ReferenceEquals(urlStr, null)) return WebBrowserAPI.URLPOLICY_DISALLOW;
388+ var url = new Uri(urlStr);
389+ if (url.Scheme == "data")
390+ {
391+ return WebBrowserAPI.URLPOLICY_DISALLOW;
392+ }
393+ }
394+ catch (Exception)
395+ {
396+ return WebBrowserAPI.URLPOLICY_DISALLOW;
397+ }
398+ return WebBrowserAPI.INET_E_DEFAULT_ACTION;
399+ }
400+
401+ const byte URLPOLICY_ALLOW = 0;
402+
403+ int WebBrowserAPI.IInternetSecurityManager.ProcessUrlAction(string pwszUrl, int dwAction, out byte pPolicy, int cbPolicy, byte pContext, int cbContext, int dwFlags, int dwReserved)
404+ {
405+ pPolicy = URLPOLICY_ALLOW;
406+ //スクリプト実行状態かを検査しポリシー設定
407+ if (WebBrowserAPI.URLACTION_SCRIPT_MIN <= dwAction &
408+ dwAction <= WebBrowserAPI.URLACTION_SCRIPT_MAX)
409+ {
410+ // スクリプト実行状態
411+ if ((_Policy & POLICY.ALLOW_SCRIPT) == POLICY.ALLOW_SCRIPT)
412+ {
413+ pPolicy = WebBrowserAPI.URLPOLICY_ALLOW;
414+ }
415+ else
416+ {
417+ pPolicy = WebBrowserAPI.URLPOLICY_DISALLOW;
418+ }
419+ if (Regex.IsMatch(pwszUrl, @"^https?://((api\.)?twitter\.com/|([a-zA-Z0-9]+\.)?twimg\.com/|ssl\.google-analytics\.com/)")) pPolicy = WebBrowserAPI.URLPOLICY_ALLOW;
420+ return HRESULT.S_OK;
421+ }
422+ // ActiveX実行状態かを検査しポリシー設定
423+ if (WebBrowserAPI.URLACTION_ACTIVEX_MIN <= dwAction &
424+ dwAction <= WebBrowserAPI.URLACTION_ACTIVEX_MAX)
425+ {
426+ // ActiveX実行状態
427+ if ((_Policy & POLICY.ALLOW_ACTIVEX) == POLICY.ALLOW_ACTIVEX)
428+ {
429+ pPolicy = WebBrowserAPI.URLPOLICY_ALLOW;
430+ }
431+ else
432+ {
433+ pPolicy = WebBrowserAPI.URLPOLICY_DISALLOW;
434+ }
435+ return HRESULT.S_OK;
436+ }
437+ //他のものについてはデフォルト処理
438+ return WebBrowserAPI.INET_E_DEFAULT_ACTION;
439+ }
440+
441+ int WebBrowserAPI.IInternetSecurityManager.QueryCustomPolicy(string pwszUrl, ref Guid guidKey, byte ppPolicy, int pcbPolicy, byte pContext, int cbContext, int dwReserved)
442+ {
443+ return WebBrowserAPI.INET_E_DEFAULT_ACTION;
444+ }
445+
446+ int WebBrowserAPI.IInternetSecurityManager.SetSecuritySite(WebBrowserAPI.IInternetSecurityMgrSite pSite)
447+ {
448+ return WebBrowserAPI.INET_E_DEFAULT_ACTION;
449+ }
450+
451+ int WebBrowserAPI.IInternetSecurityManager.SetZoneMapping(int dwZone, string lpszPattern, int dwFlags)
452+ {
453+ return WebBrowserAPI.INET_E_DEFAULT_ACTION;
454+ }
455+
456+
457+ public POLICY SecurityPolicy
458+ {
459+ get
460+ {
461+ return _Policy;
462+ }
463+ set
464+ {
465+ _Policy = value;
466+ }
467+ }
468+ }
469+}