Bug 33180 - [Qt] Support private browsing mode in plugins
Summary: [Qt] Support private browsing mode in plugins
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Qt (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords: Qt
Depends on:
Blocks:
 
Reported: 2010-01-04 13:30 PST by Robert Hogan
Modified: 2010-03-10 12:59 PST (History)
7 users (show)

See Also:


Attachments
Patch (10.87 KB, patch)
2010-01-04 14:05 PST, Robert Hogan
hausmann: review-
Details | Formatted Diff | Diff
Updated Patch (10.74 KB, patch)
2010-01-26 14:13 PST, Robert Hogan
hausmann: review+
hausmann: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Hogan 2010-01-04 13:30:51 PST
Add support for NPNVprivateModeBool property in plugins.

See also: https://developer.mozilla.org/En/Supporting_private_browsing_in_plugins

The NPNVprivateModeBool property is supported as scriptable property privateBrowsingEnabled in the test WebKit plugin. The Mac platform also supports a cachedPrivateBrowsingEnabled
property implemented in the test plugin. This allows the Layout test plugins/private-browsing-mode.html to retrieve the previous value of NPNVprivateModeBool in the test plugin. Due to the platform-specific overhead required to support this bespoke property it is not implemented as part of this patch, instead a new test, plugins/private-browsing-mode-2.html, is added to ensure that setting and resetting privateBrowsingEnabled works as expected.
Comment 1 Robert Hogan 2010-01-04 14:05:01 PST
Created attachment 45828 [details]
Patch
Comment 2 WebKit Review Bot 2010-01-04 14:07:28 PST
style-queue ran check-webkit-style on attachment 45828 [details] without any errors.
Comment 3 Kenneth Rohde Christiansen 2010-01-18 12:32:42 PST
Comment on attachment 45828 [details]
Patch

LGTM, but it seems that something went wrong with GTK, please have a look at that.

Also, where is that successfullyParsed = true; used?
Comment 4 Simon Hausmann 2010-01-22 13:46:07 PST
Comment on attachment 45828 [details]
Patch

> --- a/LayoutTests/platform/gtk/Skipped
> +++ b/LayoutTests/platform/gtk/Skipped
> @@ -3651,6 +3651,11 @@ plugins/plugin-javascript-access.html
>  # https://bugs.webkit.org/show_bug.cgi?id=30561
>  plugins/private-browsing-mode.html
>  
> +# https://bugs.webkit.org/show_bug.cgi?id=30561
> +plugins/private-browsing-mode.html

It seems strange to see these two lines being added that exist alread three lines further up :)

> +# https://bugs.webkit.org/show_bug.cgi?id=33180
> +plugins/private-browsing-mode-2.html
> +
>  #   Tests generating new results
>  plugins/embed-attributes-style.html
>  plugins/netscape-dom-access.html


> +Tests that NPNVprivateModeBool is supported by the WebKit plugin view. This test is for WebKit platforms that wish to support NPNVprivateModeBool but do not wish to implement the preference change listener required to support a cachedPrivateBrowsingEnabled property similar to the one provided by Safari and tested for in private-browsing-mode.html

I don't understand this part. It seems trivial to implement in DumpRenderTree/unix/TestNetscapePlugin/TestNetscapePlugin.cpp. Why not do it there instead of this extra test?

In fact, it seems like a bug right now that the cachedPrivateBrowsingEnabled variable isn't initialized in that file, where as it is initialized in
TestNetscapePlugIn.subproj/main.cpp. Could that be why the test was failing for you?

> +
> +    case NPNVprivateModeBool: {
> +        Page* page = m_parentFrame->page();
> +        if (!page)
> +            return NPERR_GENERIC_ERROR;
> +         *((NPBool*)value) = (!page->settings() || page->settings()->privateBrowsingEnabled())? true : false;
> +         return NPERR_NO_ERROR;
> +    }

I would leave out the ? true : false; part and the extra parentheses, it's redundant.

Otherwise the patch looks great, and certainly long-hanging fruit for the other PluginView implementations, too.
Comment 5 Robert Hogan 2010-01-24 15:12:23 PST
> 
> > +Tests that NPNVprivateModeBool is supported by the WebKit plugin view. This test is for WebKit platforms that wish to support NPNVprivateModeBool but do not wish to implement the preference change listener required to support a cachedPrivateBrowsingEnabled property similar to the one provided by Safari and tested for in private-browsing-mode.html
> 
> I don't understand this part. It seems trivial to implement in
> DumpRenderTree/unix/TestNetscapePlugin/TestNetscapePlugin.cpp. Why not do it
> there instead of this extra test?
> 
> In fact, it seems like a bug right now that the cachedPrivateBrowsingEnabled
> variable isn't initialized in that file, where as it is initialized in
> TestNetscapePlugIn.subproj/main.cpp. Could that be why the test was failing for
> you?

