Changeset 145046 in webkit


Ignore:
Timestamp:
Mar 7, 2013, 12:12:31 AM (12 years ago)
Author:
jochen@chromium.org
Message:

[chromium] expose UserGestureToken via WebKit API so PPAPI plugins can correctly consume it
https://bugs.webkit.org/show_bug.cgi?id=104268

Reviewed by Darin Fisher.

Currently, the PPAPI creates a WebScopedUserGesture up to 10 seconds
after a call with an currently active user gesture was made. It should
use the newly added WebUserGestureToken to make sure this user gesture
is not consumed multiple times.

We can't require a WebUserGestureToken for a WebScopedUserGesture, since
e.g. the extension API needs to be able to create a WebScopedUserGesture
out of the blue.

  • WebKit.gyp:
  • WebKit.gypi:
  • public/WebScopedUserGesture.h:

(WebKit):
(WebKit::WebScopedUserGesture::WebScopedUserGesture):
(WebScopedUserGesture):

  • public/WebUserGestureIndicator.h:

(WebKit):
(WebUserGestureIndicator):

  • public/WebUserGestureToken.h: Copied from Source/WebKit/chromium/public/WebScopedUserGesture.h.

(WebCore):
(WebKit):
(WebUserGestureToken):
(WebKit::WebUserGestureToken::WebUserGestureToken):
(WebKit::WebUserGestureToken::operator=):
(WebKit::WebUserGestureToken::~WebUserGestureToken):
(WebKit::WebUserGestureToken::isNull):

  • src/WebScopedUserGesture.cpp:

(WebKit::WebScopedUserGesture::initializeWithToken):
(WebKit):

  • src/WebUserGestureIndicator.cpp:

(WebKit::WebUserGestureIndicator::currentUserGestureToken):
(WebKit):

  • src/WebUserGestureToken.cpp: Copied from Source/WebKit/chromium/src/WebUserGestureIndicator.cpp.

(WebKit):
(WebKit::WebUserGestureToken::WebUserGestureToken):
(WebKit::WebUserGestureToken::operator WebCore::UserGestureToken*):
(WebKit::WebUserGestureToken::assign):
(WebKit::WebUserGestureToken::reset):

  • tests/WebUserGestureTokenTest.cpp: Copied from Source/WebKit/chromium/src/WebUserGestureIndicator.cpp.

(WebCore):
(WebCore::TEST):

