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

Side by Side Diff: webkit/plugins/ppapi/ppb_file_chooser_impl.cc

Issue 9949038: Fix Pepper file chooser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/plugins/ppapi/ppb_file_chooser_impl.h" 5 #include "webkit/plugins/ppapi/ppb_file_chooser_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 virtual ~FileChooserCompletionImpl() {} 52 virtual ~FileChooserCompletionImpl() {}
53 53
54 virtual void didChooseFile(const WebVector<WebString>& file_names) { 54 virtual void didChooseFile(const WebVector<WebString>& file_names) {
55 std::vector<std::string> files; 55 std::vector<std::string> files;
56 for (size_t i = 0; i < file_names.size(); i++) 56 for (size_t i = 0; i < file_names.size(); i++)
57 files.push_back(file_names[i].utf8()); 57 files.push_back(file_names[i].utf8());
58 58
59 file_chooser_->StoreChosenFiles(files); 59 file_chooser_->StoreChosenFiles(files);
60
61 // It is the responsibility of this method to delete the instance.
62 delete this;
60 } 63 }
61 virtual void didChooseFile(const WebVector<SelectedFileInfo>& file_names) { 64 virtual void didChooseFile(const WebVector<SelectedFileInfo>& file_names) {
62 std::vector<std::string> files; 65 std::vector<std::string> files;
63 for (size_t i = 0; i < file_names.size(); i++) 66 for (size_t i = 0; i < file_names.size(); i++)
64 files.push_back(file_names[i].path.utf8()); 67 files.push_back(file_names[i].path.utf8());
65 68
66 file_chooser_->StoreChosenFiles(files); 69 file_chooser_->StoreChosenFiles(files);
70
71 // It is the responsibility of this method to delete the instance.
72 delete this;
67 } 73 }
68 74
69 private: 75 private:
70 scoped_refptr<PPB_FileChooser_Impl> file_chooser_; 76 scoped_refptr<PPB_FileChooser_Impl> file_chooser_;
71 }; 77 };
72 78
73 } // namespace 79 } // namespace
74 80
75 PPB_FileChooser_Impl::PPB_FileChooser_Impl( 81 PPB_FileChooser_Impl::PPB_FileChooser_Impl(
76 PP_Instance instance, 82 PP_Instance instance,
(...skipping 26 matching lines...) Expand all
103 } 109 }
104 110
105 PPB_FileChooser_API* PPB_FileChooser_Impl::AsPPB_FileChooser_API() { 111 PPB_FileChooser_API* PPB_FileChooser_Impl::AsPPB_FileChooser_API() {
106 return this; 112 return this;
107 } 113 }
108 114
109 void PPB_FileChooser_Impl::StoreChosenFiles( 115 void PPB_FileChooser_Impl::StoreChosenFiles(
110 const std::vector<std::string>& files) { 116 const std::vector<std::string>& files) {
111 next_chosen_file_index_ = 0; 117 next_chosen_file_index_ = 0;
112 118
119 // It is possible that |callback_| has been run: before the user takes action
120 // on the file chooser, the page navigates away and causes the plugin module
121 // (whose instance requested to show the file chooser) to be destroyed. In
122 // that case, |callback_| has been aborted when we get here.
123 if (!TrackedCallback::IsPending(callback_)) {
124 // To be cautious, reset our internal state.
125 output_.Reset();
126 chosen_files_.clear();
127 return;
128 }
129
113 std::vector< scoped_refptr<Resource> > chosen_files; 130 std::vector< scoped_refptr<Resource> > chosen_files;
114 for (std::vector<std::string>::const_iterator it = files.begin(); 131 for (std::vector<std::string>::const_iterator it = files.begin();
115 it != files.end(); ++it) { 132 it != files.end(); ++it) {
116 #if defined(OS_WIN) 133 #if defined(OS_WIN)
117 FilePath file_path(base::SysUTF8ToWide(*it)); 134 FilePath file_path(base::SysUTF8ToWide(*it));
118 #else 135 #else
119 FilePath file_path(*it); 136 FilePath file_path(*it);
120 #endif 137 #endif
121 138
122 chosen_files.push_back(scoped_refptr<Resource>( 139 chosen_files.push_back(scoped_refptr<Resource>(
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 continue; 264 continue;
248 StringToLowerASCII(&mime_type); 265 StringToLowerASCII(&mime_type);
249 normalized_mime_type_list.push_back(WebString::fromUTF8(mime_type.data(), 266 normalized_mime_type_list.push_back(WebString::fromUTF8(mime_type.data(),
250 mime_type.size())); 267 mime_type.size()));
251 } 268 }
252 return normalized_mime_type_list; 269 return normalized_mime_type_list;
253 } 270 }
254 271
255 } // namespace ppapi 272 } // namespace ppapi
256 } // namespace webkit 273 } // namespace webkit
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698