summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_view.h
blob: 38e093dd2fce53b551e4d0b7266045147e54e8b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_

#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
#include "skia/include/SkBitmap.h"

// TODO(port): Port these files.
#if defined(OS_WIN)
#include "chrome/browser/views/hwnd_html_view.h"
#else
#include "chrome/common/temp_scaffolding_stubs.h"
#endif

class Browser;
class Extension;
class ExtensionFunctionDispatcher;
class RenderWidgetHost;
class RenderWidgetHostView;
class WebContents;
struct WebPreferences;

// This class is the browser component of an extension component's RenderView.
// It handles setting up the renderer process, if needed, with special
// priviliges available to extensions.  The view may be drawn to the screen or
// hidden.
class ExtensionView : public HWNDHtmlView,
                      public RenderViewHostDelegate,
                      public RenderViewHostDelegate::View {
 public:
  // ExtensionView
  ExtensionView(Extension* extension,
                const GURL& url,
                SiteInstance* instance,
                Browser* browser);

  Extension* extension() { return extension_; }

  // HWNDHtmlView
  virtual void CreatingRenderer();

  virtual void SetBackground(const SkBitmap& background);

  // RenderViewHostDelegate
  // TODO(mpcomplete): GetProfile is unused.
  virtual Profile* GetProfile() const { return NULL; }
  virtual ExtensionFunctionDispatcher *CreateExtensionFunctionDispatcher(
      RenderViewHost *render_view_host,
      const std::string& extension_id);
  virtual void RenderViewCreated(RenderViewHost* render_view_host);
  virtual void DidContentsPreferredWidthChange(const int pref_width);
  virtual void DidStopLoading(RenderViewHost* render_view_host);
  virtual WebPreferences GetWebkitPrefs();
  virtual void RunJavaScriptMessage(
      const std::wstring& message,
      const std::wstring& default_prompt,
      const GURL& frame_url,
      const int flags,
      IPC::Message* reply_msg,
      bool* did_suppress_message);
  virtual void DidStartLoading(RenderViewHost* render_view_host);
  virtual RenderViewHostDelegate::View* GetViewDelegate() const;

  // RenderViewHostDelegate::View
  virtual void CreateNewWindow(int route_id,
                               base::WaitableEvent* modal_dialog_event);
  virtual void CreateNewWidget(int route_id, bool activatable);
  virtual void ShowCreatedWindow(int route_id,
                                 WindowOpenDisposition disposition,
                                 const gfx::Rect& initial_pos,
                                 bool user_gesture);
  virtual void ShowCreatedWidget(int route_id,
                                 const gfx::Rect& initial_pos);
  virtual void ShowContextMenu(const ContextMenuParams& params);
  virtual void StartDragging(const WebDropData& drop_data);
  virtual void UpdateDragCursor(bool is_drop_target);
  virtual void TakeFocus(bool reverse);
  virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event);

 private:
  // We wait to show the ExtensionView until several things have loaded.
  void ShowIfCompletelyLoaded();

  // The extension that we're hosting in this view.
  Extension* extension_;

  // The browser window that this view is in.
  Browser* browser_;

  // Common implementations of some RenderViewHostDelegate::View methods.
  RenderViewHostDelegateViewHelper delegate_view_helper_;

  // Whether the RenderWidget has reported that it has stopped loading.
  bool did_stop_loading_;

  // What we should set the preferred width to once the ExtensionView has
  // loaded.
  int pending_preferred_width_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionView);
};

#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_