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/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/thread.h" | 12 #include "base/thread.h" |
| 13 #include "remoting/client/client_config.h" |
| 14 #include "remoting/client/client_util.h" |
13 #include "remoting/client/chromoting_client.h" | 15 #include "remoting/client/chromoting_client.h" |
14 #include "remoting/client/host_connection.h" | 16 #include "remoting/client/host_connection.h" |
15 #include "remoting/client/jingle_host_connection.h" | 17 #include "remoting/client/jingle_host_connection.h" |
| 18 #include "remoting/client/plugin/pepper_input_handler.h" |
16 #include "remoting/client/plugin/pepper_view.h" | 19 #include "remoting/client/plugin/pepper_view.h" |
17 #include "remoting/jingle_glue/jingle_thread.h" | 20 #include "remoting/jingle_glue/jingle_thread.h" |
18 #include "third_party/ppapi/c/pp_event.h" | 21 #include "third_party/ppapi/c/pp_event.h" |
19 #include "third_party/ppapi/c/pp_rect.h" | 22 #include "third_party/ppapi/c/pp_rect.h" |
20 #include "third_party/ppapi/cpp/completion_callback.h" | 23 #include "third_party/ppapi/cpp/completion_callback.h" |
21 | 24 |
22 using std::string; | |
23 using std::vector; | |
24 | |
25 namespace remoting { | 25 namespace remoting { |
26 | 26 |
27 const char* ChromotingPlugin::kMimeType = "pepper-application/x-chromoting"; | 27 const char* ChromotingPlugin::kMimeType = "pepper-application/x-chromoting"; |
28 | 28 |
29 ChromotingPlugin::ChromotingPlugin(PP_Instance pp_instance) | 29 ChromotingPlugin::ChromotingPlugin(PP_Instance pp_instance) |
30 : pp::Instance(pp_instance), | 30 : pp::Instance(pp_instance), |
31 pepper_main_loop_dont_post_to_me_(NULL) { | 31 pepper_main_loop_dont_post_to_me_(NULL) { |
32 } | 32 } |
33 | 33 |
34 ChromotingPlugin::~ChromotingPlugin() { | 34 ChromotingPlugin::~ChromotingPlugin() { |
35 if (host_connection_.get()) | 35 if (client_.get()) { |
36 host_connection_->Disconnect(); | 36 client_->Stop(); |
| 37 } |
37 | 38 |
38 // 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 |
39 // 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 |
40 // 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 |
41 // race condition. | 42 // race condition. |
42 if (network_thread_.get()) | 43 if (context_.get()) { |
43 network_thread_->Stop(); | 44 context_->Stop(); |
44 | 45 } |
45 if (main_thread_.get()) | |
46 main_thread_->Stop(); | |
47 } | 46 } |
48 | 47 |
49 bool ChromotingPlugin::Init(uint32_t argc, | 48 bool ChromotingPlugin::Init(uint32_t argc, |
50 const char* argn[], | 49 const char* argn[], |
51 const char* argv[]) { | 50 const char* argv[]) { |
52 CHECK(pepper_main_loop_dont_post_to_me_ == NULL); | 51 CHECK(pepper_main_loop_dont_post_to_me_ == NULL); |
53 | 52 |
54 // Record the current thread. This function should only be invoked by the | 53 // Record the current thread. This function should only be invoked by the |
55 // plugin thread, so we capture the current message loop and assume it is | 54 // plugin thread, so we capture the current message loop and assume it is |
56 // indeed the plugin thread. | 55 // indeed the plugin thread. |
(...skipping 13 matching lines...) Expand all Loading... |
70 if (strcmp(argn[i], "src") == 0) { | 69 if (strcmp(argn[i], "src") == 0) { |
71 url = argv[i]; | 70 url = argv[i]; |
72 break; | 71 break; |
73 } | 72 } |
74 } | 73 } |
75 | 74 |
76 if (!url) { | 75 if (!url) { |
77 return false; | 76 return false; |
78 } | 77 } |
79 | 78 |
80 string user_id; | 79 ClientConfig config; |
81 string auth_token; | 80 if (!GetLoginInfoFromUrlParams(url, &config)) { |
82 string host_jid; | |
83 if (!ParseUrl(url, &user_id, &auth_token, &host_jid)) { | |
84 LOG(WARNING) << "Could not parse URL: " << url; | 81 LOG(WARNING) << "Could not parse URL: " << url; |
85 return false; | 82 return false; |
86 } | 83 } |
87 | 84 |
88 // Start the threads. | 85 // Create the chromoting objects. |
89 main_thread_.reset(new base::Thread("ChromoClientMain")); | 86 host_connection_.reset(new JingleHostConnection(context_.get())); |
90 if (!main_thread_->Start()) { | |
91 LOG(ERROR) << "Main thread failed to start."; | |
92 return false; | |
93 } | |
94 network_thread_.reset(new JingleThread()); | |
95 network_thread_->Start(); | |
96 | |
97 // Create the chromting objects. | |
98 host_connection_.reset(new JingleHostConnection(network_thread_.get())); | |
99 view_.reset(new PepperView(this)); | 87 view_.reset(new PepperView(this)); |
100 client_.reset(new ChromotingClient(main_thread_->message_loop(), | 88 input_handler_.reset(new PepperInputHandler()); |
101 host_connection_.get(), view_.get())); | 89 client_.reset(new ChromotingClient(&config, |
| 90 context_.get(), |
| 91 host_connection_.get(), |
| 92 view_.get(), |
| 93 input_handler_.get(), |
| 94 NULL)); |
102 | 95 |
103 // Default to a medium grey. | 96 // Default to a medium grey. |
104 view_->SetSolidFill(0xFFCDCDCD); | 97 view_->SetSolidFill(0xFFCDCDCD); |
105 | 98 |
106 // Kick off the connection. | 99 // Kick off the connection. |
107 host_connection_->Connect(user_id, auth_token, host_jid, client_.get()); | 100 context_->Start(); |
| 101 client_->Start(); |
108 | 102 |
109 return true; | 103 return true; |
110 } | 104 } |
111 | 105 |
112 void ChromotingPlugin::ViewChanged(const PP_Rect& position, | 106 void ChromotingPlugin::ViewChanged(const PP_Rect& position, |
113 const PP_Rect& clip) { | 107 const PP_Rect& clip) { |
114 DCHECK(CurrentlyOnPluginThread()); | 108 DCHECK(CurrentlyOnPluginThread()); |
115 | 109 |
116 // TODO(ajwong): This is going to be a race condition when the view changes | 110 // TODO(ajwong): This is going to be a race condition when the view changes |
117 // and we're in the middle of a Paint(). | 111 // and we're in the middle of a Paint(). |
(...skipping 28 matching lines...) Expand all Loading... |
146 //client_->handle_char_event(npevent); | 140 //client_->handle_char_event(npevent); |
147 break; | 141 break; |
148 | 142 |
149 default: | 143 default: |
150 break; | 144 break; |
151 } | 145 } |
152 | 146 |
153 return false; | 147 return false; |
154 } | 148 } |
155 | 149 |
156 bool ChromotingPlugin::ParseUrl(const std::string& url, | |
157 string* user_id, | |
158 string* auth_token, | |
159 string* host_jid) { | |
160 // TODO(ajwong): We should use GURL or something. Don't parse this by hand! | |
161 | |
162 // The Url should be of the form: | |
163 // | |
164 // chromotocol://<hostid>?user=<userid>&auth=<authtoken>&jid=<hostjid> | |
165 // | |
166 vector<string> parts; | |
167 SplitString(url, '&', &parts); | |
168 if (parts.size() != 3) { | |
169 return false; | |
170 } | |
171 | |
172 size_t pos = parts[0].rfind('='); | |
173 if (pos == string::npos && (pos + 1) != string::npos) { | |
174 return false; | |
175 } | |
176 user_id->assign(parts[0].substr(pos + 1)); | |
177 | |
178 pos = parts[1].rfind('='); | |
179 if (pos == string::npos && (pos + 1) != string::npos) { | |
180 return false; | |
181 } | |
182 auth_token->assign(parts[1].substr(pos + 1)); | |
183 | |
184 pos = parts[2].rfind('='); | |
185 if (pos == string::npos && (pos + 1) != string::npos) { | |
186 return false; | |
187 } | |
188 host_jid->assign(parts[2].substr(pos + 1)); | |
189 | |
190 return true; | |
191 } | |
192 | |
193 } // namespace remoting | 150 } // namespace remoting |
OLD | NEW |