OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // for later (see, e.g., DOMTimer, which propagates user gestures to the timer | 53 // for later (see, e.g., DOMTimer, which propagates user gestures to the timer |
54 // fire in certain situations). Passing it to a UserGestureIndicator will cause | 54 // fire in certain situations). Passing it to a UserGestureIndicator will cause |
55 // it to be considered as currently being processed. | 55 // it to be considered as currently being processed. |
56 class PLATFORM_EXPORT UserGestureToken : public RefCounted<UserGestureToken> { | 56 class PLATFORM_EXPORT UserGestureToken : public RefCounted<UserGestureToken> { |
57 WTF_MAKE_NONCOPYABLE(UserGestureToken); | 57 WTF_MAKE_NONCOPYABLE(UserGestureToken); |
58 | 58 |
59 public: | 59 public: |
60 enum Status { NewGesture, PossiblyExistingGesture }; | 60 enum Status { NewGesture, PossiblyExistingGesture }; |
61 enum TimeoutPolicy { Default, OutOfProcess, HasPaused }; | 61 enum TimeoutPolicy { Default, OutOfProcess, HasPaused }; |
62 | 62 |
63 static PassRefPtr<UserGestureToken> create( | 63 virtual ~UserGestureToken() {} |
64 Status status = PossiblyExistingGesture) { | |
65 return adoptRef(new UserGestureToken(status)); | |
66 } | |
67 | |
68 ~UserGestureToken() {} | |
69 bool hasGestures() const; | 64 bool hasGestures() const; |
70 void transferGestureTo(UserGestureToken*); | 65 void transferGestureTo(UserGestureToken*); |
71 bool consumeGesture(); | 66 bool consumeGesture(); |
72 void setTimeoutPolicy(TimeoutPolicy); | 67 void setTimeoutPolicy(TimeoutPolicy); |
73 | 68 |
74 // If this UserGestureToken is wrapped in a UserGestureIndicator, and the | 69 // If this UserGestureToken is wrapped in a UserGestureIndicator, and the |
75 // UserGestureIndicator is the lowest on the callstack (and therefore this | 70 // UserGestureIndicator is the lowest on the callstack (and therefore this |
76 // UserGestureToken is UserGestureIndicator::s_rootToken), then the callback | 71 // UserGestureToken is UserGestureIndicator::s_rootToken), then the callback |
77 // provided here will be called when this UserGestureToken is utilized. | 72 // provided here will be called when this UserGestureToken is utilized. |
78 // Calling setUserGestureUtilizedCallback() on a UserGestureToken that is not | 73 // Calling setUserGestureUtilizedCallback() on a UserGestureToken that is not |
79 // UserGestureIndicator::s_rootToken would be unsafe and never result in a | 74 // UserGestureIndicator::s_rootToken would be unsafe and never result in a |
80 // callback, so it will fail a CHECK() instead. | 75 // callback, so it will fail a CHECK() instead. |
81 void setUserGestureUtilizedCallback(UserGestureUtilizedCallback*); | 76 void setUserGestureUtilizedCallback(UserGestureUtilizedCallback*); |
82 void userGestureUtilized(); | 77 void userGestureUtilized(); |
83 | 78 |
84 private: | 79 protected: |
85 UserGestureToken(Status); | 80 UserGestureToken(Status); |
86 | 81 |
| 82 private: |
87 bool hasTimedOut() const; | 83 bool hasTimedOut() const; |
88 | 84 |
89 size_t m_consumableGestures; | 85 size_t m_consumableGestures; |
90 double m_timestamp; | 86 double m_timestamp; |
91 TimeoutPolicy m_timeoutPolicy; | 87 TimeoutPolicy m_timeoutPolicy; |
92 UserGestureUtilizedCallback* m_usageCallback; | 88 UserGestureUtilizedCallback* m_usageCallback; |
93 }; | 89 }; |
94 | 90 |
95 class PLATFORM_EXPORT UserGestureIndicator final { | 91 class PLATFORM_EXPORT UserGestureIndicator final { |
96 USING_FAST_MALLOC(UserGestureIndicator); | 92 USING_FAST_MALLOC(UserGestureIndicator); |
(...skipping 13 matching lines...) Expand all Loading... |
110 static bool utilizeUserGesture(); | 106 static bool utilizeUserGesture(); |
111 | 107 |
112 // Mark the current user gesture (if any) as having been used, such that | 108 // Mark the current user gesture (if any) as having been used, such that |
113 // it cannot be used again. This is done only for very security-sensitive | 109 // it cannot be used again. This is done only for very security-sensitive |
114 // operations like creating a new process. | 110 // operations like creating a new process. |
115 // Like utilizeUserGesture, may invoke/clear any UserGestureUtilizedCallback. | 111 // Like utilizeUserGesture, may invoke/clear any UserGestureUtilizedCallback. |
116 static bool consumeUserGesture(); | 112 static bool consumeUserGesture(); |
117 | 113 |
118 static UserGestureToken* currentToken(); | 114 static UserGestureToken* currentToken(); |
119 | 115 |
120 // Reset the notion of "since load". | |
121 static void clearProcessedUserGestureSinceLoad(); | |
122 | |
123 // Returns whether a user gesture has occurred since page load. | |
124 static bool processedUserGestureSinceLoad(); | |
125 | |
126 explicit UserGestureIndicator(PassRefPtr<UserGestureToken>); | 116 explicit UserGestureIndicator(PassRefPtr<UserGestureToken>); |
127 ~UserGestureIndicator(); | 117 ~UserGestureIndicator(); |
128 | 118 |
129 private: | 119 private: |
130 static bool s_processedUserGestureSinceLoad; | |
131 static UserGestureToken* s_rootToken; | 120 static UserGestureToken* s_rootToken; |
132 | 121 |
133 RefPtr<UserGestureToken> m_token; | 122 RefPtr<UserGestureToken> m_token; |
134 }; | 123 }; |
135 | 124 |
136 } // namespace blink | 125 } // namespace blink |
137 | 126 |
138 #endif | 127 #endif |
OLD | NEW |