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

Unified Diff: Source/modules/webmidi/MIDIAccess.cpp

Issue 311733004: Introduce KeepAliveWhilePending to ScriptPromiseResolverWithContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@refactor-webmidi-initialization
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/modules/webmidi/MIDIAccess.cpp
diff --git a/Source/modules/webmidi/MIDIAccess.cpp b/Source/modules/webmidi/MIDIAccess.cpp
index 59c6fab56e45f2503ede5d57055bfb869094e619..567e736e40c93e21748aa029f63b73a5ab64ce34 100644
--- a/Source/modules/webmidi/MIDIAccess.cpp
+++ b/Source/modules/webmidi/MIDIAccess.cpp
@@ -31,11 +31,6 @@
#include "config.h"
#include "modules/webmidi/MIDIAccess.h"
-#include "bindings/v8/ScriptFunction.h"
-#include "bindings/v8/ScriptPromise.h"
-#include "bindings/v8/ScriptPromiseResolverWithContext.h"
-#include "bindings/v8/V8Binding.h"
-#include "core/dom/DOMError.h"
#include "core/dom/Document.h"
#include "core/loader/DocumentLoadTiming.h"
#include "core/loader/DocumentLoader.h"
@@ -48,28 +43,27 @@
namespace WebCore {
-ScriptPromise MIDIAccess::request(const MIDIOptions& options, ScriptState* scriptState)
+MIDIAccess::MIDIAccess(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled, const Vector<MIDIAccessInitializer::PortDescriptor>& ports, ExecutionContext* executionContext)
+ : ActiveDOMObject(executionContext)
+ , m_accessor(accessor)
+ , m_sysexEnabled(sysexEnabled)
{
- RefPtrWillBeRawPtr<MIDIAccess> midiAccess(adoptRefWillBeRefCountedGarbageCollected(new MIDIAccess(options, scriptState->executionContext())));
- midiAccess->suspendIfNeeded();
- // Create a wrapper to expose this object to the V8 GC so that
- // hasPendingActivity takes effect.
- toV8NoInline(midiAccess.get(), scriptState->context()->Global(), scriptState->isolate());
- // Now this object is retained because hasPending returns true.
- return midiAccess->m_initializer->initialize(scriptState);
+ ScriptWrappable::init(this);
+ m_accessor->setClient(this);
+ for (size_t i = 0; i < ports.size(); ++i) {
+ const MIDIAccessInitializer::PortDescriptor& port = ports[i];
+ if (port.type == MIDIPort::MIDIPortTypeInput) {
+ m_inputs.append(MIDIInput::create(this, port.id, port.manufacturer, port.name, port.version));
+ } else {
+ m_outputs.append(MIDIOutput::create(this, m_outputs.size(), port.id, port.manufacturer, port.name, port.version));
+ }
+ }
}
MIDIAccess::~MIDIAccess()
{
}
-MIDIAccess::MIDIAccess(const MIDIOptions& options, ExecutionContext* context)
- : ActiveDOMObject(context)
- , m_initializer(MIDIAccessInitializer::create(options, this))
-{
- ScriptWrappable::init(this);
-}
-
void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, const String& name, const String& version)
{
ASSERT(isMainThread());
@@ -125,20 +119,6 @@ void MIDIAccess::sendMIDIData(unsigned portIndex, const unsigned char* data, siz
void MIDIAccess::stop()
{
m_accessor.clear();
- m_initializer->cancel();
-}
-
-bool MIDIAccess::hasPendingActivity() const
-{
- return m_initializer->hasPendingActivity();
-}
-
-void MIDIAccess::initialize(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled)
-{
- ASSERT(accessor);
- m_accessor = accessor;
- m_accessor->setClient(this);
- m_sysexEnabled = sysexEnabled;
}
void MIDIAccess::trace(Visitor* visitor)

Powered by Google App Engine
This is Rietveld 408576698