Home | History | Annotate | Download | only in debugger
      1 // Copyright (c) 2009 The Chromium Authors. 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.
      4 
      5 #ifndef CHROME_BROWSER_DEBUGGER_INSPECTABLE_TAB_PROXY_H_
      6 #define CHROME_BROWSER_DEBUGGER_INSPECTABLE_TAB_PROXY_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/hash_tables.h"
     13 #include "chrome/browser/debugger/devtools_client_host.h"
     14 
     15 class DebuggerRemoteService;
     16 class DevToolsClientHost;
     17 class DevToolsClientHostImpl;
     18 class NavigationController;
     19 struct DevToolsMessageData;
     20 
     21 // Proxies debugged tabs' NavigationControllers using their UIDs.
     22 // Keeps track of tabs being debugged so that we can detach from
     23 // them on remote debugger connection loss.
     24 class InspectableTabProxy {
     25  public:
     26   typedef base::hash_map<int32, NavigationController*> ControllersMap;
     27   typedef base::hash_map<int32, DevToolsClientHostImpl*> IdToClientHostMap;
     28 
     29   InspectableTabProxy();
     30   virtual ~InspectableTabProxy();
     31 
     32   // Returns a map of NavigationControllerKeys to NavigationControllers
     33   // for all Browser instances. Clients should not keep the result around
     34   // for extended periods of time as tabs might get closed thus invalidating
     35   // the map.
     36   const ControllersMap& controllers_map();
     37 
     38   // Returns a DevToolsClientHostImpl for the given tab |id|.
     39   DevToolsClientHostImpl* ClientHostForTabId(int32 id);
     40 
     41   // Creates a new DevToolsClientHost implementor instance.
     42   // |id| is the UID of the tab to debug.
     43   // |service| is the DebuggerRemoteService instance the DevToolsClient
     44   //         messages shall be dispatched to.
     45   DevToolsClientHost* NewClientHost(int32 id,
     46                                     DebuggerRemoteService* service);
     47 
     48   // Gets invoked when a remote debugger is detached. In this case we should
     49   // send the corresponding message to the V8 debugger for each of the tabs
     50   // the debugger is attached to, and invoke InspectedTabClosing().
     51   void OnRemoteDebuggerDetached();
     52 
     53  private:
     54   ControllersMap controllers_map_;
     55   IdToClientHostMap id_to_client_host_map_;
     56   DISALLOW_COPY_AND_ASSIGN(InspectableTabProxy);
     57 };
     58 
     59 
     60 // An internal implementation of DevToolsClientHost that delegates
     61 // messages sent for DevToolsClient to a DebuggerShell instance.
     62 class DevToolsClientHostImpl : public DevToolsClientHost {
     63  public:
     64   DevToolsClientHostImpl(
     65     int32 id,
     66     DebuggerRemoteService* service,
     67     InspectableTabProxy::IdToClientHostMap* map);
     68   ~DevToolsClientHostImpl();
     69 
     70   DebuggerRemoteService* debugger_remote_service() {
     71     return service_;
     72   }
     73 
     74   void Close();
     75 
     76   // DevToolsClientHost interface
     77   virtual void InspectedTabClosing();
     78   virtual void SendMessageToClient(const IPC::Message& msg);
     79   virtual void TabReplaced(TabContentsWrapper* new_tab);
     80 
     81  private:
     82   // Message handling routines
     83   void OnDebuggerOutput(const std::string& msg);
     84   virtual void FrameNavigating(const std::string& url);
     85   void TabClosed();
     86 
     87   int32 id_;
     88   DebuggerRemoteService* service_;
     89   InspectableTabProxy::IdToClientHostMap* map_;
     90 };
     91 
     92 #endif  // CHROME_BROWSER_DEBUGGER_INSPECTABLE_TAB_PROXY_H_
     93