1 // Copyright (c) 2011 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 CHROME_BROWSER_NOTIFICATIONS_BALLOON_HOST_H_ 6 #define CHROME_BROWSER_NOTIFICATIONS_BALLOON_HOST_H_ 7 #pragma once 8 9 #include <string> 10 #include <vector> 11 12 #include "base/scoped_ptr.h" 13 #include "chrome/browser/extensions/extension_function_dispatcher.h" 14 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" 15 #include "content/browser/renderer_host/render_view_host_delegate.h" 16 #include "content/common/notification_observer.h" 17 #include "content/common/notification_registrar.h" 18 19 class Balloon; 20 class Browser; 21 class Profile; 22 class SiteInstance; 23 struct RendererPreferences; 24 struct WebPreferences; 25 26 class BalloonHost : public RenderViewHostDelegate, 27 public RenderViewHostDelegate::View, 28 public ExtensionFunctionDispatcher::Delegate, 29 public NotificationObserver { 30 public: 31 explicit BalloonHost(Balloon* balloon); 32 33 // Initialize the view. 34 void Init(); 35 36 // Stops showing the balloon. 37 void Shutdown(); 38 39 // ExtensionFunctionDispatcher::Delegate overrides. 40 virtual Browser* GetBrowser(); 41 virtual gfx::NativeView GetNativeViewOfHost(); 42 virtual TabContents* associated_tab_contents() const; 43 render_view_host()44 RenderViewHost* render_view_host() const { return render_view_host_; } 45 46 const string16& GetSource() const; 47 48 // RenderViewHostDelegate overrides. 49 virtual WebPreferences GetWebkitPrefs(); 50 virtual SiteInstance* GetSiteInstance() const; 51 virtual Profile* GetProfile() const; 52 virtual const GURL& GetURL() const; 53 virtual void Close(RenderViewHost* render_view_host); 54 virtual void RenderViewCreated(RenderViewHost* render_view_host); 55 virtual void RenderViewReady(RenderViewHost* render_view_host); 56 virtual void RenderViewGone(RenderViewHost* render_view_host, 57 base::TerminationStatus status, 58 int error_code); UpdateTitle(RenderViewHost * render_view_host,int32 page_id,const std::wstring & title)59 virtual void UpdateTitle(RenderViewHost* render_view_host, 60 int32 page_id, const std::wstring& title) {} 61 virtual int GetBrowserWindowID() const; 62 virtual ViewType::Type GetRenderViewType() const; 63 virtual RenderViewHostDelegate::View* GetViewDelegate(); 64 virtual void ProcessWebUIMessage( 65 const ExtensionHostMsg_DomMessage_Params& params); 66 67 // NotificationObserver override. 68 virtual void Observe(NotificationType type, 69 const NotificationSource& source, 70 const NotificationDetails& details); 71 72 73 // RenderViewHostDelegate::View methods. Only the ones for opening new 74 // windows are currently implemented. 75 virtual void CreateNewWindow( 76 int route_id, 77 const ViewHostMsg_CreateWindow_Params& params); CreateNewWidget(int route_id,WebKit::WebPopupType popup_type)78 virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type) {} CreateNewFullscreenWidget(int route_id)79 virtual void CreateNewFullscreenWidget(int route_id) {} 80 virtual void ShowCreatedWindow(int route_id, 81 WindowOpenDisposition disposition, 82 const gfx::Rect& initial_pos, 83 bool user_gesture); ShowCreatedWidget(int route_id,const gfx::Rect & initial_pos)84 virtual void ShowCreatedWidget(int route_id, 85 const gfx::Rect& initial_pos) {} ShowCreatedFullscreenWidget(int route_id)86 virtual void ShowCreatedFullscreenWidget(int route_id) {} ShowContextMenu(const ContextMenuParams & params)87 virtual void ShowContextMenu(const ContextMenuParams& params) {} ShowPopupMenu(const gfx::Rect & bounds,int item_height,double item_font_size,int selected_item,const std::vector<WebMenuItem> & items,bool right_aligned)88 virtual void ShowPopupMenu(const gfx::Rect& bounds, 89 int item_height, 90 double item_font_size, 91 int selected_item, 92 const std::vector<WebMenuItem>& items, 93 bool right_aligned) {} StartDragging(const WebDropData & drop_data,WebKit::WebDragOperationsMask allowed_ops)94 virtual void StartDragging(const WebDropData& drop_data, 95 WebKit::WebDragOperationsMask allowed_ops) {} StartDragging(const WebDropData &,WebKit::WebDragOperationsMask,const SkBitmap &,const gfx::Point &)96 virtual void StartDragging(const WebDropData&, 97 WebKit::WebDragOperationsMask, 98 const SkBitmap&, 99 const gfx::Point&) {} UpdateDragCursor(WebKit::WebDragOperation operation)100 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} GotFocus()101 virtual void GotFocus() {} TakeFocus(bool reverse)102 virtual void TakeFocus(bool reverse) {} LostCapture()103 virtual void LostCapture() {} Activate()104 virtual void Activate() {} Deactivate()105 virtual void Deactivate() {} 106 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 107 bool* is_keyboard_shortcut); HandleKeyboardEvent(const NativeWebKeyboardEvent & event)108 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} HandleMouseMove()109 virtual void HandleMouseMove() {} 110 virtual void HandleMouseDown(); HandleMouseLeave()111 virtual void HandleMouseLeave() {} HandleMouseUp()112 virtual void HandleMouseUp() {} HandleMouseActivate()113 virtual void HandleMouseActivate() {} 114 virtual void UpdatePreferredSize(const gfx::Size& pref_size); 115 virtual RendererPreferences GetRendererPrefs(Profile* profile) const; 116 117 // Enable Web UI. This has to be called before renderer is created. 118 void EnableWebUI(); 119 120 virtual void UpdateInspectorSetting(const std::string& key, 121 const std::string& value); 122 virtual void ClearInspectorSettings(); 123 124 protected: 125 virtual ~BalloonHost(); 126 // Must override in platform specific implementations. 127 virtual void InitRenderWidgetHostView() = 0; 128 virtual RenderWidgetHostView* render_widget_host_view() const = 0; 129 130 // Owned pointer to the host for the renderer process. 131 RenderViewHost* render_view_host_; 132 133 private: 134 // Called to send an event that the balloon has been disconnected from 135 // a renderer (if should_notify_on_disconnect_ is true). 136 void NotifyDisconnect(); 137 138 // Non-owned pointer to the associated balloon. 139 Balloon* balloon_; 140 141 // True after Init() has completed. 142 bool initialized_; 143 144 // Indicates whether we should notify about disconnection of this balloon. 145 // This is used to ensure disconnection notifications only happen if 146 // a connection notification has happened and that they happen only once. 147 bool should_notify_on_disconnect_; 148 149 // Site instance for the balloon/profile, to be used for opening new links. 150 scoped_refptr<SiteInstance> site_instance_; 151 152 // Common implementations of some RenderViewHostDelegate::View methods. 153 RenderViewHostDelegateViewHelper delegate_view_helper_; 154 155 // Handles requests to extension APIs. Will only be non-NULL if we are 156 // rendering a page from an extension. 157 scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; 158 159 // A flag to enable Web UI. 160 bool enable_web_ui_; 161 162 NotificationRegistrar registrar_; 163 }; 164 165 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_HOST_H_ 166