Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / devtools / devtools_window.h
index bd05a27..aa526b5 100644 (file)
@@ -9,10 +9,11 @@
 #include "chrome/browser/devtools/devtools_toggle_action.h"
 #include "chrome/browser/devtools/devtools_ui_bindings.h"
 #include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/web_contents_observer.h"
 
 class Browser;
 class BrowserWindow;
-class DevToolsControllerTest;
+class DevToolsWindowTesting;
 class DevToolsEventForwarder;
 
 namespace content {
@@ -28,18 +29,22 @@ class PrefRegistrySyncable;
 class DevToolsWindow : public DevToolsUIBindings::Delegate,
                        public content::WebContentsDelegate {
  public:
+  class ObserverWithAccessor : public content::WebContentsObserver {
+   public:
+    explicit ObserverWithAccessor(content::WebContents* web_contents);
+    virtual ~ObserverWithAccessor();
+    content::WebContents* GetWebContents();
+
+   private:
+    DISALLOW_COPY_AND_ASSIGN(ObserverWithAccessor);
+  };
+
   static const char kDevToolsApp[];
 
   virtual ~DevToolsWindow();
 
-  static std::string GetDevToolsWindowPlacementPrefKey();
   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
 
-  // Return the DevToolsWindow for the given RenderViewHost if one exists,
-  // otherwise NULL.
-  static DevToolsWindow* GetInstanceForInspectedRenderViewHost(
-      content::RenderViewHost* inspected_rvh);
-
   // Return the DevToolsWindow for the given WebContents if one exists,
   // otherwise NULL.
   static DevToolsWindow* GetInstanceForInspectedWebContents(
@@ -56,21 +61,16 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
       content::WebContents* inspected_tab,
       DevToolsContentsResizingStrategy* out_strategy);
 
-  static bool IsDevToolsWindow(content::RenderViewHost* window_rvh);
+  static bool IsDevToolsWindow(content::WebContents* web_contents);
 
   // Open or reveal DevTools window, and perform the specified action.
   static DevToolsWindow* OpenDevToolsWindow(
-      content::RenderViewHost* inspected_rvh,
+      content::WebContents* inspected_web_contents,
       const DevToolsToggleAction& action);
 
   // Open or reveal DevTools window, with no special action.
   static DevToolsWindow* OpenDevToolsWindow(
-      content::RenderViewHost* inspected_rvh);
-
-  static DevToolsWindow* OpenDevToolsWindowForTest(
-      content::RenderViewHost* inspected_rvh, bool is_docked);
-  static DevToolsWindow* OpenDevToolsWindowForTest(
-      Browser* browser, bool is_docked);
+      content::WebContents* inspected_web_contents);
 
   // Perform specified action for current WebContents inside a |browser|.
   // This may close currently open DevTools window.
@@ -89,11 +89,9 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
       Profile* profile,
       content::DevToolsAgentHost* worker_agent);
 
-  static void InspectElement(
-      content::RenderViewHost* inspected_rvh, int x, int y);
-
-  Browser* browser_for_test() { return browser_; }
-  content::WebContents* web_contents_for_test() { return main_web_contents_; }
+  static void InspectElement(content::WebContents* inspected_web_contents,
+                             int x,
+                             int y);
 
   // Sets closure to be called after load is done. If already loaded, calls
   // closure immediately.
@@ -177,11 +175,9 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
   static void OnPageCloseCanceled(content::WebContents* contents);
 
  private:
-  friend class DevToolsControllerTest;
-  friend class DevToolsSanityTest;
-  friend class BrowserWindowControllerTest;
+  friend class DevToolsWindowTesting;
 
-  // DevTools initialization typically follows this way:
+  // DevTools lifecycle typically follows this way:
   // - Toggle/Open: client call;
   // - Create;
   // - ScheduleShow: setup window to be functional, but not yet show;
@@ -189,39 +185,47 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
   // - SetIsDocked: frontend decided on docking state;
   // - OnLoadCompleted: ready to present frontend;
   // - Show: actually placing frontend WebContents to a Browser or docked place;
