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