OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/dom_ui/net_internals_ui.h" | 5 #include "chrome/browser/dom_ui/net_internals_ui.h" |
6 | 6 |
| 7 #include <sstream> |
| 8 |
7 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
8 #include "base/file_util.h" | 10 #include "base/file_util.h" |
9 #include "base/path_service.h" | 11 #include "base/path_service.h" |
10 #include "base/singleton.h" | 12 #include "base/singleton.h" |
11 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
12 #include "base/string_util.h" | 14 #include "base/string_util.h" |
13 #include "base/values.h" | 15 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chrome_thread.h" |
15 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 18 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
16 #include "chrome/browser/chrome_thread.h" | |
17 #include "chrome/browser/io_thread.h" | 19 #include "chrome/browser/io_thread.h" |
18 #include "chrome/browser/net/chrome_net_log.h" | 20 #include "chrome/browser/net/chrome_net_log.h" |
| 21 #include "chrome/browser/net/url_request_context_getter.h" |
| 22 #include "chrome/browser/profile.h" |
19 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
20 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "net/base/escape.h" |
| 26 #include "net/proxy/proxy_service.h" |
| 27 #include "net/url_request/url_request_context.h" |
21 | 28 |
22 namespace { | 29 namespace { |
23 | 30 |
| 31 // Formats |t| as a decimal number, in milliseconds. |
| 32 std::string TickCountToString(const base::TimeTicks& t) { |
| 33 return Int64ToString((t - base::TimeTicks()).InMilliseconds()); |
| 34 } |
| 35 |
24 // TODO(eroman): Bootstrap the net-internals page using the passively logged | 36 // TODO(eroman): Bootstrap the net-internals page using the passively logged |
25 // data. | 37 // data. |
26 | 38 |
27 class NetInternalsHTMLSource : public ChromeURLDataManager::DataSource { | 39 class NetInternalsHTMLSource : public ChromeURLDataManager::DataSource { |
28 public: | 40 public: |
29 NetInternalsHTMLSource(); | 41 NetInternalsHTMLSource(); |
30 | 42 |
31 // Called when the network layer has requested a resource underneath | 43 // Called when the network layer has requested a resource underneath |
32 // the path we registered. | 44 // the path we registered. |
33 virtual void StartDataRequest(const std::string& path, | 45 virtual void StartDataRequest(const std::string& path, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // Type for methods that can be used as MessageHandler callbacks. | 98 // Type for methods that can be used as MessageHandler callbacks. |
87 typedef void (IOThreadImpl::*MessageHandler)(const Value*); | 99 typedef void (IOThreadImpl::*MessageHandler)(const Value*); |
88 | 100 |
89 // Creates a proxy for |handler| that will live on the IO thread. | 101 // Creates a proxy for |handler| that will live on the IO thread. |
90 // |handler| is a weak pointer, since it is possible for the DOMMessageHandler | 102 // |handler| is a weak pointer, since it is possible for the DOMMessageHandler |
91 // to be deleted on the UI thread while we were executing on the IO thread. | 103 // to be deleted on the UI thread while we were executing on the IO thread. |
92 // |io_thread| is the global IOThread (it is passed in as an argument since | 104 // |io_thread| is the global IOThread (it is passed in as an argument since |
93 // we need to grab it from the UI thread). | 105 // we need to grab it from the UI thread). |
94 IOThreadImpl( | 106 IOThreadImpl( |
95 const base::WeakPtr<NetInternalsMessageHandler>& handler, | 107 const base::WeakPtr<NetInternalsMessageHandler>& handler, |
96 IOThread* io_thread); | 108 IOThread* io_thread, |
| 109 URLRequestContextGetter* context_getter); |
97 | 110 |
98 ~IOThreadImpl(); | 111 ~IOThreadImpl(); |
99 | 112 |
100 // Creates a callback that will run |method| on the IO thread. | 113 // Creates a callback that will run |method| on the IO thread. |
101 // | 114 // |
102 // This can be used with DOMUI::RegisterMessageCallback() to bind to a method | 115 // This can be used with DOMUI::RegisterMessageCallback() to bind to a method |
103 // on the IO thread. | 116 // on the IO thread. |
104 DOMUI::MessageCallback* CreateCallback(MessageHandler method); | 117 DOMUI::MessageCallback* CreateCallback(MessageHandler method); |
105 | 118 |
106 // Called once the DOMUI has been deleted (i.e. renderer went away), on the | 119 // Called once the DOMUI has been deleted (i.e. renderer went away), on the |
107 // IO thread. | 120 // IO thread. |
108 void Detach(); | 121 void Detach(); |
109 | 122 |
110 //-------------------------------- | 123 //-------------------------------- |
111 // Javascript message handlers: | 124 // Javascript message handlers: |
112 //-------------------------------- | 125 //-------------------------------- |
113 | 126 |
114 // This message is called after the webpage's onloaded handler has fired. | 127 // This message is called after the webpage's onloaded handler has fired. |
115 // it indicates that the renderer is ready to start receiving captured data. | 128 // it indicates that the renderer is ready to start receiving captured data. |
116 void OnRendererReady(const Value* value); | 129 void OnRendererReady(const Value* value); |
117 | 130 |
| 131 void OnGetProxySettings(const Value* value); |
| 132 void OnReloadProxySettings(const Value* value); |
| 133 void OnGetBadProxies(const Value* value); |
| 134 void OnClearBadProxies(const Value* value); |
| 135 |
118 // ChromeNetLog::Observer implementation: | 136 // ChromeNetLog::Observer implementation: |
119 virtual void OnAddEntry(const net::NetLog::Entry& entry); | 137 virtual void OnAddEntry(const net::NetLog::Entry& entry); |
120 | 138 |
121 private: | 139 private: |
122 class CallbackHelper; | 140 class CallbackHelper; |
123 | 141 |
124 // Helper that runs |method| with |arg|, and deletes |arg| on completion. | 142 // Helper that runs |method| with |arg|, and deletes |arg| on completion. |
125 void DispatchToMessageHandler(Value* arg, MessageHandler method); | 143 void DispatchToMessageHandler(Value* arg, MessageHandler method); |
126 | 144 |
127 // Helper that executes |function_name| in the attached renderer. | 145 // Helper that executes |function_name| in the attached renderer. |
128 // The function takes ownership of |arg|. | 146 // The function takes ownership of |arg|. |
129 void CallJavascriptFunction(const std::wstring& function_name, | 147 void CallJavascriptFunction(const std::wstring& function_name, |
130 Value* arg); | 148 Value* arg); |
131 | 149 |
132 private: | |
133 // Pointer to the UI-thread message handler. Only access this from | 150 // Pointer to the UI-thread message handler. Only access this from |
134 // the UI thread. | 151 // the UI thread. |
135 base::WeakPtr<NetInternalsMessageHandler> handler_; | 152 base::WeakPtr<NetInternalsMessageHandler> handler_; |
136 | 153 |
137 // The global IOThread, which contains the global NetLog to observer. | 154 // The global IOThread, which contains the global NetLog to observer. |
138 IOThread* io_thread_; | 155 IOThread* io_thread_; |
139 | 156 |
| 157 scoped_refptr<URLRequestContextGetter> context_getter_; |
| 158 |
140 // True if we have attached an observer to the NetLog already. | 159 // True if we have attached an observer to the NetLog already. |
141 bool is_observing_log_; | 160 bool is_observing_log_; |
142 friend class base::RefCountedThreadSafe<IOThreadImpl>; | 161 friend class base::RefCountedThreadSafe<IOThreadImpl>; |
143 }; | 162 }; |
144 | 163 |
145 // Helper class for a DOMUI::MessageCallback which when excuted calls | 164 // Helper class for a DOMUI::MessageCallback which when excuted calls |
146 // instance->*method(value) on the IO thread. | 165 // instance->*method(value) on the IO thread. |
147 class NetInternalsMessageHandler::IOThreadImpl::CallbackHelper | 166 class NetInternalsMessageHandler::IOThreadImpl::CallbackHelper |
148 : public DOMUI::MessageCallback { | 167 : public DOMUI::MessageCallback { |
149 public: | 168 public: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 : DataSource(chrome::kChromeUINetInternalsHost, MessageLoop::current()) { | 204 : DataSource(chrome::kChromeUINetInternalsHost, MessageLoop::current()) { |
186 } | 205 } |
187 | 206 |
188 void NetInternalsHTMLSource::StartDataRequest(const std::string& path, | 207 void NetInternalsHTMLSource::StartDataRequest(const std::string& path, |
189 bool is_off_the_record, | 208 bool is_off_the_record, |
190 int request_id) { | 209 int request_id) { |
191 // The provided |path| identifies a file in resources/net_internals/. | 210 // The provided |path| identifies a file in resources/net_internals/. |
192 std::string data_string; | 211 std::string data_string; |
193 FilePath file_path; | 212 FilePath file_path; |
194 PathService::Get(chrome::DIR_NET_INTERNALS, &file_path); | 213 PathService::Get(chrome::DIR_NET_INTERNALS, &file_path); |
195 std::string filename = path.empty() ? "index.html" : path; | 214 std::string filename; |
| 215 |
| 216 // The provided "path" may contain a fragment, or query section. We only |
| 217 // care about the path itself, and will disregard anything else. |
| 218 filename = GURL(std::string("chrome://net/") + path).path().substr(1); |
| 219 |
| 220 if (filename.empty()) |
| 221 filename = "index.html"; |
| 222 |
196 file_path = file_path.AppendASCII(filename); | 223 file_path = file_path.AppendASCII(filename); |
197 | 224 |
198 if (!file_util::ReadFileToString(file_path, &data_string)) { | 225 if (!file_util::ReadFileToString(file_path, &data_string)) { |
199 LOG(WARNING) << "Could not read resource: " << file_path.value(); | 226 LOG(WARNING) << "Could not read resource: " << file_path.value(); |
200 data_string = StringPrintf( | 227 data_string = StringPrintf( |
201 "Failed to read file RESOURCES/net_internals/%s", | 228 "Failed to read file RESOURCES/net_internals/%s", |
202 filename.c_str()); | 229 filename.c_str()); |
203 } | 230 } |
204 | 231 |
205 scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes); | 232 scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes); |
(...skipping 20 matching lines...) Expand all Loading... |
226 NetInternalsMessageHandler::~NetInternalsMessageHandler() { | 253 NetInternalsMessageHandler::~NetInternalsMessageHandler() { |
227 if (proxy_) { | 254 if (proxy_) { |
228 // Notify the handler on the IO thread that the renderer is gone. | 255 // Notify the handler on the IO thread that the renderer is gone. |
229 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, | 256 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, |
230 NewRunnableMethod(proxy_.get(), &IOThreadImpl::Detach)); | 257 NewRunnableMethod(proxy_.get(), &IOThreadImpl::Detach)); |
231 } | 258 } |
232 } | 259 } |
233 | 260 |
234 DOMMessageHandler* NetInternalsMessageHandler::Attach(DOMUI* dom_ui) { | 261 DOMMessageHandler* NetInternalsMessageHandler::Attach(DOMUI* dom_ui) { |
235 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 262 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
236 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread()); | 263 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), |
| 264 dom_ui->GetProfile()->GetRequestContext()); |
237 DOMMessageHandler* result = DOMMessageHandler::Attach(dom_ui); | 265 DOMMessageHandler* result = DOMMessageHandler::Attach(dom_ui); |
238 return result; | 266 return result; |
239 } | 267 } |
240 | 268 |
241 void NetInternalsMessageHandler::RegisterMessages() { | 269 void NetInternalsMessageHandler::RegisterMessages() { |
242 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 270 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
243 | 271 |
244 dom_ui_->RegisterMessageCallback("notifyReady", | 272 dom_ui_->RegisterMessageCallback("notifyReady", |
245 proxy_->CreateCallback(&IOThreadImpl::OnRendererReady)); | 273 proxy_->CreateCallback(&IOThreadImpl::OnRendererReady)); |
| 274 dom_ui_->RegisterMessageCallback("getProxySettings", |
| 275 proxy_->CreateCallback(&IOThreadImpl::OnGetProxySettings)); |
| 276 dom_ui_->RegisterMessageCallback("reloadProxySettings", |
| 277 proxy_->CreateCallback(&IOThreadImpl::OnReloadProxySettings)); |
| 278 dom_ui_->RegisterMessageCallback("getBadProxies", |
| 279 proxy_->CreateCallback(&IOThreadImpl::OnGetBadProxies)); |
| 280 dom_ui_->RegisterMessageCallback("clearBadProxies", |
| 281 proxy_->CreateCallback(&IOThreadImpl::OnClearBadProxies)); |
246 } | 282 } |
247 | 283 |
248 void NetInternalsMessageHandler::CallJavascriptFunction( | 284 void NetInternalsMessageHandler::CallJavascriptFunction( |
249 const std::wstring& function_name, | 285 const std::wstring& function_name, |
250 const Value& value) { | 286 const Value& value) { |
251 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 287 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
252 dom_ui_->CallJavascriptFunction(function_name, value); | 288 dom_ui_->CallJavascriptFunction(function_name, value); |
253 } | 289 } |
254 | 290 |
255 //////////////////////////////////////////////////////////////////////////////// | 291 //////////////////////////////////////////////////////////////////////////////// |
256 // | 292 // |
257 // NetInternalsMessageHandler::IOThreadImpl | 293 // NetInternalsMessageHandler::IOThreadImpl |
258 // | 294 // |
259 //////////////////////////////////////////////////////////////////////////////// | 295 //////////////////////////////////////////////////////////////////////////////// |
260 | 296 |
261 NetInternalsMessageHandler::IOThreadImpl::IOThreadImpl( | 297 NetInternalsMessageHandler::IOThreadImpl::IOThreadImpl( |
262 const base::WeakPtr<NetInternalsMessageHandler>& handler, | 298 const base::WeakPtr<NetInternalsMessageHandler>& handler, |
263 IOThread* io_thread) | 299 IOThread* io_thread, |
| 300 URLRequestContextGetter* context_getter) |
264 : handler_(handler), | 301 : handler_(handler), |
265 io_thread_(io_thread), | 302 io_thread_(io_thread), |
| 303 context_getter_(context_getter), |
266 is_observing_log_(false) { | 304 is_observing_log_(false) { |
267 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 305 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
268 } | 306 } |
269 | 307 |
270 NetInternalsMessageHandler::IOThreadImpl::~IOThreadImpl() { | 308 NetInternalsMessageHandler::IOThreadImpl::~IOThreadImpl() { |
271 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 309 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
272 } | 310 } |
273 | 311 |
274 DOMUI::MessageCallback* | 312 DOMUI::MessageCallback* |
275 NetInternalsMessageHandler::IOThreadImpl::CreateCallback( | 313 NetInternalsMessageHandler::IOThreadImpl::CreateCallback( |
(...skipping 25 matching lines...) Expand all Loading... |
301 net::NetLog::GetAllEventTypes(); | 339 net::NetLog::GetAllEventTypes(); |
302 | 340 |
303 DictionaryValue* dict = new DictionaryValue(); | 341 DictionaryValue* dict = new DictionaryValue(); |
304 | 342 |
305 for (size_t i = 0; i < event_types.size(); ++i) { | 343 for (size_t i = 0; i < event_types.size(); ++i) { |
306 const char* name = net::NetLog::EventTypeToString(event_types[i]); | 344 const char* name = net::NetLog::EventTypeToString(event_types[i]); |
307 dict->SetInteger(ASCIIToWide(name), | 345 dict->SetInteger(ASCIIToWide(name), |
308 static_cast<int>(event_types[i])); | 346 static_cast<int>(event_types[i])); |
309 } | 347 } |
310 | 348 |
311 CallJavascriptFunction(L"setLogEventTypeConstants", dict); | 349 CallJavascriptFunction(L"g_browser.receivedLogEventTypeConstants", dict); |
312 } | 350 } |
313 | 351 |
314 // Tell the javascript about the relationship between event phase enums and | 352 // Tell the javascript about the relationship between event phase enums and |
315 // their symbolic name. | 353 // their symbolic name. |
316 { | 354 { |
317 DictionaryValue* dict = new DictionaryValue(); | 355 DictionaryValue* dict = new DictionaryValue(); |
318 | 356 |
319 dict->SetInteger(L"PHASE_BEGIN", net::NetLog::PHASE_BEGIN); | 357 dict->SetInteger(L"PHASE_BEGIN", net::NetLog::PHASE_BEGIN); |
320 dict->SetInteger(L"PHASE_END", net::NetLog::PHASE_END); | 358 dict->SetInteger(L"PHASE_END", net::NetLog::PHASE_END); |
321 dict->SetInteger(L"PHASE_NONE", net::NetLog::PHASE_NONE); | 359 dict->SetInteger(L"PHASE_NONE", net::NetLog::PHASE_NONE); |
322 | 360 |
323 CallJavascriptFunction(L"setLogEventPhaseConstants", dict); | 361 CallJavascriptFunction(L"g_browser.receivedLogEventPhaseConstants", dict); |
324 } | 362 } |
325 | 363 |
326 // Tell the javascript about the relationship between source type enums and | 364 // Tell the javascript about the relationship between source type enums and |
327 // their symbolic name. | 365 // their symbolic name. |
328 // TODO(eroman): Don't duplicate the values, it will never stay up to date! | 366 // TODO(eroman): Don't duplicate the values, it will never stay up to date! |
329 { | 367 { |
330 DictionaryValue* dict = new DictionaryValue(); | 368 DictionaryValue* dict = new DictionaryValue(); |
331 | 369 |
332 dict->SetInteger(L"NONE", net::NetLog::SOURCE_NONE); | 370 dict->SetInteger(L"NONE", net::NetLog::SOURCE_NONE); |
333 dict->SetInteger(L"URL_REQUEST", net::NetLog::SOURCE_URL_REQUEST); | 371 dict->SetInteger(L"URL_REQUEST", net::NetLog::SOURCE_URL_REQUEST); |
334 dict->SetInteger(L"SOCKET_STREAM", net::NetLog::SOURCE_SOCKET_STREAM); | 372 dict->SetInteger(L"SOCKET_STREAM", net::NetLog::SOURCE_SOCKET_STREAM); |
335 dict->SetInteger(L"INIT_PROXY_RESOLVER", | 373 dict->SetInteger(L"INIT_PROXY_RESOLVER", |
336 net::NetLog::SOURCE_INIT_PROXY_RESOLVER); | 374 net::NetLog::SOURCE_INIT_PROXY_RESOLVER); |
337 dict->SetInteger(L"CONNECT_JOB", net::NetLog::SOURCE_CONNECT_JOB); | 375 dict->SetInteger(L"CONNECT_JOB", net::NetLog::SOURCE_CONNECT_JOB); |
338 | 376 |
339 CallJavascriptFunction(L"setLogSourceTypeConstants", dict); | 377 CallJavascriptFunction(L"g_browser.receivedLogSourceTypeConstants", dict); |
340 } | 378 } |
341 | 379 |
342 // Tell the javascript about the relationship between entry type enums and | 380 // Tell the javascript about the relationship between entry type enums and |
343 // their symbolic name. | 381 // their symbolic name. |
344 { | 382 { |
345 DictionaryValue* dict = new DictionaryValue(); | 383 DictionaryValue* dict = new DictionaryValue(); |
346 | 384 |
347 dict->SetInteger(L"TYPE_EVENT", net::NetLog::Entry::TYPE_EVENT); | 385 dict->SetInteger(L"TYPE_EVENT", net::NetLog::Entry::TYPE_EVENT); |
348 dict->SetInteger(L"TYPE_STRING", net::NetLog::Entry::TYPE_STRING); | 386 dict->SetInteger(L"TYPE_STRING", net::NetLog::Entry::TYPE_STRING); |
349 dict->SetInteger(L"TYPE_ERROR_CODE", net::NetLog::Entry::TYPE_ERROR_CODE); | 387 dict->SetInteger(L"TYPE_ERROR_CODE", net::NetLog::Entry::TYPE_ERROR_CODE); |
350 | 388 |
351 CallJavascriptFunction(L"setLogEntryTypeConstants", dict); | 389 CallJavascriptFunction(L"g_browser.receivedLogEntryTypeConstants", dict); |
352 } | 390 } |
| 391 |
| 392 // Tell the javascript how the "time ticks" values we have given it relate to |
| 393 // actual system times. (We used time ticks throughout since they are stable |
| 394 // across system clock changes). |
| 395 { |
| 396 int64 cur_time_ms = (base::Time::Now() - base::Time()).InMilliseconds(); |
| 397 |
| 398 int64 cur_time_ticks_ms = |
| 399 (base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds(); |
| 400 |
| 401 // If we add this number to a time tick value, it gives the timestamp. |
| 402 int64 tick_to_time_ms = cur_time_ms - cur_time_ticks_ms; |
| 403 |
| 404 // Chrome on all platforms stores times using the Windows epoch |
| 405 // (Jan 1 1601), but the javascript wants a unix epoch. |
| 406 // TODO(eroman): Getting the timestamp relative the to unix epoch should |
| 407 // be part of the time library. |
| 408 const int64 kUnixEpochMs = 11644473600000LL; |
| 409 int64 tick_to_unix_time_ms = tick_to_time_ms - kUnixEpochMs; |
| 410 |
| 411 // Pass it as a string, since it may be too large to fit in an integer. |
| 412 CallJavascriptFunction(L"g_browser.receivedTimeTickOffset", |
| 413 Value::CreateStringValue( |
| 414 Int64ToString(tick_to_unix_time_ms))); |
| 415 } |
| 416 |
| 417 // Notify the client of the basic proxy data. |
| 418 OnGetProxySettings(NULL); |
| 419 OnGetBadProxies(NULL); |
| 420 } |
| 421 |
| 422 void NetInternalsMessageHandler::IOThreadImpl::OnGetProxySettings( |
| 423 const Value* value) { |
| 424 URLRequestContext* context = context_getter_->GetURLRequestContext(); |
| 425 net::ProxyService* proxy_service = context->proxy_service(); |
| 426 |
| 427 // TODO(eroman): send a dictionary rather than a flat string, so client can do |
| 428 // its own presentation. |
| 429 std::string settings_string; |
| 430 |
| 431 if (proxy_service->config_has_been_initialized()) { |
| 432 // net::ProxyConfig defines an operator<<. |
| 433 std::ostringstream stream; |
| 434 stream << proxy_service->config(); |
| 435 settings_string = stream.str(); |
| 436 } |
| 437 |
| 438 CallJavascriptFunction(L"g_browser.receivedProxySettings", |
| 439 Value::CreateStringValue(settings_string)); |
| 440 } |
| 441 |
| 442 void NetInternalsMessageHandler::IOThreadImpl::OnReloadProxySettings( |
| 443 const Value* value) { |
| 444 URLRequestContext* context = context_getter_->GetURLRequestContext(); |
| 445 context->proxy_service()->ForceReloadProxyConfig(); |
| 446 |
| 447 // Cause the renderer to be notified of the new values. |
| 448 OnGetProxySettings(NULL); |
| 449 } |
| 450 |
| 451 void NetInternalsMessageHandler::IOThreadImpl::OnGetBadProxies( |
| 452 const Value* value) { |
| 453 URLRequestContext* context = context_getter_->GetURLRequestContext(); |
| 454 |
| 455 const net::ProxyRetryInfoMap& bad_proxies_map = |
| 456 context->proxy_service()->proxy_retry_info(); |
| 457 |
| 458 ListValue* list = new ListValue(); |
| 459 |
| 460 for (net::ProxyRetryInfoMap::const_iterator it = bad_proxies_map.begin(); |
| 461 it != bad_proxies_map.end(); ++it) { |
| 462 const std::string& proxy_uri = it->first; |
| 463 const net::ProxyRetryInfo& retry_info = it->second; |
| 464 |
| 465 DictionaryValue* dict = new DictionaryValue(); |
| 466 dict->SetString(L"proxy_uri", proxy_uri); |
| 467 dict->SetString(L"bad_until", TickCountToString(retry_info.bad_until)); |
| 468 |
| 469 list->Append(dict); |
| 470 } |
| 471 |
| 472 CallJavascriptFunction(L"g_browser.receivedBadProxies", list); |
| 473 } |
| 474 |
| 475 void NetInternalsMessageHandler::IOThreadImpl::OnClearBadProxies( |
| 476 const Value* value) { |
| 477 URLRequestContext* context = context_getter_->GetURLRequestContext(); |
| 478 context->proxy_service()->ClearBadProxiesCache(); |
| 479 |
| 480 // Cause the renderer to be notified of the new values. |
| 481 OnGetBadProxies(NULL); |
353 } | 482 } |
354 | 483 |
355 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( | 484 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( |
356 const net::NetLog::Entry& entry) { | 485 const net::NetLog::Entry& entry) { |
357 DCHECK(is_observing_log_); | 486 DCHECK(is_observing_log_); |
358 | 487 |
359 // JSONify the NetLog::Entry. | 488 // JSONify the NetLog::Entry. |
360 // TODO(eroman): Need a better format for this. | 489 // TODO(eroman): Need a better format for this. |
361 DictionaryValue* entry_dict = new DictionaryValue(); | 490 DictionaryValue* entry_dict = new DictionaryValue(); |
362 | 491 |
363 // Set the entry type. | 492 // Set the entry type. |
364 { | 493 { |
365 net::NetLog::Entry::Type entry_type = entry.type; | 494 net::NetLog::Entry::Type entry_type = entry.type; |
366 if (entry_type == net::NetLog::Entry::TYPE_STRING_LITERAL) | 495 if (entry_type == net::NetLog::Entry::TYPE_STRING_LITERAL) |
367 entry_type = net::NetLog::Entry::TYPE_STRING; | 496 entry_type = net::NetLog::Entry::TYPE_STRING; |
368 entry_dict->SetInteger(L"type", static_cast<int>(entry_type)); | 497 entry_dict->SetInteger(L"type", static_cast<int>(entry_type)); |
369 } | 498 } |
370 | 499 |
371 // Set the entry time. | 500 // Set the entry time. (Note that we send it as a string since integers |
372 entry_dict->SetInteger( | 501 // might overflow). |
373 L"time", | 502 entry_dict->SetString(L"time", TickCountToString(entry.time)); |
374 static_cast<int>((entry.time - base::TimeTicks()).InMilliseconds())); | |
375 | 503 |
376 // Set the entry source. | 504 // Set the entry source. |
377 DictionaryValue* source_dict = new DictionaryValue(); | 505 DictionaryValue* source_dict = new DictionaryValue(); |
378 source_dict->SetInteger(L"id", entry.source.id); | 506 source_dict->SetInteger(L"id", entry.source.id); |
379 source_dict->SetInteger(L"type", static_cast<int>(entry.source.type)); | 507 source_dict->SetInteger(L"type", static_cast<int>(entry.source.type)); |
380 entry_dict->Set(L"source", source_dict); | 508 entry_dict->Set(L"source", source_dict); |
381 | 509 |
382 // Set the event info (if it is an event entry). | 510 // Set the event info (if it is an event entry). |
383 if (entry.type == net::NetLog::Entry::TYPE_EVENT) { | 511 if (entry.type == net::NetLog::Entry::TYPE_EVENT) { |
384 DictionaryValue* event_dict = new DictionaryValue(); | 512 DictionaryValue* event_dict = new DictionaryValue(); |
(...skipping 10 matching lines...) Expand all Loading... |
395 | 523 |
396 // Treat string literals the same as strings. | 524 // Treat string literals the same as strings. |
397 if (entry.type == net::NetLog::Entry::TYPE_STRING_LITERAL) { | 525 if (entry.type == net::NetLog::Entry::TYPE_STRING_LITERAL) { |
398 entry_dict->SetString(L"string", entry.literal); | 526 entry_dict->SetString(L"string", entry.literal); |
399 } | 527 } |
400 | 528 |
401 if (entry.type == net::NetLog::Entry::TYPE_ERROR_CODE) { | 529 if (entry.type == net::NetLog::Entry::TYPE_ERROR_CODE) { |
402 entry_dict->SetInteger(L"error_code", entry.error_code); | 530 entry_dict->SetInteger(L"error_code", entry.error_code); |
403 } | 531 } |
404 | 532 |
405 CallJavascriptFunction(L"onLogEntryAdded", entry_dict); | 533 CallJavascriptFunction(L"g_browser.receivedLogEntry", entry_dict); |
406 } | 534 } |
407 | 535 |
408 void NetInternalsMessageHandler::IOThreadImpl::DispatchToMessageHandler( | 536 void NetInternalsMessageHandler::IOThreadImpl::DispatchToMessageHandler( |
409 Value* arg, MessageHandler method) { | 537 Value* arg, MessageHandler method) { |
410 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 538 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
411 (this->*method)(arg); | 539 (this->*method)(arg); |
412 delete arg; | 540 delete arg; |
413 } | 541 } |
414 | 542 |
415 void NetInternalsMessageHandler::IOThreadImpl::CallJavascriptFunction( | 543 void NetInternalsMessageHandler::IOThreadImpl::CallJavascriptFunction( |
(...skipping 16 matching lines...) Expand all Loading... |
432 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 560 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
433 if (!ChromeThread::PostTask( | 561 if (!ChromeThread::PostTask( |
434 ChromeThread::UI, FROM_HERE, | 562 ChromeThread::UI, FROM_HERE, |
435 NewRunnableMethod( | 563 NewRunnableMethod( |
436 this, | 564 this, |
437 &IOThreadImpl::CallJavascriptFunction, | 565 &IOThreadImpl::CallJavascriptFunction, |
438 function_name, arg))) { | 566 function_name, arg))) { |
439 // Failed posting the task, avoid leaking. | 567 // Failed posting the task, avoid leaking. |
440 delete arg; | 568 delete arg; |
441 } | 569 } |
442 | |
443 } | 570 } |
444 | 571 |
445 } // namespace | 572 } // namespace |
446 | 573 |
447 | 574 |
448 //////////////////////////////////////////////////////////////////////////////// | 575 //////////////////////////////////////////////////////////////////////////////// |
449 // | 576 // |
450 // NetInternalsUI | 577 // NetInternalsUI |
451 // | 578 // |
452 //////////////////////////////////////////////////////////////////////////////// | 579 //////////////////////////////////////////////////////////////////////////////// |
453 | 580 |
454 NetInternalsUI::NetInternalsUI(TabContents* contents) : DOMUI(contents) { | 581 NetInternalsUI::NetInternalsUI(TabContents* contents) : DOMUI(contents) { |
455 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); | 582 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); |
456 | 583 |
457 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); | 584 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); |
458 | 585 |
459 // Set up the chrome://net-internals/ source. | 586 // Set up the chrome://net-internals/ source. |
460 ChromeThread::PostTask( | 587 ChromeThread::PostTask( |
461 ChromeThread::IO, FROM_HERE, | 588 ChromeThread::IO, FROM_HERE, |
462 NewRunnableMethod( | 589 NewRunnableMethod( |
463 Singleton<ChromeURLDataManager>::get(), | 590 Singleton<ChromeURLDataManager>::get(), |
464 &ChromeURLDataManager::AddDataSource, | 591 &ChromeURLDataManager::AddDataSource, |
465 make_scoped_refptr(html_source))); | 592 make_scoped_refptr(html_source))); |
466 } | 593 } |
OLD | NEW |