Chromium Code Reviews| 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 // used (only during the scope of a UserGestureIndicator, does | |
| 56 // not flow with the UserGestureToken). It's the responsibility of the | |
| 57 // caller to ensure the UserGestureUtilizedCallback 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 read (sometimes it's just propagated | |
| 61 // elsewhere, or otherwise read in a way that's hard to know if it will | |
| 62 // actually be used), but should include the primary use cases. Therefore | |
| 63 // this is suitable mainly for diagnostics and measurement purposes. | |
| 64 class PLATFORM_EXPORT UserGestureUtilizedCallback { | |
| 65 WTF_MAKE_NONCOPYABLE(UserGestureUtilizedCallback); | |
| 66 public: | |
| 67 UserGestureUtilizedCallback() { } | |
|
jochen (gone - plz use gerrit)
2016/04/07 03:37:56
we don't need a ctor for an interface, no?
Rick Byers
2016/04/07 17:51:31
Yep, we can use the implicit default ctor by also
| |
| 68 virtual ~UserGestureUtilizedCallback() { } | |
|
jochen (gone - plz use gerrit)
2016/04/07 03:37:56
= default; ?
Rick Byers
2016/04/07 17:51:31
Done.
| |
| 69 virtual void userGestureUtilized() = 0; | |
| 70 }; | |
| 71 | |
| 54 class PLATFORM_EXPORT UserGestureIndicator final { | 72 class PLATFORM_EXPORT UserGestureIndicator final { |
| 55 USING_FAST_MALLOC(UserGestureIndicator); | 73 USING_FAST_MALLOC(UserGestureIndicator); |
| 56 WTF_MAKE_NONCOPYABLE(UserGestureIndicator); | 74 WTF_MAKE_NONCOPYABLE(UserGestureIndicator); |
| 57 public: | 75 public: |
| 76 // Returns whether a user gesture is currently in progress. | |
| 77 // Does not invoke the UserGestureUtilizedCallback. Consider calling | |
| 78 // utilizeUserGesture instead if you know for sure that the return value | |
| 79 // will have an effect. | |
| 58 static bool processingUserGesture(); | 80 static bool processingUserGesture(); |
| 81 | |
| 82 // Indicates that a user gesture (if any) is being used, without preventing it | |
| 83 // from being used again. Returns whether a user gesture is currently in pr ogress. | |
| 84 // If true, invokes (and then clears) any UserGestureUtilizedCallback. | |
| 85 static bool utilizeUserGesture(); | |
| 86 | |
| 87 // Mark the current user gesture (if any) as having been used, such that | |
| 88 // it cannot be used again. This is done only for very security-sensitive | |
| 89 // operations like creating a new process. | |
| 90 // Like utilizeUserGesture, may invoke/clear any UserGestureUtilizedCallback . | |
| 59 static bool consumeUserGesture(); | 91 static bool consumeUserGesture(); |
| 92 | |
| 60 static UserGestureToken* currentToken(); | 93 static UserGestureToken* currentToken(); |
| 94 | |
| 95 // Reset the notion of "since load". | |
| 61 static void clearProcessedUserGestureSinceLoad(); | 96 static void clearProcessedUserGestureSinceLoad(); |
| 97 | |
| 98 // Returns whether a user gesture has occurred since page load. | |
| 62 static bool processedUserGestureSinceLoad(); | 99 static bool processedUserGestureSinceLoad(); |
| 63 | 100 |
| 64 explicit UserGestureIndicator(ProcessingUserGestureState); | 101 explicit UserGestureIndicator(ProcessingUserGestureState, UserGestureUtilize dCallback* usageCallback = 0); |
|
jochen (gone - plz use gerrit)
2016/04/07 03:37:56
omit "usageCallback" (also next line)
Rick Byers
2016/04/07 17:51:31
Done.
| |
| 65 explicit UserGestureIndicator(PassRefPtr<UserGestureToken>); | 102 explicit UserGestureIndicator(PassRefPtr<UserGestureToken>, UserGestureUtili zedCallback* usageCallback = 0); |
| 66 ~UserGestureIndicator(); | 103 ~UserGestureIndicator(); |
| 67 | 104 |
| 68 private: | 105 private: |
| 69 static ProcessingUserGestureState s_state; | 106 static ProcessingUserGestureState s_state; |
| 70 static UserGestureIndicator* s_topmostIndicator; | 107 static UserGestureIndicator* s_topmostIndicator; |
| 71 static bool s_processedUserGestureSinceLoad; | 108 static bool s_processedUserGestureSinceLoad; |
| 72 ProcessingUserGestureState m_previousState; | 109 ProcessingUserGestureState m_previousState; |
| 73 RefPtr<UserGestureToken> m_token; | 110 RefPtr<UserGestureToken> m_token; |
| 111 UserGestureUtilizedCallback* m_usageCallback; | |
| 74 }; | 112 }; |
| 75 | 113 |
| 76 } // namespace blink | 114 } // namespace blink |
| 77 | 115 |
| 78 #endif | 116 #endif |
| OLD | NEW |