11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file.
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_
61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <vector>
91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/callback.h"
111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/public/browser/devtools_target.h"
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/public/browser/worker_service.h"
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class Profile;
151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace content {
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class DevToolsAgentHost;
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class RenderViewHost;
196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class WebContents;
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class DevToolsTargetImpl : public content::DevToolsTarget {
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static const char kTargetTypeApp[];
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static const char kTargetTypeBackgroundPage[];
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static const char kTargetTypePage[];
271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static const char kTargetTypeWorker[];
281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static const char kTargetTypeWebView[];
291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static const char kTargetTypeIFrame[];
301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static const char kTargetTypeOther[];
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static const char kTargetTypeServiceWorker[];
321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  explicit DevToolsTargetImpl(
34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      scoped_refptr<content::DevToolsAgentHost> agent_host);
351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~DevToolsTargetImpl();
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // content::DevToolsTarget overrides:
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual std::string GetId() const OVERRIDE;
3946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual std::string GetParentId() const OVERRIDE;
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual std::string GetType() const OVERRIDE;
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual std::string GetTitle() const OVERRIDE;
421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual std::string GetDescription() const OVERRIDE;
43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual GURL GetURL() const OVERRIDE;
44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual GURL GetFaviconURL() const OVERRIDE;
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual base::TimeTicks GetLastActivityTime() const OVERRIDE;
46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual scoped_refptr<content::DevToolsAgentHost>
47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      GetAgentHost() const OVERRIDE;
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual bool IsAttached() const OVERRIDE;
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual bool Activate() const OVERRIDE;
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual bool Close() const OVERRIDE;
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Returns the WebContents associated with the target on NULL if there is
531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // not any.
546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual content::WebContents* GetWebContents() const;
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Returns the tab id if the target is associated with a tab, -1 otherwise.
571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual int GetTabId() const;
581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Returns the extension id if the target is associated with an extension
601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // background page.
611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual std::string GetExtensionId() const;
621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Open a new DevTools window or activate the existing one.
641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void Inspect(Profile* profile) const;
651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Reload the target page.
671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void Reload() const;
681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Creates a new target associated with WebContents.
706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  static scoped_ptr<DevToolsTargetImpl> CreateForWebContents(
716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      content::WebContents* web_contents,
726e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      bool is_tab);
731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
7446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void set_parent_id(const std::string& parent_id) { parent_id_ = parent_id; }
75010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void set_type(const std::string& type) { type_ = type; }
76010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void set_title(const std::string& title) { title_ = title; }
77010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void set_description(const std::string& desc) { description_ = desc; }
78010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void set_url(const GURL& url) { url_ = url; }
79010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void set_favicon_url(const GURL& url) { favicon_url_ = url; }
80010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void set_last_activity_time(const base::TimeTicks& time) {
81010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)     last_activity_time_ = time;
82010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  }
83010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  typedef std::vector<DevToolsTargetImpl*> List;
851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  typedef base::Callback<void(const List&)> Callback;
861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  static void EnumerateAllTargets(Callback callback);
881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
89010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) private:
901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_refptr<content::DevToolsAgentHost> agent_host_;
9146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  std::string parent_id_;
921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::string type_;
931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::string title_;
941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::string description_;
951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  GURL url_;
961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  GURL favicon_url_;
971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  base::TimeTicks last_activity_time_;
981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif  // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_
101