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