OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/devtools/devtools_ui_bindings.h" | 5 #include "chrome/browser/devtools/devtools_ui_bindings.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 switches::kEnableDevToolsExperiments)) | 399 switches::kEnableDevToolsExperiments)) |
400 url_string += "&experiments=true"; | 400 url_string += "&experiments=true"; |
401 #if defined(DEBUG_DEVTOOLS) | 401 #if defined(DEBUG_DEVTOOLS) |
402 url_string += "&debugFrontend=true"; | 402 url_string += "&debugFrontend=true"; |
403 #endif // defined(DEBUG_DEVTOOLS) | 403 #endif // defined(DEBUG_DEVTOOLS) |
404 return GURL(url_string); | 404 return GURL(url_string); |
405 } | 405 } |
406 | 406 |
407 DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents) | 407 DevToolsUIBindings::DevToolsUIBindings(content::WebContents* web_contents) |
408 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 408 : profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
| 409 android_bridge_(DevToolsAndroidBridge::Factory::GetForProfile(profile_)), |
409 web_contents_(web_contents), | 410 web_contents_(web_contents), |
410 delegate_(new DefaultBindingsDelegate(web_contents_)), | 411 delegate_(new DefaultBindingsDelegate(web_contents_)), |
411 device_count_updates_enabled_(false), | 412 device_count_updates_enabled_(false), |
412 devices_updates_enabled_(false), | 413 devices_updates_enabled_(false), |
413 frontend_loaded_(false), | 414 frontend_loaded_(false), |
414 weak_factory_(this) { | 415 weak_factory_(this) { |
| 416 DCHECK(android_bridge_); |
415 g_instances.Get().push_back(this); | 417 g_instances.Get().push_back(this); |
416 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); | 418 frontend_contents_observer_.reset(new FrontendWebContentsObserver(this)); |
417 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; | 419 web_contents_->GetMutableRendererPrefs()->can_accept_load_drops = false; |
418 | 420 |
419 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_)); | 421 file_helper_.reset(new DevToolsFileHelper(web_contents_, profile_)); |
420 file_system_indexer_ = new DevToolsFileSystemIndexer(); | 422 file_system_indexer_ = new DevToolsFileSystemIndexer(); |
421 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 423 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
422 web_contents_); | 424 web_contents_); |
423 | 425 |
424 // Wipe out page icon so that the default application icon is used. | 426 // Wipe out page icon so that the default application icon is used. |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 agent_host_->DispatchProtocolMessage(message); | 774 agent_host_->DispatchProtocolMessage(message); |
773 } | 775 } |
774 | 776 |
775 void DevToolsUIBindings::RecordActionUMA(const std::string& name, int action) { | 777 void DevToolsUIBindings::RecordActionUMA(const std::string& name, int action) { |
776 if (name == kDevToolsActionTakenHistogram) | 778 if (name == kDevToolsActionTakenHistogram) |
777 UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsActionTakenBoundary); | 779 UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsActionTakenBoundary); |
778 else if (name == kDevToolsPanelShownHistogram) | 780 else if (name == kDevToolsPanelShownHistogram) |
779 UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsPanelShownBoundary); | 781 UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsPanelShownBoundary); |
780 } | 782 } |
781 | 783 |
| 784 void DevToolsUIBindings::SendJsonRequest(const DispatchCallback& callback, |
| 785 const std::string& browser_id, |
| 786 const std::string& url) { |
| 787 android_bridge_->SendJsonRequest(browser_id, url, |
| 788 base::Bind(&DevToolsUIBindings::JsonReceived, |
| 789 weak_factory_.GetWeakPtr(), |
| 790 callback)); |
| 791 } |
| 792 |
| 793 void DevToolsUIBindings::JsonReceived(const DispatchCallback& callback, |
| 794 int result, |
| 795 const std::string& message) { |
| 796 if (result != net::OK) { |
| 797 callback.Run(nullptr); |
| 798 return; |
| 799 } |
| 800 base::StringValue message_value(message); |
| 801 callback.Run(&message_value); |
| 802 } |
| 803 |
782 void DevToolsUIBindings::OnURLFetchComplete(const net::URLFetcher* source) { | 804 void DevToolsUIBindings::OnURLFetchComplete(const net::URLFetcher* source) { |
783 DCHECK(source); | 805 DCHECK(source); |
784 PendingRequestsMap::iterator it = pending_requests_.find(source); | 806 PendingRequestsMap::iterator it = pending_requests_.find(source); |
785 DCHECK(it != pending_requests_.end()); | 807 DCHECK(it != pending_requests_.end()); |
786 | 808 |
787 base::DictionaryValue response; | 809 base::DictionaryValue response; |
788 base::DictionaryValue* headers = new base::DictionaryValue(); | 810 base::DictionaryValue* headers = new base::DictionaryValue(); |
789 net::HttpResponseHeaders* rh = source->GetResponseHeaders(); | 811 net::HttpResponseHeaders* rh = source->GetResponseHeaders(); |
790 response.SetInteger("statusCode", rh ? rh->response_code() : 200); | 812 response.SetInteger("statusCode", rh ? rh->response_code() : 200); |
791 response.Set("headers", headers); | 813 response.Set("headers", headers); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 if (frontend_loaded_) | 1038 if (frontend_loaded_) |
1017 return; | 1039 return; |
1018 frontend_loaded_ = true; | 1040 frontend_loaded_ = true; |
1019 | 1041 |
1020 // Call delegate first - it seeds importants bit of information. | 1042 // Call delegate first - it seeds importants bit of information. |
1021 delegate_->OnLoadCompleted(); | 1043 delegate_->OnLoadCompleted(); |
1022 | 1044 |
1023 UpdateTheme(); | 1045 UpdateTheme(); |
1024 AddDevToolsExtensionsToClient(); | 1046 AddDevToolsExtensionsToClient(); |
1025 } | 1047 } |
OLD | NEW |