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/panels/panel.h" | 5 #include "chrome/browser/ui/panels/panel.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/ui/panels/panel_host.h" | 27 #include "chrome/browser/ui/panels/panel_host.h" |
28 #include "chrome/browser/ui/panels/panel_manager.h" | 28 #include "chrome/browser/ui/panels/panel_manager.h" |
29 #include "chrome/browser/ui/panels/stacked_panel_collection.h" | 29 #include "chrome/browser/ui/panels/stacked_panel_collection.h" |
30 #include "chrome/browser/web_applications/web_app.h" | 30 #include "chrome/browser/web_applications/web_app.h" |
31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
33 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
34 #include "content/public/browser/render_view_host.h" | 34 #include "content/public/browser/render_view_host.h" |
35 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
36 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 37 #include "extensions/browser/extension_registry.h" |
37 #include "extensions/browser/extension_system.h" | 38 #include "extensions/browser/extension_system.h" |
38 #include "extensions/browser/image_loader.h" | 39 #include "extensions/browser/image_loader.h" |
39 #include "extensions/common/constants.h" | 40 #include "extensions/common/constants.h" |
40 #include "extensions/common/extension.h" | 41 #include "extensions/common/extension.h" |
41 #include "extensions/common/manifest_handlers/icons_handler.h" | 42 #include "extensions/common/manifest_handlers/icons_handler.h" |
42 #include "ui/gfx/image/image.h" | 43 #include "ui/gfx/image/image.h" |
43 #include "ui/gfx/rect.h" | 44 #include "ui/gfx/rect.h" |
44 | 45 |
45 using base::UserMetricsAction; | 46 using base::UserMetricsAction; |
46 using content::RenderViewHost; | 47 using content::RenderViewHost; |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 433 } |
433 } | 434 } |
434 | 435 |
435 void Panel::Observe(int type, | 436 void Panel::Observe(int type, |
436 const content::NotificationSource& source, | 437 const content::NotificationSource& source, |
437 const content::NotificationDetails& details) { | 438 const content::NotificationDetails& details) { |
438 switch (type) { | 439 switch (type) { |
439 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: | 440 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: |
440 ConfigureAutoResize(content::Source<content::WebContents>(source).ptr()); | 441 ConfigureAutoResize(content::Source<content::WebContents>(source).ptr()); |
441 break; | 442 break; |
442 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: | |
443 if (content::Details<extensions::UnloadedExtensionInfo>( | |
444 details)->extension->id() == extension_id()) | |
445 Close(); | |
446 break; | |
447 case chrome::NOTIFICATION_APP_TERMINATING: | 443 case chrome::NOTIFICATION_APP_TERMINATING: |
448 Close(); | 444 Close(); |
449 break; | 445 break; |
450 default: | 446 default: |
451 NOTREACHED() << "Received unexpected notification " << type; | 447 NOTREACHED() << "Received unexpected notification " << type; |
452 } | 448 } |
453 } | 449 } |
454 | 450 |
| 451 void Panel::OnExtensionUnloaded( |
| 452 content::BrowserContext* browser_context, |
| 453 const extensions::Extension* extension, |
| 454 extensions::UnloadedExtensionInfo::Reason reason) { |
| 455 if (extension->id() == extension_id()) |
| 456 Close(); |
| 457 } |
455 void Panel::OnTitlebarClicked(panel::ClickModifier modifier) { | 458 void Panel::OnTitlebarClicked(panel::ClickModifier modifier) { |
456 if (collection_) | 459 if (collection_) |
457 collection_->OnPanelTitlebarClicked(this, modifier); | 460 collection_->OnPanelTitlebarClicked(this, modifier); |
458 | 461 |
459 // Normally the system activates a window when the titlebar is clicked. | 462 // Normally the system activates a window when the titlebar is clicked. |
460 // However, we prevent system activation of minimized panels, thus the | 463 // However, we prevent system activation of minimized panels, thus the |
461 // activation may not have occurred. Also, some OSes (Windows) will | 464 // activation may not have occurred. Also, some OSes (Windows) will |
462 // activate a minimized panel on mouse-down regardless of our attempts to | 465 // activate a minimized panel on mouse-down regardless of our attempts to |
463 // prevent system activation. Attention state is not cleared in that case. | 466 // prevent system activation. Attention state is not cleared in that case. |
464 // See Panel::OnActiveStateChanged(). | 467 // See Panel::OnActiveStateChanged(). |
(...skipping 19 matching lines...) Expand all Loading... |
484 } | 487 } |
485 | 488 |
486 void Panel::OnWindowSizeAvailable() { | 489 void Panel::OnWindowSizeAvailable() { |
487 ConfigureAutoResize(GetWebContents()); | 490 ConfigureAutoResize(GetWebContents()); |
488 } | 491 } |
489 | 492 |
490 void Panel::OnNativePanelClosed() { | 493 void Panel::OnNativePanelClosed() { |
491 // Ensure previously enqueued OnImageLoaded callbacks are ignored. | 494 // Ensure previously enqueued OnImageLoaded callbacks are ignored. |
492 image_loader_ptr_factory_.InvalidateWeakPtrs(); | 495 image_loader_ptr_factory_.InvalidateWeakPtrs(); |
493 registrar_.RemoveAll(); | 496 registrar_.RemoveAll(); |
| 497 extension_registry_->RemoveObserver(this); |
494 manager()->OnPanelClosed(this); | 498 manager()->OnPanelClosed(this); |
495 DCHECK(!collection_); | 499 DCHECK(!collection_); |
496 } | 500 } |
497 | 501 |
498 StackedPanelCollection* Panel::stack() const { | 502 StackedPanelCollection* Panel::stack() const { |
499 return collection_ && collection_->type() == PanelCollection::STACKED ? | 503 return collection_ && collection_->type() == PanelCollection::STACKED ? |
500 static_cast<StackedPanelCollection*>(collection_) : NULL; | 504 static_cast<StackedPanelCollection*>(collection_) : NULL; |
501 } | 505 } |
502 | 506 |
503 panel::Resizability Panel::CanResizeByMouse() const { | 507 panel::Resizability Panel::CanResizeByMouse() const { |
(...skipping 21 matching lines...) Expand all Loading... |
525 | 529 |
526 // Set up hosting for web contents. | 530 // Set up hosting for web contents. |
527 panel_host_.reset(new PanelHost(this, profile_)); | 531 panel_host_.reset(new PanelHost(this, profile_)); |
528 panel_host_->Init(url); | 532 panel_host_->Init(url); |
529 content::WebContents* web_contents = GetWebContents(); | 533 content::WebContents* web_contents = GetWebContents(); |
530 // The contents might be NULL for most of our tests. | 534 // The contents might be NULL for most of our tests. |
531 if (web_contents) | 535 if (web_contents) |
532 native_panel_->AttachWebContents(web_contents); | 536 native_panel_->AttachWebContents(web_contents); |
533 | 537 |
534 // Close when the extension is unloaded or the browser is exiting. | 538 // Close when the extension is unloaded or the browser is exiting. |
535 registrar_.Add(this, | 539 extension_registry_->AddObserver(this); |
536 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
537 content::Source<Profile>(profile_)); | |
538 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 540 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
539 content::NotificationService::AllSources()); | 541 content::NotificationService::AllSources()); |
540 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 542 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
541 content::Source<ThemeService>( | 543 content::Source<ThemeService>( |
542 ThemeServiceFactory::GetForProfile(profile_))); | 544 ThemeServiceFactory::GetForProfile(profile_))); |
543 | 545 |
544 #if !defined(USE_AURA) | 546 #if !defined(USE_AURA) |
545 // Keep alive for AURA has been moved to panel_view. | 547 // Keep alive for AURA has been moved to panel_view. |
546 // Prevent the browser process from shutting down while this window is open. | 548 // Prevent the browser process from shutting down while this window is open. |
547 chrome::IncrementKeepAliveCount(); | 549 chrome::IncrementKeepAliveCount(); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 } | 796 } |
795 | 797 |
796 void Panel::SetWindowCornerStyle(panel::CornerStyle corner_style) { | 798 void Panel::SetWindowCornerStyle(panel::CornerStyle corner_style) { |
797 native_panel_->SetWindowCornerStyle(corner_style); | 799 native_panel_->SetWindowCornerStyle(corner_style); |
798 } | 800 } |
799 | 801 |
800 void Panel::MinimizeBySystem() { | 802 void Panel::MinimizeBySystem() { |
801 native_panel_->MinimizePanelBySystem(); | 803 native_panel_->MinimizePanelBySystem(); |
802 } | 804 } |
803 | 805 |
804 Panel::Panel(Profile* profile, const std::string& app_name, | 806 Panel::Panel(Profile* profile, |
805 const gfx::Size& min_size, const gfx::Size& max_size) | 807 const std::string& app_name, |
| 808 const gfx::Size& min_size, |
| 809 const gfx::Size& max_size) |
806 : app_name_(app_name), | 810 : app_name_(app_name), |
807 profile_(profile), | 811 profile_(profile), |
808 collection_(NULL), | 812 collection_(NULL), |
809 initialized_(false), | 813 initialized_(false), |
810 min_size_(min_size), | 814 min_size_(min_size), |
811 max_size_(max_size), | 815 max_size_(max_size), |
812 max_size_policy_(DEFAULT_MAX_SIZE), | 816 max_size_policy_(DEFAULT_MAX_SIZE), |
813 auto_resizable_(false), | 817 auto_resizable_(false), |
814 in_preview_mode_(false), | 818 in_preview_mode_(false), |
815 native_panel_(NULL), | 819 native_panel_(NULL), |
816 attention_mode_(USE_PANEL_ATTENTION), | 820 attention_mode_(USE_PANEL_ATTENTION), |
817 expansion_state_(EXPANDED), | 821 expansion_state_(EXPANDED), |
818 command_updater_(this), | 822 command_updater_(this), |
| 823 extension_registry_(extensions::ExtensionRegistry::Get(profile_)), |
819 image_loader_ptr_factory_(this) { | 824 image_loader_ptr_factory_(this) { |
820 } | 825 } |
821 | 826 |
822 void Panel::OnImageLoaded(const gfx::Image& image) { | 827 void Panel::OnImageLoaded(const gfx::Image& image) { |
823 if (!image.IsEmpty()) { | 828 if (!image.IsEmpty()) { |
824 app_icon_ = image; | 829 app_icon_ = image; |
825 native_panel_->UpdatePanelTitleBar(); | 830 native_panel_->UpdatePanelTitleBar(); |
826 } | 831 } |
827 | 832 |
828 content::NotificationService::current()->Notify( | 833 content::NotificationService::current()->Notify( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 // static | 900 // static |
896 void Panel::FormatTitleForDisplay(base::string16* title) { | 901 void Panel::FormatTitleForDisplay(base::string16* title) { |
897 size_t current_index = 0; | 902 size_t current_index = 0; |
898 size_t match_index; | 903 size_t match_index; |
899 while ((match_index = title->find(L'\n', current_index)) != | 904 while ((match_index = title->find(L'\n', current_index)) != |
900 base::string16::npos) { | 905 base::string16::npos) { |
901 title->replace(match_index, 1, base::string16()); | 906 title->replace(match_index, 1, base::string16()); |
902 current_index = match_index; | 907 current_index = match_index; |
903 } | 908 } |
904 } | 909 } |
OLD | NEW |