render_frame_host_delegate.h revision 010d83a9304c5a91596085d917d248abff47903a
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 "base/basictypes.h" 9#include "content/common/content_export.h" 10#include "content/public/common/javascript_message_type.h" 11 12class GURL; 13 14namespace IPC { 15class Message; 16} 17 18namespace content { 19class RenderFrameHost; 20class WebContents; 21struct ContextMenuParams; 22 23// An interface implemented by an object interested in knowing about the state 24// of the RenderFrameHost. 25class CONTENT_EXPORT RenderFrameHostDelegate { 26 public: 27 // This is used to give the delegate a chance to filter IPC messages. 28 virtual bool OnMessageReceived(RenderFrameHost* render_frame_host, 29 const IPC::Message& message); 30 31 // Gets the last committed URL. See WebContents::GetLastCommittedURL for a 32 // description of the semantics. 33 virtual const GURL& GetMainFrameLastCommittedURL() const; 34 35 // A message was added to to the console. 36 virtual bool AddMessageToConsole(int32 level, 37 const base::string16& message, 38 int32 line_no, 39 const base::string16& source_id); 40 41 // Informs the delegate whenever a RenderFrameHost is created. 42 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {} 43 44 // Informs the delegate whenever a RenderFrameHost is deleted. 45 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {} 46 47 // The top-level RenderFrame began loading a new page. This corresponds to 48 // Blink's notion of the throbber starting. 49 // |to_different_document| will be true unless the load is a fragment 50 // navigation, or triggered by history.pushState/replaceState. 51 virtual void DidStartLoading(RenderFrameHost* render_frame_host, 52 bool to_different_document) {} 53 54 // The top-level RenderFrame stopped loading a page. This corresponds to 55 // Blink's notion of the throbber stopping. 56 virtual void DidStopLoading(RenderFrameHost* render_frame_host) {} 57 58 // The RenderFrameHost has been swapped out. 59 virtual void SwappedOut(RenderFrameHost* render_frame_host) {} 60 61 // Notification that a worker process has crashed. 62 virtual void WorkerCrashed(RenderFrameHost* render_frame_host) {} 63 64 // A context menu should be shown, to be built using the context information 65 // provided in the supplied params. 66 virtual void ShowContextMenu(RenderFrameHost* render_frame_host, 67 const ContextMenuParams& params) {} 68 69 // A JavaScript message, confirmation or prompt should be shown. 70 virtual void RunJavaScriptMessage(RenderFrameHost* render_frame_host, 71 const base::string16& message, 72 const base::string16& default_prompt, 73 const GURL& frame_url, 74 JavaScriptMessageType type, 75 IPC::Message* reply_msg) {} 76 77 virtual void RunBeforeUnloadConfirm(RenderFrameHost* render_frame_host, 78 const base::string16& message, 79 bool is_reload, 80 IPC::Message* reply_msg) {} 81 82 // Another page accessed the top-level initial empty document, which means it 83 // is no longer safe to display a pending URL without risking a URL spoof. 84 virtual void DidAccessInitialDocument() {} 85 86 // The frame set its opener to null, disowning it for the lifetime of the 87 // window. Only called for the top-level frame. 88 virtual void DidDisownOpener(RenderFrameHost* render_frame_host) {} 89 90 // The onload handler in the frame has completed. Only called for the top- 91 // level frame. 92 virtual void DocumentOnLoadCompleted(RenderFrameHost* render_frame_host) {} 93 94 // Return this object cast to a WebContents, if it is one. If the object is 95 // not a WebContents, returns NULL. 96 virtual WebContents* GetAsWebContents(); 97 98 protected: 99 virtual ~RenderFrameHostDelegate() {} 100}; 101 102} // namespace content 103 104#endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_ 105