Changeset 145046 in webkit
- Timestamp:
- Mar 7, 2013, 12:12:31 AM (12 years ago)
- Location:
- trunk/Source/WebKit/chromium
- Files:
-
- 7 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/chromium/ChangeLog
r145033 r145046 1 2013-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 1 50 2013-03-06 David Dorwin <ddorwin@chromium.org> 2 51 -
trunk/Source/WebKit/chromium/WebKit.gyp
r144951 r145046 278 278 'public/WebURLLoaderOptions.h', 279 279 'public/WebUserGestureIndicator.h', 280 'public/WebUserGestureToken.h', 280 281 'public/WebUserMediaClient.h', 281 282 'public/WebUserMediaRequest.h', … … 578 579 'src/WebTextFieldDecoratorClient.cpp', 579 580 'src/WebUserGestureIndicator.cpp', 581 'src/WebUserGestureToken.cpp', 580 582 'src/WebUserMediaRequest.cpp', 581 583 'src/WebViewBenchmarkSupportImpl.cpp', -
trunk/Source/WebKit/chromium/WebKit.gypi
r144830 r145046 124 124 'tests/WebPageSerializerTest.cpp', 125 125 'tests/WebPluginContainerTest.cpp', 126 'tests/WebUserGestureTokenTest.cpp', 126 127 'tests/WebSocketDeflaterTest.cpp', 127 128 'tests/WebSocketExtensionDispatcherTest.cpp', -
trunk/Source/WebKit/chromium/public/WebScopedUserGesture.h
r140621 r145046 40 40 namespace WebKit { 41 41 42 class WebUserGestureToken; 43 42 44 // An instance of this class, while kept alive, will indicate that we are in 43 45 // the context of a known user gesture. To use, create one, perform whatever 44 46 // actions were done under color of a known user gesture, and then delete it. 45 47 // 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. 46 57 class WebScopedUserGesture { 47 58 public: 59 explicit WebScopedUserGesture(const WebUserGestureToken& token) { initializeWithToken(token); } 48 60 WebScopedUserGesture() { initialize(); } 49 61 ~WebScopedUserGesture() { reset(); } … … 51 63 private: 52 64 WEBKIT_EXPORT void initialize(); 65 WEBKIT_EXPORT void initializeWithToken(const WebUserGestureToken&); 53 66 WEBKIT_EXPORT void reset(); 54 67 -
trunk/Source/WebKit/chromium/public/WebUserGestureIndicator.h
r144951 r145046 36 36 namespace WebKit { 37 37 38 class WebUserGestureToken; 39 38 40 class WebUserGestureIndicator { 39 41 public: … … 43 45 // Returns true if a consumable gesture exists and has been successfully consumed. 44 46 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(); 45 52 }; 46 53 -
trunk/Source/WebKit/chromium/public/WebUserGestureToken.h
r145045 r145046 1 1 /* 2 * Copyright (C) 201 1Google Inc. All rights reserved.2 * Copyright (C) 2013 Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 */ 30 30 31 #ifndef Web ScopedUserGesture_h32 #define Web ScopedUserGesture_h31 #ifndef WebUserGestureToken_h 32 #define WebUserGestureToken_h 33 33 34 #include "../../../Platform/chromium/public/WebPrivate OwnPtr.h"34 #include "../../../Platform/chromium/public/WebPrivatePtr.h" 35 35 36 36 namespace WebCore { 37 class UserGesture Indicator;37 class UserGestureToken; 38 38 } 39 39 40 40 namespace WebKit { 41 41 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. 45 class WebUserGestureToken { 47 46 public: 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 50 62 51 63 private: 52 WEBKIT_EXPORT void initialize();64 WEBKIT_EXPORT void assign(const WebUserGestureToken&); 53 65 WEBKIT_EXPORT void reset(); 54 66 55 WebPrivate OwnPtr<WebCore::UserGestureIndicator> m_indicator;67 WebPrivatePtr<WebCore::UserGestureToken> m_token; 56 68 }; 57 69 58 70 } // namespace WebKit 59 71 60 #endif // Web ScopedUserGesture_h72 #endif // WebUserGestureToken_h -
trunk/Source/WebKit/chromium/src/WebScopedUserGesture.cpp
r108665 r145046 33 33 34 34 #include "UserGestureIndicator.h" 35 #include "WebUserGestureToken.h" 35 36 36 37 namespace WebKit { … … 41 42 } 42 43 44 void WebScopedUserGesture::initializeWithToken(const WebUserGestureToken& token) 45 { 46 if (!token.isNull()) 47 m_indicator.reset(new WebCore::UserGestureIndicator(token)); 48 } 49 43 50 void WebScopedUserGesture::reset() 44 51 { -
trunk/Source/WebKit/chromium/src/WebUserGestureIndicator.cpp
r144951 r145046 33 33 34 34 #include "UserGestureIndicator.h" 35 #include "WebUserGestureToken.h" 35 36 36 37 using namespace WebCore; … … 48 49 } 49 50 51 WebUserGestureToken WebUserGestureIndicator::currentUserGestureToken() 52 { 53 return WebUserGestureToken(UserGestureIndicator::currentToken()); 54 } 55 50 56 } // namespace WebKit -
trunk/Source/WebKit/chromium/src/WebUserGestureToken.cpp
r145045 r145046 30 30 31 31 #include "config.h" 32 #include "WebUserGesture Indicator.h"32 #include "WebUserGestureToken.h" 33 33 34 34 #include "UserGestureIndicator.h" 35 35 36 using namespace WebCore;37 38 36 namespace WebKit { 39 37 40 bool WebUserGestureIndicator::isProcessingUserGesture()38 WebUserGestureToken::WebUserGestureToken(PassRefPtr<WebCore::UserGestureToken> token) 41 39 { 42 return UserGestureIndicator::processingUserGesture();40 m_token = token; 43 41 } 44 42 45 bool WebUserGestureIndicator::consumeUserGesture() 43 WebUserGestureToken::operator PassRefPtr<WebCore::UserGestureToken>() const 46 44 { 47 return UserGestureIndicator::consumeUserGesture(); 45 return m_token.get(); 46 } 47 48 void WebUserGestureToken::assign(const WebUserGestureToken& other) 49 { 50 m_token = other.m_token; 51 } 52 53 void WebUserGestureToken::reset() 54 { 55 m_token.reset(); 48 56 } 49 57 -
trunk/Source/WebKit/chromium/tests/WebUserGestureTokenTest.cpp
r145045 r145046 30 30 31 31 #include "config.h" 32 #include "WebUserGestureIndicator.h" 32 33 #include "WebUserGestureToken.h" 33 34 34 35 #include "UserGestureIndicator.h" 36 #include "WebScopedUserGesture.h" 37 #include "WebUserGestureIndicator.h" 38 #include <gtest/gtest.h> 35 39 40 using namespace WebKit; 36 41 using namespace WebCore; 37 42 38 namespace WebKit{43 namespace { 39 44 40 bool WebUserGestureIndicator::isProcessingUserGesture()45 TEST(WebUserGestureTokenTest, Basic) 41 46 { 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 } 43 73 } 44 74 45 bool WebUserGestureIndicator::consumeUserGesture()46 {47 return UserGestureIndicator::consumeUserGesture();48 75 } 49 50 } // namespace WebKit
Note:
See TracChangeset
for help on using the changeset viewer.