172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file.
4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_
6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_
73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once
8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
9513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch#include <string>
10513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch#include <vector>
11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
12ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/memory/scoped_ptr.h"
13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/perftimer.h"
14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/extensions/extension_function_dispatcher.h"
15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
1621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h"
17dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen#include "content/browser/renderer_host/render_view_host_delegate.h"
18ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "content/common/notification_registrar.h"
19dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if defined(TOOLKIT_VIEWS)
2172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "chrome/browser/ui/views/extensions/extension_view.h"
22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#elif defined(OS_MACOSX)
2372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h"
24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#elif defined(TOOLKIT_GTK)
25ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h"
26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif
27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass Browser;
29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass Extension;
303345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickclass FileSelectHelper;
31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass RenderProcessHost;
32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass RenderWidgetHostView;
33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass TabContents;
3472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenstruct ViewHostMsg_RunFileChooser_Params;
35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochstruct WebPreferences;
36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This class is the browser component of an extension component's RenderView.
38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// It handles setting up the renderer process, if needed, with special
39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// privileges available to extensions.  It may have a view to be shown in the
40ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// browser UI, or it may be hidden.
41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ExtensionHost : public RenderViewHostDelegate,
42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                      public RenderViewHostDelegate::View,
43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                      public ExtensionFunctionDispatcher::Delegate,
44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                      public NotificationObserver,
45731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick                      public JavaScriptAppModalDialogDelegate {
46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  class ProcessCreationQueue;
48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Enable DOM automation in created render view hosts.
50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  static void EnableDOMAutomation() { enable_dom_automation_ = true; }
51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
52513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  ExtensionHost(const Extension* extension, SiteInstance* site_instance,
53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                const GURL& url, ViewType::Type host_type);
54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  ~ExtensionHost();
55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if defined(TOOLKIT_VIEWS)
57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void set_view(ExtensionView* view) { view_.reset(view); }
5872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  const ExtensionView* view() const { return view_.get(); }
5972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  ExtensionView* view() { return view_.get(); }
60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#elif defined(OS_MACOSX)
6172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  const ExtensionViewMac* view() const { return view_.get(); }
6272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  ExtensionViewMac* view() { return view_.get(); }
63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#elif defined(TOOLKIT_GTK)
6472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  const ExtensionViewGtk* view() const { return view_.get(); }
6572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  ExtensionViewGtk* view() { return view_.get(); }
66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif
67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Create an ExtensionView and tie it to this host and |browser|.  Note NULL
69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // is a valid argument for |browser|.  Extension views may be bound to
70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // tab-contents hosted in ExternalTabContainer objects, which do not
71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // instantiate Browser objects.
72c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void CreateView(Browser* browser);
73c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
7472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  const Extension* extension() const { return extension_; }
75ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  const std::string& extension_id() const { return extension_id_; }
76c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  RenderViewHost* render_view_host() const { return render_view_host_; }
77c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  RenderProcessHost* render_process_host() const;
78c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  SiteInstance* site_instance() const;
79c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool did_stop_loading() const { return did_stop_loading_; }
80c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool document_element_available() const {
81c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    return document_element_available_;
82c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  }
83c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  Profile* profile() const { return profile_; }
85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
86c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  ViewType::Type extension_host_type() const { return extension_host_type_; }
87c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
88c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // ExtensionFunctionDispatcher::Delegate
8921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual TabContents* associated_tab_contents() const;
90c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void set_associated_tab_contents(TabContents* associated_tab_contents) {
91c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    associated_tab_contents_ = associated_tab_contents;
92c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  }
93c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
94c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns true if the render view is initialized and didn't crash.
95c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool IsRenderViewLive() const;
96c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
97c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Prepares to initializes our RenderViewHost by creating its RenderView and
98c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // navigating to this host's url. Uses host_view for the RenderViewHost's view
99c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // (can be NULL). This happens delayed to avoid locking the UI.
100c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void CreateRenderViewSoon(RenderWidgetHostView* host_view);
101c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
102c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Sets |url_| and navigates |render_view_host_|.
103c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void NavigateToURL(const GURL& url);
104c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
105c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Insert a default style sheet for Extension Infobars.
106c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void InsertInfobarCSS();
107c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
108c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Tell the renderer not to draw scrollbars on windows smaller than
109c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // |size_limit| in both width and height.
110c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void DisableScrollbarsForSmallWindows(const gfx::Size& size_limit);
111c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
11272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // RenderViewHostDelegate implementation.
11372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual bool OnMessageReceived(const IPC::Message& message);
11421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual const GURL& GetURL() const;
115c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void RenderViewCreated(RenderViewHost* render_view_host);
116c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ViewType::Type GetRenderViewType() const;
117c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual int GetBrowserWindowID() const;
11821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual void RenderViewGone(RenderViewHost* render_view_host,
11921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen                              base::TerminationStatus status,
12021d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen                              int error_code);
121c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void DidNavigate(RenderViewHost* render_view_host,
122c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                           const ViewHostMsg_FrameNavigate_Params& params);
123c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void DidStopLoading();
124c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void DocumentAvailableInMainFrame(RenderViewHost* render_view_host);
125c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void DocumentOnLoadCompletedInMainFrame(
1263345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      RenderViewHost* render_view_host,
1273345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      int32 page_id);
128c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
1293345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // RenderViewHostDelegate implementation.
1303345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual RenderViewHostDelegate::View* GetViewDelegate();
131c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual WebPreferences GetWebkitPrefs();
132ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void ProcessWebUIMessage(
133ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen      const ExtensionHostMsg_DomMessage_Params& params);
134c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void RunJavaScriptMessage(const std::wstring& message,
135c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    const std::wstring& default_prompt,
136c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    const GURL& frame_url,
137c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    const int flags,
138c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    IPC::Message* reply_msg,
139c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                    bool* did_suppress_message);
140c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void Close(RenderViewHost* render_view_host);
141c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual RendererPreferences GetRendererPrefs(Profile* profile) const;
142c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
143c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // RenderViewHostDelegate::View
144c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void CreateNewWindow(
145c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      int route_id,
14672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      const ViewHostMsg_CreateWindow_Params& params);
147c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type);
14872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual void CreateNewFullscreenWidget(int route_id);
149c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void ShowCreatedWindow(int route_id,
150c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                 WindowOpenDisposition disposition,
151c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                 const gfx::Rect& initial_pos,
152c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                 bool user_gesture);
153c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void ShowCreatedWidget(int route_id,
154c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                 const gfx::Rect& initial_pos);
1553345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual void ShowCreatedFullscreenWidget(int route_id);
156c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void ShowContextMenu(const ContextMenuParams& params);
157513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  virtual void ShowPopupMenu(const gfx::Rect& bounds,
158513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch                             int item_height,
159513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch                             double item_font_size,
160513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch                             int selected_item,
161513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch                             const std::vector<WebMenuItem>& items,
162513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch                             bool right_aligned);
163c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void StartDragging(const WebDropData& drop_data,
164c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                             WebKit::WebDragOperationsMask allowed_operations,
165c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                             const SkBitmap& image,
166c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                             const gfx::Point& image_offset);
167c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void UpdateDragCursor(WebKit::WebDragOperation operation);
168c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void GotFocus();
169c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void TakeFocus(bool reverse);
1703345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual void LostCapture();
1713345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual void Activate();
1723345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual void Deactivate();
173c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
174c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                      bool* is_keyboard_shortcut);
175c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
1763345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual void HandleMouseMove();
1773345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual void HandleMouseDown();
178c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void HandleMouseLeave();
1793345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual void HandleMouseUp();
1803345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual void HandleMouseActivate();
181c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void UpdatePreferredSize(const gfx::Size& new_size);
182731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  virtual void UpdateInspectorSetting(const std::string& key,
183731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick                                      const std::string& value);
184731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  virtual void ClearInspectorSettings();
185c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
186c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // NotificationObserver
187c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void Observe(NotificationType type,
188c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                       const NotificationSource& source,
189c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                       const NotificationDetails& details);
190c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
191731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // Overridden from JavaScriptAppModalDialogDelegate:
192c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void OnMessageBoxClosed(IPC::Message* reply_msg,
193c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                  bool success,
194c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                  const std::wstring& prompt);
195ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void SetSuppressMessageBoxes(bool suppress_message_boxes);
196731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  virtual gfx::NativeWindow GetMessageBoxRootWindow();
19721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual TabContents* AsTabContents();
19821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual ExtensionHost* AsExtensionHost();
199c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
200c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch protected:
201c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Internal functions used to support the CreateNewWidget() method. If a
202c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // platform requires plugging into widget creation at a lower level, then a
203c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // subclass might want to override these functions, but otherwise they should
204c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // be fine just implementing RenderWidgetHostView::InitAsPopup().
205c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  //
206c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The Create function returns the newly created widget so it can be
207c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // associated with the given route. When the widget needs to be shown later,
208c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // we'll look it up again and pass the object to the Show functions rather
209c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // than the route ID.
210c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual RenderWidgetHostView* CreateNewWidgetInternal(
211c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      int route_id,
212c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      WebKit::WebPopupType popup_type);
213c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void ShowCreatedWidgetInternal(RenderWidgetHostView* widget_host_view,
214c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                         const gfx::Rect& initial_pos);
215c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
216c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  friend class ProcessCreationQueue;
217c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
218c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Whether to allow DOM automation for created RenderViewHosts. This is used
219c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // for testing.
220c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  static bool enable_dom_automation_;
221c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
222c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Actually create the RenderView for this host. See CreateRenderViewSoon.
223c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void CreateRenderViewNow();
224c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
22572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Const version of below function.
22672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  const Browser* GetBrowser() const;
22772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
228c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // ExtensionFunctionDispatcher::Delegate
22972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual Browser* GetBrowser();
2303345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  virtual gfx::NativeView GetNativeViewOfHost();
231c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
23272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Message handlers.
23372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  void OnRunFileChooser(const ViewHostMsg_RunFileChooser_Params& params);
23472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
235c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Handles keyboard events that were not handled by HandleKeyboardEvent().
236c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Platform specific implementation may override this method to handle the
237c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // event in platform specific way.
238c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void UnhandledKeyboardEvent(const NativeWebKeyboardEvent& event) {}
239c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
240c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns true if we're hosting a background page.
241c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // This isn't valid until CreateRenderView is called.
242c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool is_background_page() const { return !view(); }
243c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
244c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The extension that we're hosting in this view.
245513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  const Extension* extension_;
246c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
247ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Id of extension that we're hosting in this view.
248ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  const std::string extension_id_;
249ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
250c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The profile that this host is tied to.
251c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  Profile* profile_;
252c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
253c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Optional view that shows the rendered content in the UI.
254c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if defined(TOOLKIT_VIEWS)
255c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_ptr<ExtensionView> view_;
256c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#elif defined(OS_MACOSX)
257c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_ptr<ExtensionViewMac> view_;
258c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#elif defined(TOOLKIT_GTK)
259c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_ptr<ExtensionViewGtk> view_;
260c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif
261c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
262c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The host for our HTML content.
263c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  RenderViewHost* render_view_host_;
264c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
265c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Common implementations of some RenderViewHostDelegate::View methods.
266c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  RenderViewHostDelegateViewHelper delegate_view_helper_;
267c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
268c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Whether the RenderWidget has reported that it has stopped loading.
269c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool did_stop_loading_;
270c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
271c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // True if the main frame has finished parsing.
272c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool document_element_available_;
273c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
274c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The URL being hosted.
275c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  GURL url_;
276c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
277c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  NotificationRegistrar registrar_;
278c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
279c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_;
280c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
2813345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Only EXTENSION_INFOBAR, EXTENSION_POPUP, and EXTENSION_BACKGROUND_PAGE
282c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // are used here, others are not hosted by ExtensionHost.
283c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  ViewType::Type extension_host_type_;
284c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
285c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The relevant TabContents associated with this ExtensionHost, if any.
286c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  TabContents* associated_tab_contents_;
287c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
288c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Used to measure how long it's been since the host was created.
289c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  PerfTimer since_created_;
290c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
2913345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // FileSelectHelper, lazily created.
2923345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  scoped_ptr<FileSelectHelper> file_select_helper_;
2933345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
294ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // The time that the last javascript message was dismissed.
295ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  base::TimeTicks last_javascript_message_dismissal_;
296ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
297ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Whether to suppress all javascript messages.
298ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  bool suppress_javascript_messages_;
29972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
300c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(ExtensionHost);
301c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
302c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
303c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_HOST_H_
304