render_frame_host_delegate.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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 22class GURL; 23 24namespace IPC { 25class Message; 26} 27 28namespace content { 29class RenderFrameHost; 30class WebContents; 31struct AXEventNotificationDetails; 32struct ContextMenuParams; 33 34// An interface implemented by an object interested in knowing about the state 35// of the RenderFrameHost. 36class CONTENT_EXPORT RenderFrameHostDelegate { 37 public: 38 // This is used to give the delegate a chance to filter IPC messages. 39 virtual bool OnMessageReceived(RenderFrameHost* render_frame_host, 40 const IPC::Message& message); 41 42 // Gets the last committed URL. See WebContents::GetLastCommittedURL for a 43 // description of the semantics. 44 virtual const GURL& GetMainFrameLastCommittedURL() const; 45 46 // A message was added to to the console. 47 virtual bool AddMessageToConsole(int32 level, 48 const base::string16& message, 49 int32 line_no, 50 const base::string16& source_id); 51 52 // Informs the delegate whenever a RenderFrameHost is created. 53 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {} 54 55 // Informs the delegate whenever a RenderFrameHost is deleted. 56 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {} 57 58 // The top-level RenderFrame began loading a new page. This corresponds to 59 // Blink's notion of the throbber starting. 60 // |to_different_document| will be true unless the load is a fragment 61 // navigation, or triggered by history.pushState/replaceState. 62 virtual void DidStartLoading(RenderFrameHost* render_frame_host, 63 bool to_different_document) {} 64 65 // The RenderFrameHost has been swapped out. 66 virtual void SwappedOut(RenderFrameHost* render_frame_host) {} 67 68 // Notification that the navigation on the main frame is blocked waiting 69 // for transition to occur. 70 virtual void DidDeferAfterResponseStarted( 71 const scoped_refptr<net::HttpResponseHeaders>& headers, 72 const GURL& url) {} 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 // Get the accessibility mode for the WebContents that owns this frame. 134 virtual AccessibilityMode GetAccessibilityMode() const; 135 136 // Invoked when an accessibility event is received from the renderer. 137 virtual void AccessibilityEventReceived( 138 const std::vector<AXEventNotificationDetails>& details) {} 139 140#if defined(OS_WIN) 141 // Returns the frame's parent's NativeViewAccessible. 142 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible(); 143#endif 144 145 protected: 146 virtual ~RenderFrameHostDelegate() {} 147}; 148 149} // namespace content 150 151#endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_ 152