OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 "native_client/src/shared/ppapi_proxy/plugin_ppb_view.h" |
| 6 |
| 7 #include "native_client/src/include/portability.h" |
| 8 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" |
| 9 #include "native_client/src/shared/ppapi_proxy/plugin_upcall.h" |
| 10 #include "native_client/src/shared/ppapi_proxy/utility.h" |
| 11 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 12 #include "ppapi/c/pp_completion_callback.h" |
| 13 #include "ppapi/c/pp_errors.h" |
| 14 #include "ppapi/c/pp_rect.h" |
| 15 #include "ppapi/c/pp_size.h" |
| 16 #include "srpcgen/ppb_rpc.h" |
| 17 #include "srpcgen/upcall.h" |
| 18 |
| 19 namespace ppapi_proxy { |
| 20 |
| 21 namespace { |
| 22 |
| 23 class ViewGetter { |
| 24 public: |
| 25 ViewGetter(PP_Resource resource, const char* function_name) { |
| 26 DebugPrintf("PPB_View::%s: resource=%"NACL_PRIu32"\n", |
| 27 function_name, |
| 28 resource); |
| 29 view_ = PluginResource::GetAs<PluginView>(resource); |
| 30 } |
| 31 |
| 32 PluginView* get() { return view_.get(); } |
| 33 |
| 34 private: |
| 35 NACL_DISALLOW_COPY_AND_ASSIGN(ViewGetter); |
| 36 scoped_refptr<PluginView> view_; |
| 37 }; |
| 38 |
| 39 // This macro is for starting a resource function. It makes sure resource_arg |
| 40 // is of type PluginView, and returns error_return if it's not. |
| 41 #define BEGIN_RESOURCE_THUNK(function_name, resource_arg, error_return) \ |
| 42 ViewGetter view(resource_arg, function_name); \ |
| 43 if (!view.get()) { \ |
| 44 return error_return; \ |
| 45 } |
| 46 |
| 47 PP_Bool IsView(PP_Resource resource) { |
| 48 DebugPrintf("PPB_View::IsView: resource=%"NACL_PRIu32"\n", |
| 49 resource); |
| 50 return PluginResource::GetAs<PluginView>(resource).get() |
| 51 ? PP_TRUE : PP_FALSE; |
| 52 } |
| 53 |
| 54 PP_Bool GetRect(PP_Resource resource, PP_Rect* viewport) { |
| 55 BEGIN_RESOURCE_THUNK("GetRect", resource, PP_FALSE); |
| 56 *viewport = view.get()->view_data().viewport_rect; |
| 57 return PP_TRUE; |
| 58 } |
| 59 |
| 60 PP_Bool IsFullscreen(PP_Resource resource) { |
| 61 BEGIN_RESOURCE_THUNK("IsFullscreen", resource, PP_FALSE); |
| 62 return view.get()->view_data().is_fullscreen; |
| 63 } |
| 64 |
| 65 PP_Bool IsUserVisible(PP_Resource resource) { |
| 66 BEGIN_RESOURCE_THUNK("IsUserVisible", resource, PP_FALSE); |
| 67 const ViewData& data = view.get()->view_data(); |
| 68 return PP_FromBool(data.is_page_visible && |
| 69 data.clip_rect.size.width > 0 && |
| 70 data.clip_rect.size.height > 0); |
| 71 } |
| 72 |
| 73 PP_Bool IsPageVisible(PP_Resource resource) { |
| 74 BEGIN_RESOURCE_THUNK("IsPageVisible", resource, PP_FALSE); |
| 75 return view.get()->view_data().is_page_visible; |
| 76 } |
| 77 |
| 78 PP_Bool GetClipRect(PP_Resource resource, PP_Rect* clip) { |
| 79 BEGIN_RESOURCE_THUNK("GetClipRect", resource, PP_FALSE); |
| 80 *clip = view.get()->view_data().clip_rect; |
| 81 return PP_TRUE; |
| 82 } |
| 83 |
| 84 } // namespace |
| 85 |
| 86 PluginView::PluginView() { |
| 87 } |
| 88 |
| 89 PluginView::~PluginView() { |
| 90 } |
| 91 |
| 92 void PluginView::Init(const ViewData& view_data) { |
| 93 view_data_ = view_data; |
| 94 } |
| 95 |
| 96 const PPB_View* PluginView::GetInterface() { |
| 97 static const PPB_View view_interface = { |
| 98 &IsView, |
| 99 &GetRect, |
| 100 &IsFullscreen, |
| 101 &IsUserVisible, |
| 102 &IsPageVisible, |
| 103 &GetClipRect |
| 104 }; |
| 105 return &view_interface; |
| 106 } |
| 107 |
| 108 } // namespace ppapi_proxy |
OLD | NEW |