[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 1 | // Copyright (c) 2006-2009 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_EXTENSIONS_EXTENSION_HOST_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ |
| 7 | |
| 8 | #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 9 | #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" |
| 10 | |
| 11 | class Browser; |
| 12 | class Extension; |
| 13 | class ExtensionView; |
| 14 | class RenderWidgetHost; |
| 15 | class RenderWidgetHostView; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 16 | class TabContents; |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 17 | struct WebPreferences; |
| 18 | |
| 19 | // This class is the browser component of an extension component's RenderView. |
| 20 | // It handles setting up the renderer process, if needed, with special |
| 21 | // privileges available to extensions. It may have a view to be shown in the |
| 22 | // in the browser UI, or it may be hidden. |
| 23 | class ExtensionHost : public RenderViewHostDelegate, |
| 24 | public RenderViewHostDelegate::View { |
| 25 | public: |
| 26 | ExtensionHost(Extension* extension, SiteInstance* site_instance); |
| 27 | ~ExtensionHost(); |
| 28 | |
| 29 | void set_view(ExtensionView* view) { view_ = view; } |
| 30 | ExtensionView* view() const { return view_; } |
| 31 | Extension* extension() { return extension_; } |
| 32 | RenderViewHost* render_view_host() const { return render_view_host_; } |
| 33 | SiteInstance* site_instance() const; |
| 34 | bool did_stop_loading() const { return did_stop_loading_; } |
| 35 | |
| 36 | // Initializes our RenderViewHost by creating its RenderView and navigating |
| 37 | // to the given URL. Uses host_view for the RenderViewHost's view (can be |
| 38 | // NULL). |
| 39 | void CreateRenderView(const GURL& url, RenderWidgetHostView* host_view); |
| 40 | |
| 41 | // RenderViewHostDelegate |
| 42 | // TODO(mpcomplete): GetProfile is unused. |
| 43 | virtual Profile* GetProfile() const { return NULL; } |
[email protected] | e916901c | 2009-05-07 00:14:31 | [diff] [blame^] | 44 | virtual const GURL& GetURL() const { return url_; } |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 45 | virtual void DidContentsPreferredWidthChange(const int pref_width); |
| 46 | virtual WebPreferences GetWebkitPrefs(); |
| 47 | virtual void RunJavaScriptMessage( |
| 48 | const std::wstring& message, |
| 49 | const std::wstring& default_prompt, |
| 50 | const GURL& frame_url, |
| 51 | const int flags, |
| 52 | IPC::Message* reply_msg, |
| 53 | bool* did_suppress_message); |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 54 | virtual void DidStopLoading(RenderViewHost* render_view_host); |
| 55 | virtual RenderViewHostDelegate::View* GetViewDelegate() const; |
| 56 | virtual ExtensionFunctionDispatcher* CreateExtensionFunctionDispatcher( |
| 57 | RenderViewHost *render_view_host, const std::string& extension_id); |
| 58 | |
| 59 | // RenderViewHostDelegate::View |
| 60 | virtual void CreateNewWindow(int route_id, |
| 61 | base::WaitableEvent* modal_dialog_event); |
| 62 | virtual void CreateNewWidget(int route_id, bool activatable); |
| 63 | virtual void ShowCreatedWindow(int route_id, |
| 64 | WindowOpenDisposition disposition, |
| 65 | const gfx::Rect& initial_pos, |
[email protected] | c88a70fe | 2009-05-05 20:00:22 | [diff] [blame] | 66 | bool user_gesture, |
| 67 | const GURL& creator_url); |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 68 | virtual void ShowCreatedWidget(int route_id, |
| 69 | const gfx::Rect& initial_pos); |
| 70 | virtual void ShowContextMenu(const ContextMenuParams& params); |
| 71 | virtual void StartDragging(const WebDropData& drop_data); |
| 72 | virtual void UpdateDragCursor(bool is_drop_target); |
| 73 | virtual void TakeFocus(bool reverse); |
| 74 | virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); |
| 75 | |
| 76 | private: |
| 77 | // If this ExtensionHost has a view, this returns the Browser that view is a |
| 78 | // part of. If this is a global background page, we use the active Browser |
| 79 | // instead. |
| 80 | Browser* GetBrowser(); |
| 81 | |
| 82 | // The extension that we're hosting in this view. |
| 83 | Extension* extension_; |
| 84 | |
| 85 | // Optional view that shows the rendered content in the UI. |
| 86 | ExtensionView* view_; |
| 87 | |
| 88 | // The host for our HTML content. |
| 89 | RenderViewHost* render_view_host_; |
| 90 | |
| 91 | // Common implementations of some RenderViewHostDelegate::View methods. |
| 92 | RenderViewHostDelegateViewHelper delegate_view_helper_; |
| 93 | |
| 94 | // Whether the RenderWidget has reported that it has stopped loading. |
| 95 | bool did_stop_loading_; |
| 96 | |
[email protected] | e916901c | 2009-05-07 00:14:31 | [diff] [blame^] | 97 | // The URL being hosted. |
| 98 | GURL url_; |
| 99 | |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(ExtensionHost); |
| 101 | }; |
| 102 | |
| 103 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_ |