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_RENDER_FRAME_HOST_DELEGATE_H_
      6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/i18n/rtl.h"
     12 #include "content/common/content_export.h"
     13 #include "content/common/frame_message_enums.h"
     14 #include "content/public/common/javascript_message_type.h"
     15 #include "content/public/common/media_stream_request.h"
     16 #include "net/http/http_response_headers.h"
     17 
     18 #if defined(OS_WIN)
     19 #include "ui/gfx/native_widget_types.h"
     20 #endif
     21 
     22 class GURL;
     23 
     24 namespace IPC {
     25 class Message;
     26 }
     27 
     28 namespace content {
     29 class RenderFrameHost;
     30 class WebContents;
     31 struct AXEventNotificationDetails;
     32 struct ContextMenuParams;
     33 struct TransitionLayerData;
     34 
     35 // An interface implemented by an object interested in knowing about the state
     36 // of the RenderFrameHost.
     37 class CONTENT_EXPORT RenderFrameHostDelegate {
     38  public:
     39   // This is used to give the delegate a chance to filter IPC messages.
     40   virtual bool OnMessageReceived(RenderFrameHost* render_frame_host,
     41                                  const IPC::Message& message);
     42 
     43   // Gets the last committed URL. See WebContents::GetLastCommittedURL for a
     44   // description of the semantics.
     45   virtual const GURL& GetMainFrameLastCommittedURL() const;
     46 
     47   // A message was added to to the console.
     48   virtual bool AddMessageToConsole(int32 level,
     49                                    const base::string16& message,
     50                                    int32 line_no,
     51                                    const base::string16& source_id);
     52 
     53   // Informs the delegate whenever a RenderFrameHost is created.
     54   virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {}
     55 
     56   // Informs the delegate whenever a RenderFrameHost is deleted.
     57   virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {}
     58 
     59   // The top-level RenderFrame began loading a new page. This corresponds to
     60   // Blink's notion of the throbber starting.
     61   // |to_different_document| will be true unless the load is a fragment
     62   // navigation, or triggered by history.pushState/replaceState.
     63   virtual void DidStartLoading(RenderFrameHost* render_frame_host,
     64                                bool to_different_document) {}
     65 
     66   // The RenderFrameHost has been swapped out.
     67   virtual void SwappedOut(RenderFrameHost* render_frame_host) {}
     68 
     69   // Notification that the navigation on the main frame is blocked waiting
     70   // for transition to occur.
     71   virtual void DidDeferAfterResponseStarted(
     72       const TransitionLayerData& transition_data) {}
     73 
     74   // Used to query whether the navigation transition will be handled.
     75   virtual bool WillHandleDeferAfterResponseStarted();
     76 
     77   // Notification that a worker process has crashed.
     78   virtual void WorkerCrashed(RenderFrameHost* render_frame_host) {}
     79 
     80   // A context menu should be shown, to be built using the context information
     81   // provided in the supplied params.
     82   virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
     83                                const ContextMenuParams& params) {}
     84 
     85   // A JavaScript message, confirmation or prompt should be shown.
     86   virtual void RunJavaScriptMessage(RenderFrameHost* render_frame_host,
     87                                     const base::string16& message,
     88                                     const base::string16& default_prompt,
     89                                     const GURL& frame_url,
     90                                     JavaScriptMessageType type,
     91                                     IPC::Message* reply_msg) {}
     92 
     93   virtual void RunBeforeUnloadConfirm(RenderFrameHost* render_frame_host,
     94                                       const base::string16& message,
     95                                       bool is_reload,
     96                                       IPC::Message* reply_msg) {}
     97 
     98   // Another page accessed the top-level initial empty document, which means it
     99   // is no longer safe to display a pending URL without risking a URL spoof.
    100   virtual void DidAccessInitialDocument() {}
    101 
    102   // The frame set its opener to null, disowning it for the lifetime of the
    103   // window. Only called for the top-level frame.
    104   virtual void DidDisownOpener(RenderFrameHost* render_frame_host) {}
    105 
    106   // The onload handler in the frame has completed. Only called for the top-
    107   // level frame.
    108   virtual void DocumentOnLoadCompleted(RenderFrameHost* render_frame_host) {}
    109 
    110   // The page's title was changed and should be updated. Only called for the
    111   // top-level frame.
    112   virtual void UpdateTitle(RenderFrameHost* render_frame_host,
    113                            int32 page_id,
    114                            const base::string16& title,
    115                            base::i18n::TextDirection title_direction) {}
    116 
    117   // The page's encoding was changed and should be updated. Only called for the
    118   // top-level frame.
    119   virtual void UpdateEncoding(RenderFrameHost* render_frame_host,
    120                               const std::string& encoding) {}
    121 
    122   // Return this object cast to a WebContents, if it is one. If the object is
    123   // not a WebContents, returns NULL.
    124   virtual WebContents* GetAsWebContents();
    125 
    126   // The render frame has requested access to media devices listed in
    127   // |request|, and the client should grant or deny that permission by
    128   // calling |callback|.
    129   virtual void RequestMediaAccessPermission(
    130       const MediaStreamRequest& request,
    131       const MediaResponseCallback& callback);
    132 
    133   // Checks if we have permission to access the microphone or camera. Note that
    134   // this does not query the user. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE
    135   // or MEDIA_DEVICE_VIDEO_CAPTURE.
    136   virtual bool CheckMediaAccessPermission(const GURL& security_origin,
    137                                           MediaStreamType type);
    138 
    139   // Get the accessibility mode for the WebContents that owns this frame.
    140   virtual AccessibilityMode GetAccessibilityMode() const;
    141 
    142   // Invoked when an accessibility event is received from the renderer.
    143   virtual void AccessibilityEventReceived(
    144       const std::vector<AXEventNotificationDetails>& details) {}
    145 
    146   // Find a guest RenderFrameHost by its browser plugin instance id.
    147   virtual RenderFrameHost* GetGuestByInstanceID(
    148       int browser_plugin_instance_id);
    149 
    150 #if defined(OS_WIN)
    151   // Returns the frame's parent's NativeViewAccessible.
    152   virtual gfx::NativeViewAccessible GetParentNativeViewAccessible();
    153 #endif
    154 
    155  protected:
    156   virtual ~RenderFrameHostDelegate() {}
    157 };
    158 
    159 }  // namespace content
    160 
    161 #endif  // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_
    162