diff options
author | kaznacheev@chromium.org <kaznacheev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-02 07:33:32 +0000 |
---|---|---|
committer | kaznacheev@chromium.org <kaznacheev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-02 07:33:32 +0000 |
commit | 002195f2ac6ad1b880e4b2bcd955801b910f3959 (patch) | |
tree | 136fb29e2c8b7d352abe370266a6925f1ff48744 | |
parent | 8d21392d97e22a7d6adf7903673b204193d867c9 (diff) | |
download | chromium_src-002195f2ac6ad1b880e4b2bcd955801b910f3959.zip chromium_src-002195f2ac6ad1b880e4b2bcd955801b910f3959.tar.gz chromium_src-002195f2ac6ad1b880e4b2bcd955801b910f3959.tar.bz2 |
DevTools: Add parent id to target descriptor in remote debugging.
Webviews and OOP iframes now have non-empty parentId property pointing to the target they are nested into. Also added 'webview' and 'iframe' target types.
TBR=bulach,mnaganov (for dev_tools_server.cc aw_dev_tools_server.cc)
BUG=378457
Review URL: https://codereview.chromium.org/305903004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274178 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | android_webview/native/aw_dev_tools_server.cc | 1 | ||||
-rw-r--r-- | chrome/browser/android/dev_tools_server.cc | 2 | ||||
-rw-r--r-- | chrome/browser/devtools/devtools_target_impl.cc | 20 | ||||
-rw-r--r-- | chrome/browser/devtools/devtools_target_impl.h | 4 | ||||
-rw-r--r-- | chrome/browser/devtools/devtools_targets_ui.cc | 59 | ||||
-rw-r--r-- | content/browser/devtools/devtools_http_handler_impl.cc | 4 | ||||
-rw-r--r-- | content/public/browser/devtools_target.h | 3 | ||||
-rw-r--r-- | content/shell/browser/shell_devtools_delegate.cc | 1 |
8 files changed, 46 insertions, 48 deletions
diff --git a/android_webview/native/aw_dev_tools_server.cc b/android_webview/native/aw_dev_tools_server.cc index ab08ca5..35b6455 100644 --- a/android_webview/native/aw_dev_tools_server.cc +++ b/android_webview/native/aw_dev_tools_server.cc @@ -39,6 +39,7 @@ class Target : public content::DevToolsTarget { explicit Target(WebContents* web_contents); virtual std::string GetId() const OVERRIDE { return id_; } + virtual std::string GetParentId() const OVERRIDE { return std::string(); } virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } virtual std::string GetTitle() const OVERRIDE { return title_; } virtual std::string GetDescription() const OVERRIDE { return description_; } diff --git a/chrome/browser/android/dev_tools_server.cc b/chrome/browser/android/dev_tools_server.cc index 246218e..091e901 100644 --- a/chrome/browser/android/dev_tools_server.cc +++ b/chrome/browser/android/dev_tools_server.cc @@ -79,6 +79,8 @@ static GURL GetFaviconURLForContents(WebContents* web_contents) { class TargetBase : public content::DevToolsTarget { public: // content::DevToolsTarget implementation: + virtual std::string GetParentId() const OVERRIDE { return std::string(); } + virtual std::string GetTitle() const OVERRIDE { return title_; } virtual std::string GetDescription() const OVERRIDE { return std::string(); } diff --git a/chrome/browser/devtools/devtools_target_impl.cc b/chrome/browser/devtools/devtools_target_impl.cc index bb9800e..eb32924 100644 --- a/chrome/browser/devtools/devtools_target_impl.cc +++ b/chrome/browser/devtools/devtools_target_impl.cc @@ -9,6 +9,7 @@ #include "chrome/browser/devtools/devtools_window.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tab_util.h" +#include "chrome/browser/guest_view/guest_view_base.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" @@ -35,6 +36,8 @@ const char kTargetTypeApp[] = "app"; const char kTargetTypeBackgroundPage[] = "background_page"; const char kTargetTypePage[] = "page"; const char kTargetTypeWorker[] = "worker"; +const char kTargetTypeWebView[] = "webview"; +const char kTargetTypeIFrame[] = "iframe"; const char kTargetTypeOther[] = "other"; // RenderViewHostTarget -------------------------------------------------------- @@ -67,9 +70,11 @@ RenderViewHostTarget::RenderViewHostTarget(RenderViewHost* rvh, bool is_tab) content::RenderFrameHost* rfh = rvh->GetMainFrame(); if (rfh->IsCrossProcessSubframe()) { set_url(rfh->GetLastCommittedURL()); - set_type(kTargetTypeOther); + set_type(kTargetTypeIFrame); // TODO(kaznacheev) Try setting the title when the frame navigation // refactoring is done. + RenderViewHost* parent_rvh = rfh->GetParent()->GetRenderViewHost(); + set_parent_id(DevToolsAgentHost::GetOrCreateFor(parent_rvh)->GetId()); return; } @@ -81,6 +86,15 @@ RenderViewHostTarget::RenderViewHostTarget(RenderViewHost* rvh, bool is_tab) set_favicon_url(entry->GetFavicon().url); set_last_activity_time(web_contents->GetLastActiveTime()); + GuestViewBase* guest = GuestViewBase::FromWebContents(web_contents); + if (guest) { + set_type(kTargetTypeWebView); + RenderViewHost* parent_rvh = + guest->embedder_web_contents()->GetRenderViewHost(); + set_parent_id(DevToolsAgentHost::GetOrCreateFor(parent_rvh)->GetId()); + return; + } + if (is_tab) { set_type(kTargetTypePage); tab_id_ = extensions::ExtensionTabUtil::GetTabId(web_contents); @@ -207,6 +221,10 @@ DevToolsTargetImpl::DevToolsTargetImpl( : agent_host_(agent_host) { } +std::string DevToolsTargetImpl::GetParentId() const { + return parent_id_; +} + std::string DevToolsTargetImpl::GetId() const { return agent_host_->GetId(); } diff --git a/chrome/browser/devtools/devtools_target_impl.h b/chrome/browser/devtools/devtools_target_impl.h index 2d15cd5..3275565 100644 --- a/chrome/browser/devtools/devtools_target_impl.h +++ b/chrome/browser/devtools/devtools_target_impl.h @@ -26,6 +26,7 @@ class DevToolsTargetImpl : public content::DevToolsTarget { // content::DevToolsTarget overrides: virtual std::string GetId() const OVERRIDE; + virtual std::string GetParentId() const OVERRIDE; virtual std::string GetType() const OVERRIDE; virtual std::string GetTitle() const OVERRIDE; virtual std::string GetDescription() const OVERRIDE; @@ -59,6 +60,7 @@ class DevToolsTargetImpl : public content::DevToolsTarget { static scoped_ptr<DevToolsTargetImpl> CreateForRenderViewHost( content::RenderViewHost*, bool is_tab); + void set_parent_id(const std::string& parent_id) { parent_id_ = parent_id; } void set_type(const std::string& type) { type_ = type; } void set_title(const std::string& title) { title_ = title; } void set_description(const std::string& desc) { description_ = desc; } @@ -77,7 +79,7 @@ class DevToolsTargetImpl : public content::DevToolsTarget { private: scoped_refptr<content::DevToolsAgentHost> agent_host_; - std::string id_; + std::string parent_id_; std::string type_; std::string title_; std::string description_; diff --git a/chrome/browser/devtools/devtools_targets_ui.cc b/chrome/browser/devtools/devtools_targets_ui.cc index 321d962..278961d 100644 --- a/chrome/browser/devtools/devtools_targets_ui.cc +++ b/chrome/browser/devtools/devtools_targets_ui.cc @@ -11,7 +11,6 @@ #include "base/version.h" #include "chrome/browser/devtools/device/devtools_android_bridge.h" #include "chrome/browser/devtools/devtools_target_impl.h" -#include "chrome/browser/guest_view/guest_view_base.h" #include "chrome/common/chrome_version_info.h" #include "content/public/browser/browser_child_process_observer.h" #include "content/public/browser/browser_thread.h" @@ -21,18 +20,12 @@ #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/notification_types.h" -#include "content/public/browser/render_frame_host.h" -#include "content/public/browser/render_process_host.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/web_contents.h" #include "content/public/browser/worker_service.h" #include "content/public/browser/worker_service_observer.h" #include "content/public/common/process_type.h" #include "net/base/escape.h" using content::BrowserThread; -using content::RenderFrameHost; -using content::WebContents; namespace { @@ -141,8 +134,7 @@ void RenderViewHostTargetsUIHandler::Observe( void RenderViewHostTargetsUIHandler::UpdateTargets() { scoped_ptr<base::ListValue> list_value(new base::ListValue()); - std::map<RenderFrameHost*, base::DictionaryValue*> rfh_to_descriptor; - std::vector<RenderFrameHost*> nested_frames; + std::map<std::string, base::DictionaryValue*> id_to_descriptor; DevToolsTargetImpl::List targets = DevToolsTargetImpl::EnumerateRenderViewHostTargets(); @@ -150,51 +142,26 @@ void RenderViewHostTargetsUIHandler::UpdateTargets() { STLDeleteValues(&targets_); for (DevToolsTargetImpl::List::iterator it = targets.begin(); it != targets.end(); ++it) { - scoped_ptr<DevToolsTargetImpl> target(*it); - content::RenderViewHost* rvh = target->GetRenderViewHost(); - if (!rvh) - continue; - - DevToolsTargetImpl* target_ptr = target.get(); - targets_[target_ptr->GetId()] = target.release(); - base::DictionaryValue* descriptor = Serialize(*target_ptr); - - // TODO (kaznacheev): GetMainFrame() call is a temporary hack. - // Revisit this when multiple OOP frames are supported. - RenderFrameHost* rfh = rvh->GetMainFrame(); - rfh_to_descriptor[rfh] = descriptor; - content::WebContents* web_contents = - content::WebContents::FromRenderViewHost(rvh); - if (GuestViewBase::IsGuest(web_contents) || rfh->IsCrossProcessSubframe()) { - nested_frames.push_back(rfh); - } else { - list_value->Append(descriptor); - } + DevToolsTargetImpl* target = *it; + targets_[target->GetId()] = target; + id_to_descriptor[target->GetId()] = Serialize(*target); } - // Add the list of nested targets to each of its owners. - for (std::vector<RenderFrameHost*>::iterator it(nested_frames.begin()); - it != nested_frames.end(); ++it) { - RenderFrameHost* rfh = (*it); - RenderFrameHost* parent_rfh = NULL; - content::RenderViewHost* rvh = rfh->GetRenderViewHost(); - WebContents* nested_web_contents = WebContents::FromRenderViewHost(rvh); - GuestViewBase* guest = GuestViewBase::FromWebContents(nested_web_contents); - if (guest) { - WebContents* embedder = guest->embedder_web_contents(); - parent_rfh = embedder->GetRenderViewHost()->GetMainFrame(); + for (TargetMap::iterator it(targets_.begin()); it != targets_.end(); ++it) { + DevToolsTargetImpl* target = it->second; + base::DictionaryValue* descriptor = id_to_descriptor[target->GetId()]; + + std::string parent_id = target->GetParentId(); + if (parent_id.empty() || id_to_descriptor.count(parent_id) == 0) { + list_value->Append(descriptor); } else { - parent_rfh = rfh->GetParent(); - DCHECK(parent_rfh); - } - if (parent_rfh && rfh_to_descriptor.count(parent_rfh) > 0) { - base::DictionaryValue* parent = rfh_to_descriptor[parent_rfh]; + base::DictionaryValue* parent = id_to_descriptor[parent_id]; base::ListValue* guests = NULL; if (!parent->GetList(kGuestList, &guests)) { guests = new base::ListValue(); parent->Set(kGuestList, guests); } - guests->Append(rfh_to_descriptor[rfh]); + guests->Append(descriptor); } } diff --git a/content/browser/devtools/devtools_http_handler_impl.cc b/content/browser/devtools/devtools_http_handler_impl.cc index 8678848..5a5bb09 100644 --- a/content/browser/devtools/devtools_http_handler_impl.cc +++ b/content/browser/devtools/devtools_http_handler_impl.cc @@ -54,6 +54,7 @@ const char kThumbUrlPrefix[] = "/thumb/"; const char kPageUrlPrefix[] = "/devtools/page/"; const char kTargetIdField[] = "id"; +const char kTargetParentIdField[] = "parentId"; const char kTargetTypeField[] = "type"; const char kTargetTitleField[] = "title"; const char kTargetDescriptionField[] = "description"; @@ -753,6 +754,9 @@ base::DictionaryValue* DevToolsHttpHandlerImpl::SerializeTarget( std::string id = target.GetId(); dictionary->SetString(kTargetIdField, id); + std::string parent_id = target.GetParentId(); + if (!parent_id.empty()) + dictionary->SetString(kTargetParentIdField, parent_id); dictionary->SetString(kTargetTypeField, target.GetType()); dictionary->SetString(kTargetTitleField, net::EscapeForHTML(target.GetTitle())); diff --git a/content/public/browser/devtools_target.h b/content/public/browser/devtools_target.h index ae4ab8b..8008535 100644 --- a/content/public/browser/devtools_target.h +++ b/content/public/browser/devtools_target.h @@ -28,6 +28,9 @@ class DevToolsTarget { // Returns the unique target id. virtual std::string GetId() const = 0; + // Returns the id of the parent target, or empty string if no parent. + virtual std::string GetParentId() const = 0; + // Returns the target type. virtual std::string GetType() const = 0; diff --git a/content/shell/browser/shell_devtools_delegate.cc b/content/shell/browser/shell_devtools_delegate.cc index d6f3b62..6a8f09e 100644 --- a/content/shell/browser/shell_devtools_delegate.cc +++ b/content/shell/browser/shell_devtools_delegate.cc @@ -77,6 +77,7 @@ class Target : public content::DevToolsTarget { explicit Target(WebContents* web_contents); virtual std::string GetId() const OVERRIDE { return id_; } + virtual std::string GetParentId() const OVERRIDE { return std::string(); } virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } virtual std::string GetTitle() const OVERRIDE { return title_; } virtual std::string GetDescription() const OVERRIDE { return std::string(); } |