| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 WTF_MAKE_NONCOPYABLE(UserGestureToken); | 46 WTF_MAKE_NONCOPYABLE(UserGestureToken); |
| 47 public: | 47 public: |
| 48 UserGestureToken() { } | 48 UserGestureToken() { } |
| 49 virtual ~UserGestureToken() { } | 49 virtual ~UserGestureToken() { } |
| 50 virtual bool hasGestures() const = 0; | 50 virtual bool hasGestures() const = 0; |
| 51 virtual void setOutOfProcess() = 0; | 51 virtual void setOutOfProcess() = 0; |
| 52 virtual void setJavascriptPrompt() = 0; | 52 virtual void setJavascriptPrompt() = 0; |
| 53 virtual void setPauseInDebugger() = 0; | 53 virtual void setPauseInDebugger() = 0; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // Callback to be invoked when the state of a UserGestureIndicator is |
| 57 // first tested. Must outlive any UserGestureIndicators it's used in. |
| 58 // Note that this doesn't currently track EVERY way in which the |
| 59 // state of a UserGesture can be used (sometimes it's just propagated |
| 60 // elsewhere), but should include most use cases. Therefore this is |
| 61 // suitable mainly for diagnostics and measurement purposes. |
| 62 class PLATFORM_EXPORT UserGestureUsedCallback { |
| 63 WTF_MAKE_NONCOPYABLE(UserGestureUsedCallback); |
| 64 public: |
| 65 UserGestureUsedCallback() { } |
| 66 virtual ~UserGestureUsedCallback() { } |
| 67 virtual void userGestureUsed() = 0; |
| 68 }; |
| 69 |
| 56 class PLATFORM_EXPORT UserGestureIndicator final { | 70 class PLATFORM_EXPORT UserGestureIndicator final { |
| 57 USING_FAST_MALLOC(UserGestureIndicator); | 71 USING_FAST_MALLOC(UserGestureIndicator); |
| 58 WTF_MAKE_NONCOPYABLE(UserGestureIndicator); | 72 WTF_MAKE_NONCOPYABLE(UserGestureIndicator); |
| 59 public: | 73 public: |
| 74 // Returns whether a user gesture is currently in progress. |
| 75 // If true, invokes (and then clears) any UserGestureUsedCallback. |
| 60 static bool processingUserGesture(); | 76 static bool processingUserGesture(); |
| 77 |
| 78 // Returns whether a user gesture is currently in progress. |
| 79 // Does not invoke the UserGestureQueriedCallback. |
| 80 static bool processingUserGestureUntracked(); |
| 81 |
| 82 // Mark the current user gesture (if any) as having been used, such that |
| 83 // it cannot be used again. This is done only for very security-sensitive |
| 84 // operations like creating a new process. |
| 85 // Like processingUserGesture, may invoke/clear any UserGestureUsedCallback. |
| 61 static bool consumeUserGesture(); | 86 static bool consumeUserGesture(); |
| 87 |
| 62 static UserGestureToken* currentToken(); | 88 static UserGestureToken* currentToken(); |
| 89 |
| 90 // Reset the notion of "since load". |
| 63 static void clearProcessedUserGestureSinceLoad(); | 91 static void clearProcessedUserGestureSinceLoad(); |
| 92 |
| 93 // Returns whether a user gesture has occurred since page load. |
| 64 static bool processedUserGestureSinceLoad(); | 94 static bool processedUserGestureSinceLoad(); |
| 65 | 95 |
| 66 explicit UserGestureIndicator(ProcessingUserGestureState); | 96 explicit UserGestureIndicator(ProcessingUserGestureState, UserGestureUsedCal
lback* usageCallback = 0); |
| 67 explicit UserGestureIndicator(PassRefPtr<UserGestureToken>); | 97 explicit UserGestureIndicator(PassRefPtr<UserGestureToken>, UserGestureUsedC
allback* usageCallback = 0); |
| 68 ~UserGestureIndicator(); | 98 ~UserGestureIndicator(); |
| 69 | 99 |
| 70 private: | 100 private: |
| 71 static ProcessingUserGestureState s_state; | 101 static ProcessingUserGestureState s_state; |
| 72 static UserGestureIndicator* s_topmostIndicator; | 102 static UserGestureIndicator* s_topmostIndicator; |
| 73 static bool s_processedUserGestureSinceLoad; | 103 static bool s_processedUserGestureSinceLoad; |
| 74 ProcessingUserGestureState m_previousState; | 104 ProcessingUserGestureState m_previousState; |
| 75 RefPtr<UserGestureToken> m_token; | 105 RefPtr<UserGestureToken> m_token; |
| 106 UserGestureUsedCallback* m_usageCallback; |
| 76 }; | 107 }; |
| 77 | 108 |
| 78 } // namespace blink | 109 } // namespace blink |
| 79 | 110 |
| 80 #endif | 111 #endif |
| OLD | NEW |