Home | History | Annotate | Download | only in frame_host
      1 // Copyright 2013 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 CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_
      6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/memory/ref_counted.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "base/memory/scoped_vector.h"
     14 #include "content/browser/frame_host/render_frame_host_impl.h"
     15 #include "content/browser/frame_host/render_frame_host_manager.h"
     16 #include "content/common/content_export.h"
     17 #include "url/gurl.h"
     18 
     19 namespace content {
     20 
     21 class FrameTree;
     22 class Navigator;
     23 class RenderFrameHostImpl;
     24 
     25 // When a page contains iframes, its renderer process maintains a tree structure
     26 // of those frames. We are mirroring this tree in the browser process. This
     27 // class represents a node in this tree and is a wrapper for all objects that
     28 // are frame-specific (as opposed to page-specific).
     29 class CONTENT_EXPORT FrameTreeNode {
     30  public:
     31 
     32   FrameTreeNode(FrameTree* frame_tree,
     33                 Navigator* navigator,
     34                 RenderFrameHostDelegate* render_frame_delegate,
     35                 RenderViewHostDelegate* render_view_delegate,
     36                 RenderWidgetHostDelegate* render_widget_delegate,
     37                 RenderFrameHostManager::Delegate* manager_delegate,
     38                 const std::string& name);
     39 
     40   ~FrameTreeNode();
     41 
     42   bool IsMainFrame() const;
     43 
     44   void AddChild(scoped_ptr<FrameTreeNode> child, int frame_routing_id);
     45   void RemoveChild(FrameTreeNode* child);
     46 
     47   // Clears process specific-state in this node to prepare for a new process.
     48   void ResetForNewProcess();
     49 
     50   FrameTree* frame_tree() const {
     51     return frame_tree_;
     52   }
     53 
     54   Navigator* navigator() {
     55     return navigator_.get();
     56   }
     57 
     58   RenderFrameHostManager* render_manager() {
     59     return &render_manager_;
     60   }
     61 
     62   int64 frame_tree_node_id() const {
     63     return frame_tree_node_id_;
     64   }
     65 
     66   const std::string& frame_name() const {
     67     return frame_name_;
     68   }
     69 
     70   size_t child_count() const {
     71     return children_.size();
     72   }
     73 
     74   FrameTreeNode* parent() const { return parent_; }
     75 
     76   FrameTreeNode* child_at(size_t index) const {
     77     return children_[index];
     78   }
     79 
     80   const GURL& current_url() const {
     81     return current_url_;
     82   }
     83 
     84   void set_current_url(const GURL& url) {
     85     current_url_ = url;
     86   }
     87 
     88   RenderFrameHostImpl* current_frame_host() const {
     89     return render_manager_.current_frame_host();
     90   }
     91 
     92  private:
     93   void set_parent(FrameTreeNode* parent) { parent_ = parent; }
     94 
     95   // The next available browser-global FrameTreeNode ID.
     96   static int64 next_frame_tree_node_id_;
     97 
     98   // The FrameTree that owns us.
     99   FrameTree* frame_tree_;  // not owned.
    100 
    101   // The Navigator object responsible for managing navigations at this node
    102   // of the frame tree.
    103   scoped_refptr<Navigator> navigator_;
    104 
    105   // Manages creation and swapping of RenderFrameHosts for this frame.  This
    106   // must be declared before |children_| so that it gets deleted after them.
    107   //  That's currently necessary so that RenderFrameHostImpl's destructor can
    108   // call GetProcess.
    109   RenderFrameHostManager render_manager_;
    110 
    111   // A browser-global identifier for the frame in the page, which stays stable
    112   // even if the frame does a cross-process navigation.
    113   const int64 frame_tree_node_id_;
    114 
    115   // The assigned name of the frame. This name can be empty, unlike the unique
    116   // name generated internally in the DOM tree.
    117   std::string frame_name_;
    118 
    119   // The parent node of this frame. NULL if this node is the root or if it has
    120   // not yet been attached to the frame tree.
    121   FrameTreeNode* parent_;
    122 
    123   // The immediate children of this specific frame.
    124   ScopedVector<FrameTreeNode> children_;
    125 
    126   // Track the current frame's last committed URL, so we can estimate the
    127   // process impact of out-of-process iframes.
    128   // TODO(creis): Remove this when we can store subframe URLs in the
    129   // NavigationController.
    130   GURL current_url_;
    131 
    132   DISALLOW_COPY_AND_ASSIGN(FrameTreeNode);
    133 };
    134 
    135 }  // namespace content
    136 
    137 #endif  // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_
    138