| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 #include "core/loader/appcache/DOMApplicationCache.h" | |
| 28 | |
| 29 #include "bindings/v8/ExceptionMessages.h" | |
| 30 #include "bindings/v8/ExceptionState.h" | |
| 31 #include "core/dom/Document.h" | |
| 32 #include "core/dom/EventListener.h" | |
| 33 #include "core/dom/EventNames.h" | |
| 34 #include "core/dom/ExceptionCode.h" | |
| 35 #include "core/loader/DocumentLoader.h" | |
| 36 #include "core/loader/FrameLoader.h" | |
| 37 #include "core/loader/appcache/ApplicationCacheHost.h" | |
| 38 #include "core/page/Frame.h" | |
| 39 | |
| 40 namespace WebCore { | |
| 41 | |
| 42 DOMApplicationCache::DOMApplicationCache(Frame* frame) | |
| 43 : DOMWindowProperty(frame) | |
| 44 { | |
| 45 ScriptWrappable::init(this); | |
| 46 ApplicationCacheHost* cacheHost = applicationCacheHost(); | |
| 47 if (cacheHost) | |
| 48 cacheHost->setDOMApplicationCache(this); | |
| 49 } | |
| 50 | |
| 51 void DOMApplicationCache::willDestroyGlobalObjectInFrame() | |
| 52 { | |
| 53 if (ApplicationCacheHost* cacheHost = applicationCacheHost()) | |
| 54 cacheHost->setDOMApplicationCache(0); | |
| 55 DOMWindowProperty::willDestroyGlobalObjectInFrame(); | |
| 56 } | |
| 57 | |
| 58 ApplicationCacheHost* DOMApplicationCache::applicationCacheHost() const | |
| 59 { | |
| 60 if (!m_frame || !m_frame->loader()->documentLoader()) | |
| 61 return 0; | |
| 62 return m_frame->loader()->documentLoader()->applicationCacheHost(); | |
| 63 } | |
| 64 | |
| 65 unsigned short DOMApplicationCache::status() const | |
| 66 { | |
| 67 ApplicationCacheHost* cacheHost = applicationCacheHost(); | |
| 68 if (!cacheHost) | |
| 69 return ApplicationCacheHost::UNCACHED; | |
| 70 return cacheHost->status(); | |
| 71 } | |
| 72 | |
| 73 void DOMApplicationCache::update(ExceptionState& es) | |
| 74 { | |
| 75 ApplicationCacheHost* cacheHost = applicationCacheHost(); | |
| 76 if (!cacheHost || !cacheHost->update()) | |
| 77 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu
te("update", "ApplicationCache", "there is no application cache to update.")); | |
| 78 } | |
| 79 | |
| 80 void DOMApplicationCache::swapCache(ExceptionState& es) | |
| 81 { | |
| 82 ApplicationCacheHost* cacheHost = applicationCacheHost(); | |
| 83 if (!cacheHost || !cacheHost->swapCache()) | |
| 84 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu
te("swapCache", "ApplicationCache", "there is no newer application cache to swap
to.")); | |
| 85 } | |
| 86 | |
| 87 void DOMApplicationCache::abort() | |
| 88 { | |
| 89 ApplicationCacheHost* cacheHost = applicationCacheHost(); | |
| 90 if (cacheHost) | |
| 91 cacheHost->abort(); | |
| 92 } | |
| 93 | |
| 94 const AtomicString& DOMApplicationCache::interfaceName() const | |
| 95 { | |
| 96 return eventNames().interfaceForDOMApplicationCache; | |
| 97 } | |
| 98 | |
| 99 ScriptExecutionContext* DOMApplicationCache::scriptExecutionContext() const | |
| 100 { | |
| 101 if (m_frame) | |
| 102 return m_frame->document(); | |
| 103 return 0; | |
| 104 } | |
| 105 | |
| 106 const AtomicString& DOMApplicationCache::toEventType(ApplicationCacheHost::Event
ID id) | |
| 107 { | |
| 108 switch (id) { | |
| 109 case ApplicationCacheHost::CHECKING_EVENT: | |
| 110 return eventNames().checkingEvent; | |
| 111 case ApplicationCacheHost::ERROR_EVENT: | |
| 112 return eventNames().errorEvent; | |
| 113 case ApplicationCacheHost::NOUPDATE_EVENT: | |
| 114 return eventNames().noupdateEvent; | |
| 115 case ApplicationCacheHost::DOWNLOADING_EVENT: | |
| 116 return eventNames().downloadingEvent; | |
| 117 case ApplicationCacheHost::PROGRESS_EVENT: | |
| 118 return eventNames().progressEvent; | |
| 119 case ApplicationCacheHost::UPDATEREADY_EVENT: | |
| 120 return eventNames().updatereadyEvent; | |
| 121 case ApplicationCacheHost::CACHED_EVENT: | |
| 122 return eventNames().cachedEvent; | |
| 123 case ApplicationCacheHost::OBSOLETE_EVENT: | |
| 124 return eventNames().obsoleteEvent; | |
| 125 } | |
| 126 ASSERT_NOT_REACHED(); | |
| 127 return eventNames().errorEvent; | |
| 128 } | |
| 129 | |
| 130 EventTargetData* DOMApplicationCache::eventTargetData() | |
| 131 { | |
| 132 return &m_eventTargetData; | |
| 133 } | |
| 134 | |
| 135 EventTargetData* DOMApplicationCache::ensureEventTargetData() | |
| 136 { | |
| 137 return &m_eventTargetData; | |
| 138 } | |
| 139 | |
| 140 } // namespace WebCore | |
| OLD | NEW |