OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/aura/panel_view_aura.h" | 5 #include "chrome/browser/ui/views/aura/panel_view_aura.h" |
6 | 6 |
7 #include "ash/wm/panel_frame_view.h" | 7 #include "ash/wm/panel_frame_view.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 9 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
10 #include "chrome/browser/extensions/extension_tab_util.h" | |
11 #include "chrome/browser/extensions/extension_tabs_module_constants.h" | |
12 #include "chrome/browser/extensions/extension_window_wrapper.h" | |
10 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
13 #include "chrome/common/chrome_view_type.h" | 16 #include "chrome/common/chrome_view_type.h" |
14 #include "chrome/common/extensions/extension_messages.h" | 17 #include "chrome/common/extensions/extension_messages.h" |
15 #include "content/public/browser/site_instance.h" | 18 #include "content/public/browser/site_instance.h" |
16 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_contents_delegate.h" | 20 #include "content/public/browser/web_contents_delegate.h" |
18 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
19 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
20 #include "ipc/ipc_message.h" | 23 #include "ipc/ipc_message.h" |
21 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
22 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
23 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
24 | 27 |
25 namespace { | 28 namespace { |
26 const int kMinWidth = 100; | 29 const int kMinWidth = 100; |
27 const int kMinHeight = 100; | 30 const int kMinHeight = 100; |
28 const int kDefaultWidth = 200; | 31 const int kDefaultWidth = 200; |
29 const int kDefaultHeight = 300; | 32 const int kDefaultHeight = 300; |
30 } | 33 } |
31 | 34 |
35 namespace internal { | |
36 | |
32 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
33 // PanelHost | 38 // PanelHost |
34 | 39 |
35 namespace internal { | |
36 | |
37 class PanelHost : public content::WebContentsDelegate, | 40 class PanelHost : public content::WebContentsDelegate, |
38 public content::WebContentsObserver, | 41 public content::WebContentsObserver, |
39 public ExtensionFunctionDispatcher::Delegate { | 42 public ExtensionFunctionDispatcher::Delegate { |
40 public: | 43 public: |
41 explicit PanelHost(PanelViewAura* panel_view, Profile* profile); | 44 PanelHost(PanelViewAura* panel_view, Profile* profile); |
42 virtual ~PanelHost(); | 45 virtual ~PanelHost(); |
43 | 46 |
44 void Init(const GURL& url); | 47 void Init(const GURL& url); |
45 | 48 |
46 content::WebContents* web_contents() const { return web_contents_.get(); } | 49 content::WebContents* web_contents() const { return web_contents_.get(); } |
50 Profile* profile() const { return profile_; } | |
47 | 51 |
48 // ExtensionFunctionDispatcher::Delegate overrides. | 52 // ExtensionFunctionDispatcher::Delegate overrides. |
49 virtual Browser* GetBrowser() OVERRIDE; | 53 virtual Browser* GetBrowser() OVERRIDE; |
50 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; | 54 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; |
51 | 55 |
52 // content::WebContentsDelegate implementation: | 56 // content::WebContentsDelegate implementation: |
53 virtual void CloseContents(content::WebContents* source) OVERRIDE; | 57 virtual void CloseContents(content::WebContents* source) OVERRIDE; |
54 virtual void HandleMouseDown() OVERRIDE; | 58 virtual void HandleMouseDown() OVERRIDE; |
55 virtual void UpdatePreferredSize(content::WebContents* source, | 59 virtual void UpdatePreferredSize(content::WebContents* source, |
56 const gfx::Size& pref_size) OVERRIDE; | 60 const gfx::Size& pref_size) OVERRIDE; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 IPC_MESSAGE_UNHANDLED(handled = false) | 158 IPC_MESSAGE_UNHANDLED(handled = false) |
155 IPC_END_MESSAGE_MAP() | 159 IPC_END_MESSAGE_MAP() |
156 return handled; | 160 return handled; |
157 } | 161 } |
158 | 162 |
159 void PanelHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { | 163 void PanelHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
160 extension_function_dispatcher_.Dispatch(params, | 164 extension_function_dispatcher_.Dispatch(params, |
161 web_contents_->GetRenderViewHost()); | 165 web_contents_->GetRenderViewHost()); |
162 } | 166 } |
163 | 167 |
168 //////////////////////////////////////////////////////////////////////////////// | |
169 // PanelExtensionWindowWrapper | |
170 | |
171 class PanelExtensionWindowWrapper : public ExtensionWindowWrapper { | |
172 public: | |
173 PanelExtensionWindowWrapper(PanelViewAura* panel_view, PanelHost* panel_host); | |
174 | |
175 // Overriden from ExtensionWindowWrapper: | |
176 virtual const SessionID& GetSessionId() const OVERRIDE; | |
177 virtual base::DictionaryValue* CreateWindowValue( | |
178 bool populate_tabs) const OVERRIDE; | |
179 virtual bool CanClose(ExtensionWindowWrapper::Reason* reason) const OVERRIDE; | |
180 | |
181 private: | |
182 PanelViewAura* panel_view_; | |
183 PanelHost* panel_host_; | |
184 | |
185 DISALLOW_COPY_AND_ASSIGN(PanelExtensionWindowWrapper); | |
186 }; | |
187 | |
188 PanelExtensionWindowWrapper::PanelExtensionWindowWrapper( | |
189 PanelViewAura* panel_view, PanelHost* panel_host) : | |
sky
2012/02/22 21:46:25
: on next line.
stevenjb
2012/02/23 02:19:15
Done.
| |
190 ExtensionWindowWrapper(panel_view, panel_host->profile()), | |
191 panel_view_(panel_view), | |
192 panel_host_(panel_host) { | |
193 } | |
194 | |
195 const SessionID& PanelExtensionWindowWrapper::GetSessionId() const { | |
196 return panel_view_->session_id(); | |
197 } | |
198 | |
199 namespace keys = extension_tabs_module_constants; | |
200 | |
201 base::DictionaryValue* PanelExtensionWindowWrapper::CreateWindowValue( | |
202 bool populate_tabs) const { | |
203 DictionaryValue* result = new DictionaryValue(); | |
204 result->SetInteger(keys::kIdKey, panel_view_->session_id().id()); | |
205 result->SetBoolean(keys::kIncognitoKey, | |
206 panel_host_->profile()->IsOffTheRecord()); | |
207 result->SetBoolean(keys::kFocusedKey, false); | |
208 | |
209 gfx::Rect bounds = panel_view_->GetWidget()->GetRestoredBounds(); | |
210 | |
211 result->SetInteger(keys::kLeftKey, bounds.x()); | |
212 result->SetInteger(keys::kTopKey, bounds.y()); | |
213 result->SetInteger(keys::kWidthKey, bounds.width()); | |
214 result->SetInteger(keys::kHeightKey, bounds.height()); | |
215 result->SetString(keys::kWindowTypeKey, keys::kWindowTypeValuePanel); | |
216 result->SetString(keys::kShowStateKey, keys::kShowStateValueNormal); | |
217 | |
218 if (populate_tabs) { | |
219 ListValue* tab_list = new ListValue(); | |
220 tab_list->Append(ExtensionTabUtil::CreateTabValue( | |
221 panel_host_->web_contents(), NULL, 0)); | |
222 result->Set(keys::kTabsKey, tab_list); | |
223 } | |
224 | |
225 return result; | |
226 } | |
227 | |
228 bool PanelExtensionWindowWrapper::CanClose( | |
229 ExtensionWindowWrapper::Reason* reason) const { | |
230 return true; | |
231 } | |
232 | |
164 } // namespace internal | 233 } // namespace internal |
165 | 234 |
166 //////////////////////////////////////////////////////////////////////////////// | 235 //////////////////////////////////////////////////////////////////////////////// |
167 // PanelViewAura | 236 // PanelViewAura |
168 | 237 |
169 PanelViewAura::PanelViewAura(const std::string& title) | 238 PanelViewAura::PanelViewAura(const std::string& title) |
170 : title_(title), | 239 : title_(title), |
171 preferred_size_(kMinWidth, kMinHeight), | 240 preferred_size_(kMinWidth, kMinHeight), |
172 widget_(NULL) { | 241 widget_(NULL) { |
173 } | 242 } |
174 | 243 |
175 PanelViewAura::~PanelViewAura() { | 244 PanelViewAura::~PanelViewAura() { |
245 ExtensionWindowWrapperList::GetInstance()->RemoveExtensionWindow( | |
246 extension_window_wrapper_.get()); | |
176 } | 247 } |
177 | 248 |
178 views::Widget* PanelViewAura::Init(Profile* profile, | 249 views::Widget* PanelViewAura::Init(Profile* profile, |
179 const GURL& url, | 250 const GURL& url, |
180 const gfx::Rect& bounds) { | 251 const gfx::Rect& bounds) { |
181 widget_ = new views::Widget; | 252 widget_ = new views::Widget; |
182 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); | 253 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); |
183 params.delegate = this; | 254 params.delegate = this; |
184 | 255 |
185 params.bounds = bounds; | 256 params.bounds = bounds; |
186 if (params.bounds.width() == 0) | 257 if (params.bounds.width() == 0) |
187 params.bounds.set_width(kDefaultWidth); | 258 params.bounds.set_width(kDefaultWidth); |
188 else if (params.bounds.width() < kMinWidth) | 259 else if (params.bounds.width() < kMinWidth) |
189 params.bounds.set_width(kMinWidth); | 260 params.bounds.set_width(kMinWidth); |
190 | 261 |
191 if (params.bounds.height() == 0) | 262 if (params.bounds.height() == 0) |
192 params.bounds.set_height(kDefaultHeight); | 263 params.bounds.set_height(kDefaultHeight); |
193 else if (params.bounds.height() < kMinHeight) | 264 else if (params.bounds.height() < kMinHeight) |
194 params.bounds.set_height(kMinHeight); | 265 params.bounds.set_height(kMinHeight); |
195 | 266 |
196 widget_->Init(params); | 267 widget_->Init(params); |
197 widget_->GetNativeView()->SetName(title_); | 268 widget_->GetNativeView()->SetName(title_); |
198 | 269 |
199 host_.reset(new internal::PanelHost(this, profile)); | 270 host_.reset(new internal::PanelHost(this, profile)); |
200 host_->Init(url); | 271 host_->Init(url); |
201 | 272 |
202 Attach(host_->web_contents()->GetNativeView()); | 273 Attach(host_->web_contents()->GetNativeView()); |
203 | 274 |
204 widget_->Show(); | 275 // Add the browser to the list of windows available to the extension API. |
276 extension_window_wrapper_.reset( | |
277 new internal::PanelExtensionWindowWrapper(this, host_.get())); | |
278 ExtensionWindowWrapperList::GetInstance()->AddExtensionWindow( | |
279 extension_window_wrapper_.get()); | |
280 | |
281 // Show the window, but don't activate it by default. | |
282 widget_->ShowInactive(); | |
205 | 283 |
206 return widget_; | 284 return widget_; |
207 } | 285 } |
208 | 286 |
209 content::WebContents* PanelViewAura::WebContents() { | 287 content::WebContents* PanelViewAura::WebContents() { |
210 return host_->web_contents(); | 288 return host_->web_contents(); |
211 } | 289 } |
212 | 290 |
213 void PanelViewAura::CloseView() { | 291 void PanelViewAura::CloseView() { |
214 widget_->CloseNow(); | 292 widget_->CloseNow(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 return View::GetWidget(); | 332 return View::GetWidget(); |
255 } | 333 } |
256 | 334 |
257 const views::Widget* PanelViewAura::GetWidget() const { | 335 const views::Widget* PanelViewAura::GetWidget() const { |
258 return View::GetWidget(); | 336 return View::GetWidget(); |
259 } | 337 } |
260 | 338 |
261 views::NonClientFrameView* PanelViewAura::CreateNonClientFrameView() { | 339 views::NonClientFrameView* PanelViewAura::CreateNonClientFrameView() { |
262 return new ash::PanelFrameView(); | 340 return new ash::PanelFrameView(); |
263 } | 341 } |
342 | |
343 // BaseWindow implementation: | |
344 | |
345 bool PanelViewAura::IsActive() const { | |
346 return GetWidget()->IsActive(); | |
347 } | |
348 | |
349 bool PanelViewAura::IsMaximized() const { | |
350 return GetWidget()->IsMaximized(); | |
351 } | |
352 | |
353 bool PanelViewAura::IsMinimized() const { | |
354 return GetWidget()->IsMinimized(); | |
355 } | |
356 | |
357 gfx::Rect PanelViewAura::GetRestoredBounds() const { | |
358 return GetWidget()->GetRestoredBounds(); | |
359 } | |
360 | |
361 gfx::Rect PanelViewAura::GetBounds() const { | |
362 return GetWidget()->GetWindowScreenBounds(); | |
363 } | |
364 | |
365 void PanelViewAura::Show() { | |
366 GetWidget()->Show(); | |
367 } | |
368 | |
369 void PanelViewAura::ShowInactive() { | |
370 GetWidget()->ShowInactive(); | |
371 } | |
372 | |
373 void PanelViewAura::Close() { | |
374 GetWidget()->Close(); | |
375 } | |
376 | |
377 void PanelViewAura::Activate() { | |
378 GetWidget()->Activate(); | |
379 } | |
380 | |
381 void PanelViewAura::Deactivate() { | |
382 GetWidget()->Deactivate(); | |
383 } | |
384 | |
385 void PanelViewAura::Maximize() { | |
386 NOTIMPLEMENTED(); | |
387 } | |
388 | |
389 void PanelViewAura::Minimize() { | |
390 // TODO(stevenjb): Implement | |
391 NOTIMPLEMENTED(); | |
392 } | |
393 | |
394 void PanelViewAura::Restore() { | |
395 // TODO(stevenjb): Implement | |
396 NOTIMPLEMENTED(); | |
397 } | |
398 | |
399 void PanelViewAura::SetBounds(const gfx::Rect& bounds) { | |
400 GetWidget()->SetBounds(bounds); | |
401 } | |
402 | |
403 void PanelViewAura::FlashFrame(bool flash) { | |
404 // TODO(stevenjb): Implement | |
405 NOTIMPLEMENTED(); | |
406 } | |
OLD | NEW |