-  // - DoAction: perform action passed in Toggle/Open.
-  enum LoadState {
+  // - DoAction: perform action passed in Toggle/Open;
+  // - ...;
+  // - CloseWindow: initiates before unload handling;
+  // - CloseContents: destroys frontend;
+  // - DevToolsWindow is dead once it's main_web_contents dies.
+  enum LifeStage {
     kNotLoaded,
     kOnLoadFired, // Implies SetIsDocked was not yet called.
     kIsDockedSet, // Implies DocumentOnLoadCompleted was not yet called.
-    kLoadCompleted
+    kLoadCompleted,
+    kClosing
   };
 
   DevToolsWindow(Profile* profile,
                  const GURL& frontend_url,
-                 content::RenderViewHost* inspected_rvh,
+                 content::WebContents* inspected_web_contents,
                  bool can_dock);
 
   static DevToolsWindow* Create(Profile* profile,
                                 const GURL& frontend_url,
-                                content::RenderViewHost* inspected_rvh,
+                                content::WebContents* inspected_web_contents,
                                 bool shared_worker_frontend,
                                 bool external_frontend,
-                                bool can_dock);
+                                bool can_dock,
+                                const std::string& settings);
   static GURL GetDevToolsURL(Profile* profile,
                              const GURL& base_url,
                              bool shared_worker_frontend,
                              bool external_frontend,
-                             bool can_dock);
+                             bool can_dock,
+                             const std::string& settings);
   static DevToolsWindow* FindDevToolsWindow(content::DevToolsAgentHost*);
-  static DevToolsWindow* AsDevToolsWindow(content::RenderViewHost*);
+  static DevToolsWindow* AsDevToolsWindow(content::WebContents*);
   static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile);
-  static bool FindInspectedBrowserAndTabIndex(
-      content::WebContents* inspected_web_contents, Browser**, int* tab);
   static DevToolsWindow* ToggleDevToolsWindow(
-      content::RenderViewHost* inspected_rvh,
+      content::WebContents* web_contents,
       bool force_open,
-      const DevToolsToggleAction& action);
+      const DevToolsToggleAction& action,
+      const std::string& settings);
+
+  static std::string GetDevToolsWindowPlacementPrefKey();
 
   // content::WebContentsDelegate:
   virtual content::WebContents* OpenURLFromTab(
@@ -269,8 +273,6 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
   virtual void ActivateWindow() OVERRIDE;
   virtual void CloseWindow() OVERRIDE;
   virtual void SetInspectedPageBounds(const gfx::Rect& rect) OVERRIDE;
-  virtual void SetContentsResizingStrategy(
-      const gfx::Insets& insets, const gfx::Size& min_size) OVERRIDE;
   virtual void InspectElementCompleted() OVERRIDE;
   virtual void MoveWindow(int x, int y) OVERRIDE;
   virtual void SetIsDocked(bool is_docked) OVERRIDE;
@@ -287,13 +289,11 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
   void Show(const DevToolsToggleAction& action);
   void DoAction(const DevToolsToggleAction& action);
   void LoadCompleted();
-  void SetIsDockedAndShowImmediatelyForTest(bool is_docked);
   void UpdateBrowserToolbar();
   void UpdateBrowserWindow();
   content::WebContents* GetInspectedWebContents();
 
-  class InspectedWebContentsObserver;
-  scoped_ptr<InspectedWebContentsObserver> inspected_contents_observer_;
+  scoped_ptr<ObserverWithAccessor> inspected_contents_observer_;
 
   Profile* profile_;
   content::WebContents* main_web_contents_;
@@ -302,14 +302,14 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
   Browser* browser_;
   bool is_docked_;
   const bool can_dock_;
-  LoadState load_state_;
+  LifeStage life_stage_;
   DevToolsToggleAction action_on_load_;
-  bool ignore_set_is_docked_;
   DevToolsContentsResizingStrategy contents_resizing_strategy_;
   // True if we're in the process of handling a beforeunload event originating
   // from the inspected webcontents, see InterceptPageBeforeUnload for details.
   bool intercepted_page_beforeunload_;
   base::Closure load_completed_callback_;
+  base::Closure close_callback_;
 
   base::TimeTicks inspect_element_start_time_;
   scoped_ptr<DevToolsEventForwarder> event_forwarder_;