OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/devtools/render_frame_devtools_agent_host.h" | 5 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
6 | 6 |
7 #include <tuple> | 7 #include <tuple> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 #include "content/common/view_messages.h" | 43 #include "content/common/view_messages.h" |
44 #include "content/public/browser/browser_context.h" | 44 #include "content/public/browser/browser_context.h" |
45 #include "content/public/browser/content_browser_client.h" | 45 #include "content/public/browser/content_browser_client.h" |
46 #include "content/public/browser/navigation_handle.h" | 46 #include "content/public/browser/navigation_handle.h" |
47 #include "content/public/browser/render_widget_host_iterator.h" | 47 #include "content/public/browser/render_widget_host_iterator.h" |
48 #include "content/public/browser/web_contents_delegate.h" | 48 #include "content/public/browser/web_contents_delegate.h" |
49 #include "content/public/common/browser_side_navigation_policy.h" | 49 #include "content/public/common/browser_side_navigation_policy.h" |
50 | 50 |
51 #if defined(OS_ANDROID) | 51 #if defined(OS_ANDROID) |
52 #include "content/public/browser/render_widget_host_view.h" | 52 #include "content/public/browser/render_widget_host_view.h" |
53 #include "device/power_save_blocker/power_save_blocker.h" | 53 #include "device/wake_lock/public/interfaces/wake_lock_context.mojom.h" |
54 #endif | 54 #endif |
55 | 55 |
56 namespace content { | 56 namespace content { |
57 | 57 |
58 typedef std::vector<RenderFrameDevToolsAgentHost*> Instances; | 58 typedef std::vector<RenderFrameDevToolsAgentHost*> Instances; |
59 | 59 |
60 namespace { | 60 namespace { |
61 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; | 61 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; |
62 | 62 |
63 static RenderFrameDevToolsAgentHost* FindAgentHost(RenderFrameHost* host) { | 63 static RenderFrameDevToolsAgentHost* FindAgentHost(RenderFrameHost* host) { |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 current_->InspectElement(session->session_id(), x, y); | 596 current_->InspectElement(session->session_id(), x, y); |
597 if (pending_) | 597 if (pending_) |
598 pending_->InspectElement(session->session_id(), x, y); | 598 pending_->InspectElement(session->session_id(), x, y); |
599 } | 599 } |
600 | 600 |
601 void RenderFrameDevToolsAgentHost::OnClientAttached() { | 601 void RenderFrameDevToolsAgentHost::OnClientAttached() { |
602 if (!web_contents()) | 602 if (!web_contents()) |
603 return; | 603 return; |
604 | 604 |
605 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); | 605 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); |
606 CreatePowerSaveBlocker(); | 606 #if defined(OS_ANDROID) |
607 GetWakeLockService()->RequestWakeLock(); | |
608 #endif | |
607 } | 609 } |
608 | 610 |
609 void RenderFrameDevToolsAgentHost::OnClientDetached() { | 611 void RenderFrameDevToolsAgentHost::OnClientDetached() { |
610 #if defined(OS_ANDROID) | 612 #if defined(OS_ANDROID) |
611 power_save_blocker_.reset(); | 613 GetWakeLockService()->CancelWakeLock(); |
612 #endif | 614 #endif |
613 frame_trace_recorder_.reset(); | 615 frame_trace_recorder_.reset(); |
614 in_navigation_protocol_message_buffer_.clear(); | 616 in_navigation_protocol_message_buffer_.clear(); |
615 } | 617 } |
616 | 618 |
617 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { | 619 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { |
618 Instances::iterator it = std::find(g_instances.Get().begin(), | 620 Instances::iterator it = std::find(g_instances.Get().begin(), |
619 g_instances.Get().end(), | 621 g_instances.Get().end(), |
620 this); | 622 this); |
621 if (it != g_instances.Get().end()) | 623 if (it != g_instances.Get().end()) |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
816 return false; | 818 return false; |
817 if (IsBrowserSideNavigationEnabled()) | 819 if (IsBrowserSideNavigationEnabled()) |
818 return true; | 820 return true; |
819 if (!frame_tree_node_) | 821 if (!frame_tree_node_) |
820 return !handlers_frame_host_; | 822 return !handlers_frame_host_; |
821 RenderFrameHostManager* manager = frame_tree_node_->render_manager(); | 823 RenderFrameHostManager* manager = frame_tree_node_->render_manager(); |
822 return handlers_frame_host_ == manager->current_frame_host() || | 824 return handlers_frame_host_ == manager->current_frame_host() || |
823 handlers_frame_host_ == manager->pending_frame_host(); | 825 handlers_frame_host_ == manager->pending_frame_host(); |
824 } | 826 } |
825 | 827 |
826 void RenderFrameDevToolsAgentHost::CreatePowerSaveBlocker() { | |
827 #if defined(OS_ANDROID) | 828 #if defined(OS_ANDROID) |
828 power_save_blocker_.reset(new device::PowerSaveBlocker( | 829 device::mojom::WakeLockService* |
829 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 830 RenderFrameDevToolsAgentHost::GetWakeLockService() { |
dgozman
2017/05/18 21:58:45
I'm not very good at mojo yet, so let me ask a nai
ke.he
2017/05/18 23:58:47
The design of WakeLock servicification is necessar
| |
830 device::PowerSaveBlocker::kReasonOther, "DevTools", | 831 // Here is a lazy binding, and will not reconnect after connection error. |
831 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 832 if (!wake_lock_) { |
832 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 833 device::mojom::WakeLockServiceRequest request = |
833 if (web_contents()->GetNativeView()) { | 834 mojo::MakeRequest(&wake_lock_); |
dgozman
2017/05/18 21:58:45
Inline this into line 841?
ke.he
2017/05/18 23:58:47
We don't inline this on purpose, so the |wake_lock
dgozman
2017/05/19 19:15:45
Do you mean that wake_lock_ will be functional (al
ke.he
2017/05/20 01:00:34
Yes, mojo::MakeRequest() make it be functional, bu
| |
834 power_save_blocker_->InitDisplaySleepBlocker( | 835 device::mojom::WakeLockContext* wake_lock_context = |
835 web_contents()->GetNativeView()); | 836 web_contents()->GetWakeLockContext(); |
837 if (wake_lock_context) { | |
838 wake_lock_context->GetWakeLock( | |
839 device::mojom::WakeLockType::PreventAppSuspension, | |
ke.he
2017/05/26 03:11:12
Oh! The original PowerSaveBlocker type is "kPowerS
| |
840 device::mojom::WakeLockReason::ReasonOther, "DevTools", | |
841 std::move(request)); | |
842 } | |
836 } | 843 } |
844 return wake_lock_.get(); | |
845 } | |
837 #endif | 846 #endif |
838 } | |
839 | 847 |
840 void RenderFrameDevToolsAgentHost::RenderProcessGone( | 848 void RenderFrameDevToolsAgentHost::RenderProcessGone( |
841 base::TerminationStatus status) { | 849 base::TerminationStatus status) { |
842 switch(status) { | 850 switch(status) { |
843 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 851 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
844 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 852 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
845 #if defined(OS_CHROMEOS) | 853 #if defined(OS_CHROMEOS) |
846 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: | 854 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: |
847 #endif | 855 #endif |
848 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 856 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
898 pending_handle_ = nullptr; | 906 pending_handle_ = nullptr; |
899 DCHECK(CheckConsistency()); | 907 DCHECK(CheckConsistency()); |
900 } | 908 } |
901 | 909 |
902 void RenderFrameDevToolsAgentHost::DidDetachInterstitialPage() { | 910 void RenderFrameDevToolsAgentHost::DidDetachInterstitialPage() { |
903 for (auto* page : protocol::PageHandler::ForAgentHost(this)) | 911 for (auto* page : protocol::PageHandler::ForAgentHost(this)) |
904 page->DidDetachInterstitialPage(); | 912 page->DidDetachInterstitialPage(); |
905 } | 913 } |
906 | 914 |
907 void RenderFrameDevToolsAgentHost::WasShown() { | 915 void RenderFrameDevToolsAgentHost::WasShown() { |
908 CreatePowerSaveBlocker(); | 916 #if defined(OS_ANDROID) |
917 GetWakeLockService()->RequestWakeLock(); | |
918 #endif | |
909 } | 919 } |
910 | 920 |
911 void RenderFrameDevToolsAgentHost::WasHidden() { | 921 void RenderFrameDevToolsAgentHost::WasHidden() { |
912 #if defined(OS_ANDROID) | 922 #if defined(OS_ANDROID) |
913 power_save_blocker_.reset(); | 923 GetWakeLockService()->CancelWakeLock(); |
dgozman
2017/05/18 21:58:45
I think we should destroy the service at this poin
ke.he
2017/05/18 23:58:47
we don't need to destroy the service here or in de
dgozman
2017/05/19 19:15:44
Shouldn't we do it from the performance standpoint
ke.he
2017/05/20 01:00:34
In GetWakeLockService(), the |wake_lock_| is initi
| |
914 #endif | 924 #endif |
915 } | 925 } |
916 | 926 |
917 void RenderFrameDevToolsAgentHost::DidReceiveCompositorFrame() { | 927 void RenderFrameDevToolsAgentHost::DidReceiveCompositorFrame() { |
918 const cc::CompositorFrameMetadata& metadata = | 928 const cc::CompositorFrameMetadata& metadata = |
919 RenderWidgetHostImpl::From( | 929 RenderWidgetHostImpl::From( |
920 web_contents()->GetRenderViewHost()->GetWidget()) | 930 web_contents()->GetRenderViewHost()->GetWidget()) |
921 ->last_frame_metadata(); | 931 ->last_frame_metadata(); |
922 for (auto* page : protocol::PageHandler::ForAgentHost(this)) | 932 for (auto* page : protocol::PageHandler::ForAgentHost(this)) |
923 page->OnSwapCompositorFrame(metadata.Clone()); | 933 page->OnSwapCompositorFrame(metadata.Clone()); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1169 RenderFrameHost* host) { | 1179 RenderFrameHost* host) { |
1170 return (current_ && current_->host() == host) || | 1180 return (current_ && current_->host() == host) || |
1171 (pending_ && pending_->host() == host); | 1181 (pending_ && pending_->host() == host); |
1172 } | 1182 } |
1173 | 1183 |
1174 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1184 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
1175 return current_ && current_->host()->GetParent(); | 1185 return current_ && current_->host()->GetParent(); |
1176 } | 1186 } |
1177 | 1187 |
1178 } // namespace content | 1188 } // namespace content |
OLD | NEW |