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" |
18 #include "remoting/client/plugin/pepper_input_handler.h" | 19 #include "remoting/client/plugin/pepper_input_handler.h" |
19 #include "remoting/client/plugin/pepper_view.h" | 20 #include "remoting/client/plugin/pepper_view.h" |
20 #include "remoting/jingle_glue/jingle_thread.h" | 21 #include "remoting/jingle_glue/jingle_thread.h" |
21 #include "third_party/ppapi/c/pp_event.h" | 22 #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" |
24 | 25 |
25 namespace remoting { | 26 namespace remoting { |
26 | 27 |
27 const char* ChromotingPlugin::kMimeType = "pepper-application/x-chromoting"; | 28 const char* ChromotingPlugin::kMimeType = "pepper-application/x-chromoting"; |
28 | 29 |
29 ChromotingPlugin::ChromotingPlugin(PP_Instance pp_instance) | 30 ChromotingPlugin::ChromotingPlugin(PP_Instance pp_instance) |
30 : pp::Instance(pp_instance), | 31 : pp::Instance(pp_instance), |
31 pepper_main_loop_dont_post_to_me_(NULL) { | 32 pepper_main_loop_dont_post_to_me_(NULL) { |
32 } | 33 } |
33 | 34 |
34 ChromotingPlugin::~ChromotingPlugin() { | 35 ChromotingPlugin::~ChromotingPlugin() { |
35 if (client_.get()) { | 36 if (client_.get()) { |
36 client_->Stop(); | 37 client_->Stop(); |
37 } | 38 } |
38 | 39 |
39 // TODO(ajwong): We need to ensure all objects have actually stopped posting | 40 // 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 // 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 // defined stop for the plugin process, and the thread shutdown is likely a |
42 // race condition. | 43 // race condition. |
43 if (context_.get()) { | 44 context_.Stop(); |
44 context_->Stop(); | |
45 } | |
46 } | 45 } |
47 | 46 |
48 bool ChromotingPlugin::Init(uint32_t argc, | 47 bool ChromotingPlugin::Init(uint32_t argc, |
49 const char* argn[], | 48 const char* argn[], |
50 const char* argv[]) { | 49 const char* argv[]) { |
51 CHECK(pepper_main_loop_dont_post_to_me_ == NULL); | 50 CHECK(pepper_main_loop_dont_post_to_me_ == NULL); |
52 | 51 |
53 // Record the current thread. This function should only be invoked by the | 52 // Record the current thread. This function should only be invoked by the |
54 // plugin thread, so we capture the current message loop and assume it is | 53 // plugin thread, so we capture the current message loop and assume it is |
55 // indeed the plugin thread. | 54 // indeed the plugin thread. |
56 // | 55 // |
57 // We're abusing the pepper API slightly here. We know we're running as an | 56 // We're abusing the pepper API slightly here. We know we're running as an |
58 // internal plugin, and thus we are on the pepper main thread that uses a | 57 // internal plugin, and thus we are on the pepper main thread that uses a |
59 // message loop. | 58 // message loop. |
60 // | 59 // |
61 // TODO(ajwong): See if there is a method for querying what thread we're on | 60 // TODO(ajwong): See if there is a method for querying what thread we're on |
62 // from inside the pepper API. | 61 // from inside the pepper API. |
63 pepper_main_loop_dont_post_to_me_ = MessageLoop::current(); | 62 pepper_main_loop_dont_post_to_me_ = MessageLoop::current(); |
64 LOG(INFO) << "Started ChromotingPlugin::Init"; | 63 LOG(INFO) << "Started ChromotingPlugin::Init"; |
65 | 64 |
66 // Extract the URL from the arguments. | 65 // Start all the threads. |
67 const char* url = NULL; | 66 context_.Start(); |
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 } | |
84 | 67 |
85 // Create the chromoting objects. | 68 // Create the chromoting objects. |
86 host_connection_.reset(new JingleHostConnection(context_.get())); | 69 host_connection_.reset(new JingleHostConnection(&context_)); |
87 view_.reset(new PepperView(this)); | 70 view_.reset(new PepperView(this)); |
88 input_handler_.reset(new PepperInputHandler()); | 71 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 |
89 client_.reset(new ChromotingClient(config, | 82 client_.reset(new ChromotingClient(config, |
90 context_.get(), | 83 &context_, |
91 host_connection_.get(), | 84 host_connection_.get(), |
92 view_.get(), | 85 view_.get(), |
93 input_handler_.get(), | 86 input_handler_.get(), |
94 NULL)); | 87 NULL)); |
95 | 88 |
96 // Default to a medium grey. | |
97 view_->SetSolidFill(0xFFCDCDCD); | |
98 | |
99 // Kick off the connection. | 89 // Kick off the connection. |
100 context_->Start(); | |
101 client_->Start(); | 90 client_->Start(); |
102 | |
103 return true; | |
104 } | 91 } |
105 | 92 |
106 void ChromotingPlugin::ViewChanged(const PP_Rect& position, | 93 void ChromotingPlugin::ViewChanged(const pp::Rect& position, |
107 const PP_Rect& clip) { | 94 const pp::Rect& clip) { |
108 DCHECK(CurrentlyOnPluginThread()); | 95 DCHECK(CurrentlyOnPluginThread()); |
109 | 96 |
110 // TODO(ajwong): This is going to be a race condition when the view changes | 97 // TODO(ajwong): This is going to be a race condition when the view changes |
111 // and we're in the middle of a Paint(). | 98 // and we're in the middle of a Paint(). |
112 LOG(INFO) << "ViewChanged " | 99 LOG(INFO) << "ViewChanged " |
113 << position.point.x << "," | 100 << position.x() << "," |
114 << position.point.y << "," | 101 << position.y() << "," |
115 << position.size.width << "," | 102 << position.width() << "," |
116 << position.size.height; | 103 << position.height(); |
117 | 104 |
118 view_->SetViewport(position.point.x, position.point.y, | 105 view_->SetViewport(position.x(), position.y(), |
119 position.size.width, position.size.height); | 106 position.width(), position.height()); |
120 view_->Paint(); | 107 view_->Paint(); |
121 } | 108 } |
122 | 109 |
123 bool ChromotingPlugin::CurrentlyOnPluginThread() const { | 110 bool ChromotingPlugin::CurrentlyOnPluginThread() const { |
124 return pepper_main_loop_dont_post_to_me_ == MessageLoop::current(); | 111 return pepper_main_loop_dont_post_to_me_ == MessageLoop::current(); |
125 } | 112 } |
126 | 113 |
127 bool ChromotingPlugin::HandleEvent(const PP_Event& event) { | 114 bool ChromotingPlugin::HandleEvent(const PP_Event& event) { |
128 DCHECK(CurrentlyOnPluginThread()); | 115 DCHECK(CurrentlyOnPluginThread()); |
129 | 116 |
(...skipping 10 matching lines...) Expand all Loading... |
140 //client_->handle_char_event(npevent); | 127 //client_->handle_char_event(npevent); |
141 break; | 128 break; |
142 | 129 |
143 default: | 130 default: |
144 break; | 131 break; |
145 } | 132 } |
146 | 133 |
147 return false; | 134 return false; |
148 } | 135 } |
149 | 136 |
| 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 |
150 } // namespace remoting | 151 } // namespace remoting |
OLD | NEW |