WebKit/chromium/src/WebDragData.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2009 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 #include "WebDragData.h"
       
    33 
       
    34 #include "ChromiumDataObject.h"
       
    35 #include "WebData.h"
       
    36 #include "WebString.h"
       
    37 #include "WebURL.h"
       
    38 #include "WebVector.h"
       
    39 
       
    40 #include <wtf/PassRefPtr.h>
       
    41 
       
    42 using namespace WebCore;
       
    43 
       
    44 namespace WebKit {
       
    45 
       
    46 class WebDragDataPrivate : public ChromiumDataObject {
       
    47 };
       
    48 
       
    49 void WebDragData::initialize()
       
    50 {
       
    51     assign(static_cast<WebDragDataPrivate*>(ChromiumDataObject::create().releaseRef()));
       
    52 }
       
    53 
       
    54 void WebDragData::reset()
       
    55 {
       
    56     assign(0);
       
    57 }
       
    58 
       
    59 void WebDragData::assign(const WebDragData& other)
       
    60 {
       
    61     WebDragDataPrivate* p = const_cast<WebDragDataPrivate*>(other.m_private);
       
    62     if (p)
       
    63         p->ref();
       
    64     assign(p);
       
    65 }
       
    66 
       
    67 WebURL WebDragData::url() const
       
    68 {
       
    69     ASSERT(!isNull());
       
    70     return m_private->getURL();
       
    71 }
       
    72 
       
    73 void WebDragData::setURL(const WebURL& url)
       
    74 {
       
    75     ensureMutable();
       
    76     m_private->setURL(url);
       
    77 }
       
    78 
       
    79 WebString WebDragData::urlTitle() const
       
    80 {
       
    81     ASSERT(!isNull());
       
    82     return m_private->urlTitle;
       
    83 }
       
    84 
       
    85 void WebDragData::setURLTitle(const WebString& urlTitle)
       
    86 {
       
    87     ensureMutable();
       
    88     m_private->urlTitle = urlTitle;
       
    89 }
       
    90 
       
    91 WebString WebDragData::downloadMetadata() const
       
    92 {
       
    93     ASSERT(!isNull());
       
    94     return m_private->downloadMetadata;
       
    95 }
       
    96 
       
    97 void WebDragData::setDownloadMetadata(const WebString& downloadMetadata)
       
    98 {
       
    99     ensureMutable();
       
   100     m_private->downloadMetadata = downloadMetadata;
       
   101 }
       
   102 
       
   103 WebString WebDragData::fileExtension() const
       
   104 {
       
   105     ASSERT(!isNull());
       
   106     return m_private->fileExtension;
       
   107 }
       
   108 
       
   109 void WebDragData::setFileExtension(const WebString& fileExtension)
       
   110 {
       
   111     ensureMutable();
       
   112     m_private->fileExtension = fileExtension;
       
   113 }
       
   114 
       
   115 bool WebDragData::hasFileNames() const
       
   116 {
       
   117     ASSERT(!isNull());
       
   118     return !m_private->filenames.isEmpty();
       
   119 }
       
   120 
       
   121 void WebDragData::fileNames(WebVector<WebString>& fileNames) const
       
   122 {
       
   123     ASSERT(!isNull());
       
   124     fileNames = m_private->filenames;
       
   125 }
       
   126 
       
   127 void WebDragData::setFileNames(const WebVector<WebString>& fileNames)
       
   128 {
       
   129     ensureMutable();
       
   130     m_private->filenames.clear();
       
   131     m_private->filenames.append(fileNames.data(), fileNames.size());
       
   132 }
       
   133 
       
   134 void WebDragData::appendToFileNames(const WebString& fileName)
       
   135 {
       
   136     ensureMutable();
       
   137     m_private->filenames.append(fileName);
       
   138 }
       
   139 
       
   140 WebString WebDragData::plainText() const
       
   141 {
       
   142     ASSERT(!isNull());
       
   143     return m_private->plainText;
       
   144 }
       
   145 
       
   146 void WebDragData::setPlainText(const WebString& plainText)
       
   147 {
       
   148     ensureMutable();
       
   149     m_private->plainText = plainText;
       
   150 }
       
   151 
       
   152 WebString WebDragData::htmlText() const
       
   153 {
       
   154     ASSERT(!isNull());
       
   155     return m_private->textHtml;
       
   156 }
       
   157 
       
   158 void WebDragData::setHTMLText(const WebString& htmlText)
       
   159 {
       
   160     ensureMutable();
       
   161     m_private->textHtml = htmlText;
       
   162 }
       
   163 
       
   164 WebURL WebDragData::htmlBaseURL() const
       
   165 {
       
   166     ASSERT(!isNull());
       
   167     return m_private->htmlBaseUrl;
       
   168 }
       
   169 
       
   170 void WebDragData::setHTMLBaseURL(const WebURL& htmlBaseURL)
       
   171 {
       
   172     ensureMutable();
       
   173     m_private->htmlBaseUrl = htmlBaseURL;
       
   174 }
       
   175 
       
   176 WebString WebDragData::fileContentFileName() const
       
   177 {
       
   178     ASSERT(!isNull());
       
   179     return m_private->fileContentFilename;
       
   180 }
       
   181 
       
   182 void WebDragData::setFileContentFileName(const WebString& fileName)
       
   183 {
       
   184     ensureMutable();
       
   185     m_private->fileContentFilename = fileName;
       
   186 }
       
   187 
       
   188 WebData WebDragData::fileContent() const
       
   189 {
       
   190     ASSERT(!isNull());
       
   191     return WebData(m_private->fileContent);
       
   192 }
       
   193 
       
   194 void WebDragData::setFileContent(const WebData& fileContent)
       
   195 {
       
   196     ensureMutable();
       
   197     m_private->fileContent = fileContent;
       
   198 }
       
   199 
       
   200 WebDragData::WebDragData(const WTF::PassRefPtr<WebCore::ChromiumDataObject>& data)
       
   201     : m_private(static_cast<WebDragDataPrivate*>(data.releaseRef()))
       
   202 {
       
   203 }
       
   204 
       
   205 WebDragData& WebDragData::operator=(const WTF::PassRefPtr<WebCore::ChromiumDataObject>& data)
       
   206 {
       
   207     assign(static_cast<WebDragDataPrivate*>(data.releaseRef()));
       
   208     return *this;
       
   209 }
       
   210 
       
   211 WebDragData::operator WTF::PassRefPtr<WebCore::ChromiumDataObject>() const
       
   212 {
       
   213     return PassRefPtr<ChromiumDataObject>(const_cast<WebDragDataPrivate*>(m_private));
       
   214 }
       
   215 
       
   216 void WebDragData::assign(WebDragDataPrivate* p)
       
   217 {
       
   218     // p is already ref'd for us by the caller
       
   219     if (m_private)
       
   220         m_private->deref();
       
   221     m_private = p;
       
   222 }
       
   223 
       
   224 void WebDragData::ensureMutable()
       
   225 {
       
   226     ASSERT(!isNull());
       
   227     if (!m_private->hasOneRef())
       
   228         assign(static_cast<WebDragDataPrivate*>(m_private->copy().releaseRef()));
       
   229 }
       
   230 
       
   231 } // namespace WebKit