Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 class IOThreadImpl; | 146 class IOThreadImpl; |
| 147 | 147 |
| 148 // This is the "real" message handler, which lives on the IO thread. | 148 // This is the "real" message handler, which lives on the IO thread. |
| 149 scoped_refptr<IOThreadImpl> proxy_; | 149 scoped_refptr<IOThreadImpl> proxy_; |
| 150 | 150 |
| 151 DISALLOW_COPY_AND_ASSIGN(NetInternalsMessageHandler); | 151 DISALLOW_COPY_AND_ASSIGN(NetInternalsMessageHandler); |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 // This class is the "real" message handler. With the exception of being | 154 // This class is the "real" message handler. It is allocated and destroyed on |
| 155 // allocated and destroyed on the UI thread, its methods are expected to be | 155 // the UI thread. With the exception of OnAddEntry, OnDOMUIDeleted, and |
| 156 // called from the IO thread. | 156 // CallJavascriptFunction, its methods are all expected to be called from the IO |
| 157 // thread. OnAddEntry and CallJavascriptFunction can be called from any thread, | |
| 158 // and OnDOMUIDeleted can only be called from the UI thread. | |
| 157 class NetInternalsMessageHandler::IOThreadImpl | 159 class NetInternalsMessageHandler::IOThreadImpl |
| 158 : public base::RefCountedThreadSafe< | 160 : public base::RefCountedThreadSafe< |
| 159 NetInternalsMessageHandler::IOThreadImpl, | 161 NetInternalsMessageHandler::IOThreadImpl, |
| 160 BrowserThread::DeleteOnUIThread>, | 162 BrowserThread::DeleteOnUIThread>, |
| 161 public ChromeNetLog::Observer, | 163 public ChromeNetLog::ThreadSafeObserver, |
| 162 public ConnectionTester::Delegate { | 164 public ConnectionTester::Delegate { |
| 163 public: | 165 public: |
| 164 // Type for methods that can be used as MessageHandler callbacks. | 166 // Type for methods that can be used as MessageHandler callbacks. |
| 165 typedef void (IOThreadImpl::*MessageHandler)(const ListValue*); | 167 typedef void (IOThreadImpl::*MessageHandler)(const ListValue*); |
| 166 | 168 |
| 167 // Creates a proxy for |handler| that will live on the IO thread. | 169 // Creates a proxy for |handler| that will live on the IO thread. |
| 168 // |handler| is a weak pointer, since it is possible for the DOMMessageHandler | 170 // |handler| is a weak pointer, since it is possible for the DOMMessageHandler |
| 169 // to be deleted on the UI thread while we were executing on the IO thread. | 171 // to be deleted on the UI thread while we were executing on the IO thread. |
| 170 // |io_thread| is the global IOThread (it is passed in as an argument since | 172 // |io_thread| is the global IOThread (it is passed in as an argument since |
| 171 // we need to grab it from the UI thread). | 173 // we need to grab it from the UI thread). |
| 172 IOThreadImpl( | 174 IOThreadImpl( |
| 173 const base::WeakPtr<NetInternalsMessageHandler>& handler, | 175 const base::WeakPtr<NetInternalsMessageHandler>& handler, |
| 174 IOThread* io_thread, | 176 IOThread* io_thread, |
| 175 URLRequestContextGetter* context_getter); | 177 URLRequestContextGetter* context_getter); |
| 176 | 178 |
| 177 ~IOThreadImpl(); | 179 ~IOThreadImpl(); |
| 178 | 180 |
| 179 // Creates a callback that will run |method| on the IO thread. | 181 // Creates a callback that will run |method| on the IO thread. |
| 180 // | 182 // |
| 181 // This can be used with DOMUI::RegisterMessageCallback() to bind to a method | 183 // This can be used with DOMUI::RegisterMessageCallback() to bind to a method |
| 182 // on the IO thread. | 184 // on the IO thread. |
| 183 DOMUI::MessageCallback* CreateCallback(MessageHandler method); | 185 DOMUI::MessageCallback* CreateCallback(MessageHandler method); |
| 184 | 186 |
| 185 // Called once the DOMUI has been deleted (i.e. renderer went away), on the | 187 // Called once the DOMUI has been deleted (i.e. renderer went away), on the |
| 186 // IO thread. | 188 // IO thread. |
| 187 void Detach(); | 189 void Detach(); |
| 188 | 190 |
| 191 // Sends all passive log entries in |entries| to the Javascript handler, | |
|
eroman
2010/11/18 18:04:03
|passive_entries|
| |
| 192 // called on the IO thread. | |
| 193 void SendPassiveLogEntries(const ChromeNetLog::EntryList& passive_entries); | |
| 194 | |
| 195 // Called when the DOMUI is deleted. Prevents calling Javascript functions | |
| 196 // afterwards. Called on UI thread. | |
| 197 void OnDOMUIDeleted(); | |
| 198 | |
| 189 //-------------------------------- | 199 //-------------------------------- |
| 190 // Javascript message handlers: | 200 // Javascript message handlers: |
| 191 //-------------------------------- | 201 //-------------------------------- |
| 192 | 202 |
| 193 // This message is called after the webpage's onloaded handler has fired. | |
| 194 // it indicates that the renderer is ready to start receiving captured data. | |
| 195 void OnRendererReady(const ListValue* list); | 203 void OnRendererReady(const ListValue* list); |
| 196 | 204 |
| 197 void OnGetProxySettings(const ListValue* list); | 205 void OnGetProxySettings(const ListValue* list); |
| 198 void OnReloadProxySettings(const ListValue* list); | 206 void OnReloadProxySettings(const ListValue* list); |
| 199 void OnGetBadProxies(const ListValue* list); | 207 void OnGetBadProxies(const ListValue* list); |
| 200 void OnClearBadProxies(const ListValue* list); | 208 void OnClearBadProxies(const ListValue* list); |
| 201 void OnGetHostResolverInfo(const ListValue* list); | 209 void OnGetHostResolverInfo(const ListValue* list); |
| 202 void OnClearHostResolverCache(const ListValue* list); | 210 void OnClearHostResolverCache(const ListValue* list); |
| 203 void OnEnableIPv6(const ListValue* list); | 211 void OnEnableIPv6(const ListValue* list); |
| 204 void OnGetPassiveLogEntries(const ListValue* list); | |
| 205 void OnStartConnectionTests(const ListValue* list); | 212 void OnStartConnectionTests(const ListValue* list); |
| 206 void OnGetHttpCacheInfo(const ListValue* list); | 213 void OnGetHttpCacheInfo(const ListValue* list); |
| 207 void OnGetSocketPoolInfo(const ListValue* list); | 214 void OnGetSocketPoolInfo(const ListValue* list); |
| 208 void OnGetSpdySessionInfo(const ListValue* list); | 215 void OnGetSpdySessionInfo(const ListValue* list); |
| 209 #ifdef OS_WIN | 216 #ifdef OS_WIN |
| 210 void OnGetServiceProviders(const ListValue* list); | 217 void OnGetServiceProviders(const ListValue* list); |
| 211 #endif | 218 #endif |
| 212 | 219 |
| 213 void OnSetLogLevel(const ListValue* list); | 220 void OnSetLogLevel(const ListValue* list); |
| 214 | 221 |
| 215 // ChromeNetLog::Observer implementation: | 222 // ChromeNetLog::ThreadSafeObserver implementation: |
| 216 virtual void OnAddEntry(net::NetLog::EventType type, | 223 virtual void OnAddEntry(net::NetLog::EventType type, |
| 217 const base::TimeTicks& time, | 224 const base::TimeTicks& time, |
| 218 const net::NetLog::Source& source, | 225 const net::NetLog::Source& source, |
| 219 net::NetLog::EventPhase phase, | 226 net::NetLog::EventPhase phase, |
| 220 net::NetLog::EventParameters* params); | 227 net::NetLog::EventParameters* params); |
| 221 | 228 |
| 222 // ConnectionTester::Delegate implementation: | 229 // ConnectionTester::Delegate implementation: |
| 223 virtual void OnStartConnectionTestSuite(); | 230 virtual void OnStartConnectionTestSuite(); |
| 224 virtual void OnStartConnectionTestExperiment( | 231 virtual void OnStartConnectionTestExperiment( |
| 225 const ConnectionTester::Experiment& experiment); | 232 const ConnectionTester::Experiment& experiment); |
| 226 virtual void OnCompletedConnectionTestExperiment( | 233 virtual void OnCompletedConnectionTestExperiment( |
| 227 const ConnectionTester::Experiment& experiment, | 234 const ConnectionTester::Experiment& experiment, |
| 228 int result); | 235 int result); |
| 229 virtual void OnCompletedConnectionTestSuite(); | 236 virtual void OnCompletedConnectionTestSuite(); |
| 230 | 237 |
| 231 private: | 238 private: |
| 232 class CallbackHelper; | 239 class CallbackHelper; |
| 233 | 240 |
| 234 // Helper that runs |method| with |arg|, and deletes |arg| on completion. | 241 // Helper that runs |method| with |arg|, and deletes |arg| on completion. |
| 235 void DispatchToMessageHandler(ListValue* arg, MessageHandler method); | 242 void DispatchToMessageHandler(ListValue* arg, MessageHandler method); |
| 236 | 243 |
| 237 // Helper that executes |function_name| in the attached renderer. | 244 // Helper that executes |function_name| in the attached renderer. |
| 238 // The function takes ownership of |arg|. | 245 // The function takes ownership of |arg|. Note that this can be called from |
| 246 // any thread. | |
| 239 void CallJavascriptFunction(const std::wstring& function_name, | 247 void CallJavascriptFunction(const std::wstring& function_name, |
| 240 Value* arg); | 248 Value* arg); |
| 241 | 249 |
| 242 // Pointer to the UI-thread message handler. Only access this from | 250 // Pointer to the UI-thread message handler. Only access this from |
| 243 // the UI thread. | 251 // the UI thread. |
| 244 base::WeakPtr<NetInternalsMessageHandler> handler_; | 252 base::WeakPtr<NetInternalsMessageHandler> handler_; |
| 245 | 253 |
| 254 // True if the DOM UI has been deleted. This is used to prevent calling | |
| 255 // Javascript functions after the DOM UI is destroyed. On refresh, the | |
| 256 // messages can end up being sent to the refreshed page, causing duplicate | |
| 257 // or partial entries. | |
| 258 // | |
| 259 // This is only read and written to on the UI thread. | |
| 260 bool was_domui_deleted_; | |
| 261 | |
| 246 // The global IOThread, which contains the global NetLog to observer. | 262 // The global IOThread, which contains the global NetLog to observer. |
| 247 IOThread* io_thread_; | 263 IOThread* io_thread_; |
| 248 | 264 |
| 249 scoped_refptr<URLRequestContextGetter> context_getter_; | 265 scoped_refptr<URLRequestContextGetter> context_getter_; |
| 250 | 266 |
| 251 // Helper that runs the suite of connection tests. | 267 // Helper that runs the suite of connection tests. |
| 252 scoped_ptr<ConnectionTester> connection_tester_; | 268 scoped_ptr<ConnectionTester> connection_tester_; |
| 253 | 269 |
| 254 // True if we have attached an observer to the NetLog already. | 270 // True if we have attached an observer to the NetLog already. |
| 255 bool is_observing_log_; | 271 bool is_observing_log_; |
| 272 | |
| 256 friend class base::RefCountedThreadSafe<IOThreadImpl>; | 273 friend class base::RefCountedThreadSafe<IOThreadImpl>; |
| 257 }; | 274 }; |
| 258 | 275 |
| 259 // Helper class for a DOMUI::MessageCallback which when excuted calls | 276 // Helper class for a DOMUI::MessageCallback which when excuted calls |
| 260 // instance->*method(value) on the IO thread. | 277 // instance->*method(value) on the IO thread. |
| 261 class NetInternalsMessageHandler::IOThreadImpl::CallbackHelper | 278 class NetInternalsMessageHandler::IOThreadImpl::CallbackHelper |
| 262 : public DOMUI::MessageCallback { | 279 : public DOMUI::MessageCallback { |
| 263 public: | 280 public: |
| 264 CallbackHelper(IOThreadImpl* instance, IOThreadImpl::MessageHandler method) | 281 CallbackHelper(IOThreadImpl* instance, IOThreadImpl::MessageHandler method) |
| 265 : instance_(instance), | 282 : instance_(instance), |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 //////////////////////////////////////////////////////////////////////////////// | 354 //////////////////////////////////////////////////////////////////////////////// |
| 338 // | 355 // |
| 339 // NetInternalsMessageHandler | 356 // NetInternalsMessageHandler |
| 340 // | 357 // |
| 341 //////////////////////////////////////////////////////////////////////////////// | 358 //////////////////////////////////////////////////////////////////////////////// |
| 342 | 359 |
| 343 NetInternalsMessageHandler::NetInternalsMessageHandler() {} | 360 NetInternalsMessageHandler::NetInternalsMessageHandler() {} |
| 344 | 361 |
| 345 NetInternalsMessageHandler::~NetInternalsMessageHandler() { | 362 NetInternalsMessageHandler::~NetInternalsMessageHandler() { |
| 346 if (proxy_) { | 363 if (proxy_) { |
| 364 proxy_.get()->OnDOMUIDeleted(); | |
| 347 // Notify the handler on the IO thread that the renderer is gone. | 365 // Notify the handler on the IO thread that the renderer is gone. |
| 348 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 366 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 349 NewRunnableMethod(proxy_.get(), &IOThreadImpl::Detach)); | 367 NewRunnableMethod(proxy_.get(), &IOThreadImpl::Detach)); |
| 350 } | 368 } |
| 351 } | 369 } |
| 352 | 370 |
| 353 DOMMessageHandler* NetInternalsMessageHandler::Attach(DOMUI* dom_ui) { | 371 DOMMessageHandler* NetInternalsMessageHandler::Attach(DOMUI* dom_ui) { |
| 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 355 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), | 373 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), |
| 356 dom_ui->GetProfile()->GetRequestContext()); | 374 dom_ui->GetProfile()->GetRequestContext()); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 379 dom_ui_->RegisterMessageCallback( | 397 dom_ui_->RegisterMessageCallback( |
| 380 "getHostResolverInfo", | 398 "getHostResolverInfo", |
| 381 proxy_->CreateCallback(&IOThreadImpl::OnGetHostResolverInfo)); | 399 proxy_->CreateCallback(&IOThreadImpl::OnGetHostResolverInfo)); |
| 382 dom_ui_->RegisterMessageCallback( | 400 dom_ui_->RegisterMessageCallback( |
| 383 "clearHostResolverCache", | 401 "clearHostResolverCache", |
| 384 proxy_->CreateCallback(&IOThreadImpl::OnClearHostResolverCache)); | 402 proxy_->CreateCallback(&IOThreadImpl::OnClearHostResolverCache)); |
| 385 dom_ui_->RegisterMessageCallback( | 403 dom_ui_->RegisterMessageCallback( |
| 386 "enableIPv6", | 404 "enableIPv6", |
| 387 proxy_->CreateCallback(&IOThreadImpl::OnEnableIPv6)); | 405 proxy_->CreateCallback(&IOThreadImpl::OnEnableIPv6)); |
| 388 dom_ui_->RegisterMessageCallback( | 406 dom_ui_->RegisterMessageCallback( |
| 389 "getPassiveLogEntries", | |
| 390 proxy_->CreateCallback(&IOThreadImpl::OnGetPassiveLogEntries)); | |
| 391 dom_ui_->RegisterMessageCallback( | |
| 392 "startConnectionTests", | 407 "startConnectionTests", |
| 393 proxy_->CreateCallback(&IOThreadImpl::OnStartConnectionTests)); | 408 proxy_->CreateCallback(&IOThreadImpl::OnStartConnectionTests)); |
| 394 dom_ui_->RegisterMessageCallback( | 409 dom_ui_->RegisterMessageCallback( |
| 395 "getHttpCacheInfo", | 410 "getHttpCacheInfo", |
| 396 proxy_->CreateCallback(&IOThreadImpl::OnGetHttpCacheInfo)); | 411 proxy_->CreateCallback(&IOThreadImpl::OnGetHttpCacheInfo)); |
| 397 dom_ui_->RegisterMessageCallback( | 412 dom_ui_->RegisterMessageCallback( |
| 398 "getSocketPoolInfo", | 413 "getSocketPoolInfo", |
| 399 proxy_->CreateCallback(&IOThreadImpl::OnGetSocketPoolInfo)); | 414 proxy_->CreateCallback(&IOThreadImpl::OnGetSocketPoolInfo)); |
| 400 dom_ui_->RegisterMessageCallback( | 415 dom_ui_->RegisterMessageCallback( |
| 401 "getSpdySessionInfo", | 416 "getSpdySessionInfo", |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 425 //////////////////////////////////////////////////////////////////////////////// | 440 //////////////////////////////////////////////////////////////////////////////// |
| 426 // | 441 // |
| 427 // NetInternalsMessageHandler::IOThreadImpl | 442 // NetInternalsMessageHandler::IOThreadImpl |
| 428 // | 443 // |
| 429 //////////////////////////////////////////////////////////////////////////////// | 444 //////////////////////////////////////////////////////////////////////////////// |
| 430 | 445 |
| 431 NetInternalsMessageHandler::IOThreadImpl::IOThreadImpl( | 446 NetInternalsMessageHandler::IOThreadImpl::IOThreadImpl( |
| 432 const base::WeakPtr<NetInternalsMessageHandler>& handler, | 447 const base::WeakPtr<NetInternalsMessageHandler>& handler, |
| 433 IOThread* io_thread, | 448 IOThread* io_thread, |
| 434 URLRequestContextGetter* context_getter) | 449 URLRequestContextGetter* context_getter) |
| 435 : Observer(net::NetLog::LOG_ALL_BUT_BYTES), | 450 : ThreadSafeObserver(net::NetLog::LOG_ALL_BUT_BYTES), |
| 436 handler_(handler), | 451 handler_(handler), |
| 437 io_thread_(io_thread), | 452 io_thread_(io_thread), |
| 438 context_getter_(context_getter), | 453 context_getter_(context_getter), |
| 454 was_domui_deleted_(false), | |
| 439 is_observing_log_(false) { | 455 is_observing_log_(false) { |
| 440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 441 } | 457 } |
| 442 | 458 |
| 443 NetInternalsMessageHandler::IOThreadImpl::~IOThreadImpl() { | 459 NetInternalsMessageHandler::IOThreadImpl::~IOThreadImpl() { |
| 444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 445 } | 461 } |
| 446 | 462 |
| 447 DOMUI::MessageCallback* | 463 DOMUI::MessageCallback* |
| 448 NetInternalsMessageHandler::IOThreadImpl::CreateCallback( | 464 NetInternalsMessageHandler::IOThreadImpl::CreateCallback( |
| 449 MessageHandler method) { | 465 MessageHandler method) { |
| 450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 451 return new CallbackHelper(this, method); | 467 return new CallbackHelper(this, method); |
| 452 } | 468 } |
| 453 | 469 |
| 454 void NetInternalsMessageHandler::IOThreadImpl::Detach() { | 470 void NetInternalsMessageHandler::IOThreadImpl::Detach() { |
| 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 456 // Unregister with network stack to observe events. | 472 // Unregister with network stack to observe events. |
| 457 if (is_observing_log_) | 473 if (is_observing_log_) |
| 458 io_thread_->globals()->net_log->RemoveObserver(this); | 474 io_thread_->net_log()->RemoveObserver(this); |
| 459 | 475 |
| 460 // Cancel any in-progress connection tests. | 476 // Cancel any in-progress connection tests. |
| 461 connection_tester_.reset(); | 477 connection_tester_.reset(); |
| 462 } | 478 } |
| 463 | 479 |
| 480 void NetInternalsMessageHandler::IOThreadImpl::SendPassiveLogEntries( | |
| 481 const ChromeNetLog::EntryList& passive_entries) { | |
| 482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 483 ListValue* dict_list = new ListValue(); | |
| 484 for (size_t i = 0; i < passive_entries.size(); ++i) { | |
| 485 const ChromeNetLog::Entry& e = passive_entries[i]; | |
| 486 dict_list->Append(net::NetLog::EntryToDictionaryValue(e.type, | |
| 487 e.time, | |
| 488 e.source, | |
| 489 e.phase, | |
| 490 e.params, | |
| 491 false)); | |
| 492 } | |
| 493 | |
| 494 CallJavascriptFunction(L"g_browser.receivedPassiveLogEntries", dict_list); | |
| 495 } | |
| 496 | |
| 497 void NetInternalsMessageHandler::IOThreadImpl::OnDOMUIDeleted() { | |
| 498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 499 was_domui_deleted_ = true; | |
| 500 } | |
| 501 | |
| 464 void NetInternalsMessageHandler::IOThreadImpl::OnRendererReady( | 502 void NetInternalsMessageHandler::IOThreadImpl::OnRendererReady( |
| 465 const ListValue* list) { | 503 const ListValue* list) { |
| 466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 467 DCHECK(!is_observing_log_) << "notifyReady called twice"; | 505 DCHECK(!is_observing_log_) << "notifyReady called twice"; |
| 468 | 506 |
| 469 // Register with network stack to observe events. | |
| 470 is_observing_log_ = true; | |
| 471 io_thread_->globals()->net_log->AddObserver(this); | |
| 472 | |
| 473 // Tell the javascript about the relationship between event type enums and | 507 // Tell the javascript about the relationship between event type enums and |
| 474 // their symbolic name. | 508 // their symbolic name. |
| 475 { | 509 { |
| 476 std::vector<net::NetLog::EventType> event_types = | 510 std::vector<net::NetLog::EventType> event_types = |
| 477 net::NetLog::GetAllEventTypes(); | 511 net::NetLog::GetAllEventTypes(); |
| 478 | 512 |
| 479 DictionaryValue* dict = new DictionaryValue(); | 513 DictionaryValue* dict = new DictionaryValue(); |
| 480 | 514 |
| 481 for (size_t i = 0; i < event_types.size(); ++i) { | 515 for (size_t i = 0; i < event_types.size(); ++i) { |
| 482 const char* name = net::NetLog::EventTypeToString(event_types[i]); | 516 const char* name = net::NetLog::EventTypeToString(event_types[i]); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 // be part of the time library. | 644 // be part of the time library. |
| 611 const int64 kUnixEpochMs = 11644473600000LL; | 645 const int64 kUnixEpochMs = 11644473600000LL; |
| 612 int64 tick_to_unix_time_ms = tick_to_time_ms - kUnixEpochMs; | 646 int64 tick_to_unix_time_ms = tick_to_time_ms - kUnixEpochMs; |
| 613 | 647 |
| 614 // Pass it as a string, since it may be too large to fit in an integer. | 648 // Pass it as a string, since it may be too large to fit in an integer. |
| 615 CallJavascriptFunction(L"g_browser.receivedTimeTickOffset", | 649 CallJavascriptFunction(L"g_browser.receivedTimeTickOffset", |
| 616 Value::CreateStringValue( | 650 Value::CreateStringValue( |
| 617 base::Int64ToString(tick_to_unix_time_ms))); | 651 base::Int64ToString(tick_to_unix_time_ms))); |
| 618 } | 652 } |
| 619 | 653 |
| 620 OnGetPassiveLogEntries(NULL); | 654 // Register with network stack to observe events. |
| 655 is_observing_log_ = true; | |
| 656 ChromeNetLog::EntryList entries; | |
| 657 io_thread_->net_log()->AddObserverAndGetAllPassivelyCapturedEvents(this, | |
| 658 &entries); | |
| 659 SendPassiveLogEntries(entries); | |
| 621 } | 660 } |
| 622 | 661 |
| 623 void NetInternalsMessageHandler::IOThreadImpl::OnGetProxySettings( | 662 void NetInternalsMessageHandler::IOThreadImpl::OnGetProxySettings( |
| 624 const ListValue* list) { | 663 const ListValue* list) { |
| 625 URLRequestContext* context = context_getter_->GetURLRequestContext(); | 664 URLRequestContext* context = context_getter_->GetURLRequestContext(); |
| 626 net::ProxyService* proxy_service = context->proxy_service(); | 665 net::ProxyService* proxy_service = context->proxy_service(); |
| 627 | 666 |
| 628 DictionaryValue* dict = new DictionaryValue(); | 667 DictionaryValue* dict = new DictionaryValue(); |
| 629 if (proxy_service->fetched_config().is_valid()) | 668 if (proxy_service->fetched_config().is_valid()) |
| 630 dict->Set("original", proxy_service->fetched_config().ToValue()); | 669 dict->Set("original", proxy_service->fetched_config().ToValue()); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 | 806 |
| 768 if (host_resolver_impl) { | 807 if (host_resolver_impl) { |
| 769 host_resolver_impl->SetDefaultAddressFamily( | 808 host_resolver_impl->SetDefaultAddressFamily( |
| 770 net::ADDRESS_FAMILY_UNSPECIFIED); | 809 net::ADDRESS_FAMILY_UNSPECIFIED); |
| 771 } | 810 } |
| 772 | 811 |
| 773 // Cause the renderer to be notified of the new value. | 812 // Cause the renderer to be notified of the new value. |
| 774 OnGetHostResolverInfo(NULL); | 813 OnGetHostResolverInfo(NULL); |
| 775 } | 814 } |
| 776 | 815 |
| 777 void NetInternalsMessageHandler::IOThreadImpl::OnGetPassiveLogEntries( | |
| 778 const ListValue* list) { | |
| 779 ChromeNetLog* net_log = io_thread_->globals()->net_log.get(); | |
| 780 | |
| 781 PassiveLogCollector::EntryList passive_entries; | |
| 782 net_log->passive_collector()->GetAllCapturedEvents(&passive_entries); | |
| 783 | |
| 784 ListValue* dict_list = new ListValue(); | |
| 785 for (size_t i = 0; i < passive_entries.size(); ++i) { | |
| 786 const PassiveLogCollector::Entry& e = passive_entries[i]; | |
| 787 dict_list->Append(net::NetLog::EntryToDictionaryValue(e.type, | |
| 788 e.time, | |
| 789 e.source, | |
| 790 e.phase, | |
| 791 e.params, | |
| 792 false)); | |
| 793 } | |
| 794 | |
| 795 CallJavascriptFunction(L"g_browser.receivedPassiveLogEntries", dict_list); | |
| 796 } | |
| 797 | |
| 798 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTests( | 816 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTests( |
| 799 const ListValue* list) { | 817 const ListValue* list) { |
| 800 // |value| should be: [<URL to test>]. | 818 // |value| should be: [<URL to test>]. |
| 801 string16 url_str; | 819 string16 url_str; |
| 802 CHECK(list->GetString(0, &url_str)); | 820 CHECK(list->GetString(0, &url_str)); |
| 803 | 821 |
| 804 // Try to fix-up the user provided URL into something valid. | 822 // Try to fix-up the user provided URL into something valid. |
| 805 // For example, turn "www.google.com" into "http://www.google.com". | 823 // For example, turn "www.google.com" into "http://www.google.com". |
| 806 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); | 824 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); |
| 807 | 825 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 int log_level; | 922 int log_level; |
| 905 std::string log_level_string; | 923 std::string log_level_string; |
| 906 if (!list->GetString(0, &log_level_string) || | 924 if (!list->GetString(0, &log_level_string) || |
| 907 !base::StringToInt(log_level_string, &log_level)) { | 925 !base::StringToInt(log_level_string, &log_level)) { |
| 908 NOTREACHED(); | 926 NOTREACHED(); |
| 909 return; | 927 return; |
| 910 } | 928 } |
| 911 | 929 |
| 912 DCHECK_GE(log_level, net::NetLog::LOG_ALL); | 930 DCHECK_GE(log_level, net::NetLog::LOG_ALL); |
| 913 DCHECK_LE(log_level, net::NetLog::LOG_BASIC); | 931 DCHECK_LE(log_level, net::NetLog::LOG_BASIC); |
| 914 set_log_level(static_cast<net::NetLog::LogLevel>(log_level)); | 932 SetLogLevel(static_cast<net::NetLog::LogLevel>(log_level)); |
| 915 } | 933 } |
| 916 | 934 |
| 935 // Note that unlike other methods of IOThreadImpl, this function | |
| 936 // can be called from ANY THREAD. | |
| 917 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( | 937 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( |
| 918 net::NetLog::EventType type, | 938 net::NetLog::EventType type, |
| 919 const base::TimeTicks& time, | 939 const base::TimeTicks& time, |
| 920 const net::NetLog::Source& source, | 940 const net::NetLog::Source& source, |
| 921 net::NetLog::EventPhase phase, | 941 net::NetLog::EventPhase phase, |
| 922 net::NetLog::EventParameters* params) { | 942 net::NetLog::EventParameters* params) { |
| 923 DCHECK(is_observing_log_); | |
| 924 | |
| 925 CallJavascriptFunction( | 943 CallJavascriptFunction( |
| 926 L"g_browser.receivedLogEntry", | 944 L"g_browser.receivedLogEntry", |
| 927 net::NetLog::EntryToDictionaryValue(type, time, source, phase, params, | 945 net::NetLog::EntryToDictionaryValue(type, time, source, phase, params, |
| 928 false)); | 946 false)); |
| 929 } | 947 } |
| 930 | 948 |
| 931 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTestSuite() { | 949 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTestSuite() { |
| 932 CallJavascriptFunction(L"g_browser.receivedStartConnectionTestSuite", NULL); | 950 CallJavascriptFunction(L"g_browser.receivedStartConnectionTestSuite", NULL); |
| 933 } | 951 } |
| 934 | 952 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 960 NULL); | 978 NULL); |
| 961 } | 979 } |
| 962 | 980 |
| 963 void NetInternalsMessageHandler::IOThreadImpl::DispatchToMessageHandler( | 981 void NetInternalsMessageHandler::IOThreadImpl::DispatchToMessageHandler( |
| 964 ListValue* arg, MessageHandler method) { | 982 ListValue* arg, MessageHandler method) { |
| 965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 983 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 966 (this->*method)(arg); | 984 (this->*method)(arg); |
| 967 delete arg; | 985 delete arg; |
| 968 } | 986 } |
| 969 | 987 |
| 988 // Note that this can be called from ANY THREAD. | |
| 970 void NetInternalsMessageHandler::IOThreadImpl::CallJavascriptFunction( | 989 void NetInternalsMessageHandler::IOThreadImpl::CallJavascriptFunction( |
| 971 const std::wstring& function_name, | 990 const std::wstring& function_name, |
| 972 Value* arg) { | 991 Value* arg) { |
| 973 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 992 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 974 if (handler_) { | 993 if (handler_ && !was_domui_deleted_) { |
|
eroman
2010/11/18 18:04:03
ah! so this was why we were getting javascript err
mmenke
2010/11/23 16:48:45
Yea. Since refresh keeps the same RenderView, and
| |
| 975 // We check |handler_| in case it was deleted on the UI thread earlier | 994 // We check |handler_| in case it was deleted on the UI thread earlier |
| 976 // while we were running on the IO thread. | 995 // while we were running on the IO thread. |
| 977 handler_->CallJavascriptFunction(function_name, arg); | 996 handler_->CallJavascriptFunction(function_name, arg); |
| 978 } | 997 } |
| 979 delete arg; | 998 delete arg; |
| 980 return; | 999 return; |
| 981 } | 1000 } |
| 982 | 1001 |
| 983 // Otherwise if we were called from the IO thread, bridge the request over to | |
| 984 // the UI thread. | |
| 985 | |
| 986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 987 if (!BrowserThread::PostTask( | 1002 if (!BrowserThread::PostTask( |
| 988 BrowserThread::UI, FROM_HERE, | 1003 BrowserThread::UI, FROM_HERE, |
| 989 NewRunnableMethod( | 1004 NewRunnableMethod( |
| 990 this, | 1005 this, |
| 991 &IOThreadImpl::CallJavascriptFunction, | 1006 &IOThreadImpl::CallJavascriptFunction, |
| 992 function_name, arg))) { | 1007 function_name, arg))) { |
| 993 // Failed posting the task, avoid leaking. | 1008 // Failed posting the task, avoid leaking. |
| 994 delete arg; | 1009 delete arg; |
| 995 } | 1010 } |
| 996 } | 1011 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1010 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); | 1025 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); |
| 1011 | 1026 |
| 1012 // Set up the chrome://net-internals/ source. | 1027 // Set up the chrome://net-internals/ source. |
| 1013 BrowserThread::PostTask( | 1028 BrowserThread::PostTask( |
| 1014 BrowserThread::IO, FROM_HERE, | 1029 BrowserThread::IO, FROM_HERE, |
| 1015 NewRunnableMethod( | 1030 NewRunnableMethod( |
| 1016 Singleton<ChromeURLDataManager>::get(), | 1031 Singleton<ChromeURLDataManager>::get(), |
| 1017 &ChromeURLDataManager::AddDataSource, | 1032 &ChromeURLDataManager::AddDataSource, |
| 1018 make_scoped_refptr(html_source))); | 1033 make_scoped_refptr(html_source))); |
| 1019 } | 1034 } |
| OLD | NEW |