Chromium Code Reviews| 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_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 Loading... | |
| 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()); | |
|
sky
2012/02/24 04:38:24
Seems like you could share more code between the t
stevenjb
2012/02/24 19:25:06
Done.
| |
| 211 result->SetBoolean(keys::kIncognitoKey, | |
| 212 panel_host_->profile()->IsOffTheRecord()); | |
| 213 result->SetBoolean(keys::kFocusedKey, false); | |
|
sky
2012/02/24 04:38:24
Why is this always false?
stevenjb
2012/02/24 19:25:06
Oversight. Fixed.
| |
| 214 | |
| 215 SetWindowValueBounds(panel_view_->GetRestoredBounds(), result); | |
| 216 | |
| 217 result->SetString(keys::kWindowTypeKey, keys::kWindowTypeValuePanel); | |
| 218 result->SetString(keys::kShowStateKey, keys::kShowStateValueNormal); | |
| 219 | |
| 220 return result; | |
| 221 } | |
| 222 | |
| 223 base::DictionaryValue* | |
| 224 PanelExtensionWindowController::CreateWindowValueWithTabs() const { | |
| 225 DictionaryValue* result = CreateWindowValue(); | |
| 226 | |
| 227 // Currently there is no mechanism to get a tab id without an associated | |
| 228 // TabContentsWrapper. If we need access to tabs for non-browser windows | |
| 229 // we will need to either add a TabContentsWrapper for panels, or add another | |
| 230 // mechanism for tracking tabs. | |
| 231 | |
| 232 return result; | |
| 233 } | |
| 234 | |
| 235 bool PanelExtensionWindowController::CanClose( | |
| 236 ExtensionWindowController::Reason* reason) const { | |
| 237 return true; | |
| 238 } | |
| 239 | |
| 240 void PanelExtensionWindowController::SetFullscreenMode( | |
| 241 bool is_fullscreen, const GURL& extension_url) const { | |
| 242 } | |
| 243 | |
| 164 } // namespace internal | 244 } // namespace internal |
| 165 | 245 |
| 166 //////////////////////////////////////////////////////////////////////////////// | 246 //////////////////////////////////////////////////////////////////////////////// |
| 167 // PanelViewAura | 247 // PanelViewAura |
| 168 | 248 |
| 169 PanelViewAura::PanelViewAura(const std::string& title) | 249 PanelViewAura::PanelViewAura(const std::string& title) |
| 170 : title_(title), | 250 : title_(title), |
| 171 preferred_size_(kMinWidth, kMinHeight), | 251 preferred_size_(kMinWidth, kMinHeight), |
| 172 widget_(NULL) { | 252 widget_(NULL) { |
| 173 } | 253 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 194 params.bounds.set_height(kMinHeight); | 274 params.bounds.set_height(kMinHeight); |
| 195 | 275 |
| 196 widget_->Init(params); | 276 widget_->Init(params); |
| 197 widget_->GetNativeView()->SetName(title_); | 277 widget_->GetNativeView()->SetName(title_); |
| 198 | 278 |
| 199 host_.reset(new internal::PanelHost(this, profile)); | 279 host_.reset(new internal::PanelHost(this, profile)); |
| 200 host_->Init(url); | 280 host_->Init(url); |
| 201 | 281 |
| 202 Attach(host_->web_contents()->GetNativeView()); | 282 Attach(host_->web_contents()->GetNativeView()); |
| 203 | 283 |
| 204 widget_->Show(); | 284 // Add the browser to the list of windows available to the extension API. |
| 285 extension_window_controller_.reset( | |
| 286 new internal::PanelExtensionWindowController(this, host_.get())); | |
| 287 | |
| 288 // Show the window, but don't activate it by default. | |
| 289 widget_->ShowInactive(); | |
| 205 | 290 |
| 206 return widget_; | 291 return widget_; |
| 207 } | 292 } |
| 208 | 293 |
| 209 content::WebContents* PanelViewAura::WebContents() { | 294 content::WebContents* PanelViewAura::WebContents() { |
| 210 return host_->web_contents(); | 295 return host_->web_contents(); |
| 211 } | 296 } |
| 212 | 297 |
| 213 void PanelViewAura::CloseView() { | 298 void PanelViewAura::CloseView() { |
| 214 widget_->CloseNow(); | 299 widget_->CloseNow(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 return View::GetWidget(); | 339 return View::GetWidget(); |
| 255 } | 340 } |
| 256 | 341 |
| 257 const views::Widget* PanelViewAura::GetWidget() const { | 342 const views::Widget* PanelViewAura::GetWidget() const { |
| 258 return View::GetWidget(); | 343 return View::GetWidget(); |
| 259 } | 344 } |
| 260 | 345 |
| 261 views::NonClientFrameView* PanelViewAura::CreateNonClientFrameView() { | 346 views::NonClientFrameView* PanelViewAura::CreateNonClientFrameView() { |
| 262 return new ash::PanelFrameView(); | 347 return new ash::PanelFrameView(); |
| 263 } | 348 } |
| 349 | |
| 350 // BaseWindow implementation: | |
| 351 | |
| 352 bool PanelViewAura::IsActive() const { | |
| 353 return GetWidget()->IsActive(); | |
| 354 } | |
| 355 | |
| 356 bool PanelViewAura::IsMaximized() const { | |
| 357 return GetWidget()->IsMaximized(); | |
| 358 } | |
| 359 | |
| 360 bool PanelViewAura::IsMinimized() const { | |
| 361 return GetWidget()->IsMinimized(); | |
| 362 } | |
| 363 | |
| 364 gfx::Rect PanelViewAura::GetRestoredBounds() const { | |
| 365 return GetWidget()->GetRestoredBounds(); | |
| 366 } | |
| 367 | |
| 368 gfx::Rect PanelViewAura::GetBounds() const { | |
| 369 return GetWidget()->GetWindowScreenBounds(); | |
| 370 } | |
| 371 | |
| 372 void PanelViewAura::Show() { | |
| 373 GetWidget()->Show(); | |
| 374 } | |
| 375 | |
| 376 void PanelViewAura::ShowInactive() { | |
| 377 GetWidget()->ShowInactive(); | |
| 378 } | |
| 379 | |
| 380 void PanelViewAura::Close() { | |
| 381 GetWidget()->Close(); | |
| 382 } | |
| 383 | |
| 384 void PanelViewAura::Activate() { | |
| 385 GetWidget()->Activate(); | |
| 386 } | |
| 387 | |
| 388 void PanelViewAura::Deactivate() { | |
| 389 GetWidget()->Deactivate(); | |
| 390 } | |
| 391 | |
| 392 void PanelViewAura::Maximize() { | |
| 393 NOTIMPLEMENTED(); | |
| 394 } | |
| 395 | |
| 396 void PanelViewAura::Minimize() { | |
| 397 // TODO(stevenjb): Implement | |
| 398 NOTIMPLEMENTED(); | |
| 399 } | |
| 400 | |
| 401 void PanelViewAura::Restore() { | |
| 402 // TODO(stevenjb): Implement | |
| 403 NOTIMPLEMENTED(); | |
| 404 } | |
| 405 | |
| 406 void PanelViewAura::SetBounds(const gfx::Rect& bounds) { | |
| 407 GetWidget()->SetBounds(bounds); | |
| 408 } | |
| 409 | |
| 410 void PanelViewAura::FlashFrame(bool flash) { | |
| 411 // TODO(stevenjb): Implement | |
| 412 NOTIMPLEMENTED(); | |
| 413 } | |
| OLD | NEW |