OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/net_internals_ui.h" | 5 #include "chrome/browser/ui/webui/net_internals_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/base64.h" | 13 #include "base/base64.h" |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/string_number_conversions.h" | 20 #include "base/string_number_conversions.h" |
21 #include "base/string_piece.h" | 21 #include "base/string_piece.h" |
22 #include "base/string_split.h" | 22 #include "base/string_split.h" |
23 #include "base/string_util.h" | 23 #include "base/string_util.h" |
24 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
25 #include "base/values.h" | 25 #include "base/values.h" |
26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/browsing_data_remover.h" |
27 #include "chrome/browser/io_thread.h" | 28 #include "chrome/browser/io_thread.h" |
28 #include "chrome/browser/net/chrome_net_log.h" | 29 #include "chrome/browser/net/chrome_net_log.h" |
29 #include "chrome/browser/net/connection_tester.h" | 30 #include "chrome/browser/net/connection_tester.h" |
30 #include "chrome/browser/net/passive_log_collector.h" | 31 #include "chrome/browser/net/passive_log_collector.h" |
31 #include "chrome/browser/net/url_fixer_upper.h" | 32 #include "chrome/browser/net/url_fixer_upper.h" |
32 #include "chrome/browser/prefs/pref_member.h" | 33 #include "chrome/browser/prefs/pref_member.h" |
33 #include "chrome/browser/prerender/prerender_manager.h" | 34 #include "chrome/browser/prerender/prerender_manager.h" |
34 #include "chrome/browser/prerender/prerender_manager_factory.h" | 35 #include "chrome/browser/prerender/prerender_manager_factory.h" |
35 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
36 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 37 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 void SendJavascriptCommand(const std::string& command, Value* arg); | 168 void SendJavascriptCommand(const std::string& command, Value* arg); |
168 | 169 |
169 // content::NotificationObserver implementation. | 170 // content::NotificationObserver implementation. |
170 virtual void Observe(int type, | 171 virtual void Observe(int type, |
171 const content::NotificationSource& source, | 172 const content::NotificationSource& source, |
172 const content::NotificationDetails& details) OVERRIDE; | 173 const content::NotificationDetails& details) OVERRIDE; |
173 | 174 |
174 // Javascript message handlers. | 175 // Javascript message handlers. |
175 void OnRendererReady(const ListValue* list); | 176 void OnRendererReady(const ListValue* list); |
176 void OnEnableHttpThrottling(const ListValue* list); | 177 void OnEnableHttpThrottling(const ListValue* list); |
| 178 void OnClearBrowserCache(const ListValue* list); |
| 179 void OnGetPrerenderInfo(const ListValue* list); |
177 #ifdef OS_CHROMEOS | 180 #ifdef OS_CHROMEOS |
178 void OnRefreshSystemLogs(const ListValue* list); | 181 void OnRefreshSystemLogs(const ListValue* list); |
179 void OnGetSystemLog(const ListValue* list); | 182 void OnGetSystemLog(const ListValue* list); |
180 #endif | 183 #endif |
181 void OnGetPrerenderInfo(const ListValue* list); | |
182 | 184 |
183 private: | 185 private: |
184 class IOThreadImpl; | 186 class IOThreadImpl; |
185 | 187 |
186 #ifdef OS_CHROMEOS | 188 #ifdef OS_CHROMEOS |
187 // Class that is used for getting network related ChromeOS logs. | 189 // Class that is used for getting network related ChromeOS logs. |
188 // Logs are fetched from ChromeOS libcros on user request, and only when we | 190 // Logs are fetched from ChromeOS libcros on user request, and only when we |
189 // don't yet have a copy of logs. If a copy is present, we send back data from | 191 // don't yet have a copy of logs. If a copy is present, we send back data from |
190 // it, else we save request and answer to it when we get logs from libcros. | 192 // it, else we save request and answer to it when we get logs from libcros. |
191 // If needed, we also send request for system logs to libcros. | 193 // If needed, we also send request for system logs to libcros. |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 web_ui_->RegisterMessageCallback( | 527 web_ui_->RegisterMessageCallback( |
526 "getSpdyAlternateProtocolMappings", | 528 "getSpdyAlternateProtocolMappings", |
527 base::Bind(&IOThreadImpl::CallbackHelper, | 529 base::Bind(&IOThreadImpl::CallbackHelper, |
528 &IOThreadImpl::OnGetSpdyAlternateProtocolMappings, proxy_)); | 530 &IOThreadImpl::OnGetSpdyAlternateProtocolMappings, proxy_)); |
529 #ifdef OS_WIN | 531 #ifdef OS_WIN |
530 web_ui_->RegisterMessageCallback( | 532 web_ui_->RegisterMessageCallback( |
531 "getServiceProviders", | 533 "getServiceProviders", |
532 base::Bind(&IOThreadImpl::CallbackHelper, | 534 base::Bind(&IOThreadImpl::CallbackHelper, |
533 &IOThreadImpl::OnGetServiceProviders, proxy_)); | 535 &IOThreadImpl::OnGetServiceProviders, proxy_)); |
534 #endif | 536 #endif |
535 #ifdef OS_CHROMEOS | 537 |
536 web_ui_->RegisterMessageCallback( | |
537 "refreshSystemLogs", | |
538 base::Bind(&NetInternalsMessageHandler::OnRefreshSystemLogs, | |
539 base::Unretained(this))); | |
540 web_ui_->RegisterMessageCallback( | |
541 "getSystemLog", | |
542 base::Bind(&NetInternalsMessageHandler::OnGetSystemLog, | |
543 base::Unretained(this))); | |
544 #endif | |
545 web_ui_->RegisterMessageCallback( | 538 web_ui_->RegisterMessageCallback( |
546 "setLogLevel", | 539 "setLogLevel", |
547 base::Bind(&IOThreadImpl::CallbackHelper, | 540 base::Bind(&IOThreadImpl::CallbackHelper, |
548 &IOThreadImpl::OnSetLogLevel, proxy_)); | 541 &IOThreadImpl::OnSetLogLevel, proxy_)); |
549 web_ui_->RegisterMessageCallback( | 542 web_ui_->RegisterMessageCallback( |
550 "enableHttpThrottling", | 543 "enableHttpThrottling", |
551 base::Bind(&NetInternalsMessageHandler::OnEnableHttpThrottling, | 544 base::Bind(&NetInternalsMessageHandler::OnEnableHttpThrottling, |
552 base::Unretained(this))); | 545 base::Unretained(this))); |
553 web_ui_->RegisterMessageCallback( | 546 web_ui_->RegisterMessageCallback( |
| 547 "clearBrowserCache", |
| 548 base::Bind(&NetInternalsMessageHandler::OnClearBrowserCache, |
| 549 base::Unretained(this))); |
| 550 web_ui_->RegisterMessageCallback( |
554 "getPrerenderInfo", | 551 "getPrerenderInfo", |
555 base::Bind(&NetInternalsMessageHandler::OnGetPrerenderInfo, | 552 base::Bind(&NetInternalsMessageHandler::OnGetPrerenderInfo, |
556 base::Unretained(this))); | 553 base::Unretained(this))); |
| 554 #ifdef OS_CHROMEOS |
| 555 web_ui_->RegisterMessageCallback( |
| 556 "refreshSystemLogs", |
| 557 base::Bind(&NetInternalsMessageHandler::OnRefreshSystemLogs, |
| 558 base::Unretained(this))); |
| 559 web_ui_->RegisterMessageCallback( |
| 560 "getSystemLog", |
| 561 base::Bind(&NetInternalsMessageHandler::OnGetSystemLog, |
| 562 base::Unretained(this))); |
| 563 #endif |
557 } | 564 } |
558 | 565 |
559 void NetInternalsMessageHandler::SendJavascriptCommand( | 566 void NetInternalsMessageHandler::SendJavascriptCommand( |
560 const std::string& command, | 567 const std::string& command, |
561 Value* arg) { | 568 Value* arg) { |
562 scoped_ptr<Value> command_value(Value::CreateStringValue(command)); | 569 scoped_ptr<Value> command_value(Value::CreateStringValue(command)); |
563 scoped_ptr<Value> value(arg); | 570 scoped_ptr<Value> value(arg); |
564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
565 if (value.get()) { | 572 if (value.get()) { |
566 web_ui_->CallJavascriptFunction("g_browser.receive", | 573 web_ui_->CallJavascriptFunction("g_browser.receive", |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 | 615 |
609 // We never receive OnEnableHttpThrottling unless the user has modified | 616 // We never receive OnEnableHttpThrottling unless the user has modified |
610 // the value of the checkbox on the about:net-internals page. Once the | 617 // the value of the checkbox on the about:net-internals page. Once the |
611 // user does that, we no longer change its value automatically (e.g. | 618 // user does that, we no longer change its value automatically (e.g. |
612 // by changing the default or running an experiment). | 619 // by changing the default or running an experiment). |
613 if (http_throttling_may_experiment_.GetValue()) { | 620 if (http_throttling_may_experiment_.GetValue()) { |
614 http_throttling_may_experiment_.SetValue(false); | 621 http_throttling_may_experiment_.SetValue(false); |
615 } | 622 } |
616 } | 623 } |
617 | 624 |
| 625 void NetInternalsMessageHandler::OnClearBrowserCache(const ListValue* list) { |
| 626 BrowsingDataRemover* remover = |
| 627 new BrowsingDataRemover(Profile::FromWebUI(web_ui()), |
| 628 BrowsingDataRemover::EVERYTHING, |
| 629 base::Time()); |
| 630 remover->Remove(BrowsingDataRemover::REMOVE_CACHE); |
| 631 // BrowsingDataRemover deletes itself. |
| 632 } |
| 633 |
618 void NetInternalsMessageHandler::OnGetPrerenderInfo(const ListValue* list) { | 634 void NetInternalsMessageHandler::OnGetPrerenderInfo(const ListValue* list) { |
619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
620 | 636 |
621 DictionaryValue* value = NULL; | 637 DictionaryValue* value = NULL; |
622 prerender::PrerenderManager* prerender_manager = prerender_manager_.get(); | 638 prerender::PrerenderManager* prerender_manager = prerender_manager_.get(); |
623 if (!prerender_manager) { | 639 if (!prerender_manager) { |
624 value = new DictionaryValue(); | 640 value = new DictionaryValue(); |
625 value->SetBoolean("enabled", false); | 641 value->SetBoolean("enabled", false); |
626 value->SetBoolean("omnibox_enabled", false); | 642 value->SetBoolean("omnibox_enabled", false); |
627 } else { | 643 } else { |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 return constants_dict; | 1551 return constants_dict; |
1536 } | 1552 } |
1537 | 1553 |
1538 NetInternalsUI::NetInternalsUI(TabContents* contents) : ChromeWebUI(contents) { | 1554 NetInternalsUI::NetInternalsUI(TabContents* contents) : ChromeWebUI(contents) { |
1539 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); | 1555 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); |
1540 | 1556 |
1541 // Set up the chrome://net-internals/ source. | 1557 // Set up the chrome://net-internals/ source. |
1542 GetProfile()->GetChromeURLDataManager()->AddDataSource( | 1558 GetProfile()->GetChromeURLDataManager()->AddDataSource( |
1543 CreateNetInternalsHTMLSource()); | 1559 CreateNetInternalsHTMLSource()); |
1544 } | 1560 } |
OLD | NEW |