1// Copyright 2014 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_GUEST_VIEW_WEB_VIEW_CHROME_WEB_VIEW_GUEST_DELEGATE_H_ 6#define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_CHROME_WEB_VIEW_GUEST_DELEGATE_H_ 7 8#include "chrome/browser/extensions/api/web_view/chrome_web_view_internal_api.h" 9#include "chrome/browser/ui/zoom/zoom_observer.h" 10#include "extensions/browser/guest_view/web_view/web_view_guest.h" 11#include "extensions/browser/guest_view/web_view/web_view_guest_delegate.h" 12 13#if defined(OS_CHROMEOS) 14#include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 15#endif 16 17class RenderViewContextMenu; 18 19namespace ui { 20class SimpleMenuModel; 21} // namespace ui 22 23class ChromeWebViewGuestDelegate : public extensions::WebViewGuestDelegate, 24 public ZoomObserver { 25 public : 26 explicit ChromeWebViewGuestDelegate( 27 extensions::WebViewGuest* web_view_guest); 28 virtual ~ChromeWebViewGuestDelegate(); 29 30 // WebViewGuestDelegate implementation. 31 virtual double GetZoom() OVERRIDE; 32 virtual bool HandleContextMenu( 33 const content::ContextMenuParams& params) OVERRIDE; 34 virtual void OnAttachWebViewHelpers(content::WebContents* contents) OVERRIDE; 35 virtual void OnEmbedderDestroyed() OVERRIDE; 36 virtual void OnDidAttachToEmbedder() OVERRIDE; 37 virtual void OnDidCommitProvisionalLoadForFrame(bool is_main_frame) OVERRIDE; 38 virtual void OnDidInitialize() OVERRIDE; 39 virtual void OnDocumentLoadedInFrame( 40 content::RenderFrameHost* render_frame_host) OVERRIDE; 41 virtual void OnGuestDestroyed() OVERRIDE; 42 virtual void OnSetZoom(double zoom_factor) OVERRIDE; 43 virtual void OnShowContextMenu( 44 int request_id, 45 const MenuItemVector* items) OVERRIDE; 46 47 // ZoomObserver implementation. 48 virtual void OnZoomChanged( 49 const ZoomController::ZoomChangedEventData& data) OVERRIDE; 50 51 extensions::WebViewGuest* web_view_guest() const { return web_view_guest_; } 52 53 private: 54 content::WebContents* guest_web_contents() const { 55 return web_view_guest()->web_contents(); 56 } 57 58 // Returns the top level items (ignoring submenus) as Value. 59 static scoped_ptr<base::ListValue> MenuModelToValue( 60 const ui::SimpleMenuModel& menu_model); 61 62 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); 63 64#if defined(OS_CHROMEOS) 65 // Notification of a change in the state of an accessibility setting. 66 void OnAccessibilityStatusChanged( 67 const chromeos::AccessibilityStatusEventDetails& details); 68#endif 69 70 // A counter to generate a unique request id for a context menu request. 71 // We only need the ids to be unique for a given WebViewGuest. 72 int pending_context_menu_request_id_; 73 74 // Set to |true| if ChromeVox was already injected in main frame. 75 bool chromevox_injected_; 76 77 // Stores the current zoom factor. 78 double current_zoom_factor_; 79 80 // Holds the RenderViewContextMenu that has been built but yet to be 81 // shown. This is .Reset() after ShowContextMenu(). 82 scoped_ptr<RenderViewContextMenu> pending_menu_; 83 84#if defined(OS_CHROMEOS) 85 // Subscription to receive notifications on changes to a11y settings. 86 scoped_ptr<chromeos::AccessibilityStatusSubscription> 87 accessibility_subscription_; 88#endif 89 90 extensions::WebViewGuest* const web_view_guest_; 91 92 DISALLOW_COPY_AND_ASSIGN(ChromeWebViewGuestDelegate); 93}; 94 95#endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_CHROME_WEB_VIEW_GUEST_DELEGATE_H_ 96 97