Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: remoting/client/plugin/chromoting_plugin.cc

Issue 2857011: Convert chromoting to pepperv2 API. (Closed)
Patch Set: break dep Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
18 #include "third_party/ppapi/c/pp_rect.h"
19 #include "third_party/ppapi/cpp/image_data.h"
17 20
18 using std::string; 21 using std::string;
19 using std::vector; 22 using std::vector;
20 23
21 namespace remoting { 24 namespace remoting {
22 25
23 const char* ChromotingPlugin::kMimeType = 26 const char* ChromotingPlugin::kMimeType =
24 "pepper-application/x-chromoting-plugin::Chromoting"; 27 "pepper-application/x-chromoting-plugin::Chromoting";
25 28
26 ChromotingPlugin::ChromotingPlugin(NPNetscapeFuncs* browser_funcs, 29 ChromotingPlugin::ChromotingPlugin(PP_Instance instance)
27 NPP instance) 30 : pp::Instance(instance),
28 : PepperPlugin(browser_funcs, instance), width_(0), height_(0), 31 width_(0),
29 device_(NULL) { 32 height_(0) {
30 } 33 }
31 34
32 ChromotingPlugin::~ChromotingPlugin() { 35 ChromotingPlugin::~ChromotingPlugin() {
36 if (host_connection_.get())
37 host_connection_->Disconnect();
38
39 // TODO(ajwong): We need to ensure all objects have actually stopped posting
40 // to the message loop before this point. Right now, we don't have a well
41 // defined stop for the plugin process, and the thread shutdown is likely a
42 // race condition.
43 if (network_thread_.get())
44 network_thread_->Stop();
45
46 if (main_thread_.get())
47 main_thread_->Stop();
33 } 48 }
34 49
35 NPError ChromotingPlugin::New(NPMIMEType pluginType, 50 bool ChromotingPlugin::Init(uint32_t argc, const char* argn[], const char* argv[ ]) {
36 int16 argc, char* argn[], char* argv[]) { 51 LOG(INFO) << "Started ChromotingPlugin::Init";
37 LOG(INFO) << "Started ChromotingPlugin::New";
38
39 // Verify the mime type and subtype
40 std::string mime(kMimeType);
41 std::string::size_type type_end = mime.find("/");
42 std::string::size_type subtype_end = mime.find(":", type_end);
43 if (strncmp(pluginType, kMimeType, subtype_end)) {
44 return NPERR_GENERIC_ERROR;
45 }
46 52
47 // Extract the URL from the arguments. 53 // Extract the URL from the arguments.
48 char* url = NULL; 54 const char* url = NULL;
49 for (int i = 0; i < argc; ++i) { 55 for (uint32_t i = 0; i < argc; ++i) {
50 if (strcmp(argn[i], "src") == 0) { 56 if (strcmp(argn[i], "src") == 0) {
51 url = argv[i]; 57 url = argv[i];
52 break; 58 break;
53 } 59 }
54 } 60 }
55 61
56 if (!url) { 62 if (!url) {
57 return NPERR_GENERIC_ERROR; 63 return false;
58 } 64 }
59 65
60 string user_id; 66 string user_id;
61 string auth_token; 67 string auth_token;
62 string host_jid; 68 string host_jid;
63 if (!ParseUrl(url, &user_id, &auth_token, &host_jid)) { 69 if (!ParseUrl(url, &user_id, &auth_token, &host_jid)) {
64 LOG(WARNING) << "Could not parse URL: " << url; 70 LOG(WARNING) << "Could not parse URL: " << url;
65 return NPERR_GENERIC_ERROR; 71 return false;
66 } 72 }
67 73
68 // Setup pepper context.
69 device_ = extensions()->acquireDevice(instance(), NPPepper2DDevice);
70
71 // Start the threads. 74 // Start the threads.
72 main_thread_.reset(new base::Thread("ChromoClientMain")); 75 main_thread_.reset(new base::Thread("ChromoClientMain"));
73 if (!main_thread_->Start()) { 76 if (!main_thread_->Start()) {
74 LOG(ERROR) << "Main thread failed to start."; 77 LOG(ERROR) << "Main thread failed to start.";
75 return NPERR_GENERIC_ERROR; 78 return false;
76 } 79 }
77 network_thread_.reset(new JingleThread()); 80 network_thread_.reset(new JingleThread());
78 network_thread_->Start(); 81 network_thread_->Start();
79 82
80 // Create the chromting objects. 83 // Create the chromting objects.
81 host_connection_.reset(new JingleHostConnection(network_thread_.get())); 84 host_connection_.reset(new JingleHostConnection(network_thread_.get()));
85 /*
82 view_.reset(new PepperView(main_thread_->message_loop(), device_, 86 view_.reset(new PepperView(main_thread_->message_loop(), device_,
83 instance())); 87 instance()));
84 client_.reset(new ChromotingClient(main_thread_->message_loop(), 88 */
85 host_connection_.get(), view_.get())); 89 //client_.reset(new ChromotingClient(main_thread_->message_loop(),
90 // host_connection_.get(), view_.get()));
86 91
87 // Kick off the connection. 92 // Kick off the connection.
88 host_connection_->Connect(user_id, auth_token, host_jid, client_.get()); 93 //host_connection_->Connect(user_id, auth_token, host_jid, client_.get());
89 94
90 return NPERR_NO_ERROR; 95 return true;
91 } 96 }
92 97
93 NPError ChromotingPlugin::Destroy(NPSavedData** save) { 98 void ChromotingPlugin::ViewChanged(const PP_Rect& position,
94 host_connection_->Disconnect(); 99 const PP_Rect& clip) {
100 // TODO(ajwong): This is going to be a race condition when the view changes
101 // and we're in the middle of a Paint().
102 LOG(INFO) << "ViewChanged "
103 << position.point.x << ","
104 << position.point.y << ","
105 << position.size.width << ","
106 << position.size.height;
95 107
96 // TODO(ajwong): We need to ensure all objects have actually stopped posting 108 // TODO(ajwong): Do we care about the position? Probably not...
97 // to the message loop before this point. Right now, we don't have a well 109 if (position.size.width == width_ || position.size.height == height_)
98 // defined stop for the plugin process, and the thread shutdown is likely a 110 return;
99 // race condition.
100 network_thread_->Stop();
101 main_thread_->Stop();
102 111
103 main_thread_.reset(); 112 width_ = position.size.width;
104 network_thread_.reset(); 113 height_ = position.size.height;
105 return NPERR_NO_ERROR; 114
115 device_context_ = pp::DeviceContext2D(width_, height_, false);
116 if (!BindGraphicsDeviceContext(device_context_)) {
117 LOG(ERROR) << "Couldn't bind the device context.";
118 return;
119 }
120
121 pp::ImageData image(PP_IMAGEDATAFORMAT_BGRA_PREMUL, width_, height_, false);
122 if (!image.is_null()) {
123 for (int y = 0; y < image.height(); y++) {
124 for (int x = 0; x < image.width(); x++) {
125 *image.GetAddr32(x, y) = 0xccff00cc;
126 }
127 }
128 device_context_.ReplaceContents(&image);
129 device_context_.Flush(NULL, this);
130 } else {
131 LOG(ERROR) << "Unable to allocate image.";
132 }
133
134 //client_->SetViewport(0, 0, width_, height_);
135 //client_->Repaint();
106 } 136 }
107 137
108 NPError ChromotingPlugin::SetWindow(NPWindow* window) { 138 bool ChromotingPlugin::HandleEvent(const PP_Event& event) {
109 width_ = window->width; 139 switch (event.type) {
110 height_ = window->height; 140 case PP_Event_Type_MouseDown:
111 141 case PP_Event_Type_MouseUp:
112 client_->SetViewport(0, 0, window->width, window->height); 142 case PP_Event_Type_MouseMove:
113 client_->Repaint(); 143 case PP_Event_Type_MouseEnter:
114 144 case PP_Event_Type_MouseLeave:
115 return NPERR_NO_ERROR;
116 }
117
118 int16 ChromotingPlugin::HandleEvent(void* event) {
119 NPPepperEvent* npevent = static_cast<NPPepperEvent*>(event);
120
121 switch (npevent->type) {
122 case NPEventType_MouseDown:
123 // Fall through
124 case NPEventType_MouseUp:
125 // Fall through
126 case NPEventType_MouseMove:
127 // Fall through
128 case NPEventType_MouseEnter:
129 // Fall through
130 case NPEventType_MouseLeave:
131 //client_->handle_mouse_event(npevent); 145 //client_->handle_mouse_event(npevent);
132 break; 146 break;
133 case NPEventType_MouseWheel: 147
134 case NPEventType_RawKeyDown: 148 case PP_Event_Type_Char:
135 break;
136 case NPEventType_KeyDown:
137 case NPEventType_KeyUp:
138 break;
139 case NPEventType_Char:
140 //client_->handle_char_event(npevent); 149 //client_->handle_char_event(npevent);
141 break; 150 break;
142 case NPEventType_Minimize: 151
143 case NPEventType_Focus: 152 default:
144 case NPEventType_Device:
145 break; 153 break;
146 } 154 }
147 155
148 return false; 156 return false;
149 } 157 }
150 158
151 NPError ChromotingPlugin::GetValue(NPPVariable variable, void* value) {
152 return NPERR_NO_ERROR;
153 }
154
155 NPError ChromotingPlugin::SetValue(NPNVariable variable, void* value) {
156 return NPERR_NO_ERROR;
157 }
158
159 bool ChromotingPlugin::ParseUrl(const std::string& url, 159 bool ChromotingPlugin::ParseUrl(const std::string& url,
160 string* user_id, 160 string* user_id,
161 string* auth_token, 161 string* auth_token,
162 string* host_jid) { 162 string* host_jid) {
163 // TODO(ajwong): We should use GURL or something. Don't parse this by hand! 163 // TODO(ajwong): We should use GURL or something. Don't parse this by hand!
164 164
165 // The Url should be of the form: 165 // The Url should be of the form:
166 // 166 //
167 // chromotocol://<hostid>?user=<userid>&auth=<authtoken>&jid=<hostjid> 167 // chromotocol://<hostid>?user=<userid>&auth=<authtoken>&jid=<hostjid>
168 // 168 //
(...skipping 18 matching lines...) Expand all
187 pos = parts[2].rfind('='); 187 pos = parts[2].rfind('=');
188 if (pos == string::npos && (pos + 1) != string::npos) { 188 if (pos == string::npos && (pos + 1) != string::npos) {
189 return false; 189 return false;
190 } 190 }
191 host_jid->assign(parts[2].substr(pos + 1)); 191 host_jid->assign(parts[2].substr(pos + 1));
192 192
193 return true; 193 return true;
194 } 194 }
195 195
196 } // namespace remoting 196 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/plugin/chromoting_plugin.h ('k') | remoting/client/plugin/chromoting_plugin_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698