File tree Expand file tree Collapse file tree 4 files changed +39
-6
lines changed
AngleSharp.Scripting.JavaScript Expand file tree Collapse file tree 4 files changed +39
-6
lines changed Original file line number Diff line number Diff line change 69
69
<Compile Include =" Extensions.cs" />
70
70
<Compile Include =" JavaScriptEngine.cs" />
71
71
<Compile Include =" Properties\AssemblyInfo.cs" />
72
- <Compile Include =" ScriptingService.cs" />
72
+ <Compile Include =" Services\ScriptingService.cs" />
73
+ <Compile Include =" Services\NavigatorService.cs" />
73
74
<Compile Include =" SystemTypeConverter.cs" />
74
75
<Compile Include =" UnresolvedConverter.cs" />
75
76
</ItemGroup >
Original file line number Diff line number Diff line change 1
1
namespace AngleSharp
2
2
{
3
- using AngleSharp . Scripting . JavaScript ;
3
+ using AngleSharp . Scripting . JavaScript . Services ;
4
+ using AngleSharp . Services ;
4
5
using System . Linq ;
5
6
6
7
/// <summary>
@@ -10,7 +11,8 @@ public static class ConfigurationExtensions
10
11
{
11
12
/// <summary>
12
13
/// Sets scripting to true, registers the JavaScript engine and returns
13
- /// a new configuration with the scripting service.
14
+ /// a new configuration with the scripting service and possible
15
+ /// auxiliary services, if not yet registered.
14
16
/// </summary>
15
17
/// <param name="configuration">The configuration to use.</param>
16
18
/// <returns>The new configuration.</returns>
@@ -19,6 +21,13 @@ public static IConfiguration WithJavaScript(this IConfiguration configuration)
19
21
if ( ! configuration . Services . OfType < ScriptingService > ( ) . Any ( ) )
20
22
{
21
23
var service = new ScriptingService ( ) ;
24
+
25
+ if ( ! configuration . Services . OfType < INavigatorService > ( ) . Any ( ) )
26
+ {
27
+ var navigator = new NavigatorService ( ) ;
28
+ configuration = configuration . With ( navigator ) ;
29
+ }
30
+
22
31
return configuration . With ( service ) ;
23
32
}
24
33
Original file line number Diff line number Diff line change
1
+ namespace AngleSharp . Scripting . JavaScript . Services
2
+ {
3
+ using AngleSharp . Dom ;
4
+ using AngleSharp . Dom . Navigator ;
5
+ using AngleSharp . Scripting . JavaScript . Dom ;
6
+ using AngleSharp . Services ;
7
+
8
+ /// <summary>
9
+ /// Represents the service for a navigator.
10
+ /// </summary>
11
+ public class NavigatorService : INavigatorService
12
+ {
13
+ /// <summary>
14
+ /// Creates an INavigator object for the provided window.
15
+ /// </summary>
16
+ /// <param name="window">The window that needs an INavigator.</param>
17
+ /// <returns>The INavigator instance for the window.</returns>
18
+ public virtual INavigator Create ( IWindow window )
19
+ {
20
+ return new Navigator ( ) ;
21
+ }
22
+ }
23
+ }
Original file line number Diff line number Diff line change 1
- namespace AngleSharp . Scripting . JavaScript
1
+ namespace AngleSharp . Scripting . JavaScript . Services
2
2
{
3
3
using AngleSharp . Network ;
4
4
using AngleSharp . Services ;
8
8
/// <summary>
9
9
/// Represents the service for the JavaScript engine.
10
10
/// </summary>
11
- public sealed class ScriptingService : IScriptingService
11
+ public class ScriptingService : IScriptingService
12
12
{
13
13
readonly JavaScriptEngine _engine ;
14
14
@@ -33,7 +33,7 @@ public JavaScriptEngine Engine
33
33
/// </summary>
34
34
/// <param name="mimeType">The mime-type.</param>
35
35
/// <returns>The contained engine.</returns>
36
- public IScriptEngine GetEngine ( String mimeType )
36
+ public virtual IScriptEngine GetEngine ( String mimeType )
37
37
{
38
38
if ( MimeTypes . IsJavaScript ( mimeType ) )
39
39
return _engine ;
You can’t perform that action at this time.
0 commit comments