f7eb925cf624d56a4c967ce16972d2b2cb00ed82
[platform/framework/web/crosswalk-tizen.git] /
1 // Copyright 2017 Samsung Electronics. 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 #ifndef EWK_EFL_INTEGRATION_BROWSER_JAVASCRIPT_INTERFACE_GIN_NATIVE_BOUND_OBJECT_H_
6 #define EWK_EFL_INTEGRATION_BROWSER_JAVASCRIPT_INTERFACE_GIN_NATIVE_BOUND_OBJECT_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <set>
12 #include <string>
13
14 #include "base/memory/ref_counted.h"
15 #include "public/ewk_view.h"
16
17 namespace content {
18
19 class GinNativeBoundObject
20     : public base::RefCountedThreadSafe<GinNativeBoundObject> {
21  public:
22   GinNativeBoundObject(
23       Evas_Object* obj,
24       Ewk_View_Script_Message_Cb callback,
25       const std::string& name);
26   GinNativeBoundObject(
27       Evas_Object* obj,
28       Ewk_View_Script_Message_Cb callback,
29       const std::string& name,
30       const std::set<int32_t>& holders);
31
32   typedef int32_t ObjectID;
33   static GinNativeBoundObject* CreateNamed(
34       Evas_Object* obj,
35       Ewk_View_Script_Message_Cb callback,
36       const std::string& name);
37   static GinNativeBoundObject* CreateTransient(
38       Evas_Object* obj,
39       Ewk_View_Script_Message_Cb callback,
40       const std::string& name,
41       int32_t holder);
42   void AddName() { ++names_count_; }
43   void RemoveName() { --names_count_; }
44   Evas_Object* GetView() const { return obj_; }
45   Ewk_View_Script_Message_Cb CallBack() const { return callback_; }
46   const char* Name() const { return name_.c_str(); }
47
48  private:
49   friend class base::RefCountedThreadSafe<GinNativeBoundObject>;
50   ~GinNativeBoundObject();
51
52   Evas_Object* obj_;
53   Ewk_View_Script_Message_Cb callback_;
54   std::string name_;
55
56   // An object must be kept in retained_object_set_ either if it has
57   // names or if it has a non-empty holders set.
58   int names_count_;
59   std::set<int32_t> holders_;
60 };
61
62 }  // namespace content
63
64 #endif  // EWK_EFL_INTEGRATION_BROWSER_JAVASCRIPT_INTERFACE_GIN_NATIVE_BOUND_OBJECT_H_