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 "remoting/client/plugin/chromoting_plugin.h" | 5 #include "remoting/client/plugin/chromoting_plugin.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/thread.h" | 11 #include "base/thread.h" |
12 #include "remoting/client/chromoting_client.h" | 12 #include "remoting/client/chromoting_client.h" |
13 #include "remoting/client/host_connection.h" | 13 #include "remoting/client/host_connection.h" |
14 #include "remoting/client/jingle_host_connection.h" | 14 #include "remoting/client/jingle_host_connection.h" |
15 #include "remoting/client/plugin/pepper_view.h" | 15 #include "remoting/client/plugin/pepper_view.h" |
16 #include "remoting/jingle_glue/jingle_thread.h" | 16 #include "remoting/jingle_glue/jingle_thread.h" |
17 #include "third_party/ppapi/c/pp_event.h" | 17 #include "third_party/ppapi/c/pp_event.h" |
18 #include "third_party/ppapi/c/pp_rect.h" | 18 #include "third_party/ppapi/c/pp_rect.h" |
19 #include "third_party/ppapi/cpp/image_data.h" | 19 #include "third_party/ppapi/cpp/image_data.h" |
20 | 20 |
21 using std::string; | 21 using std::string; |
22 using std::vector; | 22 using std::vector; |
23 | 23 |
24 namespace remoting { | 24 namespace remoting { |
25 | 25 |
26 const char* ChromotingPlugin::kMimeType = "pepper-application/x-chromoting"; | 26 const char* ChromotingPlugin::kMimeType = |
| 27 "pepper-application/x-chromoting-plugin::Chromoting"; |
27 | 28 |
28 ChromotingPlugin::ChromotingPlugin(PP_Instance pp_instance, | 29 ChromotingPlugin::ChromotingPlugin(PP_Instance instance) |
29 const PPB_Instance* ppb_instance_funcs) | 30 : pp::Instance(instance), |
30 : width_(0), | 31 width_(0), |
31 height_(0), | 32 height_(0) { |
32 drawing_context_(NULL), | |
33 pp_instance_(pp_instance), | |
34 ppb_instance_funcs_(ppb_instance_funcs) { | |
35 } | 33 } |
36 | 34 |
37 ChromotingPlugin::~ChromotingPlugin() { | 35 ChromotingPlugin::~ChromotingPlugin() { |
38 if (host_connection_.get()) | 36 if (host_connection_.get()) |
39 host_connection_->Disconnect(); | 37 host_connection_->Disconnect(); |
40 | 38 |
41 // TODO(ajwong): We need to ensure all objects have actually stopped posting | 39 // TODO(ajwong): We need to ensure all objects have actually stopped posting |
42 // to the message loop before this point. Right now, we don't have a well | 40 // to the message loop before this point. Right now, we don't have a well |
43 // defined stop for the plugin process, and the thread shutdown is likely a | 41 // defined stop for the plugin process, and the thread shutdown is likely a |
44 // race condition. | 42 // race condition. |
45 if (network_thread_.get()) | 43 if (network_thread_.get()) |
46 network_thread_->Stop(); | 44 network_thread_->Stop(); |
47 | 45 |
48 if (main_thread_.get()) | 46 if (main_thread_.get()) |
49 main_thread_->Stop(); | 47 main_thread_->Stop(); |
50 } | 48 } |
51 | 49 |
52 bool ChromotingPlugin::Init(uint32_t argc, const char* argn[], | 50 bool ChromotingPlugin::Init(uint32_t argc, const char* argn[], const char* argv[
]) { |
53 const char* argv[]) { | |
54 LOG(INFO) << "Started ChromotingPlugin::Init"; | 51 LOG(INFO) << "Started ChromotingPlugin::Init"; |
55 | 52 |
56 // Extract the URL from the arguments. | 53 // Extract the URL from the arguments. |
57 const char* url = NULL; | 54 const char* url = NULL; |
58 for (uint32_t i = 0; i < argc; ++i) { | 55 for (uint32_t i = 0; i < argc; ++i) { |
59 if (strcmp(argn[i], "src") == 0) { | 56 if (strcmp(argn[i], "src") == 0) { |
60 url = argv[i]; | 57 url = argv[i]; |
61 break; | 58 break; |
62 } | 59 } |
63 } | 60 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 << position.size.width << "," | 105 << position.size.width << "," |
109 << position.size.height; | 106 << position.size.height; |
110 | 107 |
111 // TODO(ajwong): Do we care about the position? Probably not... | 108 // TODO(ajwong): Do we care about the position? Probably not... |
112 if (position.size.width == width_ || position.size.height == height_) | 109 if (position.size.width == width_ || position.size.height == height_) |
113 return; | 110 return; |
114 | 111 |
115 width_ = position.size.width; | 112 width_ = position.size.width; |
116 height_ = position.size.height; | 113 height_ = position.size.height; |
117 | 114 |
118 /* | |
119 * TODO(ajwong): Reenable this code once we fingure out how we want to | |
120 * abstract away the C-api for DeviceContext2D. | |
121 device_context_ = pp::DeviceContext2D(width_, height_, false); | 115 device_context_ = pp::DeviceContext2D(width_, height_, false); |
122 if (!ppb_instance_funcs_->BindGraphicsDeviceContext( | 116 if (!BindGraphicsDeviceContext(device_context_)) { |
123 pp_instance_, | |
124 device_context_.pp_resource())) { | |
125 LOG(ERROR) << "Couldn't bind the device context."; | 117 LOG(ERROR) << "Couldn't bind the device context."; |
126 return; | 118 return; |
127 } | 119 } |
128 | 120 |
129 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, width_, height_, false); | 121 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, width_, height_, false); |
130 if (!image.is_null()) { | 122 if (!image.is_null()) { |
131 for (int y = 0; y < image.height(); y++) { | 123 for (int y = 0; y < image.height(); y++) { |
132 for (int x = 0; x < image.width(); x++) { | 124 for (int x = 0; x < image.width(); x++) { |
133 *image.GetAddr32(x, y) = 0xccff00cc; | 125 *image.GetAddr32(x, y) = 0xccff00cc; |
134 } | 126 } |
135 } | 127 } |
136 device_context_.ReplaceContents(&image); | 128 device_context_.ReplaceContents(&image); |
137 device_context_.Flush(NULL, this); | 129 device_context_.Flush(NULL, this); |
138 } else { | 130 } else { |
139 LOG(ERROR) << "Unable to allocate image."; | 131 LOG(ERROR) << "Unable to allocate image."; |
140 } | 132 } |
141 */ | |
142 | 133 |
143 //client_->SetViewport(0, 0, width_, height_); | 134 //client_->SetViewport(0, 0, width_, height_); |
144 //client_->Repaint(); | 135 //client_->Repaint(); |
145 } | 136 } |
146 | 137 |
147 bool ChromotingPlugin::HandleEvent(const PP_Event& event) { | 138 bool ChromotingPlugin::HandleEvent(const PP_Event& event) { |
148 switch (event.type) { | 139 switch (event.type) { |
149 case PP_Event_Type_MouseDown: | 140 case PP_Event_Type_MouseDown: |
150 case PP_Event_Type_MouseUp: | 141 case PP_Event_Type_MouseUp: |
151 case PP_Event_Type_MouseMove: | 142 case PP_Event_Type_MouseMove: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 pos = parts[2].rfind('='); | 187 pos = parts[2].rfind('='); |
197 if (pos == string::npos && (pos + 1) != string::npos) { | 188 if (pos == string::npos && (pos + 1) != string::npos) { |
198 return false; | 189 return false; |
199 } | 190 } |
200 host_jid->assign(parts[2].substr(pos + 1)); | 191 host_jid->assign(parts[2].substr(pos + 1)); |
201 | 192 |
202 return true; | 193 return true; |
203 } | 194 } |
204 | 195 |
205 } // namespace remoting | 196 } // namespace remoting |
OLD | NEW |