Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(660)

Side by Side Diff: Source/modules/encryptedmedia/MediaKeySession.cpp

Issue 465053002: Delay posting Message event on MediaKeySession if no event handlers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2013 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "wtf/ArrayBuffer.h" 48 #include "wtf/ArrayBuffer.h"
49 #include "wtf/ArrayBufferView.h" 49 #include "wtf/ArrayBufferView.h"
50 50
51 namespace blink { 51 namespace blink {
52 52
53 // A class holding a pending action. 53 // A class holding a pending action.
54 class MediaKeySession::PendingAction : public GarbageCollectedFinalized<MediaKey Session::PendingAction> { 54 class MediaKeySession::PendingAction : public GarbageCollectedFinalized<MediaKey Session::PendingAction> {
55 public: 55 public:
56 enum Type { 56 enum Type {
57 Update, 57 Update,
58 Release 58 Release,
59 Message
59 }; 60 };
60 61
61 Type type() const { return m_type; } 62 Type type() const { return m_type; }
62 const Persistent<ContentDecryptionModuleResult> result() const { return m_re sult; } 63
63 // |data| is only valid for Update types. 64 const Persistent<ContentDecryptionModuleResult> result() const
64 const RefPtr<ArrayBuffer> data() const { return m_data; } 65 {
66 ASSERT(m_type == Update || m_type == Release);
67 return m_result;
68 }
69
70 const RefPtr<ArrayBuffer> data() const
71 {
72 ASSERT(m_type == Update);
73 return m_data;
74 }
75
76 RefPtrWillBeRawPtr<Event> event()
77 {
78 ASSERT(m_type == Message);
79 return m_event;
80 }
65 81
66 static PendingAction* CreatePendingUpdate(ContentDecryptionModuleResult* res ult, PassRefPtr<ArrayBuffer> data) 82 static PendingAction* CreatePendingUpdate(ContentDecryptionModuleResult* res ult, PassRefPtr<ArrayBuffer> data)
67 { 83 {
68 ASSERT(result); 84 ASSERT(result);
69 ASSERT(data); 85 ASSERT(data);
70 return new PendingAction(Update, result, data); 86 return new PendingAction(Update, result, data);
71 } 87 }
72 88
73 static PendingAction* CreatePendingRelease(ContentDecryptionModuleResult* re sult) 89 static PendingAction* CreatePendingRelease(ContentDecryptionModuleResult* re sult)
74 { 90 {
75 ASSERT(result); 91 ASSERT(result);
76 return new PendingAction(Release, result, PassRefPtr<ArrayBuffer>()); 92 return new PendingAction(Release, result, PassRefPtr<ArrayBuffer>());
77 } 93 }
78 94
95 static PendingAction* CreatePendingMessage(PassRefPtrWillBeRawPtr<Event> eve nt)
96 {
97 ASSERT(event);
98 return new PendingAction(Message, event);
99 }
100
79 ~PendingAction() 101 ~PendingAction()
80 { 102 {
81 } 103 }
82 104
83 void trace(Visitor* visitor) 105 void trace(Visitor* visitor)
84 { 106 {
85 visitor->trace(m_result); 107 visitor->trace(m_result);
86 } 108 }
87 109
88 private: 110 private:
89 PendingAction(Type type, ContentDecryptionModuleResult* result, PassRefPtr<A rrayBuffer> data) 111 PendingAction(Type type, ContentDecryptionModuleResult* result, PassRefPtr<A rrayBuffer> data)
90 : m_type(type) 112 : m_type(type)
91 , m_result(result) 113 , m_result(result)
92 , m_data(data) 114 , m_data(data)
93 { 115 {
94 } 116 }
95 117
118 PendingAction(Type type, PassRefPtrWillBeRawPtr<Event> event)
119 : m_type(type)
120 , m_event(event)
121 {
122 }
123
96 const Type m_type; 124 const Type m_type;
97 const Member<ContentDecryptionModuleResult> m_result; 125 const Member<ContentDecryptionModuleResult> m_result;
98 const RefPtr<ArrayBuffer> m_data; 126 const RefPtr<ArrayBuffer> m_data;
127 const RefPtrWillBeRawPtr<Event> m_event;
99 }; 128 };
100 129
101 // This class allows a MediaKeySession object to be created asynchronously. 130 // This class allows a MediaKeySession object to be created asynchronously.
102 class MediaKeySessionInitializer : public ScriptPromiseResolver { 131 class MediaKeySessionInitializer : public ScriptPromiseResolver {
103 WTF_MAKE_NONCOPYABLE(MediaKeySessionInitializer); 132 WTF_MAKE_NONCOPYABLE(MediaKeySessionInitializer);
104 133
105 public: 134 public:
106 static ScriptPromise create(ScriptState*, MediaKeys*, const String& initData Type, PassRefPtr<ArrayBuffer> initData, const String& sessionType); 135 static ScriptPromise create(ScriptState*, MediaKeys*, const String& initData Type, PassRefPtr<ArrayBuffer> initData, const String& sessionType);
107 virtual ~MediaKeySessionInitializer(); 136 virtual ~MediaKeySessionInitializer();
108 137
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 WTF_LOG(Media, "MediaKeySession(%p)::actionTimerFired: Release", thi s); 466 WTF_LOG(Media, "MediaKeySession(%p)::actionTimerFired: Release", thi s);
438 // NOTE: Continued from step 3 of MediaKeySession::release(). 467 // NOTE: Continued from step 3 of MediaKeySession::release().
439 // 3.1 Let cdm be the cdm loaded in create(). 468 // 3.1 Let cdm be the cdm loaded in create().
440 // 3.2 Use the cdm to execute the following steps: 469 // 3.2 Use the cdm to execute the following steps:
441 // 3.2.1 Process the close request. Do not remove stored session dat a. 470 // 3.2.1 Process the close request. Do not remove stored session dat a.
442 // 3.2.2 If the previous step caused the session to be closed, run t he 471 // 3.2.2 If the previous step caused the session to be closed, run t he
443 // Session Close algorithm on this object. 472 // Session Close algorithm on this object.
444 // 3.3 Resolve promise with undefined. 473 // 3.3 Resolve promise with undefined.
445 m_session->release(action->result()->result()); 474 m_session->release(action->result()->result());
446 break; 475 break;
476 case PendingAction::Message:
477 WTF_LOG(Media, "MediaKeySession(%p)::actionTimerFired: Message", thi s);
478 m_asyncEventQueue->enqueueEvent(action->event().release());
ddorwin 2014/08/12 22:31:45 Won't ".release()" this fail to compile with Oilpa
jrummell 2014/08/12 23:12:43 With Oilpan there is a RawPtr class that has all t
479 break;
447 } 480 }
448 } 481 }
449 } 482 }
450 483
451 // Queue a task to fire a simple event named keymessage at the new object 484 // Queue a task to fire a simple event named keymessage at the new object
452 void MediaKeySession::message(const unsigned char* message, size_t messageLength , const blink::WebURL& destinationURL) 485 void MediaKeySession::message(const unsigned char* message, size_t messageLength , const blink::WebURL& destinationURL)
453 { 486 {
454 WTF_LOG(Media, "MediaKeySession(%p)::message", this); 487 WTF_LOG(Media, "MediaKeySession(%p)::message", this);
455 488
456 MediaKeyMessageEventInit init; 489 MediaKeyMessageEventInit init;
457 init.bubbles = false; 490 init.bubbles = false;
458 init.cancelable = false; 491 init.cancelable = false;
459 init.message = ArrayBuffer::create(static_cast<const void*>(message), messag eLength); 492 init.message = ArrayBuffer::create(static_cast<const void*>(message), messag eLength);
460 init.destinationURL = destinationURL.string(); 493 init.destinationURL = destinationURL.string();
461 494
462 RefPtrWillBeRawPtr<MediaKeyMessageEvent> event = MediaKeyMessageEvent::creat e(EventTypeNames::message, init); 495 RefPtrWillBeRawPtr<MediaKeyMessageEvent> event = MediaKeyMessageEvent::creat e(EventTypeNames::message, init);
463 event->setTarget(this); 496 event->setTarget(this);
497
498 if (!hasEventListeners()) {
499 // Since this event may be generated immediately after resolving the
500 // CreateSession() promise, it is possible that the JavaScript hasn't
501 // had time to run the .then() action and bind any necessary event
502 // handlers. If there are no event handlers connected, delay enqueuing
503 // this message to provide time for the JavaScript to run.
ddorwin 2014/08/12 22:31:45 Is this guaranteed to be allow sufficient time for
jrummell 2014/08/12 23:12:43 For testing I added DCHECK(hasEventListeners()) in
504 m_pendingActions.append(PendingAction::CreatePendingMessage(event.releas e()));
505 if (!m_actionTimer.isActive())
506 m_actionTimer.startOneShot(0, FROM_HERE);
507 return;
508 }
509
464 m_asyncEventQueue->enqueueEvent(event.release()); 510 m_asyncEventQueue->enqueueEvent(event.release());
465 } 511 }
466 512
467 void MediaKeySession::ready() 513 void MediaKeySession::ready()
468 { 514 {
469 WTF_LOG(Media, "MediaKeySession(%p)::ready", this); 515 WTF_LOG(Media, "MediaKeySession(%p)::ready", this);
470 516
471 RefPtrWillBeRawPtr<Event> event = Event::create(EventTypeNames::ready); 517 RefPtrWillBeRawPtr<Event> event = Event::create(EventTypeNames::ready);
472 event->setTarget(this); 518 event->setTarget(this);
473 m_asyncEventQueue->enqueueEvent(event.release()); 519 m_asyncEventQueue->enqueueEvent(event.release());
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 { 621 {
576 visitor->trace(m_error); 622 visitor->trace(m_error);
577 visitor->trace(m_asyncEventQueue); 623 visitor->trace(m_asyncEventQueue);
578 visitor->trace(m_pendingActions); 624 visitor->trace(m_pendingActions);
579 visitor->trace(m_keys); 625 visitor->trace(m_keys);
580 visitor->trace(m_closedPromise); 626 visitor->trace(m_closedPromise);
581 EventTargetWithInlineData::trace(visitor); 627 EventTargetWithInlineData::trace(visitor);
582 } 628 }
583 629
584 } 630 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698