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

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: Rebase Created 8 years, 9 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
« no previous file with comments | « chrome/browser/ui/views/aura/panel_view_aura.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = ExtensionWindowController::CreateWindowValue();
210
211 result->SetString(keys::kWindowTypeKey, keys::kWindowTypeValuePanel);
212 std::string window_state = window()->IsMinimized() ?
213 keys::kShowStateValueMinimized : keys::kShowStateValueNormal;
214 result->SetString(keys::kShowStateKey, window_state);
215
216 return result;
217 }
218
219 base::DictionaryValue*
220 PanelExtensionWindowController::CreateWindowValueWithTabs() const {
221 DictionaryValue* result = CreateWindowValue();
222
223 // TODO(stevenjb): Implement tab interface for Aura panels.
224 // Currently there is no mechanism to get a tab id without an associated
225 // TabContentsWrapper. We will need to either add a TabContentsWrapper for
226 // panels, or add another mechanism for tracking tabs. crbug.com/115532.
227
228 return result;
229 }
230
231 bool PanelExtensionWindowController::CanClose(
232 ExtensionWindowController::Reason* reason) const {
233 return true;
234 }
235
236 void PanelExtensionWindowController::SetFullscreenMode(
237 bool is_fullscreen, const GURL& extension_url) const {
238 }
239
164 } // namespace internal 240 } // namespace internal
165 241
166 //////////////////////////////////////////////////////////////////////////////// 242 ////////////////////////////////////////////////////////////////////////////////
167 // PanelViewAura 243 // PanelViewAura
168 244
169 PanelViewAura::PanelViewAura(const std::string& title) 245 PanelViewAura::PanelViewAura(const std::string& title)
170 : title_(title), 246 : title_(title),
171 preferred_size_(kMinWidth, kMinHeight), 247 preferred_size_(kMinWidth, kMinHeight),
172 widget_(NULL) { 248 widget_(NULL) {
173 } 249 }
(...skipping 20 matching lines...) Expand all
194 params.bounds.set_height(kMinHeight); 270 params.bounds.set_height(kMinHeight);
195 271
196 widget_->Init(params); 272 widget_->Init(params);
197 widget_->GetNativeView()->SetName(title_); 273 widget_->GetNativeView()->SetName(title_);
198 274
199 host_.reset(new internal::PanelHost(this, profile)); 275 host_.reset(new internal::PanelHost(this, profile));
200 host_->Init(url); 276 host_->Init(url);
201 277
202 Attach(host_->web_contents()->GetNativeView()); 278 Attach(host_->web_contents()->GetNativeView());
203 279
204 widget_->Show(); 280 // Add the browser to the list of windows available to the extension API.
281 extension_window_controller_.reset(
282 new internal::PanelExtensionWindowController(this, host_.get()));
283
284 // Show the window, but don't activate it by default.
285 widget_->ShowInactive();
205 286
206 return widget_; 287 return widget_;
207 } 288 }
208 289
209 content::WebContents* PanelViewAura::WebContents() { 290 content::WebContents* PanelViewAura::WebContents() {
210 return host_->web_contents(); 291 return host_->web_contents();
211 } 292 }
212 293
213 void PanelViewAura::CloseView() { 294 void PanelViewAura::CloseView() {
214 widget_->CloseNow(); 295 widget_->CloseNow();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 return View::GetWidget(); 335 return View::GetWidget();
255 } 336 }
256 337
257 const views::Widget* PanelViewAura::GetWidget() const { 338 const views::Widget* PanelViewAura::GetWidget() const {
258 return View::GetWidget(); 339 return View::GetWidget();
259 } 340 }
260 341
261 views::NonClientFrameView* PanelViewAura::CreateNonClientFrameView() { 342 views::NonClientFrameView* PanelViewAura::CreateNonClientFrameView() {
262 return new ash::PanelFrameView(); 343 return new ash::PanelFrameView();
263 } 344 }
345
346 // BaseWindow implementation:
347
348 bool PanelViewAura::IsActive() const {
349 return GetWidget()->IsActive();
350 }
351
352 bool PanelViewAura::IsMaximized() const {
353 return GetWidget()->IsMaximized();
354 }
355
356 bool PanelViewAura::IsMinimized() const {
357 return GetWidget()->IsMinimized();
358 }
359
360 gfx::Rect PanelViewAura::GetRestoredBounds() const {
361 return GetWidget()->GetRestoredBounds();
362 }
363
364 gfx::Rect PanelViewAura::GetBounds() const {
365 return GetWidget()->GetWindowScreenBounds();
366 }
367
368 void PanelViewAura::Show() {
369 GetWidget()->Show();
370 }
371
372 void PanelViewAura::ShowInactive() {
373 GetWidget()->ShowInactive();
374 }
375
376 void PanelViewAura::Close() {
377 GetWidget()->Close();
378 }
379
380 void PanelViewAura::Activate() {
381 GetWidget()->Activate();
382 }
383
384 void PanelViewAura::Deactivate() {
385 GetWidget()->Deactivate();
386 }
387
388 void PanelViewAura::Maximize() {
389 // Maximize is not implemented for panels.
390 }
391
392 void PanelViewAura::Minimize() {
393 // TODO(stevenjb): Implement this properly.
394 GetWidget()->Minimize();
395 NOTIMPLEMENTED();
396 }
397
398 void PanelViewAura::Restore() {
399 // TODO(stevenjb): Implement this properly.
400 GetWidget()->Restore();
401 NOTIMPLEMENTED();
402 }
403
404 void PanelViewAura::SetBounds(const gfx::Rect& bounds) {
405 GetWidget()->SetBounds(bounds);
406 }
407
408 void PanelViewAura::FlashFrame(bool flash) {
409 // TODO(stevenjb): Implement
410 NOTIMPLEMENTED();
411 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/aura/panel_view_aura.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698