Last Comment Bug 311340 - Clipboard data is lost on exit (Should implement the freedesktop.org specification for clipboard management)
: Clipboard data is lost on exit (Should implement the freedesktop.org specific...
Status: RESOLVED FIXED
: dataloss
Product: Core
Classification: Components
Component: Widget: Gtk (show other bugs)
: Trunk
: All Linux
: -- normal with 16 votes (vote)
: mozilla1.9.3a1
Assigned To: Martin Stránský
:
Mentors:
http://freedesktop.org/wiki/Specifica...
: 23386 221183 312485 330704 412782 563913 (view as bug list)
Depends on: 531580 781788
Blocks: 233462
  Show dependency treegraph
 
Reported: 2005-10-06 05:17 PDT by siimo
Modified: 2012-08-12 17:39 PDT (History)
47 users (show)
roc: blocking1.9.2-
roc: wanted1.9.2-
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Possible clipboard fix (15.06 KB, patch)
2009-06-22 12:27 PDT, Rickard Edström
no flags Details | Diff | Review
an updated patch (7.42 KB, patch)
2009-10-22 13:54 PDT, Martin Stránský
no flags Details | Diff | Review
v3 (13.45 KB, patch)
2009-11-06 05:11 PST, Martin Stránský
no flags Details | Diff | Review
v4 (16.63 KB, patch)
2009-11-09 07:01 PST, Martin Stránský
karlt: review+
Details | Diff | Review
v4+updates (16.60 KB, patch)
2009-11-10 06:12 PST, Martin Stránský
karlt: review+
Details | Diff | Review
what I landed (15.76 KB, patch)
2009-11-25 20:09 PST, Reed Loden [:reed] (use needinfo?)
no flags Details | Diff | Review
1.9.2 version (15.96 KB, patch)
2010-07-30 04:55 PDT, Martin Stránský
christian: approval1.9.2.11-
christian: approval1.9.2.9-
Details | Diff | Review

Description siimo 2005-10-06 05:17:24 PDT
Since gnome desktop that firefox attempts to blend with on linux uses the
freedesktop specs for clipboard management, anything copied from firefox is lost
when firefox is closed as firefox does not follow these specifications:
http://www.freedesktop.org/wiki/Standards_2fclipboards_2dspec

in other applications copying something and closing the application does not
cause the copied content to be lost (this clipboard manager was implemented in
gnome 2.12)
Comment 1 Adam Guthrie 2005-10-14 13:35:57 PDT
*** Bug 312485 has been marked as a duplicate of this bug. ***
Comment 2 Thomas Winwood 2006-02-24 14:30:59 PST
I'd like to bring this to the attention of the necessary developers so we can get this in - it's annoying having Firefox not interact properly with gnome-clipboard-daemon (or anything else for that matter).
Comment 3 Philip Withnall (unavailable) 2006-03-16 10:20:13 PST
*** Bug 330704 has been marked as a duplicate of this bug. ***
Comment 4 Boris Zbarsky [:bz] 2006-04-16 21:00:50 PDT
I'm not sure I follow.  We follow the spec at http://standards.freedesktop.org/clipboards-spec/clipboards-0.1.txt just fine -- the Ctrl-c key combination uses CLIPBOARD while mouse-highlight uses PRIMARY.

The behavior I observe in Mozilla is the same as the behavior I observe in Gnumeric and the Terminal thing that Fedora Core 4 ships with -- the CLIPBOARD is available until the app quits, but not after that.

So as far as I can tell, this bug is invalid -- it's demanding that we implement a specification that we already implement and implying that doing that will change what happens when the browser is shutdown (which looks like an unrelated issue to me).

What am I missing?
Comment 5 Thomas Winwood 2006-04-16 22:22:16 PDT
The problem from my perspective is that Firefox somehow bypasses gnome-clipboard-daemon which is used for ensuring that CLIPBOARD does exist after the program quits.
Comment 6 Rimas Kudelis 2006-05-28 13:42:38 PDT
I guess it's a duplicate of Bug 23386. Someone should probably dupe one of these against the other.
Comment 7 Rimas Kudelis 2006-05-28 14:33:08 PDT
Btw the Summary field of this bug is really invalid. AFAICS, gnome-clipboard-daemon is not a part of the Freedesktop.org specification.
Comment 8 Rimas Kudelis 2006-05-28 15:35:46 PDT
One last thing (sorry for too many messages). I'm using GNOME and Cutting and Pasting from Gedit (as an example) works even after I quit it. However, I've just checked and I don't see any gnome-clipboard-daemon or -manager banary running or even existing on my system. However I've found out an announcement of GNOME 2.12 [1], which states that that version of GNOME is managing the clipboard in a new, much better, way. It also states that this feature is based on a freedesktop.org specification.

The summary of this bug should be changed to something more exact, but I'm not sure about to what. However, the developers of Mozilla may want to look at the list of clipboard-related links in freedesktop.org[2].

[1] http://www.gnome.org/~davyd/gnome-2-12/
[2] http://freedesktop.org/wiki/FindPage?action=titlesearch&value=clipboard
Comment 9 Rimas Kudelis 2006-05-28 15:47:03 PDT
(one last message for now, I promise).
It's the link that is bad, not the summary. Someone please change the link to http://freedesktop.org/wiki/Standards_2fclipboard_2dmanager_2dspec

Also, please dupe Bug 23386 against this one.
Comment 10 Rimas Kudelis 2006-06-06 06:22:01 PDT
could anybody apply the changes listed in my last comment, please?
Comment 11 Rimas Kudelis 2006-09-14 14:04:45 PDT
*** Bug 23386 has been marked as a duplicate of this bug. ***
Comment 12 Rimas Kudelis 2006-09-14 14:08:04 PDT
Changing the URL and reassigning the bug to Toolkits/Widgets, as it seems more appropriate to go there.
Comment 13 disgruntled.toaster 2007-04-28 03:31:51 PDT
Anyone know if a freedesktop clipboard fix will be in Firefox 3?  Firefox sticks out like a sore thumb due to this issue and makes it look unpolished, even though it ships with many Linux distros.  (there are multiple bugs in Ubuntu's Launchpad about this as well, if devs need more info: https://bugs.launchpad.net/ubuntu/+source/firefox/+bug/21202 https://bugs.launchpad.net/ubuntu/+source/firefox/+bug/69613
https://bugs.launchpad.net/bugs/81506 https://bugs.launchpad.net/ubuntu/+source/firefox/+bug/90477 )
Comment 14 Rimas Kudelis 2007-04-28 08:49:13 PDT
I don't think this bug should be considered an RFE anymore. It's much rather a major loss of functionality, IMO.
Comment 15 Trisha 2007-09-28 22:49:27 PDT
Hi,

I want to solve this problem whether a bug or not..
Can anybody help me, I want to know where exactly this problem should be delt with.
I mean, which file in the source code contains the relevant code.
Comment 16 DStile 2008-01-16 16:03:58 PST
Since the URL field leads to a page that doesn't exist, I am pointing it to current location of Clipboard Manager specification:
http://freedesktop.org/wiki/Specifications/clipboard-manager-spec

Trisha: This bug is not about the Clipboard spec, which as B Zbarsky rightly pointed out, Firefox already implements, but rather the Clipboard *Manager* spec.
Comment 17 Eldmannen 2008-03-19 17:46:23 PDT
Please fix this.

This annoys me a lot. I must use Epiphany or other browser, if you cant fix it.
Comment 18 martin 2008-04-13 12:28:20 PDT
This bug is _the_ most annoying bug for Firefox on Ubuntu. I'm hit my this bug at least once every week.
Comment 19 Andrew Sutherland [:asuth] 2008-04-17 17:31:59 PDT
*** Bug 221183 has been marked as a duplicate of this bug. ***
Comment 20 Colin Dean 2008-05-02 13:43:03 PDT
This bug is getting aged, and it is still not fixed, nor has there been any progress on it. It would be great if this was fixed for Firefox 3.0 final.
Comment 21 Rimas Kudelis 2008-05-03 04:25:00 PDT
(In reply to comment #20)
> This bug is getting aged, and it is still not fixed, nor has there been any
> progress on it. It would be great if this was fixed for Firefox 3.0 final.

Don't expect it to happen for 3.0, I think it's feature complete already. Let's hope for the next major release.
Comment 22 Daniel Holbert [:dholbert] 2008-11-14 17:16:00 PST
*** Bug 412782 has been marked as a duplicate of this bug. ***
Comment 23 Yann Dirson 2009-01-15 07:53:42 PST
When checking what happens to the clipboard content on exit [1], we can see that any xulrunner application clears the clipboard (or sets it to be empty).  I hope this can help to pinpoint where the problem lies.

[1] eg. when running xclipboard to monitor successive contents, but under an environment that does mess by itself with the clipboard and selection, that is eg. plain fvwm, or kde 3.5 with klipper set not so sync clipboard and selection, and not to forbid empty clipboard
Comment 24 MATi 2009-02-09 08:35:07 PST
I was working on some article (in a web-based cms, sadly without autosave or drafts) and decided to save it on a usb pendrive in order to continue later on my friend's machine. So I copied the content, closed firefox, opened my editor... but couldn't paste it :/

The bug's importance should be raised, it causes *data loss* :/
Please, fix this issue.
Comment 25 robbertvandendoorn 2009-02-09 12:29:40 PST
I completely agree, MATi.

Why does it take so long to fix this bug? Why don't the developers see how important this is? It's just ridiculous this still doesn't work. Being able to copy / paste is one the basic features of an application and in my opinion those features have the highest priority to work on. After all those years this basic function still doesn't work in Firefox, but a lot of other features have been added in those years. In my opinion this is a wrong choice. Working on important basic features must have a much higher priority than working on all those features which are nice to have. Fix all those bugs first and introduce new features when those bugs are fixed.

This is not only a problem with Firefox. It seems to be a basic problem of open source projects. Looks like open source developers develop an application and keep on adding new features without first fixing existing bugs. I'm thinking about Gnomes Nautilus with its bugged list view (not being able to drag and drop a file into a folder when there are more items than fit on the screen).

Please, fix those bugs first and then start adding new features.
Comment 26 Rickard Edström 2009-06-22 12:27:05 PDT
Created attachment 384458 [details] [diff] [review]
Possible clipboard fix
Comment 27 Rickard Edström 2009-06-22 12:28:52 PDT
It seems to work for me, feel free to try, modify, and/or commit it.
Comment 28 Magnus Melin 2009-06-22 12:40:55 PDT
Richard: you need to get the patch reviewed - see https://developer.mozilla.org/en/Getting_your_patch_in_the_tree
Comment 29 Rickard Edström 2009-06-22 13:18:17 PDT
OK, have read a bit in the review info link, but I don't want to be an assignee or anything atm, just posted a patch that I thought could be useful.
Comment 30 Rimas Kudelis 2009-06-23 00:39:00 PDT
Rickard: I think you may at least want to ask for caillon's review.
Comment 31 Martin Stránský 2009-06-23 06:44:01 PDT
Comment on attachment 384458 [details] [diff] [review]
Possible clipboard fix

Can you please check this patch?
Comment 32 Martin Stránský 2009-07-16 05:35:14 PDT
Comment on attachment 384458 [details] [diff] [review]
Possible clipboard fix

Karl, can you check this one please?
Comment 33 Karl Tomlinson (ni?:karlt) 2009-07-23 21:39:28 PDT
Comment on attachment 384458 [details] [diff] [review]
Possible clipboard fix

Thank you, Rickard for submitting the patch.

It looks like gtk_clipboard_store() is a suitable function to use, but I don't
think we should be using it so often.

My reading of http://freedesktop.org/wiki/ClipboardManager is that it is
intended that the app should only ask the clipboard manager to save the
clipboard when the app is about to exit.  I think the following clauses imply
this:

  "If a client needs to exit while owning the CLIPBOARD selection, it should
   request the clipboard manager to take over the ownership of the clipboard,
   using the SAVE_TARGETS mechanism."

   "the clipboard owner will quit upon receiving the SelectionNotify"

It looks like gtk_clipboard_store() passes ownership to the clipboard manager
immediately, and I don't think we want to do this every time
nsClipboard::SetData is called with new data for the CLIPBOARD.

Saving the clipboard involves converting the data (possibly of significant size) to a number of different target formats and transferring each of these (possibly across a network) to the manager.

The clipboard manager may even prompt to check whether the user really wants
to do this.  (The spec says "possibly refusing to save large amounts of data,
or asking the user before doing so".)
Comment 34 Martin Stránský 2009-10-22 13:54:24 PDT
Created attachment 407846 [details] [diff] [review]
an updated patch

Reworked patch, data are transfered to clipboard when app quits only.
Comment 35 Karl Tomlinson (ni?:karlt) 2009-10-27 22:00:31 PDT
Comment on attachment 407846 [details] [diff] [review]
an updated patch

What makes things awkward here is that Mozilla is using low level selection
functions and signals on its own GtkWidget mWidget to set data on the
clipboard, but gtk_clipboard_store() only works on higher level GtkClipboards
which have their own GtkWidget.  There is no way to associate Mozilla's
selections on its own GtkWidget with GtkClipboards.

The patch here works around that (on quit) by changing the selection owner
from nsClipboard's mWidget to a GtkClipboard and adds code to convert the
nsITransferable to GtkClipboard format.

I'm not so enthusiastic though about having yet another place where
nsITransferables are converted to GtkSelectionData (and targets).

The conversion in nsClipboard::Store() of this patch does convert from
text/unicode _or_ images, but doesn't convert both text _and_ images (for
which support was added in bug 518249) and doesn't convert to other mime types
such as text/html (and maybe text/uri-list and text/plain, if they get used).

Also, the Clipboard Manager Specification says "Clients which support the
SAVE_TARGETS mechanism should announce this by listing SAVE_TARGETS as a
target for the CLIPBOARD", but with this patch that target only gets added to
the clipboard briefly on quit.  I assume the intention is that the
SAVE_TARGETS target informs the clipboard manager that it doesn't need to
preemptively convert the clipboard selection whenever this app changes it.

I think the best solution is to make nsClipboard use GtkClipboards for setting
data.  (It already uses GtkClipboard for getting data.)

nsClipboard::SetData() would use gtk_clipboard_set_with_data() and
gtk_clipboard_set_can_store() instead of gtk_selection_owner_set(),
gtk_selection_clear_targets(), and gtk_selection_add_target(s)().
(m*Owner and m*Transferable need to be set after gtk_clipboard_set_with_data()
as the GtkClipboardClearFunc will erase them.)

nsClipboard would no longer need mWidget.  invisible_selection_get_cb() and
selection_clear_event_cb() would be replaced with the similar callbacks for
gtk_clipboard_set_with_data().

nsClipboard::SelectionGetEvent() would be similar, except the unused arguments
would be removed.

nsClipboard::SelectionClearEvent() would get a GtkClipboard instead of a
GdkEventSelection.  That means the aEvent->selection is no longer available,
but the type of selection can be determined by comparing the GtkClipboard*
with gtk_clipboard_get(GDK_SELECTION_CLIPBOARD or GDK_SELECTION_PRIMARY).

nsClipboard::Store() would simply just call gtk_clipboard_store() and
nsClipboard::SelectionGetEvent() would be used for the conversion.

Little nits:

>+#define APP_QUIT    "quit-application"

>+    os->AddObserver(this, "quit-application", PR_FALSE);

>+    if (strcmp(aTopic, APP_QUIT) == 0) {

I'd like each of these topics to be represented consistently.

As "quit-application" is only used twice, I'd suggest just using the string
literal each time.

>+    if (aTransferable == nsnull)

Mozilla style is "!aTransferable".
https://developer.mozilla.org/En/Mozilla_Coding_Style_Guide

>+    // Save global clipboard content to gtk
>+    nsresult  Store               (void);
> 
> private:

Let's make Store() private unless you have other uses in mind.
Comment 36 Martin Stránský 2009-11-02 03:59:28 PST
Okay, It would be better and more clear solution. I'll rewrite the patch...
Comment 37 Martin Stránský 2009-11-06 05:11:07 PST
Created attachment 410768 [details] [diff] [review]
v3

A next version. 

Store() has been removed because gtk_clipboard_set_can_store() is enough.

Data are set by gtk_clipboard_set_can_store(), GtkClipboardClearFunc is not used because we don't need that (do we?).
Comment 38 Karl Tomlinson (ni?:karlt) 2009-11-08 15:22:56 PST
Comment on attachment 410768 [details] [diff] [review]
v3

I like this much better, thank you.

(In reply to comment #37)
> Store() has been removed because gtk_clipboard_set_can_store() is enough.

That would be enough when Gecko is embedded in GTK apps using gtk_main
(because that calls _gtk_clipboard_store_all), but I don't understand how it
would work with a XUL app, which uses lower level event functions.

> GtkClipboardClearFunc is not used because we don't need that (do we?).

GtkClipboardClearFunc provides notification that something else owns the
selection.  nsClipboard::SelectionClearEvent called EmptyClipboard which
released the nsITransferable and notified the owner with:

            mSelectionOwner->LosingOwnership(mSelectionTransferable);

This comment makes me suspect that this is important (though comments that say why are more helpful):

>-    // XXX make sure to set up the selection_clear event

Nits:

>+    bool ImagesAdded = PR_FALSE;

I'd like avoid mixing types here.  Either of the following would be OK:

  PRBool ImagesAdded = PR_FALSE;
  bool ImagesAdded = false;

>+    gint nTargetsNum;

Just |nTargets| or |numTargets|

>+    if(gtk_clipboard_set_with_data(gtkClipboard, gtkTargets, nTargetsNum, 

Mozilla style is a space after "if".

>-    nsCOMPtr<nsITransferable> trans = GetTransferable(whichClipboard);
>+    nsCOMPtr<nsITransferable> trans = GetTransferable(whichClipboard);    

Unnecessary extra whitespace.
Comment 39 Martin Stránský 2009-11-09 07:01:26 PST
Created attachment 411182 [details] [diff] [review]
v4

Should address the comments...
Comment 40 Karl Tomlinson (ni?:karlt) 2009-11-09 12:34:20 PST
Comment on attachment 411182 [details] [diff] [review]
v4

>+nsClipboard::Store(void)
>+{
>+    if (mSelectionTransferable) {
>+        GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
>+        gtk_clipboard_store(clipboard);
>+    }
>+    if (mGlobalTransferable) {

http://freedesktop.org/wiki/ClipboardManager seems only intended for the
CLIPBOARD selection, not the PRIMARY.  Also _gtk_clipboard_store_all() only
stores the CLIPBOARD, and gtk_clipboard_set_can_store() doesn't do anything when
clipboard->selection != GDK_SELECTION_CLIPBOARD so this first block won't do
anything, and so should be removed.

>+    PRBool ImagesAdded = PR_FALSE;

Variables in Mozilla usually start with lower case, so |imagesAdded|.
(Class names and function names start with upper case.)

>+    if (gtk_clipboard_set_with_data(gtkClipboard, gtkTargets, numTargets, 
>+                                    clipboard_get_cb, clipboard_clear_cb, (gpointer)this))

The (gpointer) cast should be unnecessary because |this| is a |void*|.

>+        if (aWhichClipboard == kSelectionClipboard) {
>+            mSelectionOwner = aOwner;
>+            mSelectionTransferable = aTransferable;
>+        }
>+        else {
>+            mGlobalOwner = aOwner;
>+            mGlobalTransferable = aTransferable;
>+        }
> 
>+        gtk_clipboard_set_can_store(gtkClipboard, gtkTargets, numTargets);

Can you move gtk_clipboard_set_can_store to the else block, please.  There's
no difference in functionality because it won't do anything when
aWhichClipboard == kSelectionClipboard, but it makes the intentions clearer.

r=karlt with these changes.
Comment 41 Martin Stránský 2009-11-10 06:12:38 PST
Created attachment 411407 [details] [diff] [review]
v4+updates
Comment 42 Martin Stránský 2009-11-10 06:13:31 PST
is sr requested here?
Comment 43 Robert O'Callahan (:roc) (Exited; email my personal email if necessary) 2009-11-10 12:05:09 PST
No
Comment 44 Karl Tomlinson (ni?:karlt) 2009-11-10 14:33:49 PST
Comment on attachment 411407 [details] [diff] [review]
v4+updates

>+    // Store current clipboard content to GTK clipboard

"Ask the clipboard manager to store the current clipboard content" would be
more accurate.

No need to ask for further review (unless you want to make further changes).  Thank you!
Comment 45 martin 2009-11-25 10:01:01 PST
If no further review is necessary, when will this patch land and on what branches? There are hordes of restless users in this downstream bug and it would be nice to give them some sort of bugfix ETA:
https://bugs.launchpad.net/ubuntu/+bug/11334
Comment 46 Daniel Holbert [:dholbert] 2009-11-25 10:54:21 PST
(In reply to comment #45)
> If no further review is necessary, when will this patch land

When someone checks it in on Martin Stránský's behalf. (Martin, could you post one final version with the comment-tweak that Karl suggested in comment 44?  Then we can add the "checkin-needed" keyword to this bug, which will get your final patch noticed & checked in.)

> and on what
> branches?

Per the current settings of the "wanted1.9.2" and "blocking1.9.2" flags at the top of this bug, this isn't targeted for landing on any branches.  Just on trunk (for Firefox 3.7+).
Comment 47 Reed Loden [:reed] (use needinfo?) 2009-11-25 20:09:11 PST
Created attachment 414679 [details] [diff] [review]
what I landed

http://hg.mozilla.org/mozilla-central/rev/270a70535807
Comment 48 Reed Loden [:reed] (use needinfo?) 2009-11-28 19:09:12 PST
I'm seeing this on the console a lot...

Gtk-CRITICAL **: gtk_clipboard_get_for_display: assertion `!display->closed' failed
Comment 49 Kevin Brosnan 2010-05-05 06:17:03 PDT
*** Bug 563913 has been marked as a duplicate of this bug. ***
Comment 50 Martin Stránský 2010-07-14 06:49:19 PDT
If we take it to branches we need bug 518249 and bug 531580 too.
Comment 51 Marc 2010-07-28 02:56:40 PDT
I have this problem on Windows Vista Home Premium SP2 English. Firefox 3.6.8 Final English. Copy url from adresbar, restart firefox, then paste copied url, and clipboard is empty...
Comment 52 Rimas Kudelis 2010-07-28 09:05:47 PDT
Marc, this particular bug is Linux-specific. You should file a new one if you happen to have this same problem on Windows. Clipboard implementations are completely different among different operating systems, so Windows issues are totally irrelevant in this Linux bug.
Comment 53 Marc 2010-07-28 10:10:31 PDT
(In reply to comment #52)
> Marc, this particular bug is Linux-specific. You should file a new one if you
> happen to have this same problem on Windows. Clipboard implementations are
> completely different among different operating systems, so Windows issues are
> totally irrelevant in this Linux bug.

Ok, thanks :)
Comment 54 Martin Stránský 2010-07-30 04:55:02 PDT
Created attachment 461511 [details] [diff] [review]
1.9.2 version
Comment 55 christian 2010-08-09 10:28:27 PDT
Comment on attachment 461511 [details] [diff] [review]
1.9.2 version

We will not be taking this for .9. Moving approval request forward.
Comment 56 christian 2010-08-27 10:38:03 PDT
There is an unfixed dependency (bug 531580) and a fixed dependency (bug 518249) that depends on an unfixed bug (bug 552449).

Until those are resolved we can't take this on the branches.

Note You need to log in before you can comment on or make changes to this bug.