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

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

Issue 339443004: Revert of 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
« no previous file with comments | « Source/modules/webmidi/MIDIAccess.h ('k') | Source/modules/webmidi/MIDIAccessInitializer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webmidi/MIDIAccess.cpp
diff --git a/Source/modules/webmidi/MIDIAccess.cpp b/Source/modules/webmidi/MIDIAccess.cpp
index b7e5bf7070273bd8aa86ef353a0195704560e786..6056cc58daeb0e9d7d106312ba08f23c0ae8ee27 100644
--- a/Source/modules/webmidi/MIDIAccess.cpp
+++ b/Source/modules/webmidi/MIDIAccess.cpp
@@ -31,6 +31,11 @@
#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"
@@ -44,25 +49,26 @@
namespace WebCore {
-MIDIAccess::MIDIAccess(PassOwnPtr<MIDIAccessor> accessor, bool sysexEnabled, const Vector<MIDIAccessInitializer::PortDescriptor>& ports, ExecutionContext* executionContext)
- : ActiveDOMObject(executionContext)
- , m_accessor(accessor)
- , m_sysexEnabled(sysexEnabled)
+ScriptPromise MIDIAccess::request(const MIDIOptions& options, ScriptState* 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));
- }
- }
+ 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);
}
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)
@@ -120,6 +126,20 @@
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)
« no previous file with comments | « Source/modules/webmidi/MIDIAccess.h ('k') | Source/modules/webmidi/MIDIAccessInitializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698