| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "content/browser/media/midi_host.h" | 5 #include "content/browser/media/midi_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/process/process.h" | 9 #include "base/process/process.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "content/browser/bad_message.h" |
| 11 #include "content/browser/browser_main_loop.h" | 12 #include "content/browser/browser_main_loop.h" |
| 12 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
| 13 #include "content/browser/media/media_internals.h" | 14 #include "content/browser/media/media_internals.h" |
| 14 #include "content/common/media/midi_messages.h" | 15 #include "content/common/media/midi_messages.h" |
| 15 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
| 16 #include "content/public/browser/media_observer.h" | 17 #include "content/public/browser/media_observer.h" |
| 17 #include "content/public/browser/user_metrics.h" | 18 #include "content/public/browser/user_metrics.h" |
| 18 #include "media/midi/midi_manager.h" | 19 #include "media/midi/midi_manager.h" |
| 19 #include "media/midi/midi_message_queue.h" | 20 #include "media/midi/midi_message_queue.h" |
| 20 #include "media/midi/midi_message_util.h" | 21 #include "media/midi/midi_message_util.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 is_session_requested_ = true; | 86 is_session_requested_ = true; |
| 86 midi_manager_->StartSession(this); | 87 midi_manager_->StartSession(this); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void MidiHost::OnSendData(uint32 port, | 90 void MidiHost::OnSendData(uint32 port, |
| 90 const std::vector<uint8>& data, | 91 const std::vector<uint8>& data, |
| 91 double timestamp) { | 92 double timestamp) { |
| 92 { | 93 { |
| 93 base::AutoLock auto_lock(output_port_count_lock_); | 94 base::AutoLock auto_lock(output_port_count_lock_); |
| 94 if (output_port_count_ <= port) { | 95 if (output_port_count_ <= port) { |
| 95 RecordAction(base::UserMetricsAction("BadMessageTerminate_MIDIPort")); | 96 bad_message::ReceivedBadMessage(this, bad_message::MH_INVALID_MIDI_PORT); |
| 96 BadMessageReceived(); | |
| 97 return; | 97 return; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 if (data.empty()) | 101 if (data.empty()) |
| 102 return; | 102 return; |
| 103 | 103 |
| 104 // Blink running in a renderer checks permission to raise a SecurityError | 104 // Blink running in a renderer checks permission to raise a SecurityError |
| 105 // in JavaScript. The actual permission check for security purposes | 105 // in JavaScript. The actual permission check for security purposes |
| 106 // happens here in the browser process. | 106 // happens here in the browser process. |
| 107 if (!has_sys_ex_permission_ && | 107 if (!has_sys_ex_permission_ && |
| 108 std::find(data.begin(), data.end(), kSysExByte) != data.end()) { | 108 std::find(data.begin(), data.end(), kSysExByte) != data.end()) { |
| 109 RecordAction(base::UserMetricsAction("BadMessageTerminate_MIDI")); | 109 bad_message::ReceivedBadMessage(this, bad_message::MH_SYS_EX_PERMISSION); |
| 110 BadMessageReceived(); | |
| 111 return; | 110 return; |
| 112 } | 111 } |
| 113 | 112 |
| 114 if (!IsValidWebMIDIData(data)) | 113 if (!IsValidWebMIDIData(data)) |
| 115 return; | 114 return; |
| 116 | 115 |
| 117 { | 116 { |
| 118 base::AutoLock auto_lock(in_flight_lock_); | 117 base::AutoLock auto_lock(in_flight_lock_); |
| 119 // Sanity check that we won't send too much data. | 118 // Sanity check that we won't send too much data. |
| 120 // TODO(yukawa): Consider to send an error event back to the renderer | 119 // TODO(yukawa): Consider to send an error event back to the renderer |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 243 } |
| 245 waiting_data_length = media::midi::GetMidiMessageLength(current); | 244 waiting_data_length = media::midi::GetMidiMessageLength(current); |
| 246 if (waiting_data_length == 0) | 245 if (waiting_data_length == 0) |
| 247 return false; // Error: |current| should have been a valid status byte. | 246 return false; // Error: |current| should have been a valid status byte. |
| 248 --waiting_data_length; // Found status byte | 247 --waiting_data_length; // Found status byte |
| 249 } | 248 } |
| 250 return waiting_data_length == 0 && !in_sysex; | 249 return waiting_data_length == 0 && !in_sysex; |
| 251 } | 250 } |
| 252 | 251 |
| 253 } // namespace content | 252 } // namespace content |
| OLD | NEW |