[Bookmark] Initial commit for bookmark API
authorKamil Nowac <k.nowac@samsung.com>
Tue, 9 Dec 2014 14:56:37 +0000 (15:56 +0100)
committerKamil Nowac <k.nowac@samsung.com>
Wed, 10 Dec 2014 14:35:44 +0000 (15:35 +0100)
Change-Id: I33ec7a9605fd38e8c98a1d1601da80b8e1157bca
Signed-off-by: Kamil Nowac <k.nowac@samsung.com>
bookmark/bookmark.gyp [new file with mode: 0644]
bookmark/bookmark_api.js [new file with mode: 0644]
bookmark/bookmark_extension.cc [new file with mode: 0644]
bookmark/bookmark_extension.h [new file with mode: 0644]
bookmark/bookmark_instance.cc [new file with mode: 0644]
bookmark/bookmark_instance.h [new file with mode: 0644]
tizen-wrt.gyp

diff --git a/bookmark/bookmark.gyp b/bookmark/bookmark.gyp
new file mode 100644 (file)
index 0000000..f969478
--- /dev/null
@@ -0,0 +1,26 @@
+{
+  'includes':[
+    '../common/common.gypi',
+  ],
+  'targets': [
+    {
+      'target_name': 'tizen_bookmark',
+      'type': 'loadable_module',
+      'includes': [
+        '../common/pkg-config.gypi',
+      ],
+      'sources': [
+        'bookmark_api.js',
+        'bookmark_extension.cc',
+        'bookmark_extension.h',
+        'bookmark_instance.cc',
+        'bookmark_instance.h',
+      ],
+      'conditions': [
+        [ 'tizen == 1', {
+            'variables': { },
+        }],
+      ],
+    },
+  ],
+}
diff --git a/bookmark/bookmark_api.js b/bookmark/bookmark_api.js
new file mode 100644 (file)
index 0000000..4709631
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function throwException_(err) {
+  throw new tizen.WebAPIException(err.code, err.name, err.message);
+}
+
+function _sendSyncMessage(msg) {
+  var data = null;
+  data = JSON.stringify(msg);
+
+  return JSON.parse(extension.internal.sendSyncMessage(data));
+}
+
+function BookmarkManager() {
+}
+
+BookmarkManager.prototype.get = function() {
+  return new BookmarkManager();
+};
+
+BookmarkManager.prototype.add = function(parent_folder, recursive) {
+  var msg = {
+    cmd: 'add',
+    arg: ''
+  };
+
+  return _sendSyncMessage(msg).value;
+};
+
+
+BookmarkManager.prototype.remove = function(bookmark) {
+  var msg = {
+    cmd: 'remove',
+    arg: ''
+  };
+
+  return _sendSyncMessage(msg).value;
+};
+
+tizen.BookmarkItem = function(title, url) {
+  var parent;
+  var title_;
+  var url_;
+};
+
+tizen.BookmarkFolder = function(title) {
+  var parent;
+  var title_;
+};
+
+exports = new BookmarkManager();
diff --git a/bookmark/bookmark_extension.cc b/bookmark/bookmark_extension.cc
new file mode 100644 (file)
index 0000000..95a6f5b
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "bookmark/bookmark_extension.h"
+#include "bookmark/bookmark_instance.h"
+
+namespace {
+  const char* kBookmark = "tizen.bookmark";
+  const char* kBookmarkItem = "tizen.BookmarkItem";
+  const char* kBookmarkFolder = "tizen.BookmarkFolder";
+}
+
+// This will be generated from bookmark_api.js.
+extern const char kSource_bookmark_api[];
+
+common::Extension* CreateExtension() {
+  return new BookmarkExtension;
+}
+
+BookmarkExtension::BookmarkExtension() {
+  SetExtensionName(kBookmark);
+  SetJavaScriptAPI(kSource_bookmark_api);
+
+  const char* entry_points[] = {
+    kBookmarkItem,
+    kBookmarkFolder,
+    NULL
+  };
+  SetExtraJSEntryPoints(entry_points);
+}
+
+BookmarkExtension::~BookmarkExtension() {}
+
+common::Instance* BookmarkExtension::CreateInstance() {
+  return new extension::bookmark::BookmarkInstance;
+}
diff --git a/bookmark/bookmark_extension.h b/bookmark/bookmark_extension.h
new file mode 100644 (file)
index 0000000..eb931fe
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BOOKMARK_BOOKMARK_EXTENSION_H_
+#define BOOKMARK_BOOKMARK_EXTENSION_H_
+
+#include "common/extension.h"
+
+class BookmarkExtension : public common::Extension {
+ public:
+  BookmarkExtension();
+  virtual ~BookmarkExtension();
+
+ private:
+  virtual common::Instance* CreateInstance();
+};
+
+#endif  // BOOKMARK_BOOKMARK_EXTENSION_H_
diff --git a/bookmark/bookmark_instance.cc b/bookmark/bookmark_instance.cc
new file mode 100644 (file)
index 0000000..2980809
--- /dev/null
@@ -0,0 +1,69 @@
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "bookmark/bookmark_instance.h"
+
+#include <string>
+
+namespace extension {
+namespace bookmark {
+
+namespace {
+  const char* kGet = "get";
+  const char* kAdd = "add";
+  const char* kRemove = "remove";
+  const char* kCmd = "cmd";
+  const char* kArg = "arg";
+  const char* kError = "error";
+  const char* kValue = "value";
+  const char* kNotImplemented = "Not implemented";
+}
+
+BookmarkInstance::BookmarkInstance() {}
+
+BookmarkInstance::~BookmarkInstance() {}
+
+void BookmarkInstance::HandleMessage(const char* msg) {}
+
+void BookmarkInstance::HandleSyncMessage(const char* msg) {
+  picojson::value v;
+  std::string err;
+
+  picojson::parse(v, msg, msg + strlen(msg), &err);
+  if (!err.empty()) {
+    return;
+  }
+
+  std::string cmd = v.get(kCmd).to_str();
+  picojson::value arg = v.get(kArg);
+  picojson::value::object o;
+
+  if (cmd == kGet) {
+    HandleGet(arg, o);
+  } else if (cmd == kAdd) {
+    HandleAdd(arg, o);
+  } else if (cmd == kRemove) {
+    HandleRemove(arg, o);
+  }
+
+  if (o.empty())
+    o[kError] = picojson::value(true);
+
+  SendSyncReply(picojson::value(o).serialize().c_str());
+}
+
+void BookmarkInstance::HandleGet(const picojson::value& arg, picojson::object& o) {
+  o[kValue] = picojson::value(kNotImplemented);
+}
+
+void BookmarkInstance::HandleAdd(const picojson::value& arg, picojson::object& o) {
+  o[kValue] = picojson::value(kNotImplemented);
+}
+
+void BookmarkInstance::HandleRemove(const picojson::value& arg, picojson::object& o) {
+  o[kValue] = picojson::value(kNotImplemented);
+}
+
+} //namespace bookmark
+} //namespace extension
diff --git a/bookmark/bookmark_instance.h b/bookmark/bookmark_instance.h
new file mode 100644 (file)
index 0000000..3943079
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BOOKMARK_BOOKMARK_INSTANCE_H_
+#define BOOKMARK_BOOKMARK_INSTANCE_H_
+
+#include "common/extension.h"
+#include "common/picojson.h"
+
+namespace extension {
+namespace bookmark {
+
+class BookmarkInstance : public common::Instance {
+ public:
+  BookmarkInstance();
+  virtual ~BookmarkInstance();
+
+ private:
+  virtual void HandleMessage(const char* msg);
+  virtual void HandleSyncMessage(const char* msg);
+
+  void HandleGet(const picojson::value& arg, picojson::value::object& o);
+  void HandleAdd(const picojson::value& arg, picojson::value::object& o);
+  void HandleRemove(const picojson::value& arg, picojson::value::object& o);
+};
+
+} // namespace bookmark
+} // namespace extension
+
+#endif  // BOOKMARK_BOOKMARK_INSTANCE_H_
index 7b197a0..79b14de 100644 (file)
@@ -14,6 +14,7 @@
         'power/power.gyp:*',
         'messageport/messageport.gyp:*',
         #'calendar/calendar.gyp:*',
+        'bookmark/bookmark.gyp:*',
       ],
     },
   ],