OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 /* |
2 // Use of this source code is governed by a BSD-style license that can be | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 // found in the LICENSE file. | 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 */ |
4 | 30 |
5 #include "config.h" | 31 #include "config.h" |
| 32 #include "InspectorClientImpl.h" |
6 | 33 |
7 #include "DOMWindow.h" | 34 #include "DOMWindow.h" |
8 #include "FloatRect.h" | 35 #include "FloatRect.h" |
9 #include "InspectorController.h" | 36 #include "InspectorController.h" |
10 #include "Page.h" | 37 #include "Page.h" |
11 #include "Settings.h" | 38 #include "Settings.h" |
| 39 #include "WebRect.h" |
| 40 #include "WebURL.h" |
| 41 #include "WebURLRequest.h" |
| 42 #include "WebViewClient.h" |
12 #include <wtf/Vector.h> | 43 #include <wtf/Vector.h> |
13 #undef LOG | 44 |
14 | 45 // FIXME: Remove this once WebDevToolsAgentImpl and WebViewImpl move out of glue/. |
15 #include "webkit/api/public/WebRect.h" | |
16 #include "webkit/api/public/WebURL.h" | |
17 #include "webkit/api/public/WebURLRequest.h" | |
18 #include "webkit/api/public/WebViewClient.h" | |
19 #include "webkit/glue/glue_util.h" | |
20 #include "webkit/glue/inspector_client_impl.h" | |
21 #include "webkit/glue/webdevtoolsagent_impl.h" | 46 #include "webkit/glue/webdevtoolsagent_impl.h" |
22 #include "webkit/glue/webkit_glue.h" | |
23 #include "webkit/glue/webview_impl.h" | 47 #include "webkit/glue/webview_impl.h" |
24 | 48 |
25 using namespace WebCore; | 49 using namespace WebCore; |
26 | 50 |
27 using WebKit::WebRect; | 51 namespace WebKit { |
28 using WebKit::WebSize; | |
29 using WebKit::WebURLRequest; | |
30 | |
31 static const float kDefaultInspectorXPos = 10; | |
32 static const float kDefaultInspectorYPos = 50; | |
33 static const float kDefaultInspectorHeight = 640; | |
34 static const float kDefaultInspectorWidth = 480; | |
35 | 52 |
36 InspectorClientImpl::InspectorClientImpl(WebViewImpl* webView) | 53 InspectorClientImpl::InspectorClientImpl(WebViewImpl* webView) |
37 : inspected_web_view_(webView) { | 54 : m_inspectedWebView(webView) |
38 ASSERT(inspected_web_view_); | 55 { |
39 } | 56 ASSERT(m_inspectedWebView); |
40 | 57 } |
41 InspectorClientImpl::~InspectorClientImpl() { | 58 |
42 } | 59 InspectorClientImpl::~InspectorClientImpl() |
43 | 60 { |
44 void InspectorClientImpl::inspectorDestroyed() { | 61 } |
45 // Our lifetime is bound to the WebViewImpl. | 62 |
46 } | 63 void InspectorClientImpl::inspectorDestroyed() |
47 | 64 { |
48 Page* InspectorClientImpl::createPage() { | 65 // Our lifetime is bound to the WebViewImpl. |
49 // This method should never be called in Chrome as inspector front-end lives | 66 } |
50 // in a separate process. | 67 |
51 ASSERT_NOT_REACHED(); | 68 Page* InspectorClientImpl::createPage() |
52 return NULL; | 69 { |
53 } | 70 // This method should never be called in Chrome as inspector front-end lives |
54 | 71 // in a separate process. |
55 void InspectorClientImpl::showWindow() { | 72 ASSERT_NOT_REACHED(); |
56 ASSERT(inspected_web_view_->GetWebDevToolsAgentImpl()); | 73 return 0; |
57 InspectorController* inspector = | 74 } |
58 inspected_web_view_->page()->inspectorController(); | 75 |
59 inspector->setWindowVisible(true); | 76 void InspectorClientImpl::showWindow() |
60 } | 77 { |
61 | 78 ASSERT(m_inspectedWebView->GetWebDevToolsAgentImpl()); |
62 void InspectorClientImpl::closeWindow() { | 79 m_inspectedWebView->page()->inspectorController()->setWindowVisible(true); |
63 if (inspected_web_view_->page()) | 80 } |
64 inspected_web_view_->page()->inspectorController()->setWindowVisible(false); | 81 |
65 } | 82 void InspectorClientImpl::closeWindow() |
66 | 83 { |
67 bool InspectorClientImpl::windowVisible() { | 84 if (m_inspectedWebView->page()) |
68 ASSERT(inspected_web_view_->GetWebDevToolsAgentImpl()); | 85 m_inspectedWebView->page()->inspectorController()->setWindowVisible(false); |
69 return false; | 86 } |
70 } | 87 |
71 | 88 bool InspectorClientImpl::windowVisible() |
72 void InspectorClientImpl::attachWindow() { | 89 { |
73 // TODO(jackson): Implement this | 90 ASSERT(m_inspectedWebView->GetWebDevToolsAgentImpl()); |
74 } | 91 return false; |
75 | 92 } |
76 void InspectorClientImpl::detachWindow() { | 93 |
77 // TODO(jackson): Implement this | 94 void InspectorClientImpl::attachWindow() |
78 } | 95 { |
79 | 96 // FIXME: Implement this |
80 void InspectorClientImpl::setAttachedWindowHeight(unsigned int height) { | 97 } |
81 // TODO(dglazkov): Implement this | 98 |
82 notImplemented(); | 99 void InspectorClientImpl::detachWindow() |
83 } | 100 { |
84 | 101 // FIXME: Implement this |
85 static void invalidateNodeBoundingRect(WebViewImpl* web_view) { | 102 } |
86 // TODO(ojan): http://b/1143996 Is it important to just invalidate the rect | 103 |
87 // of the node region given that this is not on a critical codepath? | 104 void InspectorClientImpl::setAttachedWindowHeight(unsigned int height) |
88 // In order to do so, we'd have to take scrolling into account. | 105 { |
89 const WebSize& size = web_view->size(); | 106 // FIXME: Implement this |
90 WebRect damaged_rect(0, 0, size.width, size.height); | 107 notImplemented(); |
91 if (web_view->client()) | 108 } |
92 web_view->client()->didInvalidateRect(damaged_rect); | 109 |
93 } | 110 static void invalidateNodeBoundingRect(WebViewImpl* webView) |
94 | 111 { |
95 void InspectorClientImpl::highlight(Node* node) { | 112 // FIXME: Is it important to just invalidate the rect of the node region |
96 // InspectorController does the actually tracking of the highlighted node | 113 // given that this is not on a critical codepath? In order to do so, we'd |
97 // and the drawing of the highlight. Here we just make sure to invalidate | 114 // have to take scrolling into account. |
98 // the rects of the old and new nodes. | 115 const WebSize& size = webView->size(); |
99 hideHighlight(); | 116 WebRect damagedRect(0, 0, size.width, size.height); |
100 } | 117 if (webView->client()) |
101 | 118 webView->client()->didInvalidateRect(damagedRect); |
102 void InspectorClientImpl::hideHighlight() { | 119 } |
103 // TODO: Should be able to invalidate a smaller rect. | 120 |
104 invalidateNodeBoundingRect(inspected_web_view_); | 121 void InspectorClientImpl::highlight(Node* node) |
105 } | 122 { |
106 | 123 // InspectorController does the actually tracking of the highlighted node |
107 void InspectorClientImpl::inspectedURLChanged(const String& newURL) { | 124 // and the drawing of the highlight. Here we just make sure to invalidate |
108 // TODO(jackson): Implement this | 125 // the rects of the old and new nodes. |
109 } | 126 hideHighlight(); |
110 | 127 } |
111 String InspectorClientImpl::localizedStringsURL() { | 128 |
112 notImplemented(); | 129 void InspectorClientImpl::hideHighlight() |
113 return String(); | 130 { |
114 } | 131 // FIXME: able to invalidate a smaller rect. |
115 | 132 invalidateNodeBoundingRect(m_inspectedWebView); |
116 String InspectorClientImpl::hiddenPanels() { | 133 } |
117 // Enumerate tabs that are currently disabled. | 134 |
118 return "scripts,profiles,databases"; | 135 void InspectorClientImpl::inspectedURLChanged(const String& newURL) |
119 } | 136 { |
120 | 137 // FIXME: Implement this |
121 void InspectorClientImpl::populateSetting( | 138 } |
122 const String& key, | 139 |
123 InspectorController::Setting& setting) { | 140 String InspectorClientImpl::localizedStringsURL() |
124 LoadSettings(); | 141 { |
125 if (settings_->contains(key)) | 142 notImplemented(); |
126 setting = settings_->get(key); | 143 return String(); |
127 } | 144 } |
128 | 145 |
129 void InspectorClientImpl::storeSetting( | 146 String InspectorClientImpl::hiddenPanels() |
130 const String& key, | 147 { |
131 const InspectorController::Setting& setting) { | 148 // Enumerate tabs that are currently disabled. |
132 LoadSettings(); | 149 return "scripts,profiles,databases"; |
133 settings_->set(key, setting); | 150 } |
134 SaveSettings(); | 151 |
135 } | 152 void InspectorClientImpl::populateSetting(const String& key, InspectorController::Setting& setting) |
136 | 153 { |
137 void InspectorClientImpl::removeSetting(const String& key) { | 154 loadSettings(); |
138 LoadSettings(); | 155 if (m_settings->contains(key)) |
139 settings_->remove(key); | 156 setting = m_settings->get(key); |
140 SaveSettings(); | 157 } |
141 } | 158 |
142 | 159 void InspectorClientImpl::storeSetting(const String& key, const InspectorController::Setting& setting) |
143 void InspectorClientImpl::inspectorWindowObjectCleared() { | 160 { |
144 notImplemented(); | 161 loadSettings(); |
145 } | 162 m_settings->set(key, setting); |
146 | 163 saveSettings(); |
147 void InspectorClientImpl::LoadSettings() { | 164 } |
148 if (settings_) | 165 |
149 return; | 166 void InspectorClientImpl::removeSetting(const String& key) |
150 | 167 { |
151 settings_.set(new SettingsMap); | 168 loadSettings(); |
152 String data = webkit_glue::WebStringToString( | 169 m_settings->remove(key); |
153 inspected_web_view_->inspectorSettings()); | 170 saveSettings(); |
154 if (data.isEmpty()) | 171 } |
155 return; | 172 |
156 | 173 void InspectorClientImpl::inspectorWindowObjectCleared() |
157 Vector<String> entries; | 174 { |
158 data.split("\n", entries); | 175 notImplemented(); |
159 for (Vector<String>::iterator it = entries.begin(); | 176 } |
160 it != entries.end(); ++it) { | 177 |
161 Vector<String> tokens; | 178 void InspectorClientImpl::loadSettings() |
162 it->split(":", tokens); | 179 { |
163 if (tokens.size() != 3) | 180 if (m_settings) |
164 continue; | 181 return; |
165 | 182 |
166 String name = decodeURLEscapeSequences(tokens[0]); | 183 m_settings.set(new SettingsMap); |
167 String type = tokens[1]; | 184 String data = m_inspectedWebView->inspectorSettings(); |
168 InspectorController::Setting setting; | 185 if (data.isEmpty()) |
169 bool ok = true; | 186 return; |
170 if (type == "string") | 187 |
171 setting.set(decodeURLEscapeSequences(tokens[2])); | 188 Vector<String> entries; |
172 else if (type == "double") | 189 data.split("\n", entries); |
173 setting.set(tokens[2].toDouble(&ok)); | 190 for (Vector<String>::iterator it = entries.begin(); it != entries.end(); ++it) { |
174 else if (type == "integer") | 191 Vector<String> tokens; |
175 setting.set(static_cast<long>(tokens[2].toInt(&ok))); | 192 it->split(":", tokens); |
176 else if (type == "boolean") | 193 if (tokens.size() != 3) |
177 setting.set(tokens[2] == "true"); | 194 continue; |
178 else | 195 |
179 continue; | 196 String name = decodeURLEscapeSequences(tokens[0]); |
180 | 197 String type = tokens[1]; |
181 if (ok) | 198 InspectorController::Setting setting; |
182 settings_->set(name, setting); | 199 bool ok = true; |
183 } | 200 if (type == "string") |
184 } | 201 setting.set(decodeURLEscapeSequences(tokens[2])); |
185 | 202 else if (type == "double") |
186 void InspectorClientImpl::SaveSettings() { | 203 setting.set(tokens[2].toDouble(&ok)); |
187 String data; | 204 else if (type == "integer") |
188 for (SettingsMap::iterator it = settings_->begin(); it != settings_->end(); | 205 setting.set(static_cast<long>(tokens[2].toInt(&ok))); |
189 ++it) { | 206 else if (type == "boolean") |
190 String entry; | 207 setting.set(tokens[2] == "true"); |
191 InspectorController::Setting value = it->second; | 208 else |
192 String name = encodeWithURLEscapeSequences(it->first); | 209 continue; |
193 switch (value.type()) { | 210 |
194 case InspectorController::Setting::StringType: | 211 if (ok) |
195 entry = String::format( | 212 m_settings->set(name, setting); |
196 "%s:string:%s", | |
197 name.utf8().data(), | |
198 encodeWithURLEscapeSequences(value.string()).utf8().data()); | |
199 break; | |
200 case InspectorController::Setting::DoubleType: | |
201 entry = String::format( | |
202 "%s:double:%f", | |
203 name.utf8().data(), | |
204 value.doubleValue()); | |
205 break; | |
206 case InspectorController::Setting::IntegerType: | |
207 entry = String::format( | |
208 "%s:integer:%ld", | |
209 name.utf8().data(), | |
210 value.integerValue()); | |
211 break; | |
212 case InspectorController::Setting::BooleanType: | |
213 entry = String::format("%s:boolean:%s", | |
214 name.utf8().data(), | |
215 value.booleanValue() ? "true" : "false"); | |
216 break; | |
217 case InspectorController::Setting::StringVectorType: | |
218 notImplemented(); | |
219 break; | |
220 default: | |
221 ASSERT_NOT_REACHED(); | |
222 break; | |
223 } | 213 } |
224 data.append(entry); | 214 } |
225 data.append("\n"); | 215 |
226 } | 216 void InspectorClientImpl::saveSettings() |
227 inspected_web_view_->setInspectorSettings( | 217 { |
228 webkit_glue::StringToWebString(data)); | 218 String data; |
229 if (inspected_web_view_->client()) | 219 for (SettingsMap::iterator it = m_settings->begin(); it != m_settings->end(); ++it) { |
230 inspected_web_view_->client()->didUpdateInspectorSettings(); | 220 String entry; |
231 } | 221 InspectorController::Setting value = it->second; |
| 222 String name = encodeWithURLEscapeSequences(it->first); |
| 223 switch (value.type()) { |
| 224 case InspectorController::Setting::StringType: |
| 225 entry = String::format( |
| 226 "%s:string:%s", |
| 227 name.utf8().data(), |
| 228 encodeWithURLEscapeSequences(value.string()).utf8().data()); |
| 229 break; |
| 230 case InspectorController::Setting::DoubleType: |
| 231 entry = String::format( |
| 232 "%s:double:%f", |
| 233 name.utf8().data(), |
| 234 value.doubleValue()); |
| 235 break; |
| 236 case InspectorController::Setting::IntegerType: |
| 237 entry = String::format( |
| 238 "%s:integer:%ld", |
| 239 name.utf8().data(), |
| 240 value.integerValue()); |
| 241 break; |
| 242 case InspectorController::Setting::BooleanType: |
| 243 entry = String::format("%s:boolean:%s", |
| 244 name.utf8().data(), |
| 245 value.booleanValue() ? "true" : "false"); |
| 246 break; |
| 247 case InspectorController::Setting::StringVectorType: |
| 248 notImplemented(); |
| 249 break; |
| 250 default: |
| 251 ASSERT_NOT_REACHED(); |
| 252 break; |
| 253 } |
| 254 data.append(entry); |
| 255 data.append("\n"); |
| 256 } |
| 257 m_inspectedWebView->setInspectorSettings(data); |
| 258 if (m_inspectedWebView->client()) |
| 259 m_inspectedWebView->client()->didUpdateInspectorSettings(); |
| 260 } |
| 261 |
| 262 } // namespace WebKit |
OLD | NEW |