OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "remoting/client/plugin/chromoting_plugin.h" | |
6 | |
7 #include <string> | |
8 #include <vector> | |
9 | |
10 #include "base/message_loop.h" | |
11 #include "base/string_util.h" | |
12 #include "base/thread.h" | |
13 #include "remoting/client/client_config.h" | |
14 #include "remoting/client/client_util.h" | |
15 #include "remoting/client/chromoting_client.h" | |
16 #include "remoting/client/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" | |
20 #include "remoting/client/plugin/pepper_view.h" | |
21 #include "remoting/jingle_glue/jingle_thread.h" | |
22 #include "third_party/ppapi/c/pp_event.h" | |
23 #include "third_party/ppapi/cpp/completion_callback.h" | |
24 #include "third_party/ppapi/cpp/rect.h" | |
25 | |
26 namespace remoting { | |
27 | |
28 const char* ChromotingPlugin::kMimeType = "pepper-application/x-chromoting"; | |
29 | |
30 ChromotingPlugin::ChromotingPlugin(PP_Instance pp_instance) | |
31 : pp::Instance(pp_instance), | |
32 pepper_main_loop_dont_post_to_me_(NULL) { | |
33 } | |
34 | |
35 ChromotingPlugin::~ChromotingPlugin() { | |
36 if (client_.get()) { | |
37 client_->Stop(); | |
38 } | |
39 | |
40 // 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 | |
42 // defined stop for the plugin process, and the thread shutdown is likely a | |
43 // race condition. | |
44 context_.Stop(); | |
45 } | |
46 | |
47 bool ChromotingPlugin::Init(uint32_t argc, | |
48 const char* argn[], | |
49 const char* argv[]) { | |
50 CHECK(pepper_main_loop_dont_post_to_me_ == NULL); | |
51 | |
52 // 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 // indeed the plugin thread. | |
55 // | |
56 // 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 // message loop. | |
59 // | |
60 // TODO(ajwong): See if there is a method for querying what thread we're on | |
61 // from inside the pepper API. | |
62 pepper_main_loop_dont_post_to_me_ = MessageLoop::current(); | |
63 LOG(INFO) << "Started ChromotingPlugin::Init"; | |
64 | |
65 // Start all the threads. | |
66 context_.Start(); | |
67 | |
68 // Create the chromoting objects. | |
69 host_connection_.reset(new JingleHostConnection(&context_)); | |
70 view_.reset(new PepperView(this)); | |
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 | |
82 client_.reset(new ChromotingClient(config, | |
83 &context_, | |
84 host_connection_.get(), | |
85 view_.get(), | |
86 input_handler_.get(), | |
87 NULL)); | |
88 | |
89 // Kick off the connection. | |
90 client_->Start(); | |
91 } | |
92 | |
93 void ChromotingPlugin::ViewChanged(const pp::Rect& position, | |
94 const pp::Rect& clip) { | |
95 DCHECK(CurrentlyOnPluginThread()); | |
96 | |
97 // TODO(ajwong): This is going to be a race condition when the view changes | |
98 // and we're in the middle of a Paint(). | |
99 LOG(INFO) << "ViewChanged " | |
100 << position.x() << "," | |
101 << position.y() << "," | |
102 << position.width() << "," | |
103 << position.height(); | |
104 | |
105 view_->SetViewport(position.x(), position.y(), | |
106 position.width(), position.height()); | |
107 view_->Paint(); | |
108 } | |
109 | |
110 bool ChromotingPlugin::CurrentlyOnPluginThread() const { | |
111 return pepper_main_loop_dont_post_to_me_ == MessageLoop::current(); | |
112 } | |
113 | |
114 bool ChromotingPlugin::HandleEvent(const PP_Event& event) { | |
115 DCHECK(CurrentlyOnPluginThread()); | |
116 | |
117 switch (event.type) { | |
118 case PP_EVENT_TYPE_MOUSEDOWN: | |
119 case PP_EVENT_TYPE_MOUSEUP: | |
120 case PP_EVENT_TYPE_MOUSEMOVE: | |
121 case PP_EVENT_TYPE_MOUSEENTER: | |
122 case PP_EVENT_TYPE_MOUSELEAVE: | |
123 //client_->handle_mouse_event(npevent); | |
124 break; | |
125 | |
126 case PP_EVENT_TYPE_CHAR: | |
127 //client_->handle_char_event(npevent); | |
128 break; | |
129 | |
130 default: | |
131 break; | |
132 } | |
133 | |
134 return false; | |
135 } | |
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 | |
151 } // namespace remoting | |
OLD | NEW |