Home | History | Annotate | Download | only in web
      1 /*
      2  * Copyright (C) 2011 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "config.h"
     32 
     33 #include "WebUserMediaRequest.h"
     34 
     35 #include "public/platform/WebMediaConstraints.h"
     36 #include "public/platform/WebMediaStream.h"
     37 #include "public/platform/WebMediaStreamSource.h"
     38 #include "public/platform/WebString.h"
     39 #include "public/platform/WebVector.h"
     40 #include "wtf/Vector.h"
     41 #include "WebDocument.h"
     42 #include "WebSecurityOrigin.h"
     43 #include "core/dom/Document.h"
     44 #include "core/platform/mediastream/MediaConstraints.h"
     45 #include "core/platform/mediastream/MediaStreamDescriptor.h"
     46 #include "core/platform/mediastream/MediaStreamSource.h"
     47 #include "modules/mediastream/UserMediaRequest.h"
     48 #include "weborigin/SecurityOrigin.h"
     49 
     50 using namespace WebCore;
     51 
     52 namespace WebKit {
     53 
     54 WebUserMediaRequest::WebUserMediaRequest(const PassRefPtr<UserMediaRequest>& request)
     55     : m_private(request)
     56 {
     57 }
     58 
     59 WebUserMediaRequest::WebUserMediaRequest(UserMediaRequest* request)
     60     : m_private(request)
     61 {
     62 }
     63 
     64 void WebUserMediaRequest::reset()
     65 {
     66     m_private.reset();
     67 }
     68 
     69 bool WebUserMediaRequest::audio() const
     70 {
     71     ASSERT(!isNull());
     72     return m_private->audio();
     73 }
     74 
     75 bool WebUserMediaRequest::video() const
     76 {
     77     ASSERT(!isNull());
     78     return m_private->video();
     79 }
     80 
     81 WebMediaConstraints WebUserMediaRequest::audioConstraints() const
     82 {
     83     ASSERT(!isNull());
     84     return m_private->audioConstraints();
     85 }
     86 
     87 WebMediaConstraints WebUserMediaRequest::videoConstraints() const
     88 {
     89     ASSERT(!isNull());
     90     return m_private->videoConstraints();
     91 }
     92 
     93 WebSecurityOrigin WebUserMediaRequest::securityOrigin() const
     94 {
     95     ASSERT(!isNull() && m_private->scriptExecutionContext());
     96     return WebSecurityOrigin(m_private->scriptExecutionContext()->securityOrigin());
     97 }
     98 
     99 WebDocument WebUserMediaRequest::ownerDocument() const
    100 {
    101     ASSERT(!isNull());
    102     return WebDocument(m_private->ownerDocument());
    103 }
    104 
    105 void WebUserMediaRequest::requestSucceeded(const WebMediaStream& streamDescriptor)
    106 {
    107     ASSERT(!isNull() && !streamDescriptor.isNull());
    108     m_private->succeed(streamDescriptor);
    109 }
    110 
    111 void WebUserMediaRequest::requestFailed(const WebString& description)
    112 {
    113     ASSERT(!isNull());
    114     m_private->fail(description);
    115 }
    116 
    117 void WebUserMediaRequest::requestFailedConstraint(const WebString& constraintName, const WebString& description)
    118 {
    119     ASSERT(!isNull());
    120     m_private->failConstraint(constraintName, description);
    121 }
    122 
    123 bool WebUserMediaRequest::equals(const WebUserMediaRequest& other) const
    124 {
    125     if (isNull() || other.isNull())
    126         return false;
    127     return m_private.get() == other.m_private.get();
    128 }
    129 
    130 void WebUserMediaRequest::assign(const WebUserMediaRequest& other)
    131 {
    132     m_private = other.m_private;
    133 }
    134 
    135 WebUserMediaRequest::operator UserMediaRequest*() const
    136 {
    137     return m_private.get();
    138 }
    139 
    140 } // namespace WebKit
    141