Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: webkit/glue/inspector_client_impl.cc

Issue 338041: Move a bunch of files into webkit/api/src... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6
7 #include "DOMWindow.h"
8 #include "FloatRect.h"
9 #include "InspectorController.h"
10 #include "Page.h"
11 #include "Settings.h"
12 #include <wtf/Vector.h>
13 #undef LOG
14
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"
22 #include "webkit/glue/webkit_glue.h"
23 #include "webkit/glue/webview_impl.h"
24
25 using namespace WebCore;
26
27 using WebKit::WebRect;
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
36 InspectorClientImpl::InspectorClientImpl(WebViewImpl* webView)
37 : inspected_web_view_(webView) {
38 ASSERT(inspected_web_view_);
39 }
40
41 InspectorClientImpl::~InspectorClientImpl() {
42 }
43
44 void InspectorClientImpl::inspectorDestroyed() {
45 // Our lifetime is bound to the WebViewImpl.
46 }
47
48 Page* InspectorClientImpl::createPage() {
49 // This method should never be called in Chrome as inspector front-end lives
50 // in a separate process.
51 ASSERT_NOT_REACHED();
52 return NULL;
53 }
54
55 void InspectorClientImpl::showWindow() {
56 ASSERT(inspected_web_view_->GetWebDevToolsAgentImpl());
57 InspectorController* inspector =
58 inspected_web_view_->page()->inspectorController();
59 inspector->setWindowVisible(true);
60 }
61
62 void InspectorClientImpl::closeWindow() {
63 if (inspected_web_view_->page())
64 inspected_web_view_->page()->inspectorController()->setWindowVisible(false);
65 }
66
67 bool InspectorClientImpl::windowVisible() {
68 ASSERT(inspected_web_view_->GetWebDevToolsAgentImpl());
69 return false;
70 }
71
72 void InspectorClientImpl::attachWindow() {
73 // TODO(jackson): Implement this
74 }
75
76 void InspectorClientImpl::detachWindow() {
77 // TODO(jackson): Implement this
78 }
79
80 void InspectorClientImpl::setAttachedWindowHeight(unsigned int height) {
81 // TODO(dglazkov): Implement this
82 notImplemented();
83 }
84
85 static void invalidateNodeBoundingRect(WebViewImpl* web_view) {
86 // TODO(ojan): http://b/1143996 Is it important to just invalidate the rect
87 // of the node region given that this is not on a critical codepath?
88 // In order to do so, we'd have to take scrolling into account.
89 const WebSize& size = web_view->size();
90 WebRect damaged_rect(0, 0, size.width, size.height);
91 if (web_view->client())
92 web_view->client()->didInvalidateRect(damaged_rect);
93 }
94
95 void InspectorClientImpl::highlight(Node* node) {
96 // InspectorController does the actually tracking of the highlighted node
97 // and the drawing of the highlight. Here we just make sure to invalidate
98 // the rects of the old and new nodes.
99 hideHighlight();
100 }
101
102 void InspectorClientImpl::hideHighlight() {
103 // TODO: Should be able to invalidate a smaller rect.
104 invalidateNodeBoundingRect(inspected_web_view_);
105 }
106
107 void InspectorClientImpl::inspectedURLChanged(const String& newURL) {
108 // TODO(jackson): Implement this
109 }
110
111 String InspectorClientImpl::localizedStringsURL() {
112 notImplemented();
113 return String();
114 }
115
116 String InspectorClientImpl::hiddenPanels() {
117 // Enumerate tabs that are currently disabled.
118 return "scripts,profiles,databases";
119 }
120
121 void InspectorClientImpl::populateSetting(
122 const String& key,
123 InspectorController::Setting& setting) {
124 LoadSettings();
125 if (settings_->contains(key))
126 setting = settings_->get(key);
127 }
128
129 void InspectorClientImpl::storeSetting(
130 const String& key,
131 const InspectorController::Setting& setting) {
132 LoadSettings();
133 settings_->set(key, setting);
134 SaveSettings();
135 }
136
137 void InspectorClientImpl::removeSetting(const String& key) {
138 LoadSettings();
139 settings_->remove(key);
140 SaveSettings();
141 }
142
143 void InspectorClientImpl::inspectorWindowObjectCleared() {
144 notImplemented();
145 }
146
147 void InspectorClientImpl::LoadSettings() {
148 if (settings_)
149 return;
150
151 settings_.set(new SettingsMap);
152 String data = webkit_glue::WebStringToString(
153 inspected_web_view_->inspectorSettings());
154 if (data.isEmpty())
155 return;
156
157 Vector<String> entries;
158 data.split("\n", entries);
159 for (Vector<String>::iterator it = entries.begin();
160 it != entries.end(); ++it) {
161 Vector<String> tokens;
162 it->split(":", tokens);
163 if (tokens.size() != 3)
164 continue;
165
166 String name = decodeURLEscapeSequences(tokens[0]);
167 String type = tokens[1];
168 InspectorController::Setting setting;
169 bool ok = true;
170 if (type == "string")
171 setting.set(decodeURLEscapeSequences(tokens[2]));
172 else if (type == "double")
173 setting.set(tokens[2].toDouble(&ok));
174 else if (type == "integer")
175 setting.set(static_cast<long>(tokens[2].toInt(&ok)));
176 else if (type == "boolean")
177 setting.set(tokens[2] == "true");
178 else
179 continue;
180
181 if (ok)
182 settings_->set(name, setting);
183 }
184 }
185
186 void InspectorClientImpl::SaveSettings() {
187 String data;
188 for (SettingsMap::iterator it = settings_->begin(); it != settings_->end();
189 ++it) {
190 String entry;
191 InspectorController::Setting value = it->second;
192 String name = encodeWithURLEscapeSequences(it->first);
193 switch (value.type()) {
194 case InspectorController::Setting::StringType:
195 entry = String::format(
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 }
224 data.append(entry);
225 data.append("\n");
226 }
227 inspected_web_view_->setInspectorSettings(
228 webkit_glue::StringToWebString(data));
229 if (inspected_web_view_->client())
230 inspected_web_view_->client()->didUpdateInspectorSettings();
231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698