Home | History | Annotate | Download | only in browser
      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_PUBLIC_BROWSER_RENDER_FRAME_HOST_H_
      6 #define CONTENT_PUBLIC_BROWSER_RENDER_FRAME_HOST_H_
      7 
      8 #include <string>
      9 
     10 #include "base/callback_forward.h"
     11 #include "content/common/content_export.h"
     12 #include "ipc/ipc_listener.h"
     13 #include "ipc/ipc_sender.h"
     14 #include "ui/gfx/native_widget_types.h"
     15 #include "ui/gfx/rect.h"
     16 #include "url/gurl.h"
     17 
     18 namespace base {
     19 class Value;
     20 }
     21 
     22 namespace content {
     23 class RenderProcessHost;
     24 class RenderViewHost;
     25 class ServiceRegistry;
     26 class SiteInstance;
     27 
     28 // The interface provides a communication conduit with a frame in the renderer.
     29 class CONTENT_EXPORT RenderFrameHost : public IPC::Listener,
     30                                        public IPC::Sender {
     31  public:
     32   // Returns the RenderFrameHost given its ID and the ID of its render process.
     33   // Returns NULL if the IDs do not correspond to a live RenderFrameHost.
     34   static RenderFrameHost* FromID(int render_process_id, int render_frame_id);
     35 
     36   virtual ~RenderFrameHost() {}
     37 
     38   // Returns the route id for this frame.
     39   virtual int GetRoutingID() = 0;
     40 
     41   // Returns the SiteInstance grouping all RenderFrameHosts that have script
     42   // access to this RenderFrameHost, and must therefore live in the same
     43   // process.
     44   virtual SiteInstance* GetSiteInstance() = 0;
     45 
     46   // Returns the process for this frame.
     47   virtual RenderProcessHost* GetProcess() = 0;
     48 
     49   // Returns the current RenderFrameHost of the parent frame, or NULL if there
     50   // is no parent. The result may be in a different process than the current
     51   // RenderFrameHost.
     52   virtual RenderFrameHost* GetParent() = 0;
     53 
     54   // Returns the assigned name of the frame, the name of the iframe tag
     55   // declaring it. For example, <iframe name="framename">[...]</iframe>. It is
     56   // quite possible for a frame to have no name, in which case GetFrameName will
     57   // return an empty string.
     58   virtual const std::string& GetFrameName() = 0;
     59 
     60   // Returns true if the frame is out of process.
     61   virtual bool IsCrossProcessSubframe() = 0;
     62 
     63   // Returns the last committed URL of the frame.
     64   virtual GURL GetLastCommittedURL() = 0;
     65 
     66   // Returns the associated widget's native view.
     67   virtual gfx::NativeView GetNativeView() = 0;
     68 
     69   // Runs some JavaScript in this frame's context. If a callback is provided, it
     70   // will be used to return the result, when the result is available.
     71   typedef base::Callback<void(const base::Value*)> JavaScriptResultCallback;
     72   virtual void ExecuteJavaScript(const base::string16& javascript) = 0;
     73   virtual void ExecuteJavaScript(const base::string16& javascript,
     74                                  const JavaScriptResultCallback& callback) = 0;
     75 
     76   // ONLY FOR TESTS: Same as above but adds a fake UserGestureIndicator around
     77   // execution. (crbug.com/408426)
     78   virtual void ExecuteJavaScriptForTests(const base::string16& javascript) = 0;
     79 
     80   // Accessibility actions.
     81   virtual void AccessibilitySetFocus(int acc_obj_id) = 0;
     82   virtual void AccessibilityDoDefaultAction(int acc_obj_id) = 0;
     83   virtual void AccessibilityScrollToMakeVisible(
     84       int acc_obj_id, const gfx::Rect& subfocus) = 0;
     85   virtual void AccessibilitySetTextSelection(
     86       int acc_obj_id, int start_offset, int end_offset) = 0;
     87 
     88   // Temporary until we get rid of RenderViewHost.
     89   virtual RenderViewHost* GetRenderViewHost() = 0;
     90 
     91   // Returns the ServiceRegistry for this frame.
     92   virtual ServiceRegistry* GetServiceRegistry() = 0;
     93 
     94  private:
     95   // This interface should only be implemented inside content.
     96   friend class RenderFrameHostImpl;
     97   RenderFrameHost() {}
     98 };
     99 
    100 }  // namespace content
    101 
    102 #endif  // CONTENT_PUBLIC_BROWSER_RENDER_FRAME_HOST_H_
    103