Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Issue 1513413002: Enable "Hide Extension" option when "Save Link As" on the Mac

Created:
5 years ago by shrike
Modified:
4 years, 10 months ago
CC:
chromium-reviews, darin-cc_chromium.org, jam, jochen+watch_chromium.org, mkwst+moarreviews-shell_chromium.org, mlamouri+watch-content_chromium.org, Peter Beverloo, Randy Smith (Not in Mondays)
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Enable "Hide Extension" option when "Save Link As" on the Mac When you choose "Save Link As..." on the Mac, the file picker includes an option to hide the downloaded file's extension in the Finder. This cl propagates this boolean so that the downloaded file, at the end of the download process, has its file extension hidden. To make it easier to understand what I did to implement this change, the following describes how the "Hide Extension" flag makes it from the file picker dialog to the point at which the download file's extension gets hidden. The "Hide Extension" setting comes from the Mac version of SelectFileDialogImpl::FileWasSelected(), which stores it in a ui::SelectedFileInfo that's returned to the DownloadFilePicker via its FileSelectedWithExtraInfo() method. FileSelectedWithExtraInfo() extracts the flag and passes it to DownloadFilePicker's OnFileSelected() method, which passes the flag to its file_selected_callback_, which is a call to DownloadTargetDeterminer's PromptUserForDownloadPathDone() method, defined by the FileSelectedCallback interface. The DownloadTargetDeterminer stashes the "Hide Extension" flag until its state machine completes at ScheduleCallbackAndDeleteSelf(), where it calls its completion_callback_. It places the flag inside the DownloadTargetInfo which is a parameter to the callback. The callback invokes ChromeDownloadManagerDelegate's OnDownloadTargetDetermined() method, which sends the flag to its callback, which is defined in DownloadTargetCallback. This same interface is redeclared by DownloadItemImpl, which allows a DownloadItem to be the callback destination of the DownloadTargetDeterminer. The callback invokes DownloadItemImpl::OnDownloadTargetDetermined(), which stores the flag in a DownloadFile (DownloadFile actually stores the flag in the BaseFile that it wraps; this is where the flag is ultimately needed anyway). Eventually DownloadFileImpl::RenameWithRetryInternal() calls file_.AnnotateWithSourceInformation(). base_file_mac.cc's modified version of this method now calls the newly-added SetExtensionHiddenForFile() if the BaseFile’s "Hide Extension" flag is true. The changes to the other classes, unittests, and browsertests are unfortunate collateral damage resulting from piping the "Hide Extension" flag through so many interfaces. BUG=540874

Patch Set 1 #

Total comments: 10

Patch Set 2 : Fix nits. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+214 lines, -49 lines) Patch
M chrome/browser/download/chrome_download_manager_delegate.cc View 1 chunk +2 lines, -1 line 0 comments Download
M chrome/browser/download/chrome_download_manager_delegate_unittest.cc View 2 chunks +3 lines, -2 lines 0 comments Download
M chrome/browser/download/download_file_picker.h View 2 chunks +7 lines, -3 lines 0 comments Download
M chrome/browser/download/download_file_picker.cc View 2 chunks +14 lines, -4 lines 0 comments Download
M chrome/browser/download/download_target_determiner.h View 2 chunks +3 lines, -1 line 0 comments Download
M chrome/browser/download/download_target_determiner.cc View 4 chunks +4 lines, -1 line 0 comments Download
M chrome/browser/download/download_target_determiner_delegate.h View 1 chunk +2 lines, -2 lines 0 comments Download
M chrome/browser/download/download_target_determiner_unittest.cc View 5 chunks +7 lines, -7 lines 0 comments Download
M chrome/browser/download/download_target_info.h View 1 chunk +4 lines, -0 lines 0 comments Download
M chrome/browser/download/download_test_file_activity_observer.cc View 1 chunk +2 lines, -1 line 0 comments Download
M chrome/browser/lifetime/browser_close_manager_browsertest.cc View 1 chunk +4 lines, -2 lines 0 comments Download
M content/browser/download/base_file.h View 2 chunks +6 lines, -0 lines 0 comments Download
M content/browser/download/base_file.cc View 2 chunks +6 lines, -1 line 0 comments Download
M content/browser/download/base_file_mac.cc View 1 chunk +7 lines, -0 lines 0 comments Download
M content/browser/download/download_file.h View 1 chunk +3 lines, -0 lines 0 comments Download
M content/browser/download/download_file_impl.h View 1 chunk +1 line, -0 lines 0 comments Download
M content/browser/download/download_file_impl.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M content/browser/download/download_item_impl.h View 1 chunk +2 lines, -1 line 0 comments Download
M content/browser/download/download_item_impl.cc View 2 chunks +6 lines, -1 line 0 comments Download
M content/browser/download/download_item_impl_delegate.h View 1 chunk +2 lines, -2 lines 0 comments Download
M content/browser/download/download_item_impl_delegate.cc View 1 chunk +2 lines, -1 line 0 comments Download
M content/browser/download/download_item_impl_unittest.cc View 9 chunks +10 lines, -9 lines 0 comments Download
M content/browser/download/download_manager_impl.cc View 1 chunk +2 lines, -1 line 0 comments Download
M content/browser/download/download_manager_impl_unittest.cc View 2 chunks +4 lines, -3 lines 0 comments Download
M content/browser/download/file_metadata_mac.h View 2 chunks +7 lines, -0 lines 0 comments Download
M content/browser/download/file_metadata_mac.mm View 1 1 chunk +11 lines, -0 lines 0 comments Download
A content/browser/download/file_metadata_unittest_mac.mm View 1 1 chunk +56 lines, -0 lines 0 comments Download
M content/browser/download/mock_download_file.h View 1 chunk +1 line, -0 lines 0 comments Download
M content/content_tests.gypi View 1 chunk +1 line, -0 lines 0 comments Download
M content/public/browser/download_manager_delegate.h View 1 chunk +2 lines, -1 line 0 comments Download
M content/shell/browser/shell_download_manager_delegate.cc View 3 chunks +5 lines, -3 lines 0 comments Download
M ui/shell_dialogs/select_file_dialog_mac.mm View 2 chunks +6 lines, -1 line 0 comments Download
M ui/shell_dialogs/selected_file_info.h View 1 chunk +8 lines, -0 lines 0 comments Download
M ui/shell_dialogs/selected_file_info.cc View 1 chunk +10 lines, -1 line 0 comments Download

