109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)/*
209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Copyright (C) 2014 Google Inc. All rights reserved.
309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *
409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * modification, are permitted provided that the following conditions
609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * are met:
709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
1009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
1109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *    documentation and/or other materials provided with the distribution.
1209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *
1309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
1409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GOOGLE INC. OR
1709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
1809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
1909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
2109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) */
2509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
2609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "config.h"
2709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
28f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebMediaDevicesRequest.h"
2909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
3009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/dom/Document.h"
3109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/mediastream/MediaDevicesRequest.h"
3209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/weborigin/SecurityOrigin.h"
3309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "public/platform/WebMediaDeviceInfo.h"
3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "public/platform/WebString.h"
3509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "public/platform/WebVector.h"
36f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebDocument.h"
37f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebSecurityOrigin.h"
3809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "wtf/Vector.h"
3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
4009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)namespace blink {
4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
4209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)WebMediaDevicesRequest::WebMediaDevicesRequest(MediaDevicesRequest* request)
4309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    : m_private(request)
4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
4709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void WebMediaDevicesRequest::reset()
4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_private.reset();
5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
5209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)WebSecurityOrigin WebMediaDevicesRequest::securityOrigin() const
5309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    ASSERT(!isNull() && m_private->executionContext());
5509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return WebSecurityOrigin(m_private->executionContext()->securityOrigin());
5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)WebDocument WebMediaDevicesRequest::ownerDocument() const
5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    ASSERT(!isNull());
6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return WebDocument(m_private->ownerDocument());
6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
6309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
6409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void WebMediaDevicesRequest::requestSucceeded(WebVector<WebMediaDeviceInfo> webDevices)
6509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    ASSERT(!isNull());
6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
6809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    MediaDeviceInfoVector devices(webDevices.size());
6909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    for (size_t i = 0; i < webDevices.size(); ++i)
7009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        devices[i] = MediaDeviceInfo::create(webDevices[i]);
7109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
7209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_private->succeed(devices);
7309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
7409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
7509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)bool WebMediaDevicesRequest::equals(const WebMediaDevicesRequest& other) const
7609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
7709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (isNull() || other.isNull())
7809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return false;
7909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return m_private.get() == other.m_private.get();
8009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
8109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
8209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void WebMediaDevicesRequest::assign(const WebMediaDevicesRequest& other)
8309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
8409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    m_private = other.m_private;
8509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
8709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)WebMediaDevicesRequest::operator MediaDevicesRequest*() const
8809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
8909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return m_private.get();
9009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
9109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
9209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} // namespace blink
93