Changeset 57522 in webkit


Ignore:
Timestamp:
Apr 13, 2010 10:46:46 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-04-13 Stephan Aßmus <superstippi@gmx.de>

Reviewed by David Levin.

[Haiku] Use the system clipboard instead of a private clipboard.

Fix various problems in the previous implementation.

https://bugs.webkit.org/show_bug.cgi?id=37421

No new tests needed.

  • platform/haiku/PasteboardHaiku.cpp: (WebCore::Pasteboard::~Pasteboard): (WebCore::Pasteboard::generalPasteboard):
    • Don't leak the pasteboard at program exit.

(WebCore::AutoClipboardLocker::AutoClipboardLocker):
(WebCore::AutoClipboardLocker::~AutoClipboardLocker):
(WebCore::AutoClipboardLocker::isLocked):

  • helper class for locking a BClipboard.

(WebCore::Pasteboard::writeSelection):

  • Use AddData(B_MIME_TYPE) as required by clipboard protocol.
  • Make sure we don't end up with unwanted UTF-8 characters for regular line breaks.

(WebCore::Pasteboard::writePlainText):

  • Use AddData(B_MIME_TYPE) as required by clipboard protocol.

(WebCore::Pasteboard::plainText):

  • Use FindData(B_MIME_TYPE) as required by clipboard protocol.

(WebCore::Pasteboard::documentFragment):

  • Implemented.

(WebCore::Pasteboard::writeURL):

  • Needs to use AddData(B_MIME_TYPE) instead of AddString().

