| 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_target_impl.h" | 5 #include "chrome/browser/devtools/devtools_target_impl.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/devtools/devtools_window.h" | 9 #include "chrome/browser/devtools/devtools_window.h" |
| 10 #include "chrome/browser/extensions/extension_tab_util.h" | 10 #include "chrome/browser/extensions/extension_tab_util.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 private: | 56 private: |
| 57 int tab_id_; | 57 int tab_id_; |
| 58 std::string extension_id_; | 58 std::string extension_id_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 WebContentsTarget::WebContentsTarget(WebContents* web_contents, bool is_tab) | 61 WebContentsTarget::WebContentsTarget(WebContents* web_contents, bool is_tab) |
| 62 : DevToolsTargetImpl(DevToolsAgentHost::GetOrCreateFor(web_contents)), | 62 : DevToolsTargetImpl(DevToolsAgentHost::GetOrCreateFor(web_contents)), |
| 63 tab_id_(-1) { | 63 tab_id_(-1) { |
| 64 set_type(kTargetTypeOther); | 64 set_type(kTargetTypeOther); |
| 65 | 65 |
| 66 content::RenderFrameHost* rfh = | |
| 67 web_contents->GetRenderViewHost()->GetMainFrame(); | |
| 68 if (rfh->IsCrossProcessSubframe()) { | |
| 69 set_url(rfh->GetLastCommittedURL()); | |
| 70 set_type(kTargetTypeIFrame); | |
| 71 // TODO(pfeldman) Update for out of process iframes. | |
| 72 RenderViewHost* parent_rvh = rfh->GetParent()->GetRenderViewHost(); | |
| 73 set_parent_id(DevToolsAgentHost::GetOrCreateFor( | |
| 74 WebContents::FromRenderViewHost(parent_rvh))->GetId()); | |
| 75 return; | |
| 76 } | |
| 77 | |
| 78 content::NavigationController& controller = web_contents->GetController(); | 66 content::NavigationController& controller = web_contents->GetController(); |
| 79 content::NavigationEntry* entry = controller.GetActiveEntry(); | 67 content::NavigationEntry* entry = controller.GetActiveEntry(); |
| 80 if (entry != NULL && entry->GetURL().is_valid()) | 68 if (entry != NULL && entry->GetURL().is_valid()) |
| 81 set_favicon_url(entry->GetFavicon().url); | 69 set_favicon_url(entry->GetFavicon().url); |
| 82 set_last_activity_time(web_contents->GetLastActiveTime()); | 70 set_last_activity_time(web_contents->GetLastActiveTime()); |
| 83 | 71 |
| 84 extensions::GuestViewBase* guest = | 72 extensions::GuestViewBase* guest = |
| 85 extensions::GuestViewBase::FromWebContents(web_contents); | 73 extensions::GuestViewBase::FromWebContents(web_contents); |
| 86 WebContents* guest_contents = guest ? guest->embedder_web_contents() : NULL; | 74 WebContents* guest_contents = guest ? guest->embedder_web_contents() : NULL; |
| 87 if (guest_contents) { | 75 if (guest_contents) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return extension_id_; | 124 return extension_id_; |
| 137 } | 125 } |
| 138 | 126 |
| 139 void WebContentsTarget::Inspect(Profile* profile) const { | 127 void WebContentsTarget::Inspect(Profile* profile) const { |
| 140 WebContents* web_contents = GetWebContents(); | 128 WebContents* web_contents = GetWebContents(); |
| 141 if (!web_contents) | 129 if (!web_contents) |
| 142 return; | 130 return; |
| 143 DevToolsWindow::OpenDevToolsWindow(web_contents); | 131 DevToolsWindow::OpenDevToolsWindow(web_contents); |
| 144 } | 132 } |
| 145 | 133 |
| 134 // FrameTarget ---------------------------------------------------------------- |
| 135 |
| 136 class FrameTarget : public DevToolsTargetImpl { |
| 137 public: |
| 138 explicit FrameTarget(scoped_refptr<DevToolsAgentHost> agent_host); |
| 139 |
| 140 // DevToolsTargetImpl overrides: |
| 141 void Inspect(Profile* profile) const override; |
| 142 }; |
| 143 |
| 144 FrameTarget::FrameTarget(scoped_refptr<DevToolsAgentHost> agent_host) |
| 145 : DevToolsTargetImpl(agent_host) { |
| 146 set_type(kTargetTypePage); |
| 147 WebContents* wc = agent_host->GetWebContents(); |
| 148 DCHECK(DevToolsAgentHost::GetOrCreateFor(wc).get() != agent_host.get()); |
| 149 set_parent_id(DevToolsAgentHost::GetOrCreateFor(wc)->GetId()); |
| 150 } |
| 151 |
| 152 void FrameTarget::Inspect(Profile* profile) const { |
| 153 DevToolsWindow::OpenDevToolsWindow(profile, GetAgentHost()); |
| 154 } |
| 155 |
| 146 // WorkerTarget ---------------------------------------------------------------- | 156 // WorkerTarget ---------------------------------------------------------------- |
| 147 | 157 |
| 148 class WorkerTarget : public DevToolsTargetImpl { | 158 class WorkerTarget : public DevToolsTargetImpl { |
| 149 public: | 159 public: |
| 150 explicit WorkerTarget(scoped_refptr<DevToolsAgentHost> agent_host); | 160 explicit WorkerTarget(scoped_refptr<DevToolsAgentHost> agent_host); |
| 151 | 161 |
| 152 // DevToolsTargetImpl overrides: | 162 // DevToolsTargetImpl overrides: |
| 153 void Inspect(Profile* profile) const override; | 163 void Inspect(Profile* profile) const override; |
| 154 }; | 164 }; |
| 155 | 165 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 it != agents.end(); ++it) { | 284 it != agents.end(); ++it) { |
| 275 DevToolsAgentHost* agent_host = (*it).get(); | 285 DevToolsAgentHost* agent_host = (*it).get(); |
| 276 switch (agent_host->GetType()) { | 286 switch (agent_host->GetType()) { |
| 277 case DevToolsAgentHost::TYPE_WEB_CONTENTS: | 287 case DevToolsAgentHost::TYPE_WEB_CONTENTS: |
| 278 if (WebContents* web_contents = agent_host->GetWebContents()) { | 288 if (WebContents* web_contents = agent_host->GetWebContents()) { |
| 279 const bool is_tab = | 289 const bool is_tab = |
| 280 tab_web_contents.find(web_contents) != tab_web_contents.end(); | 290 tab_web_contents.find(web_contents) != tab_web_contents.end(); |
| 281 result.push_back(new WebContentsTarget(web_contents, is_tab)); | 291 result.push_back(new WebContentsTarget(web_contents, is_tab)); |
| 282 } | 292 } |
| 283 break; | 293 break; |
| 294 case DevToolsAgentHost::TYPE_FRAME: |
| 295 result.push_back(new FrameTarget(agent_host)); |
| 296 break; |
| 284 case DevToolsAgentHost::TYPE_SHARED_WORKER: | 297 case DevToolsAgentHost::TYPE_SHARED_WORKER: |
| 285 result.push_back(new WorkerTarget(agent_host)); | 298 result.push_back(new WorkerTarget(agent_host)); |
| 286 break; | 299 break; |
| 287 case DevToolsAgentHost::TYPE_SERVICE_WORKER: | 300 case DevToolsAgentHost::TYPE_SERVICE_WORKER: |
| 288 result.push_back(new WorkerTarget(agent_host)); | 301 result.push_back(new WorkerTarget(agent_host)); |
| 289 break; | 302 break; |
| 290 default: | 303 default: |
| 291 break; | 304 break; |
| 292 } | 305 } |
| 293 } | 306 } |
| 294 | 307 |
| 295 callback.Run(result); | 308 callback.Run(result); |
| 296 } | 309 } |
| OLD | NEW |