html5localstorage.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2011 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Provides data persistence using HTML5 local storage
  16. * mechanism. Local storage must be available under window.localStorage,
  17. * see: http://www.w3.org/TR/webstorage/#the-localstorage-attribute.
  18. *
  19. */
  20. goog.provide('goog.storage.mechanism.HTML5LocalStorage');
  21. goog.require('goog.storage.mechanism.HTML5WebStorage');
  22. /**
  23. * Provides a storage mechanism that uses HTML5 local storage.
  24. *
  25. * @constructor
  26. * @struct
  27. * @extends {goog.storage.mechanism.HTML5WebStorage}
  28. */
  29. goog.storage.mechanism.HTML5LocalStorage = function() {
  30. var storage = null;
  31. try {
  32. // May throw an exception in cases where the local storage object
  33. // is visible but access to it is disabled.
  34. storage = window.localStorage || null;
  35. } catch (e) {
  36. }
  37. goog.storage.mechanism.HTML5LocalStorage.base(this, 'constructor', storage);
  38. };
  39. goog.inherits(
  40. goog.storage.mechanism.HTML5LocalStorage,
  41. goog.storage.mechanism.HTML5WebStorage);