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 <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 | 13 |
14 #include "ppapi/c/dev/ppp_printing_dev.h" | 14 #include "ppapi/c/dev/ppp_printing_dev.h" |
15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
16 #include "ppapi/c/pp_input_event.h" | 16 #include "ppapi/c/pp_input_event.h" |
17 #include "ppapi/c/pp_rect.h" | 17 #include "ppapi/c/pp_rect.h" |
18 #include "ppapi/cpp/completion_callback.h" | 18 #include "ppapi/cpp/completion_callback.h" |
19 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" | 19 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" |
20 #include "ppapi/cpp/dev/url_loader_dev.h" | |
21 #include "ppapi/cpp/dev/url_request_info_dev.h" | |
22 #include "ppapi/cpp/graphics_2d.h" | 20 #include "ppapi/cpp/graphics_2d.h" |
23 #include "ppapi/cpp/image_data.h" | 21 #include "ppapi/cpp/image_data.h" |
24 #include "ppapi/cpp/instance.h" | 22 #include "ppapi/cpp/instance.h" |
25 #include "ppapi/cpp/module.h" | 23 #include "ppapi/cpp/module.h" |
26 #include "ppapi/cpp/rect.h" | 24 #include "ppapi/cpp/rect.h" |
| 25 #include "ppapi/cpp/url_loader.h" |
| 26 #include "ppapi/cpp/url_request_info.h" |
27 #include "ppapi/cpp/var.h" | 27 #include "ppapi/cpp/var.h" |
28 | 28 |
29 static const int kStepsPerCircle = 800; | 29 static const int kStepsPerCircle = 800; |
30 | 30 |
31 void FlushCallback(void* data, int32_t result); | 31 void FlushCallback(void* data, int32_t result); |
32 | 32 |
33 void FillRect(pp::ImageData* image, int left, int top, int width, int height, | 33 void FillRect(pp::ImageData* image, int left, int top, int width, int height, |
34 uint32_t color) { | 34 uint32_t color) { |
35 for (int y = std::max(0, top); | 35 for (int y = std::max(0, top); |
36 y < std::min(image->size().height() - 1, top + height); | 36 y < std::min(image->size().height() - 1, top + height); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 class MyFetcher { | 82 class MyFetcher { |
83 public: | 83 public: |
84 MyFetcher() : client_(NULL) { | 84 MyFetcher() : client_(NULL) { |
85 callback_factory_.Initialize(this); | 85 callback_factory_.Initialize(this); |
86 } | 86 } |
87 | 87 |
88 void Start(const pp::Instance& instance, | 88 void Start(const pp::Instance& instance, |
89 const pp::Var& url, | 89 const pp::Var& url, |
90 MyFetcherClient* client) { | 90 MyFetcherClient* client) { |
91 pp::URLRequestInfo_Dev request; | 91 pp::URLRequestInfo request; |
92 request.SetURL(url); | 92 request.SetURL(url); |
93 request.SetMethod("GET"); | 93 request.SetMethod("GET"); |
94 | 94 |
95 loader_ = pp::URLLoader_Dev(instance); | 95 loader_ = pp::URLLoader(instance); |
96 client_ = client; | 96 client_ = client; |
97 | 97 |
98 pp::CompletionCallback callback = | 98 pp::CompletionCallback callback = |
99 callback_factory_.NewCallback(&MyFetcher::DidOpen); | 99 callback_factory_.NewCallback(&MyFetcher::DidOpen); |
100 int rv = loader_.Open(request, callback); | 100 int rv = loader_.Open(request, callback); |
101 if (rv != PP_ERROR_WOULDBLOCK) | 101 if (rv != PP_ERROR_WOULDBLOCK) |
102 callback.Run(rv); | 102 callback.Run(rv); |
103 } | 103 } |
104 | 104 |
105 void StartWithOpenedLoader(const pp::URLLoader_Dev& loader, | 105 void StartWithOpenedLoader(const pp::URLLoader& loader, |
106 MyFetcherClient* client) { | 106 MyFetcherClient* client) { |
107 loader_ = loader; | 107 loader_ = loader; |
108 client_ = client; | 108 client_ = client; |
109 | 109 |
110 ReadMore(); | 110 ReadMore(); |
111 } | 111 } |
112 | 112 |
113 private: | 113 private: |
114 void ReadMore() { | 114 void ReadMore() { |
115 pp::CompletionCallback callback = | 115 pp::CompletionCallback callback = |
(...skipping 19 matching lines...) Expand all Loading... |
135 DidFinish(result); | 135 DidFinish(result); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void DidFinish(int32_t result) { | 139 void DidFinish(int32_t result) { |
140 if (client_) | 140 if (client_) |
141 client_->DidFetch(result == PP_OK, data_); | 141 client_->DidFetch(result == PP_OK, data_); |
142 } | 142 } |
143 | 143 |
144 pp::CompletionCallbackFactory<MyFetcher> callback_factory_; | 144 pp::CompletionCallbackFactory<MyFetcher> callback_factory_; |
145 pp::URLLoader_Dev loader_; | 145 pp::URLLoader loader_; |
146 MyFetcherClient* client_; | 146 MyFetcherClient* client_; |
147 char buf_[4096]; | 147 char buf_[4096]; |
148 std::string data_; | 148 std::string data_; |
149 }; | 149 }; |
150 | 150 |
151 class MyInstance : public pp::Instance, public MyFetcherClient { | 151 class MyInstance : public pp::Instance, public MyFetcherClient { |
152 public: | 152 public: |
153 MyInstance(PP_Instance instance) | 153 MyInstance(PP_Instance instance) |
154 : pp::Instance(instance), | 154 : pp::Instance(instance), |
155 time_at_last_check_(0.0), | 155 time_at_last_check_(0.0), |
156 fetcher_(NULL), | 156 fetcher_(NULL), |
157 width_(0), | 157 width_(0), |
158 height_(0), | 158 height_(0), |
159 animation_counter_(0), | 159 animation_counter_(0), |
160 print_settings_valid_(false) {} | 160 print_settings_valid_(false) {} |
161 | 161 |
162 virtual ~MyInstance() { | 162 virtual ~MyInstance() { |
163 if (fetcher_) { | 163 if (fetcher_) { |
164 delete fetcher_; | 164 delete fetcher_; |
165 fetcher_ = NULL; | 165 fetcher_ = NULL; |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 169 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
170 return true; | 170 return true; |
171 } | 171 } |
172 | 172 |
173 virtual bool HandleDocumentLoad(const pp::URLLoader_Dev& loader) { | 173 virtual bool HandleDocumentLoad(const pp::URLLoader& loader) { |
174 fetcher_ = new MyFetcher(); | 174 fetcher_ = new MyFetcher(); |
175 fetcher_->StartWithOpenedLoader(loader, this); | 175 fetcher_->StartWithOpenedLoader(loader, this); |
176 return true; | 176 return true; |
177 } | 177 } |
178 | 178 |
179 virtual bool HandleInputEvent(const PP_InputEvent& event) { | 179 virtual bool HandleInputEvent(const PP_InputEvent& event) { |
180 switch (event.type) { | 180 switch (event.type) { |
181 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | 181 case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
182 //SayHello(); | 182 //SayHello(); |
183 return true; | 183 return true; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 }; | 417 }; |
418 | 418 |
419 namespace pp { | 419 namespace pp { |
420 | 420 |
421 // Factory function for your specialization of the Module object. | 421 // Factory function for your specialization of the Module object. |
422 Module* CreateModule() { | 422 Module* CreateModule() { |
423 return new MyModule(); | 423 return new MyModule(); |
424 } | 424 } |
425 | 425 |
426 } // namespace pp | 426 } // namespace pp |
OLD | NEW |