Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DocumentUserGestureToken_h | 5 #ifndef DocumentUserGestureToken_h |
| 6 #define DocumentUserGestureToken_h | 6 #define DocumentUserGestureToken_h |
| 7 | 7 |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/loader/FrameLoaderClient.h" | |
| 10 #include "platform/UserGestureIndicator.h" | 11 #include "platform/UserGestureIndicator.h" |
| 11 | 12 |
| 12 namespace blink { | 13 namespace blink { |
| 13 | 14 |
| 14 // Associates a UserGestureToken with a Document, if a non-null Document* | 15 // Associates a UserGestureToken with a Document, if a non-null Document* |
| 15 // is provided in the constructor. | 16 // is provided in the constructor. |
| 16 class DocumentUserGestureToken final : public UserGestureToken { | 17 class DocumentUserGestureToken final : public UserGestureToken { |
| 17 WTF_MAKE_NONCOPYABLE(DocumentUserGestureToken); | 18 WTF_MAKE_NONCOPYABLE(DocumentUserGestureToken); |
| 18 | 19 |
| 19 public: | 20 public: |
| 20 static PassRefPtr<UserGestureToken> create( | 21 static PassRefPtr<UserGestureToken> create( |
| 21 Document* document, | 22 Document* document, |
| 22 Status status = PossiblyExistingGesture) { | 23 Status status = PossiblyExistingGesture) { |
| 23 setHasReceivedUserGesture(document); | 24 setHasReceivedUserGesture(document); |
| 24 return adoptRef(new DocumentUserGestureToken(status)); | 25 return adoptRef(new DocumentUserGestureToken(status)); |
| 25 } | 26 } |
| 26 | 27 |
| 27 static PassRefPtr<UserGestureToken> adopt(Document* document, | 28 static PassRefPtr<UserGestureToken> adopt(Document* document, |
| 28 UserGestureToken* token) { | 29 UserGestureToken* token) { |
| 29 if (!token || !token->hasGestures()) | 30 if (!token || !token->hasGestures()) |
| 30 return nullptr; | 31 return nullptr; |
| 31 setHasReceivedUserGesture(document); | 32 setHasReceivedUserGesture(document); |
| 32 return token; | 33 return token; |
| 33 } | 34 } |
| 34 | 35 |
| 35 private: | 36 private: |
| 36 DocumentUserGestureToken(Status status) : UserGestureToken(status) {} | 37 DocumentUserGestureToken(Status status) : UserGestureToken(status) {} |
| 37 | 38 |
| 38 static void setHasReceivedUserGesture(Document* document) { | 39 static void setHasReceivedUserGesture(Document* document) { |
| 39 if (!document || document->hasReceivedUserGesture()) | 40 if (document && document->frame() && |
| 40 return; | 41 !document->frame()->hasReceivedUserGesture()) { |
| 41 document->setHasReceivedUserGesture(); | 42 document->frame()->setDocumentHasReceivedUserGesture(); |
|
Nate Chapin
2017/01/18 20:21:37
Doing this here rather than in FrameLoaderClientIm
| |
| 42 for (Frame* frame = document->frame()->tree().parent(); frame; | 43 document->frame()->loader().client()->setHasReceivedUserGesture(); |
| 43 frame = frame->tree().parent()) { | |
| 44 frame->setDocumentHasReceivedUserGesture(); | |
| 45 } | 44 } |
| 46 } | 45 } |
| 47 }; | 46 }; |
| 48 | 47 |
| 49 } // namespace blink | 48 } // namespace blink |
| 50 | 49 |
| 51 #endif // DocumentUserGestureToken_h | 50 #endif // DocumentUserGestureToken_h |
| OLD | NEW |