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" | 13 #include "remoting/client/client_config.h" |
14 #include "remoting/client/client_util.h" | 14 #include "remoting/client/client_util.h" |
15 #include "remoting/client/chromoting_client.h" | 15 #include "remoting/client/chromoting_client.h" |
16 #include "remoting/client/host_connection.h" | 16 #include "remoting/client/host_connection.h" |
17 #include "remoting/client/jingle_host_connection.h" | 17 #include "remoting/client/jingle_host_connection.h" |
18 #include "remoting/client/plugin/chromoting_scriptable_object.h" | |
19 #include "remoting/client/plugin/pepper_input_handler.h" | 18 #include "remoting/client/plugin/pepper_input_handler.h" |
20 #include "remoting/client/plugin/pepper_view.h" | 19 #include "remoting/client/plugin/pepper_view.h" |
21 #include "remoting/jingle_glue/jingle_thread.h" | 20 #include "remoting/jingle_glue/jingle_thread.h" |
22 #include "third_party/ppapi/c/pp_event.h" | 21 #include "third_party/ppapi/c/pp_event.h" |
| 22 #include "third_party/ppapi/c/pp_rect.h" |
23 #include "third_party/ppapi/cpp/completion_callback.h" | 23 #include "third_party/ppapi/cpp/completion_callback.h" |
24 #include "third_party/ppapi/cpp/rect.h" | |
25 | 24 |
26 namespace remoting { | 25 namespace remoting { |
27 | 26 |
28 const char* ChromotingPlugin::kMimeType = "pepper-application/x-chromoting"; | 27 const char* ChromotingPlugin::kMimeType = "pepper-application/x-chromoting"; |
29 | 28 |
30 ChromotingPlugin::ChromotingPlugin(PP_Instance pp_instance) | 29 ChromotingPlugin::ChromotingPlugin(PP_Instance pp_instance) |
31 : pp::Instance(pp_instance), | 30 : pp::Instance(pp_instance), |
32 pepper_main_loop_dont_post_to_me_(NULL) { | 31 pepper_main_loop_dont_post_to_me_(NULL) { |
33 } | 32 } |
34 | 33 |
35 ChromotingPlugin::~ChromotingPlugin() { | 34 ChromotingPlugin::~ChromotingPlugin() { |
36 if (client_.get()) { | 35 if (client_.get()) { |
37 client_->Stop(); | 36 client_->Stop(); |
38 } | 37 } |
39 | 38 |
40 // 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 |
41 // 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 |
42 // 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 |
43 // race condition. | 42 // race condition. |
44 context_.Stop(); | 43 if (context_.get()) { |
| 44 context_->Stop(); |
| 45 } |
45 } | 46 } |
46 | 47 |
47 bool ChromotingPlugin::Init(uint32_t argc, | 48 bool ChromotingPlugin::Init(uint32_t argc, |
48 const char* argn[], | 49 const char* argn[], |
49 const char* argv[]) { | 50 const char* argv[]) { |
50 CHECK(pepper_main_loop_dont_post_to_me_ == NULL); | 51 CHECK(pepper_main_loop_dont_post_to_me_ == NULL); |
51 | 52 |
52 // 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 |
53 // 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 |
54 // indeed the plugin thread. | 55 // indeed the plugin thread. |
55 // | 56 // |
56 // We're abusing the pepper API slightly here. We know we're running as an | 57 // We're abusing the pepper API slightly here. We know we're running as an |
57 // internal plugin, and thus we are on the pepper main thread that uses a | 58 // internal plugin, and thus we are on the pepper main thread that uses a |
58 // message loop. | 59 // message loop. |
59 // | 60 // |
60 // TODO(ajwong): See if there is a method for querying what thread we're on | 61 // TODO(ajwong): See if there is a method for querying what thread we're on |
61 // from inside the pepper API. | 62 // from inside the pepper API. |
62 pepper_main_loop_dont_post_to_me_ = MessageLoop::current(); | 63 pepper_main_loop_dont_post_to_me_ = MessageLoop::current(); |
63 LOG(INFO) << "Started ChromotingPlugin::Init"; | 64 LOG(INFO) << "Started ChromotingPlugin::Init"; |
64 | 65 |
65 // Start all the threads. | 66 // Extract the URL from the arguments. |
66 context_.Start(); | 67 const char* url = NULL; |
| 68 for (uint32_t i = 0; i < argc; ++i) { |
| 69 if (strcmp(argn[i], "src") == 0) { |
| 70 url = argv[i]; |
| 71 break; |
| 72 } |
| 73 } |
| 74 |
| 75 if (!url) { |
| 76 return false; |
| 77 } |
| 78 |
| 79 ClientConfig config; |
| 80 if (!GetLoginInfoFromUrlParams(url, &config)) { |
| 81 LOG(WARNING) << "Could not parse URL: " << url; |
| 82 return false; |
| 83 } |
67 | 84 |
68 // Create the chromoting objects. | 85 // Create the chromoting objects. |
69 host_connection_.reset(new JingleHostConnection(&context_)); | 86 host_connection_.reset(new JingleHostConnection(context_.get())); |
70 view_.reset(new PepperView(this)); | 87 view_.reset(new PepperView(this)); |
71 input_handler_.reset(new PepperInputHandler()); | 88 input_handler_.reset(new PepperInputHandler()); |
72 | |
73 // Default to a medium grey. | |
74 view_->SetSolidFill(0xFFCDCDCD); | |
75 | |
76 return true; | |
77 } | |
78 | |
79 void ChromotingPlugin::Connect(const ClientConfig& config) { | |
80 DCHECK(CurrentlyOnPluginThread()); | |
81 | |
82 client_.reset(new ChromotingClient(config, | 89 client_.reset(new ChromotingClient(config, |
83 &context_, | 90 context_.get(), |
84 host_connection_.get(), | 91 host_connection_.get(), |
85 view_.get(), | 92 view_.get(), |
86 input_handler_.get(), | 93 input_handler_.get(), |
87 NULL)); | 94 NULL)); |
88 | 95 |
| 96 // Default to a medium grey. |
| 97 view_->SetSolidFill(0xFFCDCDCD); |
| 98 |
89 // Kick off the connection. | 99 // Kick off the connection. |
| 100 context_->Start(); |
90 client_->Start(); | 101 client_->Start(); |
| 102 |
| 103 return true; |
91 } | 104 } |
92 | 105 |
93 void ChromotingPlugin::ViewChanged(const pp::Rect& position, | 106 void ChromotingPlugin::ViewChanged(const PP_Rect& position, |
94 const pp::Rect& clip) { | 107 const PP_Rect& clip) { |
95 DCHECK(CurrentlyOnPluginThread()); | 108 DCHECK(CurrentlyOnPluginThread()); |
96 | 109 |
97 // 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 |
98 // and we're in the middle of a Paint(). | 111 // and we're in the middle of a Paint(). |
99 LOG(INFO) << "ViewChanged " | 112 LOG(INFO) << "ViewChanged " |
100 << position.x() << "," | 113 << position.point.x << "," |
101 << position.y() << "," | 114 << position.point.y << "," |
102 << position.width() << "," | 115 << position.size.width << "," |
103 << position.height(); | 116 << position.size.height; |
104 | 117 |
105 view_->SetViewport(position.x(), position.y(), | 118 view_->SetViewport(position.point.x, position.point.y, |
106 position.width(), position.height()); | 119 position.size.width, position.size.height); |
107 view_->Paint(); | 120 view_->Paint(); |
108 } | 121 } |
109 | 122 |
110 bool ChromotingPlugin::CurrentlyOnPluginThread() const { | 123 bool ChromotingPlugin::CurrentlyOnPluginThread() const { |
111 return pepper_main_loop_dont_post_to_me_ == MessageLoop::current(); | 124 return pepper_main_loop_dont_post_to_me_ == MessageLoop::current(); |
112 } | 125 } |
113 | 126 |
114 bool ChromotingPlugin::HandleEvent(const PP_Event& event) { | 127 bool ChromotingPlugin::HandleEvent(const PP_Event& event) { |
115 DCHECK(CurrentlyOnPluginThread()); | 128 DCHECK(CurrentlyOnPluginThread()); |
116 | 129 |
(...skipping 10 matching lines...) Expand all Loading... |
127 //client_->handle_char_event(npevent); | 140 //client_->handle_char_event(npevent); |
128 break; | 141 break; |
129 | 142 |
130 default: | 143 default: |
131 break; | 144 break; |
132 } | 145 } |
133 | 146 |
134 return false; | 147 return false; |
135 } | 148 } |
136 | 149 |
137 pp::Var ChromotingPlugin::GetInstanceObject() { | |
138 LOG(ERROR) << "Getting instance object."; | |
139 if (instance_object_.is_void()) { | |
140 ChromotingScriptableObject* object = new ChromotingScriptableObject(this); | |
141 object->Init(); | |
142 | |
143 LOG(ERROR) << "Object initted."; | |
144 // The pp::Var takes ownership of object here. | |
145 instance_object_ = pp::Var(object); | |
146 } | |
147 | |
148 return instance_object_; | |
149 } | |
150 | |
151 } // namespace remoting | 150 } // namespace remoting |
OLD | NEW |