(WebCore::Pasteboard::clear):

Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r57521 r57522  
     12010-04-13  Stephan Aßmus  <superstippi@gmx.de>
     2
     3        Reviewed by David Levin.
     4
     5        [Haiku] Use the system clipboard instead of a private clipboard.
     6                Fix various problems in the previous implementation.
     7
     8        https://bugs.webkit.org/show_bug.cgi?id=37421
     9
     10        No new tests needed.
     11
     12        * platform/haiku/PasteboardHaiku.cpp:
     13        (WebCore::Pasteboard::~Pasteboard):
     14        (WebCore::Pasteboard::generalPasteboard):
     15            - Don't leak the pasteboard at program exit.
     16        (WebCore::AutoClipboardLocker::AutoClipboardLocker):
     17        (WebCore::AutoClipboardLocker::~AutoClipboardLocker):
     18        (WebCore::AutoClipboardLocker::isLocked):
     19            - helper class for locking a BClipboard.
     20        (WebCore::Pasteboard::writeSelection):
     21            - Use AddData(B_MIME_TYPE) as required by clipboard protocol.
     22            - Make sure we don't end up with unwanted UTF-8 characters for
     23              regular line breaks.
     24        (WebCore::Pasteboard::writePlainText):
     25            - Use AddData(B_MIME_TYPE) as required by clipboard protocol.
     26        (WebCore::Pasteboard::plainText):
     27            - Use FindData(B_MIME_TYPE) as required by clipboard protocol.
     28        (WebCore::Pasteboard::documentFragment):
     29            - Implemented.
     30        (WebCore::Pasteboard::writeURL):
     31            - Needs to use AddData(B_MIME_TYPE) instead of AddString().
     32        (WebCore::Pasteboard::clear):
     33
    1342010-04-13  Stephan Aßmus  <superstippi@gmx.de>
    235
  • trunk/WebCore/platform/haiku/PasteboardHaiku.cpp

    r48710 r57522  
    22 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
    33 * Copyright (C) 2007 Ryan Leavengood <leavengood@gmail.com>
     4 * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    2223 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2324 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2526 */
    2627
     
    3334#include "KURL.h"
    3435#include "NotImplemented.h"
     36#include "TextResourceDecoder.h"
    3537#include "markup.h"
    3638#include <support/Locker.h>
     
    3840#include <Message.h>
    3941#include <String.h>
     42#include <wtf/text/CString.h>
    4043
    4144
     
    4649}
    4750
     51Pasteboard::~Pasteboard()
     52{
     53}
     54
    4855Pasteboard* Pasteboard::generalPasteboard()
    4956{
    50     static Pasteboard* pasteboard = new Pasteboard();
    51     return pasteboard;
    52 }
     57    static Pasteboard pasteboard;
     58    return &pasteboard;
     59}
     60
     61// BClipboard unfortunately does not derive from BLocker, so we cannot use BAutolock.
     62class AutoClipboardLocker {
     63public:
     64    AutoClipboardLocker(BClipboard* clipboard)
     65        : m_clipboard(clipboard)
     66        , m_isLocked(clipboard && clipboard->Lock())
     67    {
     68    }
     69
     70    ~AutoClipboardLocker()
     71    {
     72        if (m_isLocked)
     73            m_clipboard->Unlock();
     74    }
     75
     76    bool isLocked() const
     77    {
     78        return m_isLocked;
     79    }
     80
     81private:
     82    BClipboard* m_clipboard;
     83    bool m_isLocked;
     84};
    5385
    5486void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
    5587{
    56     BClipboard clipboard("WebKit");
    57     if (!clipboard.Lock())
    58         return;
    59 
    60     clipboard.Clear();
    61     BMessage* data = clipboard.Data();
    62     if (!data)
    63         return;
    64 
    65     data->AddString("text/plain", BString(frame->selectedText()));
    66     clipboard.Commit();
    67 
    68     clipboard.Unlock();
     88    AutoClipboardLocker locker(be_clipboard);
     89    if (!locker.isLocked())
     90        return;
     91
     92    be_clipboard->Clear();
     93    BMessage* data = be_clipboard->Data();
     94    if (!data)
     95        return;
     96
     97    BString string(frame->selectedText());
     98
     99    // Replace unwanted representation of blank lines
     100    const char* utf8BlankLine = "\302\240\n";
     101    string.ReplaceAll(utf8BlankLine, "\n");
     102
     103    data->AddData("text/plain", B_MIME_TYPE, string.String(), string.Length());
     104
     105    BString markupString(createMarkup(selectedRange, 0, AnnotateForInterchange));
     106    data->AddData("text/html", B_MIME_TYPE, markupString.String(), markupString.Length());
     107
     108    be_clipboard->Commit();
    69109}
    70110
    71111void Pasteboard::writePlainText(const String& text)
    72112{
    73     BClipboard clipboard("WebKit");
    74     if (!clipboard.Lock())
    75         return;
    76 
    77     clipboard.Clear();
    78     BMessage* data = clipboard.Data();
    79     if (!data)
    80         return;
    81 
    82     data->AddString("text/plain", BString(text));
    83     clipboard.Commit();
    84 
    85     clipboard.Unlock();
     113    AutoClipboardLocker locker(be_clipboard);
     114    if (!locker.isLocked())
     115        return;
     116
     117    be_clipboard->Clear();
     118    BMessage* data = be_clipboard->Data();
     119    if (!data)
     120        return;
     121
     122    BString string(text);
     123    data->AddData("text/plain", B_MIME_TYPE, string.String(), string.Length());
     124    be_clipboard->Commit();
    86125}
    87126
     
    94133String Pasteboard::plainText(Frame* frame)
    95134{
    96     BClipboard clipboard("WebKit");
    97     if (!clipboard.Lock())
     135    AutoClipboardLocker locker(be_clipboard);
     136    if (!locker.isLocked())
    98137        return String();
    99138
    100     BMessage* data = clipboard.Data();
     139    BMessage* data = be_clipboard->Data();
    101140    if (!data)
    102141        return String();
    103142
     143    const char* buffer = 0;
     144    ssize_t bufferLength;
    104145    BString string;
    105     data->FindString("text/plain", &string);
    106 
    107     clipboard.Unlock();
     146    if (data->FindData("text/plain", B_MIME_TYPE, reinterpret_cast<const void**>(&buffer), &bufferLength) == B_OK)
     147        string.Append(buffer, bufferLength);
    108148
    109149    return string;
     
    113153                                                          bool allowPlainText, bool& chosePlainText)
    114154{
     155    chosePlainText = false;
     156
     157    AutoClipboardLocker locker(be_clipboard);
     158    if (!locker.isLocked())
     159        return 0;
     160
     161    BMessage* data = be_clipboard->Data();
     162    if (!data)
     163        return 0;
     164
     165    const char* buffer = 0;
     166    ssize_t bufferLength;
     167    if (data->FindData("text/html", B_MIME_TYPE, reinterpret_cast<const void**>(&buffer), &bufferLength) == B_OK) {
     168        RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/plain", "UTF-8", true);
     169        String html = decoder->decode(buffer, bufferLength);
     170        html += decoder->flush();
     171
     172        if (!html.isEmpty()) {
     173            RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, "", FragmentScriptingNotAllowed);
     174            if (fragment)
     175                return fragment.release();
     176        }
     177    }
     178
     179    if (!allowPlainText)
     180        return 0;
     181
     182    if (data->FindData("text/plain", B_MIME_TYPE, reinterpret_cast<const void**>(&buffer), &bufferLength) == B_OK) {
     183        BString plainText(buffer, bufferLength);
     184
     185        chosePlainText = true;
     186        RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), plainText);
     187        if (fragment)
     188            return fragment.release();
     189    }
     190
     191    return 0;
     192}
     193
     194void Pasteboard::writeURL(const KURL& url, const String&, Frame*)
     195{
     196    AutoClipboardLocker locker(be_clipboard);
     197    if (!locker.isLocked())
     198        return;
     199
     200    be_clipboard->Clear();
     201
     202    BMessage* data = be_clipboard->Data();
     203    if (!data)
     204        return;
     205
     206    BString string(url.string());
     207    data->AddData("text/plain", B_MIME_TYPE, string.String(), string.Length());
     208    be_clipboard->Commit();
     209}
     210
     211void Pasteboard::writeImage(Node*, const KURL&, const String&)
     212{
    115213    notImplemented();
    116     return 0;
    117 }
    118 
    119 void Pasteboard::writeURL(const KURL& url, const String&, Frame*)
    120 {
    121     BClipboard clipboard("WebKit");
    122     if (!clipboard.Lock())
    123         return;
    124 
    125     clipboard.Clear();
    126 
    127     BMessage* data = clipboard.Data();
    128     if (!data)
    129         return;
    130 
    131     data->AddString("text/plain", url.string());
    132     clipboard.Commit();
    133 
    134     clipboard.Unlock();
    135 }
    136 
    137 void Pasteboard::writeImage(Node*, const KURL&, const String&)
    138 {
    139     notImplemented();
    140214}
    141215
    142216void Pasteboard::clear()
    143217{
    144     BClipboard clipboard("WebKit");
    145     if (!clipboard.Lock())
    146         return;
    147 
    148     clipboard.Clear();
    149     clipboard.Commit();
    150 
    151     clipboard.Unlock();
     218    AutoClipboardLocker locker(be_clipboard);
     219    if (!locker.isLocked())
     220        return;
     221
     222    be_clipboard->Clear();
     223    be_clipboard->Commit();
    152224}
    153225
Note: See TracChangeset for help on using the changeset viewer.