INavigationInterceptorAddRule Method (NavigationFilterRule)Awesomium.NET 1.7.6Awesomium.NET
Adds a navigation filtering rule for navigations to resources that match the specified Filter.

Namespace: Awesomium.Core
Assembly: Awesomium.Core (in Awesomium.Core.dll) Version: 1.7.6.0
Syntax

CollectionChangeAction AddRule(
	NavigationFilterRule filterRule
)

Parameters

filterRule
Type: Awesomium.CoreNavigationFilterRule
A NavigationFilterRule representing the rule to apply to a filtering pattern.

Return Value

Type: CollectionChangeAction
A CollectionChangeAction value indicating if the rule was added, replaced existing rules or ignored.

The following table explains the possible return values:

Return Value Description
Add The rule was successfully added.
Refresh The rule was added, replacing older narrowing rules.
Remove The rule was ignored. A widening rule already exists.
Remarks

This method can simply add a rule, replace older rules or be ignored. For a demonstration, see the Examples section.

Depending on the Filter specified in filterRule, added rules can be accessed through the Whitelist and Blacklist properties.

Examples

This example demonstrates adding navigation rules to a INavigationInterceptor.
private void webView_NativeViewInitialized( object sender, WebViewEventArgs e )
{
    INavigationInterceptor navigationInterceptor = webView.GetService( typeof( INavigationInterceptor ) ) as INavigationInterceptor;

     if ( navigationInterceptor == null )
         return;

    CollectionChangeAction res;

    // 1.
    // This call will successfully add a Deny rule for the specified URL pattern.
    res = navigationInterceptor.AddRule( @"http?://*.somedomain.info/*", NavigationRule.Deny );
    Debug.Print( res.ToString() );

    // 2.
    // This call will be ignored, as it attempts to narrow an already wider rule (1).
    res = navigationInterceptor.AddRule( @"http?://*admin.somedomain.info/*", NavigationRule.Deny );
    Debug.Print( res.ToString() );

    // 3.
    // This call will replace the first (1) rule.
    res = navigationInterceptor.AddRule( @"http?://*domain.info/*", NavigationRule.Deny );
    Debug.Print( res.ToString() );

    // 4.
    // This call will successfully add an Allow rule for the specified URL pattern.
    // Although the pattern narrows the one specified in the third (3) call, this call is not 
    // ignored as it specifies an Allow (Whitelist) rule.
    res = navigationInterceptor.AddRule( @"http?://*.somedomain.info/*", NavigationRule.Allow );
    Debug.Print( res.ToString() );

    // 5.
    // This call will replace everything added so far, including the third (3) rule.
    // Patterns must be unique irrespective of the rule applied. An Allow and Deny rule
    // cannot be applied to the same pattern. The last rule added, replaces an existing
    // rule with the same pattern.
    res = navigationInterceptor.AddRule( @"http?://*domain.info/*", NavigationRule.Allow );
    Debug.Print( res.ToString() );
}
Output:
            Add
            Remove
            Refresh
            Add
            Refresh
            
See Also

Reference