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_TAB_CONTENTS_RENDER_VIEW_HOST_DELEGATE_HELPER_H_ 6 #define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_DELEGATE_HELPER_H_ 7 #pragma once 8 9 #include <map> 10 11 #include "base/basictypes.h" 12 #include "content/browser/webui/web_ui.h" 13 #include "content/common/window_container_type.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h" 15 #include "ui/gfx/rect.h" 16 #include "webkit/glue/webpreferences.h" 17 #include "webkit/glue/window_open_disposition.h" 18 19 class BackgroundContents; 20 class Profile; 21 class RenderProcessHost; 22 class RenderViewHost; 23 class RenderViewHostDelegate; 24 class RenderWidgetHost; 25 class RenderWidgetHostView; 26 class SiteInstance; 27 class TabContents; 28 29 // Provides helper methods that provide common implementations of some 30 // RenderViewHostDelegate::View methods. 31 class RenderViewHostDelegateViewHelper { 32 public: 33 RenderViewHostDelegateViewHelper(); 34 virtual ~RenderViewHostDelegateViewHelper(); 35 36 // Creates a new renderer for window.open. This will either be a 37 // BackgroundContents (if the window_container_type == 38 // WINDOW_CONTAINER_TYPE_BACKGROUND and permissions allow) or a TabContents. 39 // If a TabContents is created, it is returned. Otherwise NULL is returned. 40 virtual TabContents* CreateNewWindow( 41 int route_id, 42 Profile* profile, 43 SiteInstance* site, 44 WebUI::TypeID webui_type, 45 RenderViewHostDelegate* opener, 46 WindowContainerType window_container_type, 47 const string16& frame_name); 48 49 // Creates a new RenderWidgetHost and saves it for later retrieval by 50 // GetCreatedWidget. 51 virtual RenderWidgetHostView* CreateNewWidget(int route_id, 52 WebKit::WebPopupType popup_type, 53 RenderProcessHost* process); 54 55 virtual RenderWidgetHostView* CreateNewFullscreenWidget( 56 int route_id, RenderProcessHost* process); 57 58 // Finds the new RenderWidgetHost and returns it. Note that this can only be 59 // called once as this call also removes it from the internal map. 60 virtual RenderWidgetHostView* GetCreatedWidget(int route_id); 61 62 // Finds the new RenderViewHost/Delegate by route_id, initializes it for 63 // for renderer-initiated creation, and returns the TabContents that needs 64 // to be shown, if there is one (i.e. not a BackgroundContents). Note that 65 // this can only be called once as this call also removes it from the internal 66 // map. 67 virtual TabContents* GetCreatedWindow(int route_id); 68 69 // Removes |host| from the internal map of pending RenderWidgets. 70 void RenderWidgetHostDestroyed(RenderWidgetHost* host); 71 72 private: 73 BackgroundContents* MaybeCreateBackgroundContents( 74 int route_id, 75 Profile* profile, 76 SiteInstance* site, 77 const GURL& opener_url, 78 const string16& frame_name); 79 80 // Tracks created RenderViewHost objects that have not been shown yet. 81 // They are identified by the route ID passed to CreateNewWindow. 82 typedef std::map<int, RenderViewHost*> PendingContents; 83 PendingContents pending_contents_; 84 85 // These maps hold on to the widgets that we created on behalf of the 86 // renderer that haven't shown yet. 87 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews; 88 PendingWidgetViews pending_widget_views_; 89 90 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDelegateViewHelper); 91 }; 92 93 94 // Provides helper methods that provide common implementations of some 95 // RenderViewHostDelegate methods. 96 class RenderViewHostDelegateHelper { 97 public: 98 static WebPreferences GetWebkitPrefs(Profile* profile, bool is_web_ui); 99 100 static void UpdateInspectorSetting(Profile* profile, 101 const std::string& key, 102 const std::string& value); 103 static void ClearInspectorSettings(Profile* profile); 104 105 static bool gpu_enabled() { return gpu_enabled_; } 106 static void set_gpu_enabled(bool enabled) { gpu_enabled_ = enabled; } 107 108 private: 109 RenderViewHostDelegateHelper(); 110 111 // Master switch for enabling/disabling GPU acceleration for the current 112 // browser session. It does not change the acceleration settings for 113 // existing tabs, just the future ones. 114 static bool gpu_enabled_; 115 116 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDelegateHelper); 117 }; 118 119 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_DELEGATE_HELPER_H_ 120