Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 #include "core/dom/DOMException.h" | 35 #include "core/dom/DOMException.h" |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
| 38 #include "core/frame/Navigator.h" | 38 #include "core/frame/Navigator.h" |
| 39 #include "core/frame/UseCounter.h" | 39 #include "core/frame/UseCounter.h" |
| 40 #include "modules/webmidi/MIDIAccessInitializer.h" | 40 #include "modules/webmidi/MIDIAccessInitializer.h" |
| 41 #include "modules/webmidi/MIDIOptions.h" | 41 #include "modules/webmidi/MIDIOptions.h" |
| 42 | 42 |
| 43 namespace blink { | 43 namespace blink { |
| 44 | 44 |
| 45 NavigatorWebMIDI::NavigatorWebMIDI(LocalFrame* frame) : ContextClient(frame) {} | 45 NavigatorWebMIDI::NavigatorWebMIDI(Navigator& navigator) |
| 46 : Supplement<Navigator>(navigator) {} | |
| 46 | 47 |
| 47 DEFINE_TRACE(NavigatorWebMIDI) { | 48 DEFINE_TRACE(NavigatorWebMIDI) { |
| 48 Supplement<Navigator>::trace(visitor); | 49 Supplement<Navigator>::trace(visitor); |
| 49 ContextClient::trace(visitor); | |
| 50 } | 50 } |
| 51 | 51 |
| 52 const char* NavigatorWebMIDI::supplementName() { | 52 const char* NavigatorWebMIDI::supplementName() { |
| 53 return "NavigatorWebMIDI"; | 53 return "NavigatorWebMIDI"; |
| 54 } | 54 } |
| 55 | 55 |
| 56 NavigatorWebMIDI& NavigatorWebMIDI::from(Navigator& navigator) { | 56 NavigatorWebMIDI& NavigatorWebMIDI::from(Navigator& navigator) { |
| 57 NavigatorWebMIDI* supplement = static_cast<NavigatorWebMIDI*>( | 57 NavigatorWebMIDI* supplement = static_cast<NavigatorWebMIDI*>( |
| 58 Supplement<Navigator>::from(navigator, supplementName())); | 58 Supplement<Navigator>::from(navigator, supplementName())); |
| 59 if (!supplement) { | 59 if (!supplement) { |
| 60 supplement = new NavigatorWebMIDI(navigator.frame()); | 60 supplement = new NavigatorWebMIDI(navigator); |
| 61 provideTo(navigator, supplementName(), supplement); | 61 provideTo(navigator, supplementName(), supplement); |
| 62 } | 62 } |
| 63 return *supplement; | 63 return *supplement; |
| 64 } | 64 } |
| 65 | 65 |
| 66 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(ScriptState* scriptState, | 66 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(ScriptState* scriptState, |
| 67 Navigator& navigator, | 67 Navigator& navigator, |
| 68 const MIDIOptions& options) { | 68 const MIDIOptions& options) { |
| 69 return NavigatorWebMIDI::from(navigator).requestMIDIAccess(scriptState, | 69 return NavigatorWebMIDI::from(navigator).requestMIDIAccess(scriptState, |
| 70 options); | 70 options); |
| 71 } | 71 } |
| 72 | 72 |
| 73 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(ScriptState* scriptState, | 73 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(ScriptState* scriptState, |
| 74 const MIDIOptions& options) { | 74 const MIDIOptions& options) { |
| 75 if (!frame() || frame()->document()->isContextDestroyed()) { | 75 if (!scriptState->contextIsValid()) { |
|
haraken
2017/01/06 01:11:19
This is "mostly" equivalent to the previous check
sof
2017/01/06 07:33:33
If |scriptState| represents the script state of th
haraken
2017/01/06 08:13:35
I think the two frames should match. The user scri
sof
2017/01/06 10:21:20
agreed, thanks for clarifying.
| |
| 76 return ScriptPromise::rejectWithDOMException( | 76 return ScriptPromise::rejectWithDOMException( |
| 77 scriptState, | 77 scriptState, |
| 78 DOMException::create(AbortError, "The frame is not working.")); | 78 DOMException::create(AbortError, "The frame is not working.")); |
| 79 } | 79 } |
| 80 | 80 |
| 81 UseCounter::countCrossOriginIframe(*frame()->document(), | 81 UseCounter::countCrossOriginIframe( |
| 82 UseCounter::RequestMIDIAccessIframe); | 82 *toDocument(scriptState->getExecutionContext()), |
| 83 UseCounter::RequestMIDIAccessIframe); | |
| 83 return MIDIAccessInitializer::start(scriptState, options); | 84 return MIDIAccessInitializer::start(scriptState, options); |
| 84 } | 85 } |
| 85 | 86 |
| 86 } // namespace blink | 87 } // namespace blink |
| OLD | NEW |