// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ #include #include #include #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "content/browser/frame_host/render_frame_host_impl.h" #include "content/browser/frame_host/render_frame_host_manager.h" #include "content/common/content_export.h" #include "content/common/frame_replication_state.h" #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" #include "url/gurl.h" #include "url/origin.h" namespace content { class FrameTree; class NavigationRequest; class Navigator; class RenderFrameHostImpl; // When a page contains iframes, its renderer process maintains a tree structure // of those frames. We are mirroring this tree in the browser process. This // class represents a node in this tree and is a wrapper for all objects that // are frame-specific (as opposed to page-specific). class CONTENT_EXPORT FrameTreeNode { public: class Observer { public: // Invoked when a FrameTreeNode is being destroyed. virtual void OnFrameTreeNodeDestroyed(FrameTreeNode* node) {} // Invoked when a FrameTreeNode becomes focused. virtual void OnFrameTreeNodeFocused(FrameTreeNode* node) {} virtual ~Observer() {} }; static const int kFrameTreeNodeInvalidId = -1; // Returns the FrameTreeNode with the given global |frame_tree_node_id|, // regardless of which FrameTree it is in. static FrameTreeNode* GloballyFindByID(int frame_tree_node_id); // Callers are are expected to initialize sandbox flags separately after // calling the constructor. FrameTreeNode(FrameTree* frame_tree, Navigator* navigator, RenderFrameHostDelegate* render_frame_delegate, RenderViewHostDelegate* render_view_delegate, RenderWidgetHostDelegate* render_widget_delegate, RenderFrameHostManager::Delegate* manager_delegate, blink::WebTreeScopeType scope, const std::string& name, const std::string& unique_name, const blink::WebFrameOwnerProperties& frame_owner_properties); ~FrameTreeNode(); void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); bool IsMainFrame() const; FrameTreeNode* AddChild(scoped_ptr child, int process_id, int frame_routing_id); void RemoveChild(FrameTreeNode* child); // Clears process specific-state in this node to prepare for a new process. void ResetForNewProcess(); FrameTree* frame_tree() const { return frame_tree_; } Navigator* navigator() { return navigator_.get(); } RenderFrameHostManager* render_manager() { return &render_manager_; } int frame_tree_node_id() const { return frame_tree_node_id_; } const std::string& frame_name() const { return replication_state_.name; } const url::Origin& frame_origin() const { return replication_state_.origin; } size_t child_count() const { return children_.size(); } FrameTreeNode* parent() const { return parent_; } FrameTreeNode* opener() const { return opener_; } // Assigns a new opener for this node and, if |opener| is non-null, registers // an observer that will clear this node's opener if |opener| is ever // destroyed. void SetOpener(FrameTreeNode* opener); FrameTreeNode* child_at(size_t index) const { return children_[index].get(); } // Returns the URL of the last committed page in the current frame. const GURL& current_url() const { return current_frame_host()->last_committed_url(); } // Sets the last committed URL for this frame and updates // has_committed_real_load accordingly. void SetCurrentURL(const GURL& url); // Returns true iff SetCurrentURL has been called with a non-blank URL. bool has_committed_real_load() const { return has_committed_real_load_; } // Returns the origin of the last committed page in this frame. const url::Origin& current_origin() const { return replication_state_.origin; } // Set the current origin and notify proxies about the update. void SetCurrentOrigin(const url::Origin& origin, bool is_potentially_trustworthy_unique_origin); // Set the current name and notify proxies about the update. void SetFrameName(const std::string& name, const std::string& unique_name); // Sets the current enforcement of strict mixed content checking and // notifies proxies about the update. void SetEnforceStrictMixedContentChecking(bool should_enforce); // Returns the currently active sandbox flags for this frame. This includes // flags inherited from parent frames and the currently active flags from the //