| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/glue/plugins/pepper_file_chooser.h" | 5 #include "webkit/glue/plugins/pepper_file_chooser.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 14 matching lines...) Expand all Loading... |
| 25 using WebKit::WebFileChooserCompletion; | 25 using WebKit::WebFileChooserCompletion; |
| 26 using WebKit::WebFileChooserParams; | 26 using WebKit::WebFileChooserParams; |
| 27 using WebKit::WebString; | 27 using WebKit::WebString; |
| 28 using WebKit::WebVector; | 28 using WebKit::WebVector; |
| 29 | 29 |
| 30 namespace pepper { | 30 namespace pepper { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 PP_Resource Create(PP_Instance instance_id, | 34 PP_Resource Create(PP_Instance instance_id, |
| 35 const PP_FileChooserOptions* options) { | 35 const PP_FileChooserOptions_Dev* options) { |
| 36 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); | 36 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
| 37 if (!instance) | 37 if (!instance) |
| 38 return 0; | 38 return 0; |
| 39 | 39 |
| 40 FileChooser* chooser = new FileChooser(instance, options); | 40 FileChooser* chooser = new FileChooser(instance, options); |
| 41 return chooser->GetReference(); | 41 return chooser->GetReference(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool IsFileChooser(PP_Resource resource) { | 44 bool IsFileChooser(PP_Resource resource) { |
| 45 return !!Resource::GetAs<FileChooser>(resource); | 45 return !!Resource::GetAs<FileChooser>(resource); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 60 if (!chooser) | 60 if (!chooser) |
| 61 return 0; | 61 return 0; |
| 62 | 62 |
| 63 scoped_refptr<FileRef> file_ref(chooser->GetNextChosenFile()); | 63 scoped_refptr<FileRef> file_ref(chooser->GetNextChosenFile()); |
| 64 if (!file_ref) | 64 if (!file_ref) |
| 65 return 0; | 65 return 0; |
| 66 | 66 |
| 67 return file_ref->GetReference(); | 67 return file_ref->GetReference(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 const PPB_FileChooser ppb_filechooser = { | 70 const PPB_FileChooser_Dev ppb_filechooser = { |
| 71 &Create, | 71 &Create, |
| 72 &IsFileChooser, | 72 &IsFileChooser, |
| 73 &Show, | 73 &Show, |
| 74 &GetNextChosenFile | 74 &GetNextChosenFile |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 class FileChooserCompletionImpl : public WebFileChooserCompletion { | 77 class FileChooserCompletionImpl : public WebFileChooserCompletion { |
| 78 public: | 78 public: |
| 79 FileChooserCompletionImpl(pepper::FileChooser* file_chooser) | 79 FileChooserCompletionImpl(pepper::FileChooser* file_chooser) |
| 80 : file_chooser_(file_chooser) { | 80 : file_chooser_(file_chooser) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 91 file_chooser_->StoreChosenFiles(files); | 91 file_chooser_->StoreChosenFiles(files); |
| 92 } | 92 } |
| 93 | 93 |
| 94 private: | 94 private: |
| 95 FileChooser* file_chooser_; | 95 FileChooser* file_chooser_; |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 } // namespace | 98 } // namespace |
| 99 | 99 |
| 100 FileChooser::FileChooser(PluginInstance* instance, | 100 FileChooser::FileChooser(PluginInstance* instance, |
| 101 const PP_FileChooserOptions* options) | 101 const PP_FileChooserOptions_Dev* options) |
| 102 : Resource(instance->module()), | 102 : Resource(instance->module()), |
| 103 delegate_(instance->delegate()), | 103 delegate_(instance->delegate()), |
| 104 mode_(options->mode), | 104 mode_(options->mode), |
| 105 accept_mime_types_(options->accept_mime_types), | 105 accept_mime_types_(options->accept_mime_types), |
| 106 completion_callback_() { | 106 completion_callback_() { |
| 107 } | 107 } |
| 108 | 108 |
| 109 FileChooser::~FileChooser() { | 109 FileChooser::~FileChooser() { |
| 110 } | 110 } |
| 111 | 111 |
| 112 // static | 112 // static |
| 113 const PPB_FileChooser* FileChooser::GetInterface() { | 113 const PPB_FileChooser_Dev* FileChooser::GetInterface() { |
| 114 return &ppb_filechooser; | 114 return &ppb_filechooser; |
| 115 } | 115 } |
| 116 | 116 |
| 117 void FileChooser::StoreChosenFiles(const std::vector<std::string>& files) { | 117 void FileChooser::StoreChosenFiles(const std::vector<std::string>& files) { |
| 118 next_chosen_file_index_ = 0; | 118 next_chosen_file_index_ = 0; |
| 119 std::vector<std::string>::const_iterator end_it = files.end(); | 119 std::vector<std::string>::const_iterator end_it = files.end(); |
| 120 for (std::vector<std::string>::const_iterator it = files.begin(); | 120 for (std::vector<std::string>::const_iterator it = files.begin(); |
| 121 it != end_it; it++) | 121 it != end_it; it++) |
| 122 chosen_files_.push_back( | 122 chosen_files_.push_back( |
| 123 new FileRef(module(), PP_FILESYSTEMTYPE_LOCALPERSISTENT, *it, "")); | 123 new FileRef(module(), PP_FILESYSTEMTYPE_LOCALPERSISTENT, *it, "")); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 146 } | 146 } |
| 147 | 147 |
| 148 scoped_refptr<FileRef> FileChooser::GetNextChosenFile() { | 148 scoped_refptr<FileRef> FileChooser::GetNextChosenFile() { |
| 149 if (next_chosen_file_index_ >= chosen_files_.size()) | 149 if (next_chosen_file_index_ >= chosen_files_.size()) |
| 150 return NULL; | 150 return NULL; |
| 151 | 151 |
| 152 return chosen_files_[next_chosen_file_index_++]; | 152 return chosen_files_[next_chosen_file_index_++]; |
| 153 } | 153 } |
| 154 | 154 |
| 155 } // namespace pepper | 155 } // namespace pepper |
| OLD | NEW |