| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #endif | 9 #endif |
| 10 #include <time.h> | 10 #include <time.h> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <sstream> | 13 #include <sstream> |
| 14 | 14 |
| 15 #include "ppapi/c/dev/ppb_console_dev.h" | 15 #include "ppapi/c/dev/ppb_console_dev.h" |
| 16 #include "ppapi/c/dev/ppb_cursor_control_dev.h" | 16 #include "ppapi/c/dev/ppb_cursor_control_dev.h" |
| 17 #include "ppapi/c/dev/ppp_printing_dev.h" | 17 #include "ppapi/c/dev/ppp_printing_dev.h" |
| 18 #include "ppapi/c/pp_errors.h" | 18 #include "ppapi/c/pp_errors.h" |
| 19 #include "ppapi/c/pp_input_event.h" | 19 #include "ppapi/c/pp_input_event.h" |
| 20 #include "ppapi/c/pp_rect.h" | 20 #include "ppapi/c/pp_rect.h" |
| 21 #include "ppapi/c/ppb_var.h" | 21 #include "ppapi/c/ppb_var.h" |
| 22 #include "ppapi/cpp/completion_callback.h" | 22 #include "ppapi/cpp/completion_callback.h" |
| 23 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" | 23 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" |
| 24 #include "ppapi/cpp/graphics_2d.h" | 24 #include "ppapi/cpp/graphics_2d.h" |
| 25 #include "ppapi/cpp/image_data.h" | 25 #include "ppapi/cpp/image_data.h" |
| 26 #include "ppapi/cpp/instance.h" | 26 #include "ppapi/cpp/private/instance_private.h" |
| 27 #include "ppapi/cpp/module.h" | 27 #include "ppapi/cpp/module.h" |
| 28 #include "ppapi/cpp/private/var_private.h" | 28 #include "ppapi/cpp/private/var_private.h" |
| 29 #include "ppapi/cpp/rect.h" | 29 #include "ppapi/cpp/rect.h" |
| 30 #include "ppapi/cpp/url_loader.h" | 30 #include "ppapi/cpp/url_loader.h" |
| 31 #include "ppapi/cpp/url_request_info.h" | 31 #include "ppapi/cpp/url_request_info.h" |
| 32 | 32 |
| 33 static const int kStepsPerCircle = 800; | 33 static const int kStepsPerCircle = 800; |
| 34 | 34 |
| 35 void FlushCallback(void* data, int32_t result); | 35 void FlushCallback(void* data, int32_t result); |
| 36 | 36 |
| 37 void FillRect(pp::ImageData* image, int left, int top, int width, int height, | 37 void FillRect(pp::ImageData* image, int left, int top, int width, int height, |
| 38 uint32_t color) { | 38 uint32_t color) { |
| 39 for (int y = std::max(0, top); | 39 for (int y = std::max(0, top); |
| 40 y < std::min(image->size().height() - 1, top + height); | 40 y < std::min(image->size().height() - 1, top + height); |
| 41 y++) { | 41 y++) { |
| 42 for (int x = std::max(0, left); | 42 for (int x = std::max(0, left); |
| 43 x < std::min(image->size().width() - 1, left + width); | 43 x < std::min(image->size().width() - 1, left + width); |
| 44 x++) | 44 x++) |
| 45 *image->GetAddr32(pp::Point(x, y)) = color; | 45 *image->GetAddr32(pp::Point(x, y)) = color; |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 class MyScriptableObject : public pp::deprecated::ScriptableObject { | 49 class MyScriptableObject : public pp::deprecated::ScriptableObject { |
| 50 public: | 50 public: |
| 51 explicit MyScriptableObject(pp::Instance* instance) : instance_(instance) {} | 51 explicit MyScriptableObject(pp::InstancePrivate* instance) |
| 52 : instance_(instance) {} |
| 52 | 53 |
| 53 virtual bool HasMethod(const pp::Var& method, pp::Var* exception) { | 54 virtual bool HasMethod(const pp::Var& method, pp::Var* exception) { |
| 54 return method.AsString() == "toString"; | 55 return method.AsString() == "toString"; |
| 55 } | 56 } |
| 56 | 57 |
| 57 virtual bool HasProperty(const pp::Var& name, pp::Var* exception) { | 58 virtual bool HasProperty(const pp::Var& name, pp::Var* exception) { |
| 58 if (name.is_string() && name.AsString() == "blah") | 59 if (name.is_string() && name.AsString() == "blah") |
| 59 return true; | 60 return true; |
| 60 return false; | 61 return false; |
| 61 } | 62 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 73 | 74 |
| 74 virtual pp::Var Call(const pp::Var& method, | 75 virtual pp::Var Call(const pp::Var& method, |
| 75 const std::vector<pp::Var>& args, | 76 const std::vector<pp::Var>& args, |
| 76 pp::Var* exception) { | 77 pp::Var* exception) { |
| 77 if (method.AsString() == "toString") | 78 if (method.AsString() == "toString") |
| 78 return pp::Var("hello world"); | 79 return pp::Var("hello world"); |
| 79 return pp::Var(); | 80 return pp::Var(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 private: | 83 private: |
| 83 pp::Instance* instance_; | 84 pp::InstancePrivate* instance_; |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 class MyFetcherClient { | 87 class MyFetcherClient { |
| 87 public: | 88 public: |
| 88 virtual void DidFetch(bool success, const std::string& data) = 0; | 89 virtual void DidFetch(bool success, const std::string& data) = 0; |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 class MyFetcher { | 92 class MyFetcher { |
| 92 public: | 93 public: |
| 93 MyFetcher() : client_(NULL) { | 94 MyFetcher() : client_(NULL) { |
| 94 callback_factory_.Initialize(this); | 95 callback_factory_.Initialize(this); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void Start(const pp::Instance& instance, | 98 void Start(const pp::InstancePrivate& instance, |
| 98 const pp::Var& url, | 99 const pp::Var& url, |
| 99 MyFetcherClient* client) { | 100 MyFetcherClient* client) { |
| 100 pp::URLRequestInfo request; | 101 pp::URLRequestInfo request; |
| 101 request.SetURL(url); | 102 request.SetURL(url); |
| 102 request.SetMethod("GET"); | 103 request.SetMethod("GET"); |
| 103 | 104 |
| 104 loader_ = pp::URLLoader(instance); | 105 loader_ = pp::URLLoader(instance); |
| 105 client_ = client; | 106 client_ = client; |
| 106 | 107 |
| 107 pp::CompletionCallback callback = | 108 pp::CompletionCallback callback = |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 client_->DidFetch(result == PP_OK, data_); | 151 client_->DidFetch(result == PP_OK, data_); |
| 151 } | 152 } |
| 152 | 153 |
| 153 pp::CompletionCallbackFactory<MyFetcher> callback_factory_; | 154 pp::CompletionCallbackFactory<MyFetcher> callback_factory_; |
| 154 pp::URLLoader loader_; | 155 pp::URLLoader loader_; |
| 155 MyFetcherClient* client_; | 156 MyFetcherClient* client_; |
| 156 char buf_[4096]; | 157 char buf_[4096]; |
| 157 std::string data_; | 158 std::string data_; |
| 158 }; | 159 }; |
| 159 | 160 |
| 160 class MyInstance : public pp::Instance, public MyFetcherClient { | 161 class MyInstance : public pp::InstancePrivate, public MyFetcherClient { |
| 161 public: | 162 public: |
| 162 MyInstance(PP_Instance instance) | 163 MyInstance(PP_Instance instance) |
| 163 : pp::Instance(instance), | 164 : pp::InstancePrivate(instance), |
| 164 time_at_last_check_(0.0), | 165 time_at_last_check_(0.0), |
| 165 fetcher_(NULL), | 166 fetcher_(NULL), |
| 166 width_(0), | 167 width_(0), |
| 167 height_(0), | 168 height_(0), |
| 168 animation_counter_(0), | 169 animation_counter_(0), |
| 169 print_settings_valid_(false), | 170 print_settings_valid_(false), |
| 170 showing_custom_cursor_(false) {} | 171 showing_custom_cursor_(false) {} |
| 171 | 172 |
| 172 virtual ~MyInstance() { | 173 virtual ~MyInstance() { |
| 173 if (fetcher_) { | 174 if (fetcher_) { |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 }; | 475 }; |
| 475 | 476 |
| 476 namespace pp { | 477 namespace pp { |
| 477 | 478 |
| 478 // Factory function for your specialization of the Module object. | 479 // Factory function for your specialization of the Module object. |
| 479 Module* CreateModule() { | 480 Module* CreateModule() { |
| 480 return new MyModule(); | 481 return new MyModule(); |
| 481 } | 482 } |
| 482 | 483 |
| 483 } // namespace pp | 484 } // namespace pp |
| OLD | NEW |