| 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/completion_callback.h" | 19 #include "third_party/ppapi/cpp/completion_callback.h" |
| 20 #include "third_party/ppapi/cpp/image_data.h" | 20 #include "third_party/ppapi/cpp/image_data.h" |
| 21 | 21 |
| 22 using std::string; | 22 using std::string; |
| 23 using std::vector; | 23 using std::vector; |
| 24 | 24 |
| 25 namespace remoting { | 25 namespace remoting { |
| 26 | 26 |
| 27 const char* ChromotingPlugin::kMimeType = | 27 const char* ChromotingPlugin::kMimeType = "pepper-application/x-chromoting"; |
| 28 "pepper-application/x-chromoting-plugin::Chromoting"; | |
| 29 | 28 |
| 30 ChromotingPlugin::ChromotingPlugin(PP_Instance instance) | 29 ChromotingPlugin::ChromotingPlugin(PP_Instance pp_instance, |
| 31 : pp::Instance(instance), | 30 const PPB_Instance* ppb_instance_funcs) |
| 32 width_(0), | 31 : width_(0), |
| 33 height_(0) { | 32 height_(0), |
| 33 drawing_context_(NULL), |
| 34 pp_instance_(pp_instance), |
| 35 ppb_instance_funcs_(ppb_instance_funcs) { |
| 34 } | 36 } |
| 35 | 37 |
| 36 ChromotingPlugin::~ChromotingPlugin() { | 38 ChromotingPlugin::~ChromotingPlugin() { |
| 37 if (host_connection_.get()) | 39 if (host_connection_.get()) |
| 38 host_connection_->Disconnect(); | 40 host_connection_->Disconnect(); |
| 39 | 41 |
| 40 // TODO(ajwong): We need to ensure all objects have actually stopped posting | 42 // TODO(ajwong): We need to ensure all objects have actually stopped posting |
| 41 // to the message loop before this point. Right now, we don't have a well | 43 // to the message loop before this point. Right now, we don't have a well |
| 42 // defined stop for the plugin process, and the thread shutdown is likely a | 44 // defined stop for the plugin process, and the thread shutdown is likely a |
| 43 // race condition. | 45 // race condition. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 << position.size.width << "," | 110 << position.size.width << "," |
| 109 << position.size.height; | 111 << position.size.height; |
| 110 | 112 |
| 111 // TODO(ajwong): Do we care about the position? Probably not... | 113 // TODO(ajwong): Do we care about the position? Probably not... |
| 112 if (position.size.width == width_ || position.size.height == height_) | 114 if (position.size.width == width_ || position.size.height == height_) |
| 113 return; | 115 return; |
| 114 | 116 |
| 115 width_ = position.size.width; | 117 width_ = position.size.width; |
| 116 height_ = position.size.height; | 118 height_ = position.size.height; |
| 117 | 119 |
| 120 /* |
| 121 * TODO(ajwong): Reenable this code once we fingure out how we want to |
| 122 * abstract away the C-api for DeviceContext2D. |
| 118 device_context_ = pp::DeviceContext2D(width_, height_, false); | 123 device_context_ = pp::DeviceContext2D(width_, height_, false); |
| 119 if (!BindGraphicsDeviceContext(device_context_)) { | 124 if (!ppb_instance_funcs_->BindGraphicsDeviceContext( |
| 125 pp_instance_, |
| 126 device_context_.pp_resource())) { |
| 120 LOG(ERROR) << "Couldn't bind the device context."; | 127 LOG(ERROR) << "Couldn't bind the device context."; |
| 121 return; | 128 return; |
| 122 } | 129 } |
| 123 | 130 |
| 124 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, width_, height_, false); | 131 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, width_, height_, false); |
| 125 if (!image.is_null()) { | 132 if (!image.is_null()) { |
| 126 for (int y = 0; y < image.height(); y++) { | 133 for (int y = 0; y < image.height(); y++) { |
| 127 for (int x = 0; x < image.width(); x++) { | 134 for (int x = 0; x < image.width(); x++) { |
| 128 *image.GetAddr32(x, y) = 0xccff00cc; | 135 *image.GetAddr32(x, y) = 0xccff00cc; |
| 129 } | 136 } |
| 130 } | 137 } |
| 131 device_context_.ReplaceContents(&image); | 138 device_context_.ReplaceContents(&image); |
| 132 device_context_.Flush(pp::CompletionCallback(NULL, this)); | 139 device_context_.Flush(pp::CompletionCallback(NULL, this)); |
| 133 } else { | 140 } else { |
| 134 LOG(ERROR) << "Unable to allocate image."; | 141 LOG(ERROR) << "Unable to allocate image."; |
| 135 } | 142 } |
| 143 */ |
| 136 | 144 |
| 137 //client_->SetViewport(0, 0, width_, height_); | 145 //client_->SetViewport(0, 0, width_, height_); |
| 138 //client_->Repaint(); | 146 //client_->Repaint(); |
| 139 } | 147 } |
| 140 | 148 |
| 141 bool ChromotingPlugin::HandleEvent(const PP_Event& event) { | 149 bool ChromotingPlugin::HandleEvent(const PP_Event& event) { |
| 142 switch (event.type) { | 150 switch (event.type) { |
| 143 case PP_Event_Type_MouseDown: | 151 case PP_Event_Type_MouseDown: |
| 144 case PP_Event_Type_MouseUp: | 152 case PP_Event_Type_MouseUp: |
| 145 case PP_Event_Type_MouseMove: | 153 case PP_Event_Type_MouseMove: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 pos = parts[2].rfind('='); | 198 pos = parts[2].rfind('='); |
| 191 if (pos == string::npos && (pos + 1) != string::npos) { | 199 if (pos == string::npos && (pos + 1) != string::npos) { |
| 192 return false; | 200 return false; |
| 193 } | 201 } |
| 194 host_jid->assign(parts[2].substr(pos + 1)); | 202 host_jid->assign(parts[2].substr(pos + 1)); |
| 195 | 203 |
| 196 return true; | 204 return true; |
| 197 } | 205 } |
| 198 | 206 |
| 199 } // namespace remoting | 207 } // namespace remoting |
| OLD | NEW |