OLD | NEW |
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 <math.h> | 5 #include <math.h> |
6 #include <stdio.h> // FIXME(brettw) erase me. | 6 #include <stdio.h> // FIXME(brettw) erase me. |
7 #ifndef _WIN32 | 7 #ifndef _WIN32 |
8 #include <sys/time.h> | 8 #include <sys/time.h> |
9 #else | 9 #else |
10 #include <windows.h> | 10 #include <windows.h> |
11 #endif | 11 #endif |
12 #include <time.h> | 12 #include <time.h> |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 | 15 |
16 #include "ppapi/c/dev/ppb_console_dev.h" | 16 #include "ppapi/c/dev/ppb_console_dev.h" |
17 #include "ppapi/c/dev/ppb_cursor_control_dev.h" | 17 #include "ppapi/c/dev/ppb_cursor_control_dev.h" |
18 #include "ppapi/c/dev/ppp_printing_dev.h" | 18 #include "ppapi/c/dev/ppp_printing_dev.h" |
19 #include "ppapi/c/pp_errors.h" | 19 #include "ppapi/c/pp_errors.h" |
20 #include "ppapi/c/pp_rect.h" | 20 #include "ppapi/c/pp_rect.h" |
21 #include "ppapi/cpp/completion_callback.h" | 21 #include "ppapi/cpp/completion_callback.h" |
| 22 #include "ppapi/cpp/dev/file_chooser_dev.h" |
22 #include "ppapi/cpp/dev/memory_dev.h" | 23 #include "ppapi/cpp/dev/memory_dev.h" |
23 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" | 24 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" |
24 #include "ppapi/cpp/graphics_2d.h" | 25 #include "ppapi/cpp/graphics_2d.h" |
25 #include "ppapi/cpp/image_data.h" | 26 #include "ppapi/cpp/image_data.h" |
26 #include "ppapi/cpp/input_event.h" | 27 #include "ppapi/cpp/input_event.h" |
27 #include "ppapi/cpp/private/instance_private.h" | 28 #include "ppapi/cpp/private/instance_private.h" |
28 #include "ppapi/cpp/module.h" | 29 #include "ppapi/cpp/module.h" |
29 #include "ppapi/cpp/private/var_private.h" | 30 #include "ppapi/cpp/private/var_private.h" |
30 #include "ppapi/cpp/rect.h" | 31 #include "ppapi/cpp/rect.h" |
31 #include "ppapi/cpp/url_loader.h" | 32 #include "ppapi/cpp/url_loader.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 MyInstance(PP_Instance instance) | 174 MyInstance(PP_Instance instance) |
174 : pp::InstancePrivate(instance), | 175 : pp::InstancePrivate(instance), |
175 time_at_last_check_(0.0), | 176 time_at_last_check_(0.0), |
176 fetcher_(NULL), | 177 fetcher_(NULL), |
177 width_(0), | 178 width_(0), |
178 height_(0), | 179 height_(0), |
179 animation_counter_(0), | 180 animation_counter_(0), |
180 print_settings_valid_(false), | 181 print_settings_valid_(false), |
181 showing_custom_cursor_(false) { | 182 showing_custom_cursor_(false) { |
182 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | 183 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); |
| 184 callback_factory_.Initialize(this); |
183 } | 185 } |
184 | 186 |
185 virtual ~MyInstance() { | 187 virtual ~MyInstance() { |
186 if (fetcher_) { | 188 if (fetcher_) { |
187 delete fetcher_; | 189 delete fetcher_; |
188 fetcher_ = NULL; | 190 fetcher_ = NULL; |
189 } | 191 } |
190 } | 192 } |
191 | 193 |
192 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 194 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
193 return true; | 195 return true; |
194 } | 196 } |
195 | 197 |
196 void Log(PP_LogLevel_Dev level, const pp::Var& value) { | 198 void Log(PP_LogLevel_Dev level, const pp::Var& value) { |
197 const PPB_Console_Dev* console = reinterpret_cast<const PPB_Console_Dev*>( | 199 const PPB_Console_Dev* console = reinterpret_cast<const PPB_Console_Dev*>( |
198 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)); | 200 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)); |
199 if (!console) | 201 if (!console) |
200 return; | 202 return; |
201 console->Log(pp_instance(), level, value.pp_var()); | 203 console->Log(pp_instance(), level, value.pp_var()); |
202 } | 204 } |
203 | 205 |
204 virtual bool HandleDocumentLoad(const pp::URLLoader& loader) { | 206 virtual bool HandleDocumentLoad(const pp::URLLoader& loader) { |
205 fetcher_ = new MyFetcher(); | 207 fetcher_ = new MyFetcher(); |
206 fetcher_->StartWithOpenedLoader(loader, this); | 208 fetcher_->StartWithOpenedLoader(loader, this); |
207 return true; | 209 return true; |
208 } | 210 } |
209 | 211 |
| 212 pp::FileChooser_Dev chooser_; |
| 213 pp::CompletionCallbackFactory<MyInstance> callback_factory_; |
| 214 |
| 215 void GotFile(int32_t result, const std::vector<pp::FileRef>& files) { |
| 216 } |
| 217 |
210 virtual bool HandleInputEvent(const pp::InputEvent& event) { | 218 virtual bool HandleInputEvent(const pp::InputEvent& event) { |
211 switch (event.GetType()) { | 219 switch (event.GetType()) { |
212 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | 220 case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
213 SayHello(); | 221 chooser_ = pp::FileChooser_Dev(this, PP_FILECHOOSERMODE_OPEN, "text/html
"); |
214 ToggleCursor(); | 222 //< std::vector<FileRef> > |
| 223 chooser_.Show(callback_factory_.NewCallbackWithOutput(&MyInstance::GotFi
le)); |
| 224 //SayHello(); |
| 225 //ToggleCursor(); |
215 return true; | 226 return true; |
216 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | 227 case PP_INPUTEVENT_TYPE_MOUSEMOVE: |
217 return true; | 228 return true; |
218 case PP_INPUTEVENT_TYPE_KEYDOWN: | 229 case PP_INPUTEVENT_TYPE_KEYDOWN: |
219 return true; | 230 return true; |
220 default: | 231 default: |
221 return false; | 232 return false; |
222 } | 233 } |
223 } | 234 } |
224 | 235 |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 }; | 506 }; |
496 | 507 |
497 namespace pp { | 508 namespace pp { |
498 | 509 |
499 // Factory function for your specialization of the Module object. | 510 // Factory function for your specialization of the Module object. |
500 Module* CreateModule() { | 511 Module* CreateModule() { |
501 return new MyModule(); | 512 return new MyModule(); |
502 } | 513 } |
503 | 514 |
504 } // namespace pp | 515 } // namespace pp |
OLD | NEW |