browser_plugin_guest_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_PUBLIC_BROWSER_BROWSER_PLUGIN_GUEST_DELEGATE_H_ 6#define CONTENT_PUBLIC_BROWSER_BROWSER_PLUGIN_GUEST_DELEGATE_H_ 7 8#include "base/callback_forward.h" 9#include "base/process/kill.h" 10#include "base/strings/string16.h" 11#include "base/values.h" 12#include "content/common/content_export.h" 13#include "content/public/common/browser_plugin_permission_type.h" 14#include "content/public/common/media_stream_request.h" 15#include "ui/gfx/geometry/rect.h" 16#include "ui/gfx/size.h" 17#include "url/gurl.h" 18 19namespace content { 20 21class JavaScriptDialogManager; 22struct ContextMenuParams; 23struct NativeWebKeyboardEvent; 24class WebContents; 25 26// Objects implement this interface to get notified about changes in the guest 27// WebContents and to provide necessary functionality. 28class CONTENT_EXPORT BrowserPluginGuestDelegate { 29 public: 30 virtual ~BrowserPluginGuestDelegate() {} 31 32 // Add a message to the console. 33 virtual void AddMessageToConsole(int32 level, 34 const base::string16& message, 35 int32 line_no, 36 const base::string16& source_id) {} 37 38 // Request the delegate to close this guest, and do whatever cleanup it needs 39 // to do. 40 virtual void Close() {} 41 42 // Notification that the embedder has completed attachment. 43 virtual void DidAttach() {} 44 45 // Returns the opener for this guest. 46 // TODO(fsamuel): Remove this once the New Window API is migrated outside of 47 // the content layer. 48 virtual WebContents* GetOpener() const; 49 50 // Informs the delegate that the guest render process is gone. |status| 51 // indicates whether the guest was killed, crashed, or was terminated 52 // gracefully. 53 virtual void GuestProcessGone(base::TerminationStatus status) {} 54 55 // Informs the delegate that the embedder has been destroyed. 56 virtual void EmbedderDestroyed() {} 57 58 // Informs the delegate of a reply to the find request specified by 59 // |request_id|. 60 virtual void FindReply(int request_id, 61 int number_of_matches, 62 const gfx::Rect& selection_rect, 63 int active_match_ordinal, 64 bool final_update) {} 65 66 virtual bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event); 67 68 // Requests setting the zoom level to the provided |zoom_level|. 69 virtual void SetZoom(double zoom_factor) {} 70 71 virtual bool IsDragAndDropEnabled(); 72 73 // Returns whether the user agent for the guest is being overridden. 74 virtual bool IsOverridingUserAgent() const; 75 76 // Notification that a load in the guest resulted in abort. Note that |url| 77 // may be invalid. 78 virtual void LoadAbort(bool is_top_level, 79 const GURL& url, 80 const std::string& error_type) {} 81 82 // Notification that the page has made some progress loading. |progress| is a 83 // value between 0.0 (nothing loaded) and 1.0 (page loaded completely). 84 virtual void LoadProgressed(double progress) {} 85 86 // Notification that the guest is no longer hung. 87 virtual void RendererResponsive() {} 88 89 // Notification that the guest is hung. 90 virtual void RendererUnresponsive() {} 91 92 typedef base::Callback<void(bool /* allow */, 93 const std::string& /* user_input */)> 94 PermissionResponseCallback; 95 96 // Request permission from the delegate to perform an action of the provided 97 // |permission_type|. Details of the permission request are found in 98 // |request_info|. A |callback| is provided to make the decision. 99 virtual void RequestPermission( 100 BrowserPluginPermissionType permission_type, 101 const base::DictionaryValue& request_info, 102 const PermissionResponseCallback& callback, 103 bool allowed_by_default) {} 104 105 // Requests resolution of a potentially relative URL. 106 virtual GURL ResolveURL(const std::string& src); 107 108 // Informs the delegate of the WebContents that created delegate's associated 109 // WebContents. 110 // TODO(fsamuel): Remove this once the New Window API is migrated outside of 111 // the content layer. 112 virtual void SetOpener(WebContents* opener) {} 113 114 // Notifies that the content size of the guest has changed in autosize mode. 115 virtual void SizeChanged(const gfx::Size& old_size, 116 const gfx::Size& new_size) {} 117 118 // Asks permission to use the camera and/or microphone. If permission is 119 // granted, a call should be made to |callback| with the devices. If the 120 // request is denied, a call should be made to |callback| with an empty list 121 // of devices. |request| has the details of the request (e.g. which of audio 122 // and/or video devices are requested, and lists of available devices). 123 virtual void RequestMediaAccessPermission( 124 const MediaStreamRequest& request, 125 const MediaResponseCallback& callback); 126 127 // Asks the delegate if the given guest can download. 128 // Invoking the |callback| synchronously is OK. 129 virtual void CanDownload(const std::string& request_method, 130 const GURL& url, 131 const base::Callback<void(bool)>& callback); 132 133 // Asks the delegate if the given guest can lock the pointer. 134 // Invoking the |callback| synchronously is OK. 135 virtual void RequestPointerLockPermission( 136 bool user_gesture, 137 bool last_unlocked_by_target, 138 const base::Callback<void(bool)>& callback) {} 139 140 // Returns a pointer to a service to manage JavaScript dialogs. May return 141 // NULL in which case dialogs aren't shown. 142 virtual JavaScriptDialogManager* GetJavaScriptDialogManager(); 143 144 // Returns true if the context menu operation was handled by the delegate. 145 virtual bool HandleContextMenu(const ContextMenuParams& params); 146}; 147 148} // namespace content 149 150#endif // CONTENT_PUBLIC_BROWSER_BROWSER_PLUGIN_GUEST_DELEGATE_H_ 151