Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / ui / extensions / shell_window.h
blob2f8b89cd041c3ea5a52f2c0a33d3734e9f3b1f38
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_
6 #define CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/extensions/extension_function_dispatcher.h"
10 #include "chrome/browser/extensions/extension_keybinding_registry.h"
11 #include "chrome/browser/extensions/image_loading_tracker.h"
12 #include "chrome/browser/sessions/session_id.h"
13 #include "chrome/browser/ui/base_window.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/web_contents_delegate.h"
17 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/common/console_message_level.h"
19 #include "ui/gfx/image/image.h"
20 #include "ui/gfx/rect.h"
22 class GURL;
23 class Profile;
24 class NativeShellWindow;
26 namespace content {
27 class WebContents;
30 namespace extensions {
31 class Extension;
32 class PlatformAppBrowserTest;
33 class WindowController;
35 struct DraggableRegion;
38 // ShellWindow is the type of window used by platform apps. Shell windows
39 // have a WebContents but none of the chrome of normal browser windows.
40 class ShellWindow : public content::NotificationObserver,
41 public content::WebContentsDelegate,
42 public content::WebContentsObserver,
43 public ExtensionFunctionDispatcher::Delegate,
44 public ImageLoadingTracker::Observer,
45 public extensions::ExtensionKeybindingRegistry::Delegate {
46 public:
47 struct CreateParams {
48 enum Frame {
49 FRAME_CHROME, // Chrome-style window frame.
50 FRAME_NONE, // Frameless window.
53 CreateParams();
54 ~CreateParams();
56 Frame frame;
57 // Specify the initial bounds of the window. INT_MIN designates
58 // 'unspecified' for any coordinate, and should be replaced with a default
59 // value.
60 gfx::Rect bounds;
62 gfx::Size minimum_size;
63 gfx::Size maximum_size;
65 std::string window_key;
67 // The process ID of the process that requested the create.
68 int32 creator_process_id;
70 // If true, don't show the window after creation.
71 bool hidden;
74 static ShellWindow* Create(Profile* profile,
75 const extensions::Extension* extension,
76 const GURL& url,
77 const CreateParams& params);
79 // Convert draggable regions in raw format to SkRegion format. Caller is
80 // responsible for deleting the returned SkRegion instance.
81 static SkRegion* RawDraggableRegionsToSkRegion(
82 const std::vector<extensions::DraggableRegion>& regions);
84 const std::string& window_key() const { return window_key_; }
85 const SessionID& session_id() const { return session_id_; }
86 const extensions::Extension* extension() const { return extension_; }
87 content::WebContents* web_contents() const { return web_contents_.get(); }
88 Profile* profile() const { return profile_; }
89 const gfx::Image& app_icon() const { return app_icon_; }
91 BaseWindow* GetBaseWindow();
92 gfx::NativeWindow GetNativeWindow() {
93 return GetBaseWindow()->GetNativeWindow();
96 // NativeShellWindows should call this to determine what the window's title
97 // is on startup and from within UpdateWindowTitle().
98 virtual string16 GetTitle() const;
100 // Call to notify ShellRegistry and delete the window. Subclasses should
101 // invoke this method instead of using "delete this".
102 void OnNativeClose();
104 // Should be called by native implementations when the window size/position
105 // has changed.
106 void SaveWindowPosition();
108 protected:
109 ShellWindow(Profile* profile,
110 const extensions::Extension* extension);
111 virtual ~ShellWindow();
113 private:
114 // PlatformAppBrowserTest needs access to web_contents()
115 friend class extensions::PlatformAppBrowserTest;
117 // Instantiates a platform-specific ShellWindow subclass (one implementation
118 // per platform). Public users of ShellWindow should use ShellWindow::Create.
119 void Init(const GURL& url, const CreateParams& params);
121 // content::WebContentsObserver implementation.
122 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
124 // content::WebContentsDelegate implementation.
125 virtual void CloseContents(content::WebContents* contents) OVERRIDE;
126 virtual bool ShouldSuppressDialogs() OVERRIDE;
127 virtual void WebIntentDispatch(
128 content::WebContents* web_contents,
129 content::WebIntentsDispatcher* intents_dispatcher) OVERRIDE;
130 virtual void RunFileChooser(
131 content::WebContents* tab,
132 const content::FileChooserParams& params) OVERRIDE;
133 virtual bool IsPopupOrPanel(
134 const content::WebContents* source) const OVERRIDE;
135 virtual void MoveContents(
136 content::WebContents* source, const gfx::Rect& pos) OVERRIDE;
137 virtual void NavigationStateChanged(const content::WebContents* source,
138 unsigned changed_flags) OVERRIDE;
139 virtual void ToggleFullscreenModeForTab(content::WebContents* source,
140 bool enter_fullscreen) OVERRIDE;
141 virtual bool IsFullscreenForTabOrPending(
142 const content::WebContents* source) const OVERRIDE;
143 virtual void RequestMediaAccessPermission(
144 content::WebContents* web_contents,
145 const content::MediaStreamRequest* request,
146 const content::MediaResponseCallback& callback) OVERRIDE;
147 virtual content::WebContents* OpenURLFromTab(
148 content::WebContents* source,
149 const content::OpenURLParams& params) OVERRIDE;
150 virtual void AddNewContents(content::WebContents* source,
151 content::WebContents* new_contents,
152 WindowOpenDisposition disposition,
153 const gfx::Rect& initial_pos,
154 bool user_gesture,
155 bool* was_blocked) OVERRIDE;
156 virtual void HandleKeyboardEvent(
157 content::WebContents* source,
158 const content::NativeWebKeyboardEvent& event) OVERRIDE;
160 // content::NotificationObserver implementation.
161 virtual void Observe(int type,
162 const content::NotificationSource& source,
163 const content::NotificationDetails& details) OVERRIDE;
165 // ExtensionFunctionDispatcher::Delegate implementation.
166 virtual extensions::WindowController* GetExtensionWindowController() const
167 OVERRIDE;
168 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
170 // Message handlers.
171 void OnRequest(const ExtensionHostMsg_Request_Params& params);
173 // Helper method to add a message to the renderer's DevTools console.
174 void AddMessageToDevToolsConsole(content::ConsoleMessageLevel level,
175 const std::string& message);
177 // Sends an update message with the current bounds to the renderer.
178 void SendBoundsUpdate();
180 virtual void UpdateDraggableRegions(
181 const std::vector<extensions::DraggableRegion>& regions);
183 // Load the app's image, firing a load state change when loaded.
184 void UpdateExtensionAppIcon();
186 // ImageLoadingTracker::Observer implementation.
187 virtual void OnImageLoaded(const gfx::Image& image,
188 const std::string& extension_id,
189 int index) OVERRIDE;
191 // extensions::ExtensionKeybindingRegistry::Delegate implementation.
192 virtual extensions::ActiveTabPermissionGranter*
193 GetActiveTabPermissionGranter() OVERRIDE;
195 Profile* profile_; // weak pointer - owned by ProfileManager.
196 // weak pointer - owned by ExtensionService.
197 const extensions::Extension* extension_;
199 // Identifier that is used when saving and restoring geometry for this
200 // window.
201 std::string window_key_;
203 const SessionID session_id_;
204 scoped_ptr<content::WebContents> web_contents_;
205 content::NotificationRegistrar registrar_;
206 ExtensionFunctionDispatcher extension_function_dispatcher_;
208 // Icon showed in the task bar.
209 gfx::Image app_icon_;
211 // Used for loading app_icon_.
212 scoped_ptr<ImageLoadingTracker> app_icon_loader_;
214 scoped_ptr<NativeShellWindow> native_window_;
216 DISALLOW_COPY_AND_ASSIGN(ShellWindow);
219 #endif // CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_