OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_instance.h" | 5 #include "remoting/client/plugin/chromoting_instance.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/string_split.h" | 17 #include "base/string_split.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
21 #include "base/values.h" | 21 #include "base/values.h" |
22 #include "jingle/glue/thread_wrapper.h" | 22 #include "jingle/glue/thread_wrapper.h" |
23 #include "media/base/media.h" | 23 #include "media/base/media.h" |
24 #include "ppapi/cpp/completion_callback.h" | 24 #include "ppapi/cpp/completion_callback.h" |
25 #include "ppapi/cpp/input_event.h" | 25 #include "ppapi/cpp/input_event.h" |
26 #include "ppapi/cpp/mouse_cursor.h" | |
26 #include "ppapi/cpp/rect.h" | 27 #include "ppapi/cpp/rect.h" |
27 // TODO(wez): Remove this when crbug.com/86353 is complete. | 28 // TODO(wez): Remove this when crbug.com/86353 is complete. |
28 #include "ppapi/cpp/private/var_private.h" | 29 #include "ppapi/cpp/private/var_private.h" |
29 #include "remoting/base/constants.h" | 30 #include "remoting/base/constants.h" |
30 #include "remoting/base/util.h" | 31 #include "remoting/base/util.h" |
31 #include "remoting/client/client_config.h" | 32 #include "remoting/client/client_config.h" |
32 #include "remoting/client/chromoting_client.h" | 33 #include "remoting/client/chromoting_client.h" |
33 #include "remoting/client/frame_consumer_proxy.h" | 34 #include "remoting/client/frame_consumer_proxy.h" |
34 #include "remoting/client/plugin/chromoting_scriptable_object.h" | 35 #include "remoting/client/plugin/chromoting_scriptable_object.h" |
35 #include "remoting/client/plugin/pepper_input_handler.h" | 36 #include "remoting/client/plugin/pepper_input_handler.h" |
36 #include "remoting/client/plugin/pepper_port_allocator.h" | 37 #include "remoting/client/plugin/pepper_port_allocator.h" |
37 #include "remoting/client/plugin/pepper_view.h" | 38 #include "remoting/client/plugin/pepper_view.h" |
38 #include "remoting/client/plugin/pepper_xmpp_proxy.h" | 39 #include "remoting/client/plugin/pepper_xmpp_proxy.h" |
39 #include "remoting/client/rectangle_update_decoder.h" | 40 #include "remoting/client/rectangle_update_decoder.h" |
40 #include "remoting/protocol/connection_to_host.h" | 41 #include "remoting/protocol/connection_to_host.h" |
41 #include "remoting/protocol/host_stub.h" | 42 #include "remoting/protocol/host_stub.h" |
42 #include "remoting/protocol/input_event_tracker.h" | 43 #include "remoting/protocol/input_event_tracker.h" |
43 #include "remoting/protocol/libjingle_transport_factory.h" | 44 #include "remoting/protocol/libjingle_transport_factory.h" |
44 #include "remoting/protocol/mouse_input_filter.h" | 45 #include "remoting/protocol/mouse_input_filter.h" |
45 | 46 |
46 // Windows defines 'PostMessage', so we have to undef it. | 47 // Windows defines 'PostMessage', so we have to undef it. |
47 #if defined(PostMessage) | 48 #if defined(PostMessage) |
48 #undef PostMessage | 49 #undef PostMessage |
49 #endif | 50 #endif |
50 | 51 |
51 namespace remoting { | 52 namespace remoting { |
52 | 53 |
53 namespace { | 54 namespace { |
54 | 55 |
56 // 32-bit BGRA is 4 bytes per pixel. | |
57 const int kBytesPerPixel = 4; | |
58 | |
55 const int kPerfStatsIntervalMs = 1000; | 59 const int kPerfStatsIntervalMs = 1000; |
56 | 60 |
57 std::string ConnectionStateToString(ChromotingInstance::ConnectionState state) { | 61 std::string ConnectionStateToString(ChromotingInstance::ConnectionState state) { |
58 switch (state) { | 62 switch (state) { |
59 case ChromotingInstance::STATE_CONNECTING: | 63 case ChromotingInstance::STATE_CONNECTING: |
60 return "CONNECTING"; | 64 return "CONNECTING"; |
61 case ChromotingInstance::STATE_INITIALIZING: | 65 case ChromotingInstance::STATE_INITIALIZING: |
62 return "INITIALIZING"; | 66 return "INITIALIZING"; |
63 case ChromotingInstance::STATE_CONNECTED: | 67 case ChromotingInstance::STATE_CONNECTED: |
64 return "CONNECTED"; | 68 return "CONNECTED"; |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 } | 590 } |
587 | 591 |
588 void ChromotingInstance::InjectClipboardEvent( | 592 void ChromotingInstance::InjectClipboardEvent( |
589 const protocol::ClipboardEvent& event) { | 593 const protocol::ClipboardEvent& event) { |
590 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 594 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
591 data->SetString("mimeType", event.mime_type()); | 595 data->SetString("mimeType", event.mime_type()); |
592 data->SetString("item", event.data()); | 596 data->SetString("item", event.data()); |
593 PostChromotingMessage("injectClipboardItem", data.Pass()); | 597 PostChromotingMessage("injectClipboardItem", data.Pass()); |
594 } | 598 } |
595 | 599 |
600 void ChromotingInstance::SetCursorShape( | |
601 const protocol::CursorShapeInfo& cursor_shape) { | |
602 if (!cursor_shape.has_data() || | |
603 !cursor_shape.has_width() || | |
604 !cursor_shape.has_height() || | |
605 !cursor_shape.has_hotspot_x() || | |
606 !cursor_shape.has_hotspot_y()) { | |
607 return; | |
608 } | |
609 | |
610 if (pp::ImageData::GetNativeImageDataFormat() != | |
611 PP_IMAGEDATAFORMAT_BGRA_PREMUL) { | |
612 LOG(WARNING) << "Unable to set cursor shape - non-native image format"; | |
Wez
2012/05/30 23:42:42
nit: Consider making this a VLOG, otherwise you'll
garykac
2012/05/31 00:29:41
Done.
| |
613 return; | |
614 } | |
615 | |
616 int width = cursor_shape.width(); | |
617 int height = cursor_shape.height(); | |
618 | |
619 if (width > 32 || height > 32) { | |
620 LOG(WARNING) << "Cursor too large for SetCursor: " | |
621 << width << "x" << height << " > 32x32"; | |
Wez
2012/05/30 23:42:42
nit: Consider using VLOG here, too.
garykac
2012/05/31 00:29:41
Done.
| |
622 return; | |
623 } | |
624 | |
625 int hotspot_x = cursor_shape.hotspot_x(); | |
626 int hotspot_y = cursor_shape.hotspot_y(); | |
627 | |
628 pp::ImageData cursor_image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, | |
629 pp::Size(width, height), false); | |
630 | |
631 int bytes_per_row = width * kBytesPerPixel; | |
632 const uint8* src_row_data = reinterpret_cast<const uint8*>( | |
633 cursor_shape.data().data()); | |
634 uint8* dst_row_data = reinterpret_cast<uint8*>(cursor_image.data()); | |
635 for (int row = 0; row < height; row++) { | |
636 memcpy(dst_row_data, src_row_data, bytes_per_row); | |
637 src_row_data += bytes_per_row; | |
638 dst_row_data += cursor_image.stride(); | |
639 } | |
640 | |
641 pp::MouseCursor::SetCursor(this, PP_MOUSECURSOR_TYPE_CUSTOM, | |
642 cursor_image, | |
643 pp::Point(hotspot_x, hotspot_y)); | |
644 } | |
645 | |
596 // static | 646 // static |
597 void ChromotingInstance::RegisterLogMessageHandler() { | 647 void ChromotingInstance::RegisterLogMessageHandler() { |
598 base::AutoLock lock(g_logging_lock.Get()); | 648 base::AutoLock lock(g_logging_lock.Get()); |
599 | 649 |
600 VLOG(1) << "Registering global log handler"; | 650 VLOG(1) << "Registering global log handler"; |
601 | 651 |
602 // Record previous handler so we can call it in a chain. | 652 // Record previous handler so we can call it in a chain. |
603 g_logging_old_handler = logging::GetLogMessageHandler(); | 653 g_logging_old_handler = logging::GetLogMessageHandler(); |
604 | 654 |
605 // Set up log message handler. | 655 // Set up log message handler. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 } | 742 } |
693 g_logging_to_plugin = false; | 743 g_logging_to_plugin = false; |
694 } | 744 } |
695 | 745 |
696 bool ChromotingInstance::IsConnected() { | 746 bool ChromotingInstance::IsConnected() { |
697 return host_connection_.get() && | 747 return host_connection_.get() && |
698 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); | 748 (host_connection_->state() == protocol::ConnectionToHost::CONNECTED); |
699 } | 749 } |
700 | 750 |
701 } // namespace remoting | 751 } // namespace remoting |
OLD | NEW |