The mac port listens for changes to the users webkit preferences and halts any netscape plugins currently running if pluginsEnabled has changed to false. Setting the 'cachedPrivateBrowsingMode' value rides on the coat-tails of this feature - which Qt doesn't have, and possibly should. I don't think it's trivial to implement though. So will leave it out of this patch if that's ok?
Comment 6 Robert Hogan 2010-01-26 14:13:38 PST
Created attachment 47448 [details]
Updated Patch

Fixed style issues. Simon - if you agree with my response to your comments this should be ok to r+. I could look at halting plugins when pluginsEnabled gets set to false separately - or maybe address that first and make it a blocker for this bug.
Comment 7 Simon Hausmann 2010-01-27 14:54:40 PST
(In reply to comment #5)
> > 
> > > +Tests that NPNVprivateModeBool is supported by the WebKit plugin view. This test is for WebKit platforms that wish to support NPNVprivateModeBool but do not wish to implement the preference change listener required to support a cachedPrivateBrowsingEnabled property similar to the one provided by Safari and tested for in private-browsing-mode.html
> > 
> > I don't understand this part. It seems trivial to implement in
> > DumpRenderTree/unix/TestNetscapePlugin/TestNetscapePlugin.cpp. Why not do it
> > there instead of this extra test?
> > 
> > In fact, it seems like a bug right now that the cachedPrivateBrowsingEnabled
> > variable isn't initialized in that file, where as it is initialized in
> > TestNetscapePlugIn.subproj/main.cpp. Could that be why the test was failing for
> > you?
> 
> The mac port listens for changes to the users webkit preferences and halts any
> netscape plugins currently running if pluginsEnabled has changed to false.
> Setting the 'cachedPrivateBrowsingMode' value rides on the coat-tails of this
> feature - which Qt doesn't have, and possibly should. I don't think it's
> trivial to implement though. So will leave it out of this patch if that's ok?

I think I understand now, but I don't see that the mac port stops the plugin. Instead looking at - (void)privateBrowsingModeDidChange in WebNetscapePluginView.mm I can see that the private browsing mode value is _propagated_ to the plugin (setvalue), and _that_ is what the other part of the private-browsing-mode.html tests.

Your patch implements the part that allows the plugin to query the browser if private browsing is enabled or not, and your added test verifies that.

The Mac port also implements _notifying_ the plugin if the private browsing mode changes, which appears to be an important feature to have.

I agree with you that this is okay to implement in a second patch. I guess once the setting in WebCore changes, the page should iterate through its plugins and notify them via setvalue calls.
Comment 8 Simon Hausmann 2010-01-27 14:56:22 PST
Comment on attachment 47448 [details]
Updated Patch


> +    case NPNVprivateModeBool: {
> +        Page* page = m_parentFrame->page();
> +        if (!page)
> +            return NPERR_GENERIC_ERROR;
> +        *((NPBool*)value) = !page->settings() || page->settings()->privateBrowsingEnabled();
> +        return NPERR_NO_ERROR;
> +    }

r=me, but when landing you may want to change the above to return NPERR_GENERIC_ERROR if !page->settings() and only return the real value to the plugin if we have a settings object.
Comment 9 Robert Hogan 2010-02-17 11:32:17 PST
(In reply to comment #7)
> (In reply to comment #5)
> > > 
> > > > +Tests that NPNVprivateModeBool is supported by the WebKit plugin view. This test is for WebKit platforms that wish to support NPNVprivateModeBool but do not wish to implement the preference change listener required to support a cachedPrivateBrowsingEnabled property similar to the one provided by Safari and tested for in private-browsing-mode.html
> > > 
> > > I don't understand this part. It seems trivial to implement in
> > > DumpRenderTree/unix/TestNetscapePlugin/TestNetscapePlugin.cpp. Why not do it
> > > there instead of this extra test?
> > > 
> > > In fact, it seems like a bug right now that the cachedPrivateBrowsingEnabled
> > > variable isn't initialized in that file, where as it is initialized in
> > > TestNetscapePlugIn.subproj/main.cpp. Could that be why the test was failing for
> > > you?
> > 
> > The mac port listens for changes to the users webkit preferences and halts any
> > netscape plugins currently running if pluginsEnabled has changed to false.
> > Setting the 'cachedPrivateBrowsingMode' value rides on the coat-tails of this
> > feature - which Qt doesn't have, and possibly should. I don't think it's
> > trivial to implement though. So will leave it out of this patch if that's ok?
> 
> I think I understand now, but I don't see that the mac port stops the plugin.

I came to the conclusion from reading in WebBaseNetscapePluginView.mm:

- (void)preferencesHaveChanged:(NSNotification *)notification
{
    WebPreferences *preferences = [[self webView] preferences];

    if ([notification object] != preferences)
        return;
    
    BOOL arePlugInsEnabled = [preferences arePlugInsEnabled];
    if (_isStarted != arePlugInsEnabled) {
        if (arePlugInsEnabled) {
            if ([self currentWindow]) {
                [self start];
            }
        } else {
            [self stop];
            [self invalidatePluginContentRect:[self bounds]];
        }
    }
    
    BOOL isPrivateBrowsingEnabled = [preferences privateBrowsingEnabled];
    if (isPrivateBrowsingEnabled != _isPrivateBrowsingEnabled) {
        _isPrivateBrowsingEnabled = isPrivateBrowsingEnabled;
        [self privateBrowsingModeDidChange];
    }
}


> Instead looking at - (void)privateBrowsingModeDidChange in
> WebNetscapePluginView.mm I can see that the private browsing mode value is
> _propagated_ to the plugin (setvalue), and _that_ is what the other part of the
> private-browsing-mode.html tests.
> 
> Your patch implements the part that allows the plugin to query the browser if
> private browsing is enabled or not, and your added test verifies that.
> 
> The Mac port also implements _notifying_ the plugin if the private browsing
> mode changes, which appears to be an important feature to have.
> 

Ah OK, it actually sets the value of NPNVprivateModeBool there and then:

- (void)privateBrowsingModeDidChange
{
    if (!_isStarted)
        return;
    
    NPBool value = _isPrivateBrowsingEnabled;

    [self willCallPlugInFunction];
    {
        JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly);
        if ([_pluginPackage.get() pluginFuncs]->setvalue)
            [_pluginPackage.get() pluginFuncs]->setvalue(plugin, NPNVprivateModeBool, &value);
    }
    [self didCallPlugInFunction];
}

I was under the misapprehension that any time a plugin wants to check the value of NPNVprivateModeBool it would have to perform a getvalue() but it will actually receive the setvalue event from the browser and act appropriately. Got it now.

> I agree with you that this is okay to implement in a second patch. I guess once
> the setting in WebCore changes, the page should iterate through its plugins and
> notify them via setvalue calls.
Comment 10 Robert Hogan 2010-02-17 11:35:09 PST
(In reply to comment #8)
> (From update of attachment 47448 [details])
> 
> > +    case NPNVprivateModeBool: {
> > +        Page* page = m_parentFrame->page();
> > +        if (!page)
> > +            return NPERR_GENERIC_ERROR;
> > +        *((NPBool*)value) = !page->settings() || page->settings()->privateBrowsingEnabled();
> > +        return NPERR_NO_ERROR;
> > +    }
> 
> r=me, but when landing you may want to change the above to return
> NPERR_GENERIC_ERROR if !page->settings() and only return the real value to the
> plugin if we have a settings object.

Elsewhere in the code the default behaviour for security-sensitive settings is to assume that if !page->settings() then the setting is true.

e.g. in WebCore/loader/DocLoader.cpp:

    Settings* settings = frame()->settings();
    if (!settings || settings->privateBrowsingEnabled())
        return;
Comment 11 Robert Hogan 2010-02-28 04:58:38 PST
Manually committed r55358: http://trac.webkit.org/changeset/55358
Comment 12 Dimitri Glazkov (Google) 2010-02-28 11:08:50 PST
If this is a Qt-specific font, maybe it should live under platform/qt?
Comment 13 Robert Hogan 2010-03-01 11:06:06 PST
(In reply to comment #12)
> If this is a Qt-specific font, maybe it should live under platform/qt?

Hi Dimitri,

Is this comment on the correct bug? If it's regarding the additions to the skiplists, I've added plugins/private-browsing-mode-2.html to any platform that already skips plugins/private-browsing-mode.html since it likely as not will fail it.
Comment 14 Dimitri Glazkov (Google) 2010-03-01 11:08:41 PST
(In reply to comment #13)
> (In reply to comment #12)
> > If this is a Qt-specific font, maybe it should live under platform/qt?
> 
> Hi Dimitri,
> 
> Is this comment on the correct bug? If it's regarding the additions to the
> skiplists, I've added plugins/private-browsing-mode-2.html to any platform that
> already skips plugins/private-browsing-mode.html since it likely as not will
> fail it.

Sorry, comment fail on my part :)

What I meant to say is that if this is a Qt-specific test, you could've put it in platform/qt and this way there would've been no need to update Skipped lists for other platforms.

Just a suggestion.
Comment 15 Mark Rowe (bdash) 2010-03-02 15:19:32 PST
I believe the functionality that you described implementing in a second patch was what I just landed as part of bug 35576.  Qt should be able to unskip the original private browsing plug-in patch after that change.
Comment 16 Tor Arne Vestbø 2010-03-10 06:28:43 PST
Please follow the QtWebKit bug reporting guidelines when reporting bugs.

See http://trac.webkit.org/wiki/QtWebKitBugs

Specifically:

  - The 'QtWebKit' component should only be used for bugs/features in the
    public QtWebKit API layer, not to signify that the bug is specific to
    the Qt port of WebKit

      http://trac.webkit.org/wiki/QtWebKitBugs#Component

  - Add the keyword 'Qt' to signal that it's a Qt-related bug

      http://trac.webkit.org/wiki/QtWebKitBugs#Keywords