Messages

Total messages: 19 (5 generated)
shrike
Hello, PTAL and let me know your thoughts on this cl. Thank you.
5 years ago (2015-12-11 20:35:43 UTC) #4
Avi (use Gerrit)
Random Mac nit-picky stuff. It's unfortunate that we have that boolean *everywhere* now, that we ...
5 years ago (2015-12-12 00:41:46 UTC) #5
jochen (gone - plz use gerrit)
+rdsmith for downloads
5 years ago (2015-12-14 12:30:53 UTC) #7
Randy Smith (Not in Mondays)
Lateralling to Asanka, who knows the Downloads UI code in general, and several of the ...
5 years ago (2015-12-14 12:34:04 UTC) #9
asanka
https://codereview.chromium.org/1513413002/diff/1/ui/shell_dialogs/select_file_dialog_mac.mm File ui/shell_dialogs/select_file_dialog_mac.mm (right): https://codereview.chromium.org/1513413002/diff/1/ui/shell_dialogs/select_file_dialog_mac.mm#newcode155 ui/shell_dialogs/select_file_dialog_mac.mm:155: if ([dialog isExtensionHidden]) { Doesn't this mean that the ...
5 years ago (2015-12-16 02:54:26 UTC) #10
shrike
On 2015/12/12 00:41:46, Avi wrote: > Random Mac nit-picky stuff. > > It's unfortunate that ...
5 years ago (2015-12-16 18:40:46 UTC) #11
shrike
https://codereview.chromium.org/1513413002/diff/1/content/browser/download/file_metadata_mac.mm File content/browser/download/file_metadata_mac.mm (right): https://codereview.chromium.org/1513413002/diff/1/content/browser/download/file_metadata_mac.mm#newcode173 content/browser/download/file_metadata_mac.mm:173: NSNumber* boolNumber = [NSNumber numberWithBool:hidden ? YES : NO]; ...
5 years ago (2015-12-16 19:04:12 UTC) #12
shrike
Hello reviewers, Happy New Year! Can you give me some feedback on this cl?
4 years, 11 months ago (2016-01-19 19:38:17 UTC) #13
shrike
Reviewers, this cl has made no progress for about 6 weeks. I would appreciate you ...
4 years, 10 months ago (2016-02-04 19:28:08 UTC) #14
jochen (gone - plz use gerrit)
asanka, can you have another look?
4 years, 10 months ago (2016-02-05 14:49:46 UTC) #15
asanka
Can a Mac person confirm that this is in fact desired behavior? It looks like ...
4 years, 10 months ago (2016-02-05 19:15:10 UTC) #16
shrike
On 2016/02/05 19:15:10, asanka wrote: > Can a Mac person confirm that this is in ...
4 years, 10 months ago (2016-02-05 20:05:14 UTC) #17
asanka
On 2016/02/05 20:05:14, shrike wrote: > On 2016/02/05 19:15:10, asanka wrote: > > Can a ...
4 years, 10 months ago (2016-02-05 22:03:50 UTC) #18
Avi (use Gerrit)
4 years, 10 months ago (2016-02-06 07:05:51 UTC) #19
On 2016/02/05 22:03:50, asanka wrote:
> On 2016/02/05 20:05:14, shrike wrote:
> > On 2016/02/05 19:15:10, asanka wrote:
> > > Can a Mac person confirm that this is in fact desired behavior? It looks
> like
> > > this CL is taking the property returned by [NSSavePanel isExtensionHidden]
> and
> > > then using it to manually hide the extension of the downloaded file.
Before
> we
> > > review the download code, I'd like to have some confirmation that this is
> the
> > > intended behavior.
> > > 
> > > Looking at the documentation for NSSavePanel's isExtensionHidden getter, I
> > see:
> > > 
> > > "  When the value of this property is YES, the extension-hiding checkbox
is
> > > visible and checked. You should rarely set this property, because the
state
> is
> > > saved on a per-application basis. Setting this property has no effect if
the
> > > user has chosen to show all file extensions in Finder. "
> > > 
> > > I see nothing indicating that the caller should take this value and then
use
> > it
> > > to manually hide the extension of the resulting filename. So what gives?
> > 
> > Are you asking for a Mac person to confirm that this is the desired
behavior,
> or
> > a Mac person other than me to confirm it? I have been writing Mac OS X code
> for
> > the past 15 years, and before that spent 11 years writing code for the NeXT
> > Machine/Rhapsody while a developer at several of my own start-ups, as an
> > employee at NeXT Computer, and as a manager of a lab of NeXT Machines in
1989.
> I
> > can confirm to you that I am a Mac person, and that I am using this obscure
> bit
> > of API correctly.
> >
> > Back when OS X first shipped there was a big stink about file extensions.
The
> > Mac, up until that point, hid file type info within each file. With the
switch
> > to OS X/UNIX, file type info was suddenly appended to the file name. So many
> Mac
> > users complained that Apple added the ability to hide file extensions. As OS
X
> > has gotten on in years, the issue of visible file extensions isn't as big as
> it
> > once was. I think the lack of adequate documentation for this API is a
result
> of
> > that. I also think this API is poorly worded.
> > 
> > I'm not sure what else to tell you beyond this. File extensions on the Mac
are
> > hidden on a per-file basis. You can select a file in the Finder and hide the
> > extension of an existing file, or click the Hide Extension checkbox in the
> Save
> > Panel to hide the file extension of a file you are about to create. Toggling
> > that button in the Save Panel hides the file extension in the textfield
where
> > you type the name of the new file, but it does *not* cause the file's
> extension
> > to actually be hidden in the file system (how could it - the Save Panel
knows
> > nothing about what your app is doing to save the file, and so does not know
> when
> > it can hide the extension). It is up to the application to read the value of
> the
> > Hide Extension checkbox and configure the file system to hide the extension
if
> > so directed. Nor does toggling the File Extension button govern the
visibility
> > of file extensions in the Finder.
> 
> Thank you for the background. I don't mean to question your judgement on
whether
> this behavior is correct or not.
> 
> But this CL introduces a lot of Mac OS X plumbing for a behavior that was not
> requested in a user bug report and one that isn't documented. At this point
I'd
> like to humbly request another Mac person (i.e. avi@) to evaluate whether this
> behavior should be added to Chrome because I don't consider myself qualified
to
> make this call. Based on my layman's perspective I'm having a hard time seeing
> how this [undocumented] behavior jives with user expectation given how
unlikely
> it is to be implemented correctly by someone who doesn't have the above
> background.
> 
> avi: ^^^
> 
> If it is in fact a matter of correctness that is likely to affect our users,
> then sure. If it's something that can be implemented in a manner that doesn't
> involve threading through multiple architectural layers (unlikely), then
great.
> I think given all the layers involved, there's a non-negligible maintenance
cost
> to adding this, which is why I'm asking.
> 
> Once that's resolved, I'd be happy to review the rest of the CL.

It's a legitimate feature that Mac users are missing and would expect.

The question is how to do this is 1) a non-hacky way and 2) a non-intrusive way.

Can we satisfy both?

Powered by Google App Engine
This is Rietveld 408576698