Location:
trunk/Source/WebKit/chromium
Files:
7 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/chromium/ChangeLog

    r145033 r145046  
     12013-03-07  Jochen Eisinger  <jochen@chromium.org>
     2
     3        [chromium] expose UserGestureToken via WebKit API so PPAPI plugins can correctly consume it
     4        https://bugs.webkit.org/show_bug.cgi?id=104268
     5
     6        Reviewed by Darin Fisher.
     7
     8        Currently, the PPAPI creates a WebScopedUserGesture up to 10 seconds
     9        after a call with an currently active user gesture was made. It should
     10        use the newly added WebUserGestureToken to make sure this user gesture
     11        is not consumed multiple times.
     12
     13        We can't require a WebUserGestureToken for a WebScopedUserGesture, since
     14        e.g. the extension API needs to be able to create a WebScopedUserGesture
     15        out of the blue.
     16
     17        * WebKit.gyp:
     18        * WebKit.gypi:
     19        * public/WebScopedUserGesture.h:
     20        (WebKit):
     21        (WebKit::WebScopedUserGesture::WebScopedUserGesture):
     22        (WebScopedUserGesture):
     23        * public/WebUserGestureIndicator.h:
     24        (WebKit):
     25        (WebUserGestureIndicator):
     26        * public/WebUserGestureToken.h: Copied from Source/WebKit/chromium/public/WebScopedUserGesture.h.
     27        (WebCore):
     28        (WebKit):
     29        (WebUserGestureToken):
     30        (WebKit::WebUserGestureToken::WebUserGestureToken):
     31        (WebKit::WebUserGestureToken::operator=):
     32        (WebKit::WebUserGestureToken::~WebUserGestureToken):
     33        (WebKit::WebUserGestureToken::isNull):
     34        * src/WebScopedUserGesture.cpp:
     35        (WebKit::WebScopedUserGesture::initializeWithToken):
     36        (WebKit):
     37        * src/WebUserGestureIndicator.cpp:
     38        (WebKit::WebUserGestureIndicator::currentUserGestureToken):
     39        (WebKit):
     40        * src/WebUserGestureToken.cpp: Copied from Source/WebKit/chromium/src/WebUserGestureIndicator.cpp.
     41        (WebKit):
     42        (WebKit::WebUserGestureToken::WebUserGestureToken):
     43        (WebKit::WebUserGestureToken::operator WebCore::UserGestureToken*):
     44        (WebKit::WebUserGestureToken::assign):
     45        (WebKit::WebUserGestureToken::reset):
     46        * tests/WebUserGestureTokenTest.cpp: Copied from Source/WebKit/chromium/src/WebUserGestureIndicator.cpp.
     47        (WebCore):
     48        (WebCore::TEST):
     49
    1502013-03-06  David Dorwin  <ddorwin@chromium.org>
    251
  • trunk/Source/WebKit/chromium/WebKit.gyp

    r144951 r145046  
    278278                'public/WebURLLoaderOptions.h',
    279279                'public/WebUserGestureIndicator.h',
     280                'public/WebUserGestureToken.h',
    280281                'public/WebUserMediaClient.h',
    281282                'public/WebUserMediaRequest.h',
     
    578579                'src/WebTextFieldDecoratorClient.cpp',
    579580                'src/WebUserGestureIndicator.cpp',
     581                'src/WebUserGestureToken.cpp',
    580582                'src/WebUserMediaRequest.cpp',
    581583                'src/WebViewBenchmarkSupportImpl.cpp',
  • trunk/Source/WebKit/chromium/WebKit.gypi

    r144830 r145046  
    124124            'tests/WebPageSerializerTest.cpp',
    125125            'tests/WebPluginContainerTest.cpp',
     126            'tests/WebUserGestureTokenTest.cpp',
    126127            'tests/WebSocketDeflaterTest.cpp',
    127128            'tests/WebSocketExtensionDispatcherTest.cpp',
  • trunk/Source/WebKit/chromium/public/WebScopedUserGesture.h

    r140621 r145046  
    4040namespace WebKit {
    4141
     42class WebUserGestureToken;
     43
    4244// An instance of this class, while kept alive, will indicate that we are in
    4345// the context of a known user gesture. To use, create one, perform whatever
    4446// actions were done under color of a known user gesture, and then delete it.
    4547// Usually this will be done on the stack.
     48//
     49// SECURITY WARNING: Do not create several instances of this class for the same
     50// user gesture. Doing so might enable malicious code to work around certain
     51// restrictions such as opening multiple windows.
     52// Instead, obtain the current WebUserGestureToken from the
     53// WebUserGestureIndicator, and use this token to create a
     54// WebScopedUserGesture. If the token was alrady consumed, the new
     55// WebScopedUserGesture will not indicate that we are in the context of a user
     56// gesture.
    4657class WebScopedUserGesture {
    4758public:
     59    explicit WebScopedUserGesture(const WebUserGestureToken& token) { initializeWithToken(token); }
    4860    WebScopedUserGesture() { initialize(); }
    4961    ~WebScopedUserGesture() { reset(); }
     
    5163private:
    5264    WEBKIT_EXPORT void initialize();
     65    WEBKIT_EXPORT void initializeWithToken(const WebUserGestureToken&);
    5366    WEBKIT_EXPORT void reset();
    5467
  • trunk/Source/WebKit/chromium/public/WebUserGestureIndicator.h

    r144951 r145046  
    3636namespace WebKit {
    3737
     38class WebUserGestureToken;
     39
    3840class WebUserGestureIndicator {
    3941public:
     
    4345    // Returns true if a consumable gesture exists and has been successfully consumed.
    4446    WEBKIT_EXPORT static bool consumeUserGesture();
     47
     48    // Returns a token for the currently active user gesture. It can be used to
     49    // continue processing the user gesture later on using a
     50    // WebScopedUserGesture.
     51    WEBKIT_EXPORT static WebUserGestureToken currentUserGestureToken();
    4552};
    4653
  • trunk/Source/WebKit/chromium/public/WebUserGestureToken.h

    r145045 r145046  
    11/*
    2  * Copyright (C) 2011 Google Inc. All rights reserved.
     2 * Copyright (C) 2013 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929 */
    3030
    31 #ifndef WebScopedUserGesture_h
    32 #define WebScopedUserGesture_h
     31#ifndef WebUserGestureToken_h
     32#define WebUserGestureToken_h
    3333
    34 #include "../../../Platform/chromium/public/WebPrivateOwnPtr.h"
     34#include "../../../Platform/chromium/public/WebPrivatePtr.h"
    3535
    3636namespace WebCore {
    37 class UserGestureIndicator;
     37class UserGestureToken;
    3838}
    3939
    4040namespace WebKit {
    4141
    42 // An instance of this class, while kept alive, will indicate that we are in
    43 // the context of a known user gesture. To use, create one, perform whatever
    44 // actions were done under color of a known user gesture, and then delete it.
    45 // Usually this will be done on the stack.
    46 class WebScopedUserGesture {
     42// A WebUserGestureToken allows for storing the user gesture state of the
     43// currently active context and reinstantiating it later on to continue
     44// processing the user gesture in case it was not consumed meanwhile.
     45class WebUserGestureToken {
    4746public:
    48     WebScopedUserGesture() { initialize(); }
    49     ~WebScopedUserGesture() { reset(); }
     47    WebUserGestureToken() { }
     48    WebUserGestureToken(const WebUserGestureToken& other) { assign(other); }
     49    WebUserGestureToken& operator=(const WebUserGestureToken& other)
     50    {
     51        assign(other);
     52        return *this;
     53    }
     54    ~WebUserGestureToken() { reset(); }
     55
     56    bool isNull() const { return m_token.isNull(); }
     57
     58#if WEBKIT_IMPLEMENTATION
     59    explicit WebUserGestureToken(PassRefPtr<WebCore::UserGestureToken>);
     60    operator PassRefPtr<WebCore::UserGestureToken>() const;
     61#endif
    5062
    5163private:
    52     WEBKIT_EXPORT void initialize();
     64    WEBKIT_EXPORT void assign(const WebUserGestureToken&);
    5365    WEBKIT_EXPORT void reset();
    5466
    55     WebPrivateOwnPtr<WebCore::UserGestureIndicator> m_indicator;
     67    WebPrivatePtr<WebCore::UserGestureToken> m_token;
    5668};
    5769
    5870} // namespace WebKit
    5971
    60 #endif // WebScopedUserGesture_h
     72#endif // WebUserGestureToken_h
  • trunk/Source/WebKit/chromium/src/WebScopedUserGesture.cpp

    r108665 r145046  
    3333
    3434#include "UserGestureIndicator.h"
     35#include "WebUserGestureToken.h"
    3536
    3637namespace WebKit {
     
    4142}
    4243
     44void WebScopedUserGesture::initializeWithToken(const WebUserGestureToken& token)
     45{
     46    if (!token.isNull())
     47        m_indicator.reset(new WebCore::UserGestureIndicator(token));
     48}
     49
    4350void WebScopedUserGesture::reset()
    4451{
  • trunk/Source/WebKit/chromium/src/WebUserGestureIndicator.cpp

    r144951 r145046  
    3333
    3434#include "UserGestureIndicator.h"
     35#include "WebUserGestureToken.h"
    3536
    3637using namespace WebCore;
     
    4849}
    4950
     51WebUserGestureToken WebUserGestureIndicator::currentUserGestureToken()
     52{
     53    return WebUserGestureToken(UserGestureIndicator::currentToken());
     54}
     55
    5056} // namespace WebKit
  • trunk/Source/WebKit/chromium/src/WebUserGestureToken.cpp

    r145045 r145046  
    3030
    3131#include "config.h"
    32 #include "WebUserGestureIndicator.h"
     32#include "WebUserGestureToken.h"
    3333
    3434#include "UserGestureIndicator.h"
    3535
    36 using namespace WebCore;
    37 
    3836namespace WebKit {
    3937
    40 bool WebUserGestureIndicator::isProcessingUserGesture()
     38WebUserGestureToken::WebUserGestureToken(PassRefPtr<WebCore::UserGestureToken> token)
    4139{
    42     return UserGestureIndicator::processingUserGesture();
     40    m_token = token;
    4341}
    4442
    45 bool WebUserGestureIndicator::consumeUserGesture()
     43WebUserGestureToken::operator PassRefPtr<WebCore::UserGestureToken>() const
    4644{
    47     return UserGestureIndicator::consumeUserGesture();
     45    return m_token.get();
     46}
     47
     48void WebUserGestureToken::assign(const WebUserGestureToken& other)
     49{
     50    m_token = other.m_token;
     51}
     52
     53void WebUserGestureToken::reset()
     54{
     55    m_token.reset();
    4856}
    4957
  • trunk/Source/WebKit/chromium/tests/WebUserGestureTokenTest.cpp

    r145045 r145046  
    3030
    3131#include "config.h"
    32 #include "WebUserGestureIndicator.h"
     32
     33#include "WebUserGestureToken.h"
    3334
    3435#include "UserGestureIndicator.h"
     36#include "WebScopedUserGesture.h"
     37#include "WebUserGestureIndicator.h"
     38#include <gtest/gtest.h>
    3539
     40using namespace WebKit;
    3641using namespace WebCore;
    3742
    38 namespace WebKit {
     43namespace {
    3944
    40 bool WebUserGestureIndicator::isProcessingUserGesture()
     45TEST(WebUserGestureTokenTest, Basic)
    4146{
    42     return UserGestureIndicator::processingUserGesture();
     47    WebUserGestureToken token;
     48
     49    {
     50        WebScopedUserGesture indicator(token);
     51        EXPECT_FALSE(WebUserGestureIndicator::isProcessingUserGesture());
     52    }
     53
     54    {
     55        UserGestureIndicator indicator(DefinitelyProcessingUserGesture);
     56        EXPECT_TRUE(WebUserGestureIndicator::isProcessingUserGesture());
     57        token = WebUserGestureIndicator::currentUserGestureToken();
     58    }
     59
     60    EXPECT_FALSE(WebUserGestureIndicator::isProcessingUserGesture());
     61
     62    {
     63        WebScopedUserGesture indicator(token);
     64        EXPECT_TRUE(WebUserGestureIndicator::isProcessingUserGesture());
     65        WebUserGestureIndicator::consumeUserGesture();
     66        EXPECT_FALSE(WebUserGestureIndicator::isProcessingUserGesture());
     67    }
     68
     69    {
     70        WebScopedUserGesture indicator(token);
     71        EXPECT_FALSE(WebUserGestureIndicator::isProcessingUserGesture());
     72    }
    4373}
    4474
    45 bool WebUserGestureIndicator::consumeUserGesture()
    46 {
    47     return UserGestureIndicator::consumeUserGesture();
    4875}
    49 
    50 } // namespace WebKit
Note: See TracChangeset for help on using the changeset viewer.