| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 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 are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "InspectorClientImpl.h" | |
| 33 | |
| 34 #include "DOMWindow.h" | |
| 35 #include "FloatRect.h" | |
| 36 #include "InspectorController.h" | |
| 37 #include "NotImplemented.h" | |
| 38 #include "Page.h" | |
| 39 #include "Settings.h" | |
| 40 #include "WebRect.h" | |
| 41 #include "WebURL.h" | |
| 42 #include "WebURLRequest.h" | |
| 43 #include "WebViewClient.h" | |
| 44 #include "WebViewImpl.h" | |
| 45 #include <wtf/Vector.h> | |
| 46 | |
| 47 using namespace WebCore; | |
| 48 | |
| 49 namespace WebKit { | |
| 50 | |
| 51 InspectorClientImpl::InspectorClientImpl(WebViewImpl* webView) | |
| 52 : m_inspectedWebView(webView) | |
| 53 { | |
| 54 ASSERT(m_inspectedWebView); | |
| 55 } | |
| 56 | |
| 57 InspectorClientImpl::~InspectorClientImpl() | |
| 58 { | |
| 59 } | |
| 60 | |
| 61 void InspectorClientImpl::inspectorDestroyed() | |
| 62 { | |
| 63 // Our lifetime is bound to the WebViewImpl. | |
| 64 } | |
| 65 | |
| 66 Page* InspectorClientImpl::createPage() | |
| 67 { | |
| 68 // This method should never be called in Chrome as inspector front-end lives | |
| 69 // in a separate process. | |
| 70 ASSERT_NOT_REACHED(); | |
| 71 return 0; | |
| 72 } | |
| 73 | |
| 74 void InspectorClientImpl::showWindow() | |
| 75 { | |
| 76 ASSERT(m_inspectedWebView->devToolsAgentPrivate()); | |
| 77 m_inspectedWebView->page()->inspectorController()->setWindowVisible(true); | |
| 78 } | |
| 79 | |
| 80 void InspectorClientImpl::closeWindow() | |
| 81 { | |
| 82 if (m_inspectedWebView->page()) | |
| 83 m_inspectedWebView->page()->inspectorController()->setWindowVisible(false); | |
| 84 } | |
| 85 | |
| 86 bool InspectorClientImpl::windowVisible() | |
| 87 { | |
| 88 ASSERT(m_inspectedWebView->devToolsAgentPrivate()); | |
| 89 return false; | |
| 90 } | |
| 91 | |
| 92 void InspectorClientImpl::attachWindow() | |
| 93 { | |
| 94 // FIXME: Implement this | |
| 95 } | |
| 96 | |
| 97 void InspectorClientImpl::detachWindow() | |
| 98 { | |
| 99 // FIXME: Implement this | |
| 100 } | |
| 101 | |
| 102 void InspectorClientImpl::setAttachedWindowHeight(unsigned int height) | |
| 103 { | |
| 104 // FIXME: Implement this | |
| 105 notImplemented(); | |
| 106 } | |
| 107 | |
| 108 static void invalidateNodeBoundingRect(WebViewImpl* webView) | |
| 109 { | |
| 110 // FIXME: Is it important to just invalidate the rect of the node region | |
| 111 // given that this is not on a critical codepath? In order to do so, we'd | |
| 112 // have to take scrolling into account. | |
| 113 const WebSize& size = webView->size(); | |
| 114 WebRect damagedRect(0, 0, size.width, size.height); | |
| 115 if (webView->client()) | |
| 116 webView->client()->didInvalidateRect(damagedRect); | |
| 117 } | |
| 118 | |
| 119 void InspectorClientImpl::highlight(Node* node) | |
| 120 { | |
| 121 // InspectorController does the actually tracking of the highlighted node | |
| 122 // and the drawing of the highlight. Here we just make sure to invalidate | |
| 123 // the rects of the old and new nodes. | |
| 124 hideHighlight(); | |
| 125 } | |
| 126 | |
| 127 void InspectorClientImpl::hideHighlight() | |
| 128 { | |
| 129 // FIXME: able to invalidate a smaller rect. | |
| 130 invalidateNodeBoundingRect(m_inspectedWebView); | |
| 131 } | |
| 132 | |
| 133 void InspectorClientImpl::inspectedURLChanged(const String& newURL) | |
| 134 { | |
| 135 // FIXME: Implement this | |
| 136 } | |
| 137 | |
| 138 String InspectorClientImpl::localizedStringsURL() | |
| 139 { | |
| 140 notImplemented(); | |
| 141 return String(); | |
| 142 } | |
| 143 | |
| 144 String InspectorClientImpl::hiddenPanels() | |
| 145 { | |
| 146 // Enumerate tabs that are currently disabled. | |
| 147 return "scripts,profiles,databases"; | |
| 148 } | |
| 149 | |
| 150 void InspectorClientImpl::populateSetting(const String& key, InspectorController::Setting& setting) | |
| 151 { | |
| 152 loadSettings(); | |
| 153 if (m_settings->contains(key)) | |
| 154 setting = m_settings->get(key); | |
| 155 } | |
| 156 | |
| 157 void InspectorClientImpl::storeSetting(const String& key, const InspectorController::Setting& setting) | |
| 158 { | |
| 159 loadSettings(); | |
| 160 m_settings->set(key, setting); | |
| 161 saveSettings(); | |
| 162 } | |
| 163 | |
| 164 void InspectorClientImpl::removeSetting(const String& key) | |
| 165 { | |
| 166 loadSettings(); | |
| 167 m_settings->remove(key); | |
| 168 saveSettings(); | |
| 169 } | |
| 170 | |
| 171 void InspectorClientImpl::inspectorWindowObjectCleared() | |
| 172 { | |
| 173 notImplemented(); | |
| 174 } | |
| 175 | |
| 176 void InspectorClientImpl::loadSettings() | |
| 177 { | |
| 178 if (m_settings) | |
| 179 return; | |
| 180 | |
| 181 m_settings.set(new SettingsMap); | |
| 182 String data = m_inspectedWebView->inspectorSettings(); | |
| 183 if (data.isEmpty()) | |
| 184 return; | |
| 185 | |
| 186 Vector<String> entries; | |
| 187 data.split("\n", entries); | |
| 188 for (Vector<String>::iterator it = entries.begin(); it != entries.end(); ++it) { | |
| 189 Vector<String> tokens; | |
| 190 it->split(":", tokens); | |
| 191 if (tokens.size() != 3) | |
| 192 continue; | |
| 193 | |
| 194 String name = decodeURLEscapeSequences(tokens[0]); | |
| 195 String type = tokens[1]; | |
| 196 InspectorController::Setting setting; | |
| 197 bool ok = true; | |
| 198 if (type == "string") | |
| 199 setting.set(decodeURLEscapeSequences(tokens[2])); | |
| 200 else if (type == "double") | |
| 201 setting.set(tokens[2].toDouble(&ok)); | |
| 202 else if (type == "integer") | |
| 203 setting.set(static_cast<long>(tokens[2].toInt(&ok))); | |
| 204 else if (type == "boolean") | |
| 205 setting.set(tokens[2] == "true"); | |
| 206 else | |
| 207 continue; | |
| 208 | |
| 209 if (ok) | |
| 210 m_settings->set(name, setting); | |
| 211 } | |
| 212 } | |
| 213 | |
| 214 void InspectorClientImpl::saveSettings() | |
| 215 { | |
| 216 String data; | |
| 217 for (SettingsMap::iterator it = m_settings->begin(); it != m_settings->end(); ++it) { | |
| 218 String entry; | |
| 219 InspectorController::Setting value = it->second; | |
| 220 String name = encodeWithURLEscapeSequences(it->first); | |
| 221 switch (value.type()) { | |
| 222 case InspectorController::Setting::StringType: | |
| 223 entry = String::format( | |
| 224 "%s:string:%s", | |
| 225 name.utf8().data(), | |
| 226 encodeWithURLEscapeSequences(value.string()).utf8().data()); | |
| 227 break; | |
| 228 case InspectorController::Setting::DoubleType: | |
| 229 entry = String::format( | |
| 230 "%s:double:%f", | |
| 231 name.utf8().data(), | |
| 232 value.doubleValue()); | |
| 233 break; | |
| 234 case InspectorController::Setting::IntegerType: | |
| 235 entry = String::format( | |
| 236 "%s:integer:%ld", | |
| 237 name.utf8().data(), | |
| 238 value.integerValue()); | |
| 239 break; | |
| 240 case InspectorController::Setting::BooleanType: | |
| 241 entry = String::format("%s:boolean:%s", | |
| 242 name.utf8().data(), | |
| 243 value.booleanValue() ? "true" : "false"); | |
| 244 break; | |
| 245 case InspectorController::Setting::StringVectorType: | |
| 246 notImplemented(); | |
| 247 break; | |
| 248 default: | |
| 249 ASSERT_NOT_REACHED(); | |
| 250 break; | |
| 251 } | |
| 252 data.append(entry); | |
| 253 data.append("\n"); | |
| 254 } | |
| 255 m_inspectedWebView->setInspectorSettings(data); | |
| 256 if (m_inspectedWebView->client()) | |
| 257 m_inspectedWebView->client()->didUpdateInspectorSettings(); | |
| 258 } | |
| 259 | |
| 260 } // namespace WebKit | |
| OLD | NEW |