tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebKit / mac / WebCoreSupport / WebOpenPanelResultListener.mm
1 /*
2  * Copyright (C) 2008 Apple 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
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #import "WebOpenPanelResultListener.h"
27
28 #import <WebCore/FileChooser.h>
29 #import <wtf/PassRefPtr.h>
30
31 using namespace WebCore;
32
33 @implementation WebOpenPanelResultListener
34
35 - (id)initWithChooser:(PassRefPtr<FileChooser>)chooser
36 {
37     self = [super init];
38     if (!self)
39         return nil;
40     _chooser = chooser.leakRef();
41     return self;
42 }
43
44 #ifndef NDEBUG
45 - (void)dealloc
46 {
47     ASSERT(!_chooser);
48     [super dealloc];
49 }
50
51 - (void)finalize
52 {
53     ASSERT(!_chooser);
54     [super finalize];
55 }
56 #endif
57
58 - (void)cancel
59 {
60     ASSERT(_chooser);
61     if (!_chooser)
62         return;
63     _chooser->deref();
64     _chooser = 0;
65 }
66
67 - (void)chooseFilename:(NSString *)filename
68 {
69     ASSERT(_chooser);
70     if (!_chooser)
71         return;
72     _chooser->chooseFile(filename);
73     _chooser->deref();
74     _chooser = 0;
75 }
76
77 - (void)chooseFilenames:(NSArray *)filenames
78 {
79     ASSERT(_chooser);
80     if (!_chooser)
81         return;
82     int count = [filenames count]; 
83     Vector<String> names(count);
84     for (int i = 0; i < count; i++)
85         names[i] = [filenames objectAtIndex:i];
86     _chooser->chooseFiles(names);
87     _chooser->deref();
88     _chooser = 0;
89 }
90
91 @end