1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "base/compiler_specific.h"
MSVC_PUSH_WARNING_LEVEL(0);
#include "DOMWindow.h"
#include "FloatRect.h"
#include "InspectorController.h"
#include "Page.h"
#include "Settings.h"
#include <wtf/Vector.h>
MSVC_POP_WARNING();
#undef LOG
#include "base/logging.h"
#include "base/gfx/rect.h"
#include "base/string_util.h"
#include "webkit/api/public/WebRect.h"
#include "webkit/api/public/WebURL.h"
#include "webkit/api/public/WebURLRequest.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/inspector_client_impl.h"
#include "webkit/glue/webdevtoolsagent_impl.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/webview_impl.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
using namespace WebCore;
using WebKit::WebRect;
using WebKit::WebSize;
using WebKit::WebURLRequest;
static const float kDefaultInspectorXPos = 10;
static const float kDefaultInspectorYPos = 50;
static const float kDefaultInspectorHeight = 640;
static const float kDefaultInspectorWidth = 480;
WebInspectorClient::WebInspectorClient(WebViewImpl* webView)
: inspected_web_view_(webView)
, inspector_web_view_(0) {
ASSERT(inspected_web_view_);
}
WebInspectorClient::~WebInspectorClient() {
}
void WebInspectorClient::inspectorDestroyed() {
delete this;
}
Page* WebInspectorClient::createPage() {
if (inspected_web_view_->GetWebDevToolsAgentImpl())
return NULL;
WebCore::Page* page;
if (inspector_web_view_ != NULL) {
page = inspector_web_view_->page();
ASSERT(page != NULL);
if (page != NULL)
return page;
}
WebViewDelegate* delegate = inspected_web_view_->GetDelegate();
if (!delegate)
return NULL;
inspector_web_view_ = static_cast<WebViewImpl*>(
delegate->CreateWebView(inspected_web_view_, true, GURL()));
if (!inspector_web_view_)
return NULL;
inspector_web_view_->main_frame()->LoadRequest(
WebURLRequest(webkit_glue::GetInspectorURL()));
page = inspector_web_view_->page();
page->chrome()->setToolbarsVisible(false);
page->chrome()->setStatusbarVisible(false);
page->chrome()->setScrollbarsVisible(false);
page->chrome()->setMenubarVisible(false);
page->chrome()->setResizable(true);
// Don't allow inspection of inspector.
page->settings()->setDeveloperExtrasEnabled(false);
page->settings()->setPrivateBrowsingEnabled(true);
page->settings()->setPluginsEnabled(false);
page->settings()->setJavaEnabled(false);
FloatRect windowRect = page->chrome()->windowRect();
FloatSize pageSize = page->chrome()->pageRect().size();
windowRect.setX(kDefaultInspectorXPos);
windowRect.setY(kDefaultInspectorYPos);
windowRect.setWidth(kDefaultInspectorHeight);
windowRect.setHeight(kDefaultInspectorWidth);
page->chrome()->setWindowRect(windowRect);
page->chrome()->show();
return page;
}
void WebInspectorClient::showWindow() {
if (inspected_web_view_->GetWebDevToolsAgentImpl())
return;
InspectorController* inspector = inspected_web_view_->page()->inspectorController();
inspector->setWindowVisible(true);
// Notify the webview delegate of how many resources we're inspecting.
WebViewDelegate* d = inspected_web_view_->delegate();
DCHECK(d);
}
void WebInspectorClient::closeWindow() {
if (inspected_web_view_->GetWebDevToolsAgentImpl())
return;
inspector_web_view_ = NULL;
hideHighlight();
if (inspected_web_view_->page())
inspected_web_view_->page()->inspectorController()->setWindowVisible(false);
}
bool WebInspectorClient::windowVisible() {
if (inspected_web_view_->GetWebDevToolsAgentImpl())
return false;
if (inspector_web_view_ != NULL) {
Page* page = inspector_web_view_->page();
ASSERT(page != NULL);
if (page != NULL)
return true;
}
return false;
}
void WebInspectorClient::attachWindow() {
// TODO(jackson): Implement this
}
void WebInspectorClient::detachWindow() {
// TODO(jackson): Implement this
}
void WebInspectorClient::setAttachedWindowHeight(unsigned int height) {
// TODO(dglazkov): Implement this
NOTIMPLEMENTED();
}
static void invalidateNodeBoundingRect(WebViewImpl* web_view) {
// TODO(ojan): http://b/1143996 Is it important to just invalidate the rect
// of the node region given that this is not on a critical codepath?
// In order to do so, we'd have to take scrolling into account.
const WebSize& size = web_view->size();
WebRect damaged_rect(0, 0, size.width, size.height);
if (web_view->GetDelegate())
web_view->GetDelegate()->didInvalidateRect(damaged_rect);
}
void WebInspectorClient::highlight(Node* node) {
// InspectorController does the actually tracking of the highlighted node
// and the drawing of the highlight. Here we just make sure to invalidate
// the rects of the old and new nodes.
hideHighlight();
}
void WebInspectorClient::hideHighlight() {
// TODO: Should be able to invalidate a smaller rect.
invalidateNodeBoundingRect(inspected_web_view_);
}
void WebInspectorClient::inspectedURLChanged(const String& newURL) {
// TODO(jackson): Implement this
}
String WebInspectorClient::localizedStringsURL() {
NOTIMPLEMENTED();
return String();
}
String WebInspectorClient::hiddenPanels() {
// Enumerate tabs that are currently disabled.
return "scripts,profiles,databases";
}
void WebInspectorClient::populateSetting(
const String& key,
InspectorController::Setting& setting) {
LoadSettings();
if (settings_->contains(key))
setting = settings_->get(key);
}
void WebInspectorClient::storeSetting(
const String& key,
const InspectorController::Setting& setting) {
LoadSettings();
settings_->set(key, setting);
SaveSettings();
}
void WebInspectorClient::removeSetting(const String& key) {
LoadSettings();
settings_->remove(key);
SaveSettings();
}
void WebInspectorClient::LoadSettings() {
if (settings_)
return;
settings_.set(new SettingsMap);
String data = webkit_glue::StdWStringToString(
inspected_web_view_->GetPreferences().inspector_settings);
if (data.isEmpty())
return;
Vector<String> entries;
data.split("\n", entries);
for (Vector<String>::iterator it = entries.begin();
it != entries.end(); ++it) {
Vector<String> tokens;
it->split(":", tokens);
if (tokens.size() != 3)
continue;
String name = decodeURLEscapeSequences(tokens[0]);
String type = tokens[1];
InspectorController::Setting setting;
bool ok = true;
if (type == "string")
setting.set(decodeURLEscapeSequences(tokens[2]));
else if (type == "double")
setting.set(tokens[2].toDouble(&ok));
else if (type == "integer")
setting.set(static_cast<long>(tokens[2].toInt(&ok)));
else if (type == "boolean")
setting.set(tokens[2] == "true");
else
continue;
if (ok)
settings_->set(name, setting);
}
}
void WebInspectorClient::SaveSettings() {
String data;
for (SettingsMap::iterator it = settings_->begin(); it != settings_->end();
++it) {
String entry;
InspectorController::Setting value = it->second;
String name = encodeWithURLEscapeSequences(it->first);
switch (value.type()) {
case InspectorController::Setting::StringType:
entry = String::format(
"%s:string:%s",
name.utf8().data(),
encodeWithURLEscapeSequences(value.string()).utf8().data());
break;
case InspectorController::Setting::DoubleType:
entry = String::format(
"%s:double:%f",
name.utf8().data(),
value.doubleValue());
break;
case InspectorController::Setting::IntegerType:
entry = String::format(
"%s:integer:%ld",
name.utf8().data(),
value.integerValue());
break;
case InspectorController::Setting::BooleanType:
entry = String::format("%s:boolean:%s",
name.utf8().data(),
value.booleanValue() ? "true" : "false");
break;
case InspectorController::Setting::StringVectorType:
NOTIMPLEMENTED();
break;
default:
NOTREACHED();
break;
}
data.append(entry);
data.append("\n");
}
inspected_web_view_->delegate()->UpdateInspectorSettings(
webkit_glue::StringToStdWString(data));
}
|