html5sessionstorage.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 session storage
  16. * mechanism. Session storage must be available under window.sessionStorage,
  17. * see: http://www.w3.org/TR/webstorage/#the-sessionstorage-attribute.
  18. *
  19. */
  20. goog.provide('goog.storage.mechanism.HTML5SessionStorage');
  21. goog.require('goog.storage.mechanism.HTML5WebStorage');
  22. /**
  23. * Provides a storage mechanism that uses HTML5 session storage.
  24. *
  25. * @constructor
  26. * @struct
  27. * @extends {goog.storage.mechanism.HTML5WebStorage}
  28. */
  29. goog.storage.mechanism.HTML5SessionStorage = function() {
  30. var storage = null;
  31. try {
  32. // May throw an exception in cases where the session storage object is
  33. // visible but access to it is disabled. For example, accessing the file
  34. // in local mode in Firefox throws 'Operation is not supported' exception.
  35. storage = window.sessionStorage || null;
  36. } catch (e) {
  37. }
  38. goog.storage.mechanism.HTML5SessionStorage.base(this, 'constructor', storage);
  39. };
  40. goog.inherits(
  41. goog.storage.mechanism.HTML5SessionStorage,
  42. goog.storage.mechanism.HTML5WebStorage);