1 // Copyright 2014 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "devtools_manager_delegate_efl.h"
7 #include "content/public/browser/devtools_agent_host.h"
8 #include "content/public/browser/web_contents.h"
9 #include "content/public/browser/navigation_entry.h"
10 #include "content/public/browser/favicon_status.h"
11 #include "content/public/browser/web_contents_delegate.h"
12 #include "content/public/browser/render_view_host.h"
14 using content::DevToolsAgentHost;
15 using content::WebContents;
16 using content::RenderViewHost;
20 const char kTargetTypePage[] = "page";
21 const char kTargetTypeServiceWorker[] = "service_worker";
22 const char kTargetTypeOther[] = "other";
24 class Target : public devtools_discovery::DevToolsTargetDescriptor {
27 explicit Target(scoped_refptr<DevToolsAgentHost> agent_host);
29 virtual std::string GetId() const override { return agent_host_->GetId(); }
30 virtual std::string GetParentId() const override { return std::string(); }
31 virtual std::string GetType() const override {
32 switch (agent_host_->GetType()) {
33 case DevToolsAgentHost::TYPE_WEB_CONTENTS:
34 return kTargetTypePage;
35 case DevToolsAgentHost::TYPE_SERVICE_WORKER:
36 return kTargetTypeServiceWorker;
40 return kTargetTypeOther;
42 virtual std::string GetTitle() const override {
43 return agent_host_->GetTitle();
45 virtual std::string GetDescription() const override { return std::string(); }
46 virtual GURL GetURL() const override { return agent_host_->GetURL(); }
47 virtual GURL GetFaviconURL() const override { return favicon_url_; }
48 virtual base::TimeTicks GetLastActivityTime() const override {
49 return last_activity_time_;
51 virtual bool IsAttached() const override {
52 return agent_host_->IsAttached();
54 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const override {
57 virtual bool Activate() const override;
58 virtual bool Close() const override;
62 scoped_refptr<DevToolsAgentHost> agent_host_;
67 base::TimeTicks last_activity_time_;
70 Target::Target(scoped_refptr<content::DevToolsAgentHost> agent_host)
71 : agent_host_(agent_host) {
72 if (WebContents* web_contents = agent_host_->GetWebContents()) {
73 last_activity_time_ = web_contents->GetLastActiveTime();
74 content::NavigationController& controller = web_contents->GetController();
75 content::NavigationEntry* entry = controller.GetActiveEntry();
76 if (entry != NULL && entry->GetURL().is_valid())
77 favicon_url_ = entry->GetFavicon().url;
81 bool Target::Activate() const {
82 WebContents* web_contents = agent_host_->GetWebContents();
85 web_contents->GetDelegate()->ActivateContents(web_contents);
89 bool Target::Close() const {
90 WebContents* web_contents = agent_host_->GetWebContents();
93 web_contents->ClosePage();
101 DevToolsManagerDelegateEfl::DevToolsManagerDelegateEfl() {
104 DevToolsManagerDelegateEfl::~DevToolsManagerDelegateEfl() {
107 base::DictionaryValue* DevToolsManagerDelegateEfl::HandleCommand(
108 content::DevToolsAgentHost* agent_host,
109 base::DictionaryValue* command_dict) {
113 } // namespace content