| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2011 Google 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 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
| 14 * its contributors may be used to endorse or promote products derived | |
| 15 * from this software without specific prior written permission. | |
| 16 * | |
| 17 * THIS SOFTWARE IS PROVIDED BY GOOGLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 */ | |
| 28 | |
| 29 #include "sky/engine/config.h" | |
| 30 #include "sky/engine/v8_inspector/InspectorState.h" | |
| 31 | |
| 32 #include "sky/engine/v8_inspector/JSONParser.h" | |
| 33 #include "sky/engine/wtf/PassOwnPtr.h" | |
| 34 | |
| 35 namespace blink { | |
| 36 | |
| 37 InspectorState::InspectorState(InspectorStateUpdateListener* listener, PassRefPt
r<JSONObject> properties) | |
| 38 : m_listener(listener) | |
| 39 , m_properties(properties) | |
| 40 { | |
| 41 } | |
| 42 | |
| 43 void InspectorState::updateCookie() | |
| 44 { | |
| 45 if (m_listener) | |
| 46 m_listener->inspectorStateUpdated(); | |
| 47 } | |
| 48 | |
| 49 void InspectorState::setFromCookie(PassRefPtr<JSONObject> properties) | |
| 50 { | |
| 51 m_properties = properties; | |
| 52 } | |
| 53 | |
| 54 void InspectorState::setValue(const String& propertyName, PassRefPtr<JSONValue>
value) | |
| 55 { | |
| 56 m_properties->setValue(propertyName, value); | |
| 57 updateCookie(); | |
| 58 } | |
| 59 | |
| 60 void InspectorState::remove(const String& propertyName) | |
| 61 { | |
| 62 m_properties->remove(propertyName); | |
| 63 updateCookie(); | |
| 64 } | |
| 65 | |
| 66 bool InspectorState::getBoolean(const String& propertyName) | |
| 67 { | |
| 68 JSONObject::iterator it = m_properties->find(propertyName); | |
| 69 bool value = false; | |
| 70 if (it != m_properties->end()) | |
| 71 it->value->asBoolean(&value); | |
| 72 return value; | |
| 73 } | |
| 74 | |
| 75 String InspectorState::getString(const String& propertyName) | |
| 76 { | |
| 77 JSONObject::iterator it = m_properties->find(propertyName); | |
| 78 String value; | |
| 79 if (it != m_properties->end()) | |
| 80 it->value->asString(&value); | |
| 81 return value; | |
| 82 } | |
| 83 | |
| 84 long InspectorState::getLong(const String& propertyName) | |
| 85 { | |
| 86 return getLong(propertyName, 0); | |
| 87 } | |
| 88 | |
| 89 | |
| 90 long InspectorState::getLong(const String& propertyName, long defaultValue) | |
| 91 { | |
| 92 JSONObject::iterator it = m_properties->find(propertyName); | |
| 93 long value = defaultValue; | |
| 94 if (it != m_properties->end()) | |
| 95 it->value->asNumber(&value); | |
| 96 return value; | |
| 97 } | |
| 98 | |
| 99 double InspectorState::getDouble(const String& propertyName) | |
| 100 { | |
| 101 return getDouble(propertyName, 0); | |
| 102 } | |
| 103 | |
| 104 double InspectorState::getDouble(const String& propertyName, double defaultValue
) | |
| 105 { | |
| 106 JSONObject::iterator it = m_properties->find(propertyName); | |
| 107 double value = defaultValue; | |
| 108 if (it != m_properties->end()) | |
| 109 it->value->asNumber(&value); | |
| 110 return value; | |
| 111 } | |
| 112 | |
| 113 PassRefPtr<JSONObject> InspectorState::getObject(const String& propertyName) | |
| 114 { | |
| 115 JSONObject::iterator it = m_properties->find(propertyName); | |
| 116 if (it == m_properties->end()) { | |
| 117 m_properties->setObject(propertyName, JSONObject::create()); | |
| 118 it = m_properties->find(propertyName); | |
| 119 } | |
| 120 return it->value->asObject(); | |
| 121 } | |
| 122 | |
| 123 InspectorState* InspectorCompositeState::createAgentState(const String& agentNam
e) | |
| 124 { | |
| 125 ASSERT(m_stateObject->find(agentName) == m_stateObject->end()); | |
| 126 ASSERT(m_inspectorStateMap.find(agentName) == m_inspectorStateMap.end()); | |
| 127 RefPtr<JSONObject> stateProperties = JSONObject::create(); | |
| 128 m_stateObject->setObject(agentName, stateProperties); | |
| 129 OwnPtr<InspectorState> statePtr = adoptPtr(new InspectorState(this, statePro
perties)); | |
| 130 InspectorState* state = statePtr.get(); | |
| 131 m_inspectorStateMap.add(agentName, statePtr.release()); | |
| 132 return state; | |
| 133 } | |
| 134 | |
| 135 void InspectorCompositeState::loadFromCookie(const String& inspectorCompositeSta
teCookie) | |
| 136 { | |
| 137 RefPtr<JSONValue> cookie = parseJSON(inspectorCompositeStateCookie); | |
| 138 if (cookie) | |
| 139 m_stateObject = cookie->asObject(); | |
| 140 if (!m_stateObject) | |
| 141 m_stateObject = JSONObject::create(); | |
| 142 | |
| 143 InspectorStateMap::iterator end = m_inspectorStateMap.end(); | |
| 144 for (InspectorStateMap::iterator it = m_inspectorStateMap.begin(); it != end
; ++it) { | |
| 145 RefPtr<JSONObject> agentStateObject = m_stateObject->getObject(it->key); | |
| 146 if (!agentStateObject) { | |
| 147 agentStateObject = JSONObject::create(); | |
| 148 m_stateObject->setObject(it->key, agentStateObject); | |
| 149 } | |
| 150 it->value->setFromCookie(agentStateObject); | |
| 151 } | |
| 152 } | |
| 153 | |
| 154 void InspectorCompositeState::mute() | |
| 155 { | |
| 156 m_isMuted = true; | |
| 157 } | |
| 158 | |
| 159 void InspectorCompositeState::unmute() | |
| 160 { | |
| 161 m_isMuted = false; | |
| 162 } | |
| 163 | |
| 164 void InspectorCompositeState::inspectorStateUpdated() | |
| 165 { | |
| 166 // FIXME(Sky): tell clients? | |
| 167 } | |
| 168 | |
| 169 } // namespace blink | |
| 170 | |
| OLD | NEW |