summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/shell_dialogs_mac.mm
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 15:54:24 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 15:54:24 +0000
commit74f4183d376412c21943477c4f721b4838c01117 (patch)
treec996f214512254cc3b3646f35cccd3ea535a8fc7 /chrome/browser/cocoa/shell_dialogs_mac.mm
parent07f95c3adba7041b51da5243db704b26b2f0498b (diff)
downloadchromium_src-74f4183d376412c21943477c4f721b4838c01117.zip
chromium_src-74f4183d376412c21943477c4f721b4838c01117.tar.gz
chromium_src-74f4183d376412c21943477c4f721b4838c01117.tar.bz2
Keep packages from being selected in a Cocoa open single file dialog.
Patch from Vernon Tang. BUG=33483 TEST=Check that user can't select an .app using an html file input element. Check that the "load unpacked extension" and "pack extension" browse dialogs in chrome://extensions/ continue to work as expected. Review URL: http://codereview.chromium.org/548199 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37693 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/shell_dialogs_mac.mm')
-rw-r--r--chrome/browser/cocoa/shell_dialogs_mac.mm24
1 files changed, 24 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/shell_dialogs_mac.mm b/chrome/browser/cocoa/shell_dialogs_mac.mm
index c1f0b98..64acbd3 100644
--- a/chrome/browser/cocoa/shell_dialogs_mac.mm
+++ b/chrome/browser/cocoa/shell_dialogs_mac.mm
@@ -31,6 +31,9 @@ class SelectFileDialogImpl;
withReturn:(int)returnCode
context:(void *)context;
+// NSSavePanel delegate method
+- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename;
+
@end
// Implementation of SelectFileDialog that shows Cocoa dialogs for choosing a
@@ -63,6 +66,8 @@ class SelectFileDialogImpl : public SelectFileDialog {
const std::vector<FilePath>& files,
int index);
+ bool ShouldEnableFilename(NSPanel* dialog, NSString* filename);
+
struct SheetContext {
Type type;
NSWindow* owning_window;
@@ -85,6 +90,9 @@ class SelectFileDialogImpl : public SelectFileDialog {
// The set of all parent windows for which we are currently running dialogs.
std::set<NSWindow*> parents_;
+ // A map from file dialogs to their types.
+ std::map<NSPanel*, Type> type_map_;
+
DISALLOW_COPY_AND_ASSIGN(SelectFileDialogImpl);
};
@@ -175,6 +183,7 @@ void SelectFileDialogImpl::SelectFile(
[dialog setRequiredFileType:base::SysUTF8ToNSString(default_extension)];
params_map_[dialog] = params;
+ type_map_[dialog] = type;
SheetContext* context = new SheetContext;
context->type = type;
@@ -203,6 +212,7 @@ void SelectFileDialogImpl::SelectFile(
[open_dialog setCanChooseDirectories:NO];
}
+ [open_dialog setDelegate:bridge_.get()];
[open_dialog beginSheetForDirectory:default_dir
file:default_filename
types:allowed_file_types
@@ -222,6 +232,7 @@ void SelectFileDialogImpl::FileWasSelected(NSPanel* dialog,
void* params = params_map_[dialog];
params_map_.erase(dialog);
parents_.erase(parent_window);
+ type_map_.erase(dialog);
if (!listener_)
return;
@@ -293,6 +304,15 @@ NSView* SelectFileDialogImpl::GetAccessoryView(const FileTypeInfo* file_types,
return accessory_view;
}
+bool SelectFileDialogImpl::ShouldEnableFilename(NSPanel* dialog,
+ NSString* filename) {
+ // If this is a single open file dialog, disable selecting packages.
+ if (type_map_[dialog] != SELECT_OPEN_FILE)
+ return true;
+
+ return ![[NSWorkspace sharedWorkspace] isFilePackageAtPath:filename];
+}
+
@implementation SelectFileDialogBridge
- (id)initWithSelectFileDialogImpl:(SelectFileDialogImpl*)s {
@@ -348,4 +368,8 @@ NSView* SelectFileDialogImpl::GetAccessoryView(const FileTypeInfo* file_types,
[panel release];
}
+- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename {
+ return selectFileDialogImpl_->ShouldEnableFilename(sender, filename);
+}
+
@end