diff options
author | gbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-28 20:19:31 +0000 |
---|---|---|
committer | gbillock@chromium.org <gbillock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-28 20:19:31 +0000 |
commit | 7c6d948a2a351c1fc1a5055d509865fe0cfda51b (patch) | |
tree | 0341454d8507805c72e8a795915ab7be1bed88f0 /content | |
parent | bbb26915eae6ccf279877e8f7f033a73b551f757 (diff) | |
download | chromium_src-7c6d948a2a351c1fc1a5055d509865fe0cfda51b.zip chromium_src-7c6d948a2a351c1fc1a5055d509865fe0cfda51b.tar.gz chromium_src-7c6d948a2a351c1fc1a5055d509865fe0cfda51b.tar.bz2 |
[Media] Add user gesture reporting for API calls to midi and media streams.
BUG=332115
Review URL: https://codereview.chromium.org/185863003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260257 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
20 files changed, 58 insertions, 23 deletions
diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc index 5bc237b..5ab23a8 100644 --- a/content/browser/download/download_manager_impl_unittest.cc +++ b/content/browser/download/download_manager_impl_unittest.cc @@ -406,11 +406,12 @@ class MockBrowserContext : public BrowserContext { MOCK_METHOD2(GetMediaRequestContextForStoragePartition, net::URLRequestContextGetter*( const base::FilePath& partition_path, bool in_memory)); - MOCK_METHOD5(RequestMidiSysExPermission, + MOCK_METHOD6(RequestMidiSysExPermission, void(int render_process_id, int render_view_id, int bridge_id, const GURL& requesting_frame, + bool user_gesture, const MidiSysExPermissionCallback& callback)); MOCK_METHOD4(CancelMidiSysExPermissionRequest, void(int render_process_id, diff --git a/content/browser/renderer_host/media/media_stream_dispatcher_host.cc b/content/browser/renderer_host/media/media_stream_dispatcher_host.cc index 1708c50..0698e21 100644 --- a/content/browser/renderer_host/media/media_stream_dispatcher_host.cc +++ b/content/browser/renderer_host/media/media_stream_dispatcher_host.cc @@ -127,21 +127,23 @@ void MediaStreamDispatcherHost::OnGenerateStream( int render_view_id, int page_request_id, const StreamOptions& components, - const GURL& security_origin) { + const GURL& security_origin, + bool user_gesture) { DVLOG(1) << "MediaStreamDispatcherHost::OnGenerateStream(" << render_view_id << ", " << page_request_id << ", [" << " audio:" << components.audio_requested << " video:" << components.video_requested << " ], " - << security_origin.spec() << ")"; + << security_origin.spec() + << ", " << user_gesture << ")"; if (!IsURLAllowed(security_origin)) return; media_stream_manager_->GenerateStream( this, render_process_id_, render_view_id, salt_callback_, - page_request_id, components, security_origin); + page_request_id, components, security_origin, user_gesture); } void MediaStreamDispatcherHost::OnCancelGenerateStream(int render_view_id, diff --git a/content/browser/renderer_host/media/media_stream_dispatcher_host.h b/content/browser/renderer_host/media/media_stream_dispatcher_host.h index 4149586..f34054e 100644 --- a/content/browser/renderer_host/media/media_stream_dispatcher_host.h +++ b/content/browser/renderer_host/media/media_stream_dispatcher_host.h @@ -68,7 +68,8 @@ class CONTENT_EXPORT MediaStreamDispatcherHost : public BrowserMessageFilter, void OnGenerateStream(int render_view_id, int page_request_id, const StreamOptions& components, - const GURL& security_origin); + const GURL& security_origin, + bool user_gesture); void OnCancelGenerateStream(int render_view_id, int page_request_id); void OnStopStreamDevice(int render_view_id, diff --git a/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc b/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc index d9331cd..65f2618 100644 --- a/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc +++ b/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc @@ -68,7 +68,7 @@ class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, const base::Closure& quit_closure) { quit_closures_.push(quit_closure); MediaStreamDispatcherHost::OnGenerateStream( - render_view_id, page_request_id, components, security_origin); + render_view_id, page_request_id, components, security_origin, false); } void OnStopStreamDevice(int render_view_id, diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc index 839c0cb..2740db4 100644 --- a/content/browser/renderer_host/media/media_stream_manager.cc +++ b/content/browser/renderer_host/media/media_stream_manager.cc @@ -173,6 +173,7 @@ class MediaStreamManager::DeviceRequest { int requesting_view_id, int page_request_id, const GURL& security_origin, + bool user_gesture, MediaStreamRequestType request_type, const StreamOptions& options, const ResourceContext::SaltCallback& salt_callback) @@ -181,6 +182,7 @@ class MediaStreamManager::DeviceRequest { requesting_view_id(requesting_view_id), page_request_id(page_request_id), security_origin(security_origin), + user_gesture(user_gesture), request_type(request_type), options(options), salt_callback(salt_callback), @@ -214,6 +216,7 @@ class MediaStreamManager::DeviceRequest { requesting_view_id, page_request_id, security_origin, + user_gesture, request_type, requested_audio_device_id, requested_video_device_id, @@ -231,6 +234,7 @@ class MediaStreamManager::DeviceRequest { target_render_view_id, page_request_id, security_origin, + user_gesture, request_type, "", "", @@ -299,6 +303,8 @@ class MediaStreamManager::DeviceRequest { const GURL security_origin; + const bool user_gesture; + const MediaStreamRequestType request_type; const StreamOptions options; @@ -389,6 +395,7 @@ std::string MediaStreamManager::MakeMediaAccessRequest( render_view_id, page_request_id, security_origin, + false, // user gesture MEDIA_DEVICE_ACCESS, options, base::Bind(&ReturnEmptySalt)); @@ -414,7 +421,8 @@ void MediaStreamManager::GenerateStream(MediaStreamRequester* requester, const ResourceContext::SaltCallback& sc, int page_request_id, const StreamOptions& options, - const GURL& security_origin) { + const GURL& security_origin, + bool user_gesture) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DVLOG(1) << "GenerateStream()"; if (CommandLine::ForCurrentProcess()->HasSwitch( @@ -427,6 +435,7 @@ void MediaStreamManager::GenerateStream(MediaStreamRequester* requester, render_view_id, page_request_id, security_origin, + user_gesture, MEDIA_GENERATE_STREAM, options, sc); @@ -619,6 +628,7 @@ std::string MediaStreamManager::EnumerateDevices( render_view_id, page_request_id, security_origin, + false, // user gesture MEDIA_ENUMERATE_DEVICES, StreamOptions(), sc); @@ -698,6 +708,7 @@ void MediaStreamManager::OpenDevice(MediaStreamRequester* requester, render_view_id, page_request_id, security_origin, + false, // user gesture MEDIA_OPEN_DEVICE, options, sc); diff --git a/content/browser/renderer_host/media/media_stream_manager.h b/content/browser/renderer_host/media/media_stream_manager.h index e254a29..b1d9e61 100644 --- a/content/browser/renderer_host/media/media_stream_manager.h +++ b/content/browser/renderer_host/media/media_stream_manager.h @@ -97,7 +97,8 @@ class CONTENT_EXPORT MediaStreamManager const ResourceContext::SaltCallback& sc, int page_request_id, const StreamOptions& components, - const GURL& security_origin); + const GURL& security_origin, + bool user_gesture); void CancelRequest(int render_process_id, int render_view_id, diff --git a/content/browser/renderer_host/media/media_stream_ui_proxy_unittest.cc b/content/browser/renderer_host/media/media_stream_ui_proxy_unittest.cc index 929b902..4529b49 100644 --- a/content/browser/renderer_host/media/media_stream_ui_proxy_unittest.cc +++ b/content/browser/renderer_host/media/media_stream_ui_proxy_unittest.cc @@ -95,7 +95,7 @@ MATCHER_P(SameRequest, expected, "") { } TEST_F(MediaStreamUIProxyTest, Deny) { - MediaStreamRequest request(0, 0, 0, GURL("http://origin/"), + MediaStreamRequest request(0, 0, 0, GURL("http://origin/"), false, MEDIA_GENERATE_STREAM, std::string(), std::string(), MEDIA_DEVICE_AUDIO_CAPTURE, @@ -121,7 +121,7 @@ TEST_F(MediaStreamUIProxyTest, Deny) { } TEST_F(MediaStreamUIProxyTest, AcceptAndStart) { - MediaStreamRequest request(0, 0, 0, GURL("http://origin/"), + MediaStreamRequest request(0, 0, 0, GURL("http://origin/"), false, MEDIA_GENERATE_STREAM, std::string(), std::string(), MEDIA_DEVICE_AUDIO_CAPTURE, @@ -155,7 +155,7 @@ TEST_F(MediaStreamUIProxyTest, AcceptAndStart) { // Verify that the proxy can be deleted before the request is processed. TEST_F(MediaStreamUIProxyTest, DeleteBeforeAccepted) { - MediaStreamRequest request(0, 0, 0, GURL("http://origin/"), + MediaStreamRequest request(0, 0, 0, GURL("http://origin/"), false, MEDIA_GENERATE_STREAM, std::string(), std::string(), MEDIA_DEVICE_AUDIO_CAPTURE, @@ -177,7 +177,7 @@ TEST_F(MediaStreamUIProxyTest, DeleteBeforeAccepted) { } TEST_F(MediaStreamUIProxyTest, StopFromUI) { - MediaStreamRequest request(0, 0, 0, GURL("http://origin/"), + MediaStreamRequest request(0, 0, 0, GURL("http://origin/"), false, MEDIA_GENERATE_STREAM, std::string(), std::string(), MEDIA_DEVICE_AUDIO_CAPTURE, @@ -225,6 +225,7 @@ TEST_F(MediaStreamUIProxyTest, WindowIdCallbackCalled) { 0, 0, GURL("http://origin/"), + false, MEDIA_GENERATE_STREAM, std::string(), std::string(), diff --git a/content/browser/renderer_host/media/midi_dispatcher_host.cc b/content/browser/renderer_host/media/midi_dispatcher_host.cc index e42fe11..e69a566 100644 --- a/content/browser/renderer_host/media/midi_dispatcher_host.cc +++ b/content/browser/renderer_host/media/midi_dispatcher_host.cc @@ -45,7 +45,8 @@ void MidiDispatcherHost::OverrideThreadForMessage( void MidiDispatcherHost::OnRequestSysExPermission(int render_view_id, int bridge_id, - const GURL& origin) { + const GURL& origin, + bool user_gesture) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); browser_context_->RequestMidiSysExPermission( @@ -53,6 +54,7 @@ void MidiDispatcherHost::OnRequestSysExPermission(int render_view_id, render_view_id, bridge_id, origin, + user_gesture, base::Bind(&MidiDispatcherHost::WasSysExPermissionGranted, base::Unretained(this), render_view_id, diff --git a/content/browser/renderer_host/media/midi_dispatcher_host.h b/content/browser/renderer_host/media/midi_dispatcher_host.h index 8bc1bb0..d8b3533 100644 --- a/content/browser/renderer_host/media/midi_dispatcher_host.h +++ b/content/browser/renderer_host/media/midi_dispatcher_host.h @@ -32,7 +32,8 @@ class MidiDispatcherHost : public BrowserMessageFilter { private: void OnRequestSysExPermission(int render_view_id, int bridge_id, - const GURL& origin); + const GURL& origin, + bool user_gesture); void OnCancelSysExPermissionRequest(int render_view_id, int bridge_id, const GURL& requesting_frame); diff --git a/content/common/media/media_stream_messages.h b/content/common/media/media_stream_messages.h index 5d106c0..0afa9ec 100644 --- a/content/common/media/media_stream_messages.h +++ b/content/common/media/media_stream_messages.h @@ -113,11 +113,12 @@ IPC_MESSAGE_CONTROL0(MediaStreamMsg_DisableAecDump) // Messages sent from the renderer to the browser. // Request a new media stream. -IPC_MESSAGE_CONTROL4(MediaStreamHostMsg_GenerateStream, +IPC_MESSAGE_CONTROL5(MediaStreamHostMsg_GenerateStream, int /* render view id */, int /* request id */, content::StreamOptions /* components */, - GURL /* security origin */) + GURL /* security origin */, + bool /* user_gesture */) // Request to cancel the request for a new media stream. IPC_MESSAGE_CONTROL2(MediaStreamHostMsg_CancelGenerateStream, diff --git a/content/common/media/midi_messages.h b/content/common/media/midi_messages.h index 5a0fd7e..c907a98 100644 --- a/content/common/media/midi_messages.h +++ b/content/common/media/midi_messages.h @@ -25,10 +25,11 @@ IPC_STRUCT_TRAITS_END() // Messages for IPC between MidiDispatcher and MidiDispatcherHost. // Renderer request to browser for using system exclusive messages. -IPC_MESSAGE_CONTROL3(MidiHostMsg_RequestSysExPermission, +IPC_MESSAGE_CONTROL4(MidiHostMsg_RequestSysExPermission, int /* routing id */, int /* client id */, - GURL /* origin */) + GURL /* origin */, + bool /* user_gesture */) // Renderer request to browser for canceling a previous permission request. IPC_MESSAGE_CONTROL3(MidiHostMsg_CancelSysExPermissionRequest, diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h index 4f9e967..0cb1b5b 100644 --- a/content/public/browser/browser_context.h +++ b/content/public/browser/browser_context.h @@ -131,6 +131,7 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { int render_view_id, int bridge_id, const GURL& requesting_frame, + bool user_gesture, const MidiSysExPermissionCallback& callback) = 0; // Cancels a pending MIDI permission request. diff --git a/content/public/common/media_stream_request.cc b/content/public/common/media_stream_request.cc index 2f12be3..4a4bf72 100644 --- a/content/public/common/media_stream_request.cc +++ b/content/public/common/media_stream_request.cc @@ -72,6 +72,7 @@ MediaStreamRequest::MediaStreamRequest( int render_view_id, int page_request_id, const GURL& security_origin, + bool user_gesture, MediaStreamRequestType request_type, const std::string& requested_audio_device_id, const std::string& requested_video_device_id, @@ -81,6 +82,7 @@ MediaStreamRequest::MediaStreamRequest( render_view_id(render_view_id), page_request_id(page_request_id), security_origin(security_origin), + user_gesture(user_gesture), request_type(request_type), requested_audio_device_id(requested_audio_device_id), requested_video_device_id(requested_video_device_id), diff --git a/content/public/common/media_stream_request.h b/content/public/common/media_stream_request.h index 6518422..7a58061 100644 --- a/content/public/common/media_stream_request.h +++ b/content/public/common/media_stream_request.h @@ -181,6 +181,7 @@ struct CONTENT_EXPORT MediaStreamRequest { int render_view_id, int page_request_id, const GURL& security_origin, + bool user_gesture, MediaStreamRequestType request_type, const std::string& requested_audio_device_id, const std::string& requested_video_device_id, @@ -209,6 +210,9 @@ struct CONTENT_EXPORT MediaStreamRequest { // The WebKit security origin for the current request (e.g. "html5rocks.com"). GURL security_origin; + // Set to true if the call was made in the context of a user gesture. + bool user_gesture; + // Stores the type of request that was made to the media controller. Right now // this is only used to distinguish between WebRTC and Pepper requests, as the // latter should not be subject to user approval but only to policy check. diff --git a/content/public/test/test_browser_context.cc b/content/public/test/test_browser_context.cc index a708c26..20b7b88 100644 --- a/content/public/test/test_browser_context.cc +++ b/content/public/test/test_browser_context.cc @@ -103,6 +103,7 @@ void TestBrowserContext::RequestMidiSysExPermission( int render_view_id, int bridge_id, const GURL& requesting_frame, + bool user_gesture, const MidiSysExPermissionCallback& callback) { // Always reject requests for testing. callback.Run(false); diff --git a/content/public/test/test_browser_context.h b/content/public/test/test_browser_context.h index 2c0021e..9019330 100644 --- a/content/public/test/test_browser_context.h +++ b/content/public/test/test_browser_context.h @@ -45,6 +45,7 @@ class TestBrowserContext : public BrowserContext { int render_view_id, int bridge_id, const GURL& requesting_frame, + bool user_gesture, const MidiSysExPermissionCallback& callback) OVERRIDE; virtual void CancelMidiSysExPermissionRequest( int render_process_id, diff --git a/content/renderer/media/media_stream_dispatcher.cc b/content/renderer/media/media_stream_dispatcher.cc index 51b708b..6446c3c 100644 --- a/content/renderer/media/media_stream_dispatcher.cc +++ b/content/renderer/media/media_stream_dispatcher.cc @@ -10,6 +10,7 @@ #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" +#include "third_party/WebKit/public/web/WebUserGestureIndicator.h" #include "url/gurl.h" namespace content { @@ -78,10 +79,9 @@ void MediaStreamDispatcher::GenerateStream( DVLOG(1) << "MediaStreamDispatcher::GenerateStream(" << request_id << ")"; requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); - Send(new MediaStreamHostMsg_GenerateStream(routing_id(), - next_ipc_id_++, - components, - security_origin)); + Send(new MediaStreamHostMsg_GenerateStream( + routing_id(), next_ipc_id_++, components, security_origin, + blink::WebUserGestureIndicator::isProcessingUserGesture())); } void MediaStreamDispatcher::CancelGenerateStream( diff --git a/content/renderer/media/midi_dispatcher.cc b/content/renderer/media/midi_dispatcher.cc index 7d81cd9..eaf89de 100644 --- a/content/renderer/media/midi_dispatcher.cc +++ b/content/renderer/media/midi_dispatcher.cc @@ -10,6 +10,7 @@ #include "content/renderer/render_view_impl.h" #include "third_party/WebKit/public/web/WebMIDIPermissionRequest.h" #include "third_party/WebKit/public/web/WebSecurityOrigin.h" +#include "third_party/WebKit/public/web/WebUserGestureIndicator.h" using blink::WebMIDIPermissionRequest; using blink::WebSecurityOrigin; @@ -38,7 +39,8 @@ void MidiDispatcher::requestSysexPermission( WebSecurityOrigin security_origin = request.securityOrigin(); std::string origin = security_origin.toString().utf8(); GURL url(origin); - Send(new MidiHostMsg_RequestSysExPermission(routing_id(), bridge_id, url)); + Send(new MidiHostMsg_RequestSysExPermission(routing_id(), bridge_id, url, + blink::WebUserGestureIndicator::isProcessingUserGesture())); } void MidiDispatcher::cancelSysexPermissionRequest( diff --git a/content/shell/browser/shell_browser_context.cc b/content/shell/browser/shell_browser_context.cc index dbceb62..b37521e 100644 --- a/content/shell/browser/shell_browser_context.cc +++ b/content/shell/browser/shell_browser_context.cc @@ -183,6 +183,7 @@ void ShellBrowserContext::RequestMidiSysExPermission( int render_view_id, int bridge_id, const GURL& requesting_frame, + bool user_gesture, const MidiSysExPermissionCallback& callback) { // Always reject requests for LayoutTests for now. // TODO(toyoshim): Make it programmable to improve test coverage. diff --git a/content/shell/browser/shell_browser_context.h b/content/shell/browser/shell_browser_context.h index e9ca9bd..3bd5192 100644 --- a/content/shell/browser/shell_browser_context.h +++ b/content/shell/browser/shell_browser_context.h @@ -48,6 +48,7 @@ class ShellBrowserContext : public BrowserContext { int render_view_id, int bridge_id, const GURL& requesting_frame, + bool user_gesture, const MidiSysExPermissionCallback& callback) OVERRIDE; virtual void CancelMidiSysExPermissionRequest( int render_process_id, |