OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_targets_ui.h" | 5 #include "chrome/browser/devtools/devtools_targets_ui.h" |
6 | 6 |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "base/version.h" | 11 #include "base/version.h" |
12 #include "chrome/browser/devtools/device/devtools_android_bridge.h" | 12 #include "chrome/browser/devtools/device/devtools_android_bridge.h" |
13 #include "chrome/browser/devtools/devtools_target_impl.h" | 13 #include "chrome/browser/devtools/devtools_target_impl.h" |
14 #include "chrome/browser/guest_view/guest_view_base.h" | |
15 #include "chrome/common/chrome_version_info.h" | 14 #include "chrome/common/chrome_version_info.h" |
16 #include "content/public/browser/browser_child_process_observer.h" | 15 #include "content/public/browser/browser_child_process_observer.h" |
17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/child_process_data.h" | 17 #include "content/public/browser/child_process_data.h" |
19 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
21 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
23 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/render_frame_host.h" | |
25 #include "content/public/browser/render_process_host.h" | |
26 #include "content/public/browser/render_view_host.h" | |
27 #include "content/public/browser/web_contents.h" | |
28 #include "content/public/browser/worker_service.h" | 23 #include "content/public/browser/worker_service.h" |
29 #include "content/public/browser/worker_service_observer.h" | 24 #include "content/public/browser/worker_service_observer.h" |
30 #include "content/public/common/process_type.h" | 25 #include "content/public/common/process_type.h" |
31 #include "net/base/escape.h" | 26 #include "net/base/escape.h" |
32 | 27 |
33 using content::BrowserThread; | 28 using content::BrowserThread; |
34 using content::RenderFrameHost; | |
35 using content::WebContents; | |
36 | 29 |
37 namespace { | 30 namespace { |
38 | 31 |
39 const char kTargetSourceField[] = "source"; | 32 const char kTargetSourceField[] = "source"; |
40 const char kTargetSourceRenderer[] = "renderers"; | 33 const char kTargetSourceRenderer[] = "renderers"; |
41 const char kTargetSourceWorker[] = "workers"; | 34 const char kTargetSourceWorker[] = "workers"; |
42 const char kTargetSourceAdb[] = "adb"; | 35 const char kTargetSourceAdb[] = "adb"; |
43 | 36 |
44 const char kTargetIdField[] = "id"; | 37 const char kTargetIdField[] = "id"; |
45 const char kTargetTypeField[] = "type"; | 38 const char kTargetTypeField[] = "type"; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 timer_.reset( | 127 timer_.reset( |
135 new CancelableTimer( | 128 new CancelableTimer( |
136 base::Bind(&RenderViewHostTargetsUIHandler::UpdateTargets, | 129 base::Bind(&RenderViewHostTargetsUIHandler::UpdateTargets, |
137 base::Unretained(this)), | 130 base::Unretained(this)), |
138 base::TimeDelta::FromMilliseconds(kUpdateDelay))); | 131 base::TimeDelta::FromMilliseconds(kUpdateDelay))); |
139 } | 132 } |
140 | 133 |
141 void RenderViewHostTargetsUIHandler::UpdateTargets() { | 134 void RenderViewHostTargetsUIHandler::UpdateTargets() { |
142 scoped_ptr<base::ListValue> list_value(new base::ListValue()); | 135 scoped_ptr<base::ListValue> list_value(new base::ListValue()); |
143 | 136 |
144 std::map<RenderFrameHost*, base::DictionaryValue*> rfh_to_descriptor; | 137 std::map<std::string, base::DictionaryValue*> id_to_descriptor; |
145 std::vector<RenderFrameHost*> nested_frames; | |
146 | 138 |
147 DevToolsTargetImpl::List targets = | 139 DevToolsTargetImpl::List targets = |
148 DevToolsTargetImpl::EnumerateRenderViewHostTargets(); | 140 DevToolsTargetImpl::EnumerateRenderViewHostTargets(); |
149 | 141 |
150 STLDeleteValues(&targets_); | 142 STLDeleteValues(&targets_); |
151 for (DevToolsTargetImpl::List::iterator it = targets.begin(); | 143 for (DevToolsTargetImpl::List::iterator it = targets.begin(); |
152 it != targets.end(); ++it) { | 144 it != targets.end(); ++it) { |
153 scoped_ptr<DevToolsTargetImpl> target(*it); | 145 DevToolsTargetImpl* target = *it; |
154 content::RenderViewHost* rvh = target->GetRenderViewHost(); | 146 targets_[target->GetId()] = target; |
155 if (!rvh) | 147 id_to_descriptor[target->GetId()] = Serialize(*target); |
156 continue; | |
157 | |
158 DevToolsTargetImpl* target_ptr = target.get(); | |
159 targets_[target_ptr->GetId()] = target.release(); | |
160 base::DictionaryValue* descriptor = Serialize(*target_ptr); | |
161 | |
162 // TODO (kaznacheev): GetMainFrame() call is a temporary hack. | |
163 // Revisit this when multiple OOP frames are supported. | |
164 RenderFrameHost* rfh = rvh->GetMainFrame(); | |
165 rfh_to_descriptor[rfh] = descriptor; | |
166 content::WebContents* web_contents = | |
167 content::WebContents::FromRenderViewHost(rvh); | |
168 if (GuestViewBase::IsGuest(web_contents) || rfh->IsCrossProcessSubframe()) { | |
169 nested_frames.push_back(rfh); | |
170 } else { | |
171 list_value->Append(descriptor); | |
172 } | |
173 } | 148 } |
174 | 149 |
175 // Add the list of nested targets to each of its owners. | 150 for (TargetMap::iterator it(targets_.begin()); it != targets_.end(); ++it) { |
176 for (std::vector<RenderFrameHost*>::iterator it(nested_frames.begin()); | 151 DevToolsTargetImpl* target = it->second; |
177 it != nested_frames.end(); ++it) { | 152 base::DictionaryValue* descriptor = id_to_descriptor[target->GetId()]; |
178 RenderFrameHost* rfh = (*it); | 153 |
179 RenderFrameHost* parent_rfh = NULL; | 154 std::string parent_id = target->GetParentId(); |
180 content::RenderViewHost* rvh = rfh->GetRenderViewHost(); | 155 if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) { |
181 WebContents* nested_web_contents = WebContents::FromRenderViewHost(rvh); | 156 list_value->Append(descriptor); |
182 GuestViewBase* guest = GuestViewBase::FromWebContents(nested_web_contents); | |
183 if (guest) { | |
184 WebContents* embedder = guest->embedder_web_contents(); | |
185 parent_rfh = embedder->GetRenderViewHost()->GetMainFrame(); | |
186 } else { | 157 } else { |
187 parent_rfh = rfh->GetParent(); | 158 base::DictionaryValue* parent = id_to_descriptor[parent_id]; |
188 DCHECK(parent_rfh); | |
189 } | |
190 if (parent_rfh && rfh_to_descriptor.count(parent_rfh) > 0) { | |
191 base::DictionaryValue* parent = rfh_to_descriptor[parent_rfh]; | |
192 base::ListValue* guests = NULL; | 159 base::ListValue* guests = NULL; |
193 if (!parent->GetList(kGuestList, &guests)) { | 160 if (!parent->GetList(kGuestList, &guests)) { |
194 guests = new base::ListValue(); | 161 guests = new base::ListValue(); |
195 parent->Set(kGuestList, guests); | 162 parent->Set(kGuestList, guests); |
196 } | 163 } |
197 guests->Append(rfh_to_descriptor[rfh]); | 164 guests->Append(descriptor); |
198 } | 165 } |
199 } | 166 } |
200 | 167 |
201 SendSerializedTargets(list_value.Pass()); | 168 SendSerializedTargets(list_value.Pass()); |
202 } | 169 } |
203 | 170 |
204 // WorkerObserver ------------------------------------------------------------- | 171 // WorkerObserver ------------------------------------------------------------- |
205 | 172 |
206 class WorkerObserver | 173 class WorkerObserver |
207 : public content::WorkerServiceObserver, | 174 : public content::WorkerServiceObserver, |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 base::StringPrintf("%d", it->first), it->second); | 568 base::StringPrintf("%d", it->first), it->second); |
602 } | 569 } |
603 | 570 |
604 std::string device_id = base::StringPrintf( | 571 std::string device_id = base::StringPrintf( |
605 kAdbDeviceIdFormat, | 572 kAdbDeviceIdFormat, |
606 sit->first.c_str()); | 573 sit->first.c_str()); |
607 result.Set(device_id, device_status_dict); | 574 result.Set(device_id, device_status_dict); |
608 } | 575 } |
609 callback_.Run(result); | 576 callback_.Run(result); |
610 } | 577 } |
OLD | NEW |