Home | History | Annotate | Download | only in debugger
      1 // Copyright (c) 2011 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_DEVTOOLS_WINDOW_H_
      6 #define CHROME_BROWSER_DEBUGGER_DEVTOOLS_WINDOW_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "chrome/browser/debugger/devtools_client_host.h"
     13 #include "chrome/browser/debugger/devtools_toggle_action.h"
     14 #include "content/browser/tab_contents/tab_contents_delegate.h"
     15 #include "content/common/notification_observer.h"
     16 #include "content/common/notification_registrar.h"
     17 
     18 namespace IPC {
     19 class Message;
     20 }
     21 
     22 class Browser;
     23 class BrowserWindow;
     24 class Profile;
     25 class RenderViewHost;
     26 class Value;
     27 
     28 class DevToolsWindow
     29     : public DevToolsClientHost,
     30       public NotificationObserver,
     31       public TabContentsDelegate {
     32  public:
     33   static const char kDevToolsApp[];
     34   static TabContentsWrapper* GetDevToolsContents(TabContents* inspected_tab);
     35 
     36   DevToolsWindow(Profile* profile, RenderViewHost* inspected_rvh, bool docked);
     37   virtual ~DevToolsWindow();
     38 
     39   // Overridden from DevToolsClientHost.
     40   virtual DevToolsWindow* AsDevToolsWindow();
     41   virtual void SendMessageToClient(const IPC::Message& message);
     42   virtual void InspectedTabClosing();
     43   virtual void TabReplaced(TabContentsWrapper* new_tab);
     44 
     45   void Show(DevToolsToggleAction action);
     46   void Activate();
     47   void SetDocked(bool docked);
     48   RenderViewHost* GetRenderViewHost();
     49 
     50   TabContentsWrapper* tab_contents() { return tab_contents_; }
     51   Browser* browser() { return browser_; }  // For tests.
     52   bool is_docked() { return docked_; }
     53 
     54  private:
     55   void CreateDevToolsBrowser();
     56   bool FindInspectedBrowserAndTabIndex(Browser**, int* tab);
     57   BrowserWindow* GetInspectedBrowserWindow();
     58   bool IsInspectedBrowserPopup();
     59   void UpdateFrontendAttachedState();
     60 
     61   // Overridden from NotificationObserver.
     62   virtual void Observe(NotificationType type,
     63                        const NotificationSource& source,
     64                        const NotificationDetails& details);
     65 
     66   void ScheduleAction(DevToolsToggleAction action);
     67   void DoAction();
     68   GURL GetDevToolsUrl();
     69   void UpdateTheme();
     70   void AddDevToolsExtensionsToClient();
     71   void CallClientFunction(const string16& function_name,
     72                           const Value& arg);
     73   // Overridden from TabContentsDelegate.
     74   virtual void OpenURLFromTab(TabContents* source,
     75                               const GURL& url,
     76                               const GURL& referrer,
     77                               WindowOpenDisposition disposition,
     78                               PageTransition::Type transition);
     79   virtual void NavigationStateChanged(const TabContents* source,
     80                                       unsigned changed_flags) {}
     81   virtual void AddNewContents(TabContents* source,
     82                               TabContents* new_contents,
     83                               WindowOpenDisposition disposition,
     84                               const gfx::Rect& initial_pos,
     85                               bool user_gesture);
     86   virtual void ActivateContents(TabContents* contents) {}
     87   virtual void DeactivateContents(TabContents* contents) {}
     88   virtual void LoadingStateChanged(TabContents* source) {}
     89   virtual void CloseContents(TabContents* source) {}
     90   virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {}
     91   virtual bool CanReloadContents(TabContents* source) const;
     92   virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
     93   virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
     94                                       bool* is_keyboard_shortcut);
     95   virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
     96 
     97   virtual void FrameNavigating(const std::string& url) {}
     98 
     99   Profile* profile_;
    100   TabContents* inspected_tab_;
    101   TabContentsWrapper* tab_contents_;
    102   Browser* browser_;
    103   bool docked_;
    104   bool is_loaded_;
    105   DevToolsToggleAction action_on_load_;
    106   NotificationRegistrar registrar_;
    107   DISALLOW_COPY_AND_ASSIGN(DevToolsWindow);
    108 };
    109 
    110 #endif  // CHROME_BROWSER_DEBUGGER_DEVTOOLS_WINDOW_H_
    111