1 // Copyright (c) 2014 Intel Corporation. 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.
5 var application = requireNative('application');
6 var common = requireNative('widget_common');
11 var widgetStringInfo = {
13 "description" : empty,
18 "authorEmail" : empty,
24 function defineReadOnlyProperty(object, key, value) {
25 Object.defineProperty(object, key, {
30 value = window.innerWidth;
31 } else if (key == "height") {
32 value = window.innerHeight;
33 } else if (value == empty) {
34 value = extension.internal.sendSyncMessage(
35 { cmd: 'GetWidgetInfo', widgetKey: key });
43 for (var key in widgetStringInfo) {
44 defineReadOnlyProperty(exports, key, widgetStringInfo[key]);
47 var WidgetStorage = function() {
48 var _keyList = new Array();
50 this.init = function() {
51 var result = extension.internal.sendSyncMessage(
52 { cmd: 'GetAllItems' });
53 for (var itemKey in result) {
54 var itemValue = result[itemKey];
55 this[itemKey] = itemValue;
56 _keyList.push(itemKey);
60 this.__defineGetter__('length', function() {
61 return _keyList.length;
64 this.key = function(index) {
65 return _keyList[index];
68 this.getItem = function(itemKey) {
69 return this[String(itemKey)];
72 this.setItem = function(itemKey, itemValue) {
73 var result = extension.internal.sendSyncMessage({
74 cmd: 'SetPreferencesItem',
75 preferencesItemKey: String(itemKey),
76 preferencesItemValue: String(itemValue) });
79 this[String(itemKey)] = String(itemValue);
80 _keyList.push(String(itemKey));
82 throw new common.CustomDOMException(
83 common.CustomDOMException.NO_MODIFICATION_ALLOWED_ERR,
84 'The object can not be modified.');
88 this.removeItem = function(itemKey) {
89 var result = extension.internal.sendSyncMessage({
90 cmd: 'RemovePreferencesItem',
91 preferencesItemKey: String(itemKey) });
95 delete _keyList[_keyList.indexOf(String(itemKey))];
97 throw new common.CustomDOMException(
98 common.CustomDOMException.NO_MODIFICATION_ALLOWED_ERR,
99 'The object can not be modified.');
103 this.clear = function() {
105 var result = extension.internal.sendSyncMessage({
106 cmd: 'ClearAllItems' });
111 for (var i = _keyList.length-1; i >= 0; --i) {
112 // if the itemKey is still in DB(e.g. readonly),
113 // we should keep it in JS side.
114 var exists = extension.internal.sendSyncMessage({
116 preferencesItemKey: _keyList[i] });
119 delete this[_keyList[i]];
120 _keyList.splice(i, 1);
128 var widgetStorage = new WidgetStorage();
129 exports.preferences = widgetStorage;
131 exports.toString = function() {
132 return '[object Widget]';
135 Object.defineProperty(exports, 'preferences', {
139 return widgetStorage;