Chromium Code Reviews| 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 23 matching lines...) Expand all Loading... | |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const char kTargetTypeApp[] = "app"; | 36 const char kTargetTypeApp[] = "app"; |
| 37 const char kTargetTypeBackgroundPage[] = "background_page"; | 37 const char kTargetTypeBackgroundPage[] = "background_page"; |
| 38 const char kTargetTypePage[] = "page"; | 38 const char kTargetTypePage[] = "page"; |
| 39 const char kTargetTypeWorker[] = "worker"; | 39 const char kTargetTypeWorker[] = "worker"; |
| 40 const char kTargetTypeWebView[] = "webview"; | 40 const char kTargetTypeWebView[] = "webview"; |
| 41 const char kTargetTypeIFrame[] = "iframe"; | 41 const char kTargetTypeIFrame[] = "iframe"; |
| 42 const char kTargetTypeOther[] = "other"; | 42 const char kTargetTypeOther[] = "other"; |
| 43 | 43 |
| 44 // RenderViewHostTarget -------------------------------------------------------- | 44 // WebContentsTarget -------------------------------------------------------- |
| 45 | 45 |
| 46 class RenderViewHostTarget : public DevToolsTargetImpl { | 46 class WebContentsTarget : public DevToolsTargetImpl { |
| 47 public: | 47 public: |
| 48 explicit RenderViewHostTarget(RenderViewHost* rvh, bool is_tab); | 48 WebContentsTarget(WebContents* web_contents, bool is_tab); |
| 49 | 49 |
| 50 // DevToolsTargetImpl overrides: | 50 // DevToolsTargetImpl overrides: |
| 51 virtual bool Activate() const OVERRIDE; | 51 virtual bool Activate() const OVERRIDE; |
| 52 virtual bool Close() const OVERRIDE; | 52 virtual bool Close() const OVERRIDE; |
| 53 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE; | 53 virtual WebContents* GetWebContents() const OVERRIDE; |
| 54 virtual int GetTabId() const OVERRIDE; | 54 virtual int GetTabId() const OVERRIDE; |
| 55 virtual std::string GetExtensionId() const OVERRIDE; | 55 virtual std::string GetExtensionId() const OVERRIDE; |
| 56 virtual void Inspect(Profile* profile) const OVERRIDE; | 56 virtual void Inspect(Profile* profile) const OVERRIDE; |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 int tab_id_; | 59 int tab_id_; |
| 60 std::string extension_id_; | 60 std::string extension_id_; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 RenderViewHostTarget::RenderViewHostTarget(RenderViewHost* rvh, bool is_tab) | 63 WebContentsTarget::WebContentsTarget(WebContents* web_contents, bool is_tab) |
| 64 : DevToolsTargetImpl(DevToolsAgentHost::GetOrCreateFor(rvh)), | 64 : DevToolsTargetImpl(DevToolsAgentHost::GetOrCreateFor(web_contents)), |
| 65 tab_id_(-1) { | 65 tab_id_(-1) { |
| 66 set_type(kTargetTypeOther); | 66 set_type(kTargetTypeOther); |
| 67 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | |
| 68 if (!web_contents) | |
| 69 return; // Orphan RVH will show up with no title/url/icon in clients. | |
| 70 | 67 |
| 71 content::RenderFrameHost* rfh = rvh->GetMainFrame(); | 68 content::RenderFrameHost* rfh = |
| 69 web_contents->GetRenderViewHost()->GetMainFrame(); | |
| 72 if (rfh->IsCrossProcessSubframe()) { | 70 if (rfh->IsCrossProcessSubframe()) { |
|
dgozman
2014/08/06 19:22:20
Does this mean OOP frames have their own WebConten
pfeldman
2014/08/07 09:03:08
We'll figure it out. Updated the TODO below.
| |
| 73 set_url(rfh->GetLastCommittedURL()); | 71 set_url(rfh->GetLastCommittedURL()); |
| 74 set_type(kTargetTypeIFrame); | 72 set_type(kTargetTypeIFrame); |
| 75 // TODO(kaznacheev) Try setting the title when the frame navigation | 73 // TODO(kaznacheev) Try setting the title when the frame navigation |
| 76 // refactoring is done. | 74 // refactoring is done. |
| 77 RenderViewHost* parent_rvh = rfh->GetParent()->GetRenderViewHost(); | 75 RenderViewHost* parent_rvh = rfh->GetParent()->GetRenderViewHost(); |
| 78 set_parent_id(DevToolsAgentHost::GetOrCreateFor(parent_rvh)->GetId()); | 76 set_parent_id(DevToolsAgentHost::GetOrCreateFor( |
| 77 WebContents::FromRenderViewHost(parent_rvh))->GetId()); | |
| 79 return; | 78 return; |
| 80 } | 79 } |
| 81 | 80 |
| 82 set_title(base::UTF16ToUTF8(web_contents->GetTitle())); | 81 set_title(base::UTF16ToUTF8(web_contents->GetTitle())); |
| 83 set_url(web_contents->GetURL()); | 82 set_url(web_contents->GetURL()); |
| 84 content::NavigationController& controller = web_contents->GetController(); | 83 content::NavigationController& controller = web_contents->GetController(); |
| 85 content::NavigationEntry* entry = controller.GetActiveEntry(); | 84 content::NavigationEntry* entry = controller.GetActiveEntry(); |
| 86 if (entry != NULL && entry->GetURL().is_valid()) | 85 if (entry != NULL && entry->GetURL().is_valid()) |
| 87 set_favicon_url(entry->GetFavicon().url); | 86 set_favicon_url(entry->GetFavicon().url); |
| 88 set_last_activity_time(web_contents->GetLastActiveTime()); | 87 set_last_activity_time(web_contents->GetLastActiveTime()); |
| 89 | 88 |
| 90 GuestViewBase* guest = GuestViewBase::FromWebContents(web_contents); | 89 GuestViewBase* guest = GuestViewBase::FromWebContents(web_contents); |
| 91 WebContents* guest_contents = guest ? guest->embedder_web_contents() : NULL; | 90 WebContents* guest_contents = guest ? guest->embedder_web_contents() : NULL; |
| 92 RenderViewHost* guest_parent_rvh = | 91 if (guest_contents) { |
| 93 guest_contents ? guest_contents->GetRenderViewHost() : NULL; | |
| 94 if (guest_parent_rvh) { | |
| 95 set_type(kTargetTypeWebView); | 92 set_type(kTargetTypeWebView); |
| 96 set_parent_id(DevToolsAgentHost::GetOrCreateFor(guest_parent_rvh)->GetId()); | 93 set_parent_id(DevToolsAgentHost::GetOrCreateFor(guest_contents)->GetId()); |
| 97 return; | 94 return; |
| 98 } | 95 } |
| 99 | 96 |
| 100 if (is_tab) { | 97 if (is_tab) { |
| 101 set_type(kTargetTypePage); | 98 set_type(kTargetTypePage); |
| 102 tab_id_ = extensions::ExtensionTabUtil::GetTabId(web_contents); | 99 tab_id_ = extensions::ExtensionTabUtil::GetTabId(web_contents); |
| 103 return; | 100 return; |
| 104 } | 101 } |
| 105 | 102 |
| 106 const extensions::Extension* extension = extensions::ExtensionRegistry::Get( | 103 const extensions::Extension* extension = extensions::ExtensionRegistry::Get( |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 126 } else if (extension->is_hosted_app() | 123 } else if (extension->is_hosted_app() |
| 127 || extension->is_legacy_packaged_app() | 124 || extension->is_legacy_packaged_app() |
| 128 || extension->is_platform_app()) { | 125 || extension->is_platform_app()) { |
| 129 set_type(kTargetTypeApp); | 126 set_type(kTargetTypeApp); |
| 130 } | 127 } |
| 131 set_favicon_url(extensions::ExtensionIconSource::GetIconURL( | 128 set_favicon_url(extensions::ExtensionIconSource::GetIconURL( |
| 132 extension, extension_misc::EXTENSION_ICON_SMALLISH, | 129 extension, extension_misc::EXTENSION_ICON_SMALLISH, |
| 133 ExtensionIconSet::MATCH_BIGGER, false, NULL)); | 130 ExtensionIconSet::MATCH_BIGGER, false, NULL)); |
| 134 } | 131 } |
| 135 | 132 |
| 136 bool RenderViewHostTarget::Activate() const { | 133 bool WebContentsTarget::Activate() const { |
| 137 RenderViewHost* rvh = GetRenderViewHost(); | 134 WebContents* web_contents = GetWebContents(); |
| 138 if (!rvh) | |
| 139 return false; | |
| 140 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | |
| 141 if (!web_contents) | 135 if (!web_contents) |
| 142 return false; | 136 return false; |
| 143 web_contents->GetDelegate()->ActivateContents(web_contents); | 137 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 144 return true; | 138 return true; |
| 145 } | 139 } |
| 146 | 140 |
| 147 bool RenderViewHostTarget::Close() const { | 141 bool WebContentsTarget::Close() const { |
| 148 RenderViewHost* rvh = GetRenderViewHost(); | 142 WebContents* web_contents = GetWebContents(); |
| 149 if (!rvh) | 143 if (!web_contents) |
| 150 return false; | 144 return false; |
| 151 rvh->ClosePage(); | 145 web_contents->GetRenderViewHost()->ClosePage(); |
| 152 return true; | 146 return true; |
| 153 } | 147 } |
| 154 | 148 |
| 155 RenderViewHost* RenderViewHostTarget::GetRenderViewHost() const { | 149 WebContents* WebContentsTarget::GetWebContents() const { |
| 156 return GetAgentHost()->GetRenderViewHost(); | 150 return GetAgentHost()->GetWebContents(); |
| 157 } | 151 } |
| 158 | 152 |
| 159 int RenderViewHostTarget::GetTabId() const { | 153 int WebContentsTarget::GetTabId() const { |
| 160 return tab_id_; | 154 return tab_id_; |
| 161 } | 155 } |
| 162 | 156 |
| 163 std::string RenderViewHostTarget::GetExtensionId() const { | 157 std::string WebContentsTarget::GetExtensionId() const { |
| 164 return extension_id_; | 158 return extension_id_; |
| 165 } | 159 } |
| 166 | 160 |
| 167 void RenderViewHostTarget::Inspect(Profile* profile) const { | 161 void WebContentsTarget::Inspect(Profile* profile) const { |
| 168 RenderViewHost* rvh = GetRenderViewHost(); | 162 WebContents* web_contents = GetWebContents(); |
| 169 if (!rvh) | 163 if (!web_contents) |
| 170 return; | 164 return; |
| 171 DevToolsWindow::OpenDevToolsWindow(rvh); | 165 DevToolsWindow::OpenDevToolsWindow(web_contents); |
| 172 } | 166 } |
| 173 | 167 |
| 174 // WorkerTarget ---------------------------------------------------------------- | 168 // WorkerTarget ---------------------------------------------------------------- |
| 175 | 169 |
| 176 class WorkerTarget : public DevToolsTargetImpl { | 170 class WorkerTarget : public DevToolsTargetImpl { |
| 177 public: | 171 public: |
| 178 explicit WorkerTarget(const WorkerService::WorkerInfo& worker_info); | 172 explicit WorkerTarget(const WorkerService::WorkerInfo& worker_info); |
| 179 | 173 |
| 180 // content::DevToolsTarget overrides: | 174 // content::DevToolsTarget overrides: |
| 181 virtual bool Close() const OVERRIDE; | 175 virtual bool Close() const OVERRIDE; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 } | 267 } |
| 274 | 268 |
| 275 bool DevToolsTargetImpl::Close() const { | 269 bool DevToolsTargetImpl::Close() const { |
| 276 return false; | 270 return false; |
| 277 } | 271 } |
| 278 | 272 |
| 279 int DevToolsTargetImpl::GetTabId() const { | 273 int DevToolsTargetImpl::GetTabId() const { |
| 280 return -1; | 274 return -1; |
| 281 } | 275 } |
| 282 | 276 |
| 283 RenderViewHost* DevToolsTargetImpl::GetRenderViewHost() const { | 277 WebContents* DevToolsTargetImpl::GetWebContents() const { |
| 284 return NULL; | 278 return NULL; |
| 285 } | 279 } |
| 286 | 280 |
| 287 std::string DevToolsTargetImpl::GetExtensionId() const { | 281 std::string DevToolsTargetImpl::GetExtensionId() const { |
| 288 return std::string(); | 282 return std::string(); |
| 289 } | 283 } |
| 290 | 284 |
| 291 void DevToolsTargetImpl::Inspect(Profile* /*profile*/) const { | 285 void DevToolsTargetImpl::Inspect(Profile* /*profile*/) const { |
| 292 } | 286 } |
| 293 | 287 |
| 294 void DevToolsTargetImpl::Reload() const { | 288 void DevToolsTargetImpl::Reload() const { |
| 295 } | 289 } |
| 296 | 290 |
| 297 // static | 291 // static |
| 298 scoped_ptr<DevToolsTargetImpl> DevToolsTargetImpl::CreateForRenderViewHost( | 292 scoped_ptr<DevToolsTargetImpl> DevToolsTargetImpl::CreateForWebContents( |
| 299 content::RenderViewHost* rvh, bool is_tab) { | 293 content::WebContents* web_contents, |
| 300 return scoped_ptr<DevToolsTargetImpl>(new RenderViewHostTarget(rvh, is_tab)); | 294 bool is_tab) { |
| 295 return scoped_ptr<DevToolsTargetImpl>( | |
| 296 new WebContentsTarget(web_contents, is_tab)); | |
| 301 } | 297 } |
| 302 | 298 |
| 303 // static | 299 // static |
| 304 DevToolsTargetImpl::List DevToolsTargetImpl::EnumerateRenderViewHostTargets() { | 300 DevToolsTargetImpl::List DevToolsTargetImpl::EnumerateWebContentsTargets() { |
| 305 std::set<RenderViewHost*> tab_rvhs; | 301 std::set<WebContents*> tab_web_contents; |
| 306 for (TabContentsIterator it; !it.done(); it.Next()) | 302 for (TabContentsIterator it; !it.done(); it.Next()) |
| 307 tab_rvhs.insert(it->GetRenderViewHost()); | 303 tab_web_contents.insert(*it); |
| 308 | 304 |
| 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 310 DevToolsTargetImpl::List result; | 306 DevToolsTargetImpl::List result; |
| 311 std::vector<RenderViewHost*> rvh_list = | 307 std::vector<WebContents*> wc_list = |
| 312 content::DevToolsAgentHost::GetValidRenderViewHosts(); | 308 content::DevToolsAgentHost::GetInspectableWebContents(); |
| 313 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin(); | 309 for (std::vector<WebContents*>::iterator it = wc_list.begin(); |
| 314 it != rvh_list.end(); ++it) { | 310 it != wc_list.end(); |
| 315 bool is_tab = tab_rvhs.find(*it) != tab_rvhs.end(); | 311 ++it) { |
| 316 result.push_back(new RenderViewHostTarget(*it, is_tab)); | 312 bool is_tab = tab_web_contents.find(*it) != tab_web_contents.end(); |
| 313 result.push_back(new WebContentsTarget(*it, is_tab)); | |
| 317 } | 314 } |
| 318 return result; | 315 return result; |
| 319 } | 316 } |
| 320 | 317 |
| 321 static void CreateWorkerTargets( | 318 static void CreateWorkerTargets( |
| 322 const std::vector<WorkerService::WorkerInfo>& worker_info, | 319 const std::vector<WorkerService::WorkerInfo>& worker_info, |
| 323 DevToolsTargetImpl::Callback callback) { | 320 DevToolsTargetImpl::Callback callback) { |
| 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 325 DevToolsTargetImpl::List result; | 322 DevToolsTargetImpl::List result; |
| 326 for (size_t i = 0; i < worker_info.size(); ++i) { | 323 for (size_t i = 0; i < worker_info.size(); ++i) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 338 base::Bind(&CreateWorkerTargets, | 335 base::Bind(&CreateWorkerTargets, |
| 339 WorkerService::GetInstance()->GetWorkers(), | 336 WorkerService::GetInstance()->GetWorkers(), |
| 340 callback)); | 337 callback)); |
| 341 } | 338 } |
| 342 | 339 |
| 343 static void CollectAllTargets( | 340 static void CollectAllTargets( |
| 344 DevToolsTargetImpl::Callback callback, | 341 DevToolsTargetImpl::Callback callback, |
| 345 const DevToolsTargetImpl::List& worker_targets) { | 342 const DevToolsTargetImpl::List& worker_targets) { |
| 346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 347 DevToolsTargetImpl::List result = | 344 DevToolsTargetImpl::List result = |
| 348 DevToolsTargetImpl::EnumerateRenderViewHostTargets(); | 345 DevToolsTargetImpl::EnumerateWebContentsTargets(); |
| 349 result.insert(result.begin(), worker_targets.begin(), worker_targets.end()); | 346 result.insert(result.begin(), worker_targets.begin(), worker_targets.end()); |
| 350 callback.Run(result); | 347 callback.Run(result); |
| 351 } | 348 } |
| 352 | 349 |
| 353 // static | 350 // static |
| 354 void DevToolsTargetImpl::EnumerateAllTargets(Callback callback) { | 351 void DevToolsTargetImpl::EnumerateAllTargets(Callback callback) { |
| 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 356 content::BrowserThread::PostTask( | 353 content::BrowserThread::PostTask( |
| 357 content::BrowserThread::IO, | 354 content::BrowserThread::IO, |
| 358 FROM_HERE, | 355 FROM_HERE, |
| 359 base::Bind(&DevToolsTargetImpl::EnumerateWorkerTargets, | 356 base::Bind(&DevToolsTargetImpl::EnumerateWorkerTargets, |
| 360 base::Bind(&CollectAllTargets, callback))); | 357 base::Bind(&CollectAllTargets, callback))); |
| 361 } | 358 } |
| OLD | NEW |