Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: chrome/browser/ui/views/aura/panel_view_aura.cc

Issue 9428018: Create BaseWindow and ExtensionWindowWrapper for extension API access to Panels (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address comments, rename -> ExtensionWindowController Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_controller.h"
13 #include "chrome/browser/extensions/extension_window_list.h"
10 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/common/chrome_view_type.h" 17 #include "chrome/common/chrome_view_type.h"
14 #include "chrome/common/extensions/extension_messages.h" 18 #include "chrome/common/extensions/extension_messages.h"
15 #include "content/public/browser/site_instance.h" 19 #include "content/public/browser/site_instance.h"
16 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_delegate.h" 21 #include "content/public/browser/web_contents_delegate.h"
18 #include "content/public/browser/web_contents_observer.h" 22 #include "content/public/browser/web_contents_observer.h"
19 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
20 #include "ipc/ipc_message.h" 24 #include "ipc/ipc_message.h"
21 #include "ipc/ipc_message_macros.h" 25 #include "ipc/ipc_message_macros.h"
22 #include "ui/aura/window.h" 26 #include "ui/aura/window.h"
23 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
24 28
25 namespace { 29 namespace {
26 const int kMinWidth = 100; 30 const int kMinWidth = 100;
27 const int kMinHeight = 100; 31 const int kMinHeight = 100;
28 const int kDefaultWidth = 200; 32 const int kDefaultWidth = 200;
29 const int kDefaultHeight = 300; 33 const int kDefaultHeight = 300;
30 } 34 }
31 35
36 namespace internal {
37
32 //////////////////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////////////////
33 // PanelHost 39 // PanelHost
34 40
35 namespace internal {
36
37 class PanelHost : public content::WebContentsDelegate, 41 class PanelHost : public content::WebContentsDelegate,
38 public content::WebContentsObserver, 42 public content::WebContentsObserver,
39 public ExtensionFunctionDispatcher::Delegate { 43 public ExtensionFunctionDispatcher::Delegate {
40 public: 44 public:
41 explicit PanelHost(PanelViewAura* panel_view, Profile* profile); 45 PanelHost(PanelViewAura* panel_view, Profile* profile);
42 virtual ~PanelHost(); 46 virtual ~PanelHost();
43 47
44 void Init(const GURL& url); 48 void Init(const GURL& url);
45 49
46 content::WebContents* web_contents() const { return web_contents_.get(); } 50 content::WebContents* web_contents() const { return web_contents_.get(); }
51 Profile* profile() const { return profile_; }
47 52
48 // ExtensionFunctionDispatcher::Delegate overrides. 53 // ExtensionFunctionDispatcher::Delegate overrides.
49 virtual Browser* GetBrowser() OVERRIDE; 54 virtual Browser* GetBrowser() OVERRIDE;
50 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; 55 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
51 56
52 // content::WebContentsDelegate implementation: 57 // content::WebContentsDelegate implementation:
53 virtual void CloseContents(content::WebContents* source) OVERRIDE; 58 virtual void CloseContents(content::WebContents* source) OVERRIDE;
54 virtual void HandleMouseDown() OVERRIDE; 59 virtual void HandleMouseDown() OVERRIDE;
55 virtual void UpdatePreferredSize(content::WebContents* source, 60 virtual void UpdatePreferredSize(content::WebContents* source,
56 const gfx::Size& pref_size) OVERRIDE; 61 const gfx::Size& pref_size) OVERRIDE;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 IPC_MESSAGE_UNHANDLED(handled = false) 159 IPC_MESSAGE_UNHANDLED(handled = false)
155 IPC_END_MESSAGE_MAP() 160 IPC_END_MESSAGE_MAP()
156 return handled; 161 return handled;
157 } 162 }
158 163
159 void PanelHost::OnRequest(const ExtensionHostMsg_Request_Params& params) { 164 void PanelHost::OnRequest(const ExtensionHostMsg_Request_Params& params) {
160 extension_function_dispatcher_.Dispatch(params, 165 extension_function_dispatcher_.Dispatch(params,
161 web_contents_->GetRenderViewHost()); 166 web_contents_->GetRenderViewHost());
162 } 167 }
163 168
169 ////////////////////////////////////////////////////////////////////////////////
170 // PanelExtensionWindowController
171
172 class PanelExtensionWindowController : public ExtensionWindowController {
173 public:
174 PanelExtensionWindowController(PanelViewAura* panel_view,
175 PanelHost* panel_host);
176
177 // Overriden from ExtensionWindowController:
178 virtual const SessionID& GetSessionId() const OVERRIDE;
179 virtual base::DictionaryValue* CreateWindowValue() const OVERRIDE;
180 virtual base::DictionaryValue* CreateWindowValueWithTabs() const OVERRIDE;
181 virtual bool CanClose(
182 ExtensionWindowController::Reason* reason) const OVERRIDE;
183 virtual void SetFullscreenMode(bool is_fullscreen,
184 const GURL& extension_url) const OVERRIDE;
185
186 private:
187 PanelViewAura* panel_view_;
188 PanelHost* panel_host_;
189
190 DISALLOW_COPY_AND_ASSIGN(PanelExtensionWindowController);
191 };
192
193 PanelExtensionWindowController::PanelExtensionWindowController(
194 PanelViewAura* panel_view,
195 PanelHost* panel_host)
196 : ExtensionWindowController(panel_view, panel_host->profile()),
197 panel_view_(panel_view),
198 panel_host_(panel_host) {
199 }
200
201 const SessionID& PanelExtensionWindowController::GetSessionId() const {
202 return panel_view_->session_id();
203 }
204
205 namespace keys = extension_tabs_module_constants;
206
207 base::DictionaryValue*
208 PanelExtensionWindowController::CreateWindowValue() const {
209 DictionaryValue* result = new DictionaryValue();
210 result->SetInteger(keys::kIdKey, panel_view_->session_id().id());
211 result->SetBoolean(keys::kIncognitoKey,
212 panel_host_->profile()->IsOffTheRecord());
213 result->SetBoolean(keys::kFocusedKey, false);
214
215 gfx::Rect bounds = panel_view_->GetWidget()->GetRestoredBounds();
216
217 result->SetInteger(keys::kLeftKey, bounds.x());
218 result->SetInteger(keys::kTopKey, bounds.y());
219 result->SetInteger(keys::kWidthKey, bounds.width());
220 result->SetInteger(keys::kHeightKey, bounds.height());
221 result->SetString(keys::kWindowTypeKey, keys::kWindowTypeValuePanel);
222 result->SetString(keys::kShowStateKey, keys::kShowStateValueNormal);
223
224 return result;
225 }
226
227 base::DictionaryValue*
228 PanelExtensionWindowController::CreateWindowValueWithTabs() const {
229 DictionaryValue* result = CreateWindowValue();
230 ListValue* tab_list = new ListValue();
231 tab_list->Append(ExtensionTabUtil::CreateTabValue(
232 panel_host_->web_contents(), NULL, 0));
233 result->Set(keys::kTabsKey, tab_list);
234 return result;
235 }
236
237 bool PanelExtensionWindowController::CanClose(
238 ExtensionWindowController::Reason* reason) const {
239 return true;
240 }
241
242 void PanelExtensionWindowController::SetFullscreenMode(
243 bool is_fullscreen, const GURL& extension_url) const {
244 }
245
164 } // namespace internal 246 } // namespace internal
165 247
166 //////////////////////////////////////////////////////////////////////////////// 248 ////////////////////////////////////////////////////////////////////////////////
167 // PanelViewAura 249 // PanelViewAura
168 250
169 PanelViewAura::PanelViewAura(const std::string& title) 251 PanelViewAura::PanelViewAura(const std::string& title)
170 : title_(title), 252 : title_(title),
171 preferred_size_(kMinWidth, kMinHeight), 253 preferred_size_(kMinWidth, kMinHeight),
172 widget_(NULL) { 254 widget_(NULL) {
173 } 255 }
174 256
175 PanelViewAura::~PanelViewAura() { 257 PanelViewAura::~PanelViewAura() {
258 ExtensionWindowList::GetInstance()->RemoveExtensionWindow(
Mihai Parparita -not on Chrome 2012/02/23 02:35:36 Why not do the registration/deregistration in the
stevenjb 2012/02/23 19:57:51 Good suggestion, I can do that now. (The registrat
259 extension_window_controller_.get());
176 } 260 }
177 261
178 views::Widget* PanelViewAura::Init(Profile* profile, 262 views::Widget* PanelViewAura::Init(Profile* profile,
179 const GURL& url, 263 const GURL& url,
180 const gfx::Rect& bounds) { 264 const gfx::Rect& bounds) {
181 widget_ = new views::Widget; 265 widget_ = new views::Widget;
182 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); 266 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL);
183 params.delegate = this; 267 params.delegate = this;
184 268
185 params.bounds = bounds; 269 params.bounds = bounds;
186 if (params.bounds.width() == 0) 270 if (params.bounds.width() == 0)
187 params.bounds.set_width(kDefaultWidth); 271 params.bounds.set_width(kDefaultWidth);
188 else if (params.bounds.width() < kMinWidth) 272 else if (params.bounds.width() < kMinWidth)
189 params.bounds.set_width(kMinWidth); 273 params.bounds.set_width(kMinWidth);
190 274
191 if (params.bounds.height() == 0) 275 if (params.bounds.height() == 0)
192 params.bounds.set_height(kDefaultHeight); 276 params.bounds.set_height(kDefaultHeight);
193 else if (params.bounds.height() < kMinHeight) 277 else if (params.bounds.height() < kMinHeight)
194 params.bounds.set_height(kMinHeight); 278 params.bounds.set_height(kMinHeight);
195 279
196 widget_->Init(params); 280 widget_->Init(params);
197 widget_->GetNativeView()->SetName(title_); 281 widget_->GetNativeView()->SetName(title_);
198 282
199 host_.reset(new internal::PanelHost(this, profile)); 283 host_.reset(new internal::PanelHost(this, profile));
200 host_->Init(url); 284 host_->Init(url);
201 285
202 Attach(host_->web_contents()->GetNativeView()); 286 Attach(host_->web_contents()->GetNativeView());
203 287
204 widget_->Show(); 288 // Add the browser to the list of windows available to the extension API.
289 extension_window_controller_.reset(
290 new internal::PanelExtensionWindowController(this, host_.get()));
291 ExtensionWindowList::GetInstance()->AddExtensionWindow(
292 extension_window_controller_.get());
293
294 // Show the window, but don't activate it by default.
295 widget_->ShowInactive();
205 296
206 return widget_; 297 return widget_;
207 } 298 }
208 299
209 content::WebContents* PanelViewAura::WebContents() { 300 content::WebContents* PanelViewAura::WebContents() {
210 return host_->web_contents(); 301 return host_->web_contents();
211 } 302 }
212 303
213 void PanelViewAura::CloseView() { 304 void PanelViewAura::CloseView() {
214 widget_->CloseNow(); 305 widget_->CloseNow();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 return View::GetWidget(); 345 return View::GetWidget();
255 } 346 }
256 347
257 const views::Widget* PanelViewAura::GetWidget() const { 348 const views::Widget* PanelViewAura::GetWidget() const {
258 return View::GetWidget(); 349 return View::GetWidget();
259 } 350 }
260 351
261 views::NonClientFrameView* PanelViewAura::CreateNonClientFrameView() { 352 views::NonClientFrameView* PanelViewAura::CreateNonClientFrameView() {
262 return new ash::PanelFrameView(); 353 return new ash::PanelFrameView();
263 } 354 }
355
356 // BaseWindow implementation:
357
358 bool PanelViewAura::IsActive() const {
359 return GetWidget()->IsActive();
360 }
361
362 bool PanelViewAura::IsMaximized() const {
363 return GetWidget()->IsMaximized();
364 }
365
366 bool PanelViewAura::IsMinimized() const {
367 return GetWidget()->IsMinimized();
368 }
369
370 gfx::Rect PanelViewAura::GetRestoredBounds() const {
371 return GetWidget()->GetRestoredBounds();
372 }
373
374 gfx::Rect PanelViewAura::GetBounds() const {
375 return GetWidget()->GetWindowScreenBounds();
376 }
377
378 void PanelViewAura::Show() {
379 GetWidget()->Show();
380 }
381
382 void PanelViewAura::ShowInactive() {
383 GetWidget()->ShowInactive();
384 }
385
386 void PanelViewAura::Close() {
387 GetWidget()->Close();
388 }
389
390 void PanelViewAura::Activate() {
391 GetWidget()->Activate();
392 }
393
394 void PanelViewAura::Deactivate() {
395 GetWidget()->Deactivate();
396 }
397
398 void PanelViewAura::Maximize() {
399 NOTIMPLEMENTED();
400 }
401
402 void PanelViewAura::Minimize() {
403 // TODO(stevenjb): Implement
404 NOTIMPLEMENTED();
405 }
406
407 void PanelViewAura::Restore() {
408 // TODO(stevenjb): Implement
409 NOTIMPLEMENTED();
410 }
411
412 void PanelViewAura::SetBounds(const gfx::Rect& bounds) {
413 GetWidget()->SetBounds(bounds);
414 }
415
416 void PanelViewAura::FlashFrame(bool flash) {
417 // TODO(stevenjb): Implement
418 NOTIMPLEMENTED();
419 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698