| 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/extensions/extension_popup.h" | 5 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/devtools/devtools_window.h" | 9 #include "chrome/browser/devtools/devtools_window.h" |
| 10 #include "chrome/browser/extensions/extension_view_host.h" | 10 #include "chrome/browser/extensions/extension_view_host.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 const int ExtensionPopup::kMaxWidth = 800; | 41 const int ExtensionPopup::kMaxWidth = 800; |
| 42 const int ExtensionPopup::kMaxHeight = 600; | 42 const int ExtensionPopup::kMaxHeight = 600; |
| 43 | 43 |
| 44 #if !defined(USE_AURA) | 44 #if !defined(USE_AURA) |
| 45 // static | 45 // static |
| 46 ExtensionPopup* ExtensionPopup::Create(extensions::ExtensionViewHost* host, | 46 ExtensionPopup* ExtensionPopup::Create(extensions::ExtensionViewHost* host, |
| 47 views::View* anchor_view, | 47 views::View* anchor_view, |
| 48 views::BubbleBorder::Arrow arrow, | 48 views::BubbleBorder::Arrow arrow, |
| 49 ShowAction show_action) { | 49 ShowAction show_action) { |
| 50 auto popup = new ExtensionPopup(host, anchor_view, arrow, show_action); | 50 auto popup = new ExtensionPopup(host, anchor_view, arrow, show_action); |
| 51 views::BubbleDelegateView::CreateBubble(popup); | 51 views::BubbleDialogDelegateView::CreateBubble(popup); |
| 52 return popup; | 52 return popup; |
| 53 } | 53 } |
| 54 #endif | 54 #endif |
| 55 | 55 |
| 56 ExtensionPopup::ExtensionPopup(extensions::ExtensionViewHost* host, | 56 ExtensionPopup::ExtensionPopup(extensions::ExtensionViewHost* host, |
| 57 views::View* anchor_view, | 57 views::View* anchor_view, |
| 58 views::BubbleBorder::Arrow arrow, | 58 views::BubbleBorder::Arrow arrow, |
| 59 ShowAction show_action) | 59 ShowAction show_action) |
| 60 : BubbleDelegateView(anchor_view, arrow), | 60 : BubbleDialogDelegateView(anchor_view, arrow), |
| 61 host_(host), | 61 host_(host), |
| 62 devtools_callback_(base::Bind( | 62 devtools_callback_(base::Bind( |
| 63 &ExtensionPopup::OnDevToolsStateChanged, base::Unretained(this))), | 63 &ExtensionPopup::OnDevToolsStateChanged, base::Unretained(this))), |
| 64 widget_initialized_(false) { | 64 widget_initialized_(false) { |
| 65 inspect_with_devtools_ = show_action == SHOW_AND_INSPECT; | 65 inspect_with_devtools_ = show_action == SHOW_AND_INSPECT; |
| 66 set_margins(gfx::Insets(kBubbleMargin)); | 66 set_margins(gfx::Insets(kBubbleMargin)); |
| 67 SetLayoutManager(new views::FillLayout()); | 67 SetLayoutManager(new views::FillLayout()); |
| 68 AddChildView(GetExtensionView(host)); | 68 AddChildView(GetExtensionView(host)); |
| 69 GetExtensionView(host)->set_container(this); | 69 GetExtensionView(host)->set_container(this); |
| 70 // ExtensionPopup closes itself on very specific de-activation conditions. | 70 // ExtensionPopup closes itself on very specific de-activation conditions. |
| 71 set_close_on_deactivate(false); | 71 set_close_on_deactivate(false); |
| 72 | 72 |
| 73 | |
| 74 // Listen for the containing view calling window.close(); | 73 // Listen for the containing view calling window.close(); |
| 75 registrar_.Add( | 74 registrar_.Add( |
| 76 this, | 75 this, |
| 77 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 76 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 78 content::Source<content::BrowserContext>(host->browser_context())); | 77 content::Source<content::BrowserContext>(host->browser_context())); |
| 79 content::DevToolsAgentHost::AddAgentStateCallback(devtools_callback_); | 78 content::DevToolsAgentHost::AddAgentStateCallback(devtools_callback_); |
| 80 | 79 |
| 81 GetExtensionView(host)->GetBrowser()->tab_strip_model()->AddObserver(this); | 80 GetExtensionView(host)->GetBrowser()->tab_strip_model()->AddObserver(this); |
| 82 | 81 |
| 83 // If the host had somehow finished loading, then we'd miss the notification | 82 // If the host had somehow finished loading, then we'd miss the notification |
| 84 // and not show. This seems to happen in single-process mode. | 83 // and not show. This seems to happen in single-process mode. |
| 85 if (host_->has_loaded_once()) { | 84 if (host_->has_loaded_once()) { |
| 86 ShowBubble(); | 85 ShowBubble(); |
| 87 } else { | 86 } else { |
| 88 // Wait to show the popup until the contained host finishes loading. | 87 // Wait to show the popup until the contained host finishes loading. |
| 89 registrar_.Add(this, | 88 registrar_.Add(this, |
| 90 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 89 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 91 content::Source<content::WebContents>( | 90 content::Source<content::WebContents>( |
| 92 host_->host_contents())); | 91 host_->host_contents())); |
| 93 } | 92 } |
| 94 } | 93 } |
| 95 | 94 |
| 96 ExtensionPopup::~ExtensionPopup() { | 95 ExtensionPopup::~ExtensionPopup() { |
| 97 content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_); | 96 content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_); |
| 98 | 97 |
| 99 GetExtensionView( | 98 GetExtensionView( |
| 100 host_.get())->GetBrowser()->tab_strip_model()->RemoveObserver(this); | 99 host_.get())->GetBrowser()->tab_strip_model()->RemoveObserver(this); |
| 101 } | 100 } |
| 102 | 101 |
| 102 int ExtensionPopup::GetDialogButtons() const { |
| 103 return ui::DIALOG_BUTTON_NONE; |
| 104 } |
| 105 |
| 103 void ExtensionPopup::Observe(int type, | 106 void ExtensionPopup::Observe(int type, |
| 104 const content::NotificationSource& source, | 107 const content::NotificationSource& source, |
| 105 const content::NotificationDetails& details) { | 108 const content::NotificationDetails& details) { |
| 106 switch (type) { | 109 switch (type) { |
| 107 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | 110 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
| 108 DCHECK_EQ(host()->host_contents(), | 111 DCHECK_EQ(host()->host_contents(), |
| 109 content::Source<content::WebContents>(source).ptr()); | 112 content::Source<content::WebContents>(source).ptr()); |
| 110 // Show when the content finishes loading and its width is computed. | 113 // Show when the content finishes loading and its width is computed. |
| 111 ShowBubble(); | 114 ShowBubble(); |
| 112 break; | 115 break; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 GetWidget()->Show(); | 198 GetWidget()->Show(); |
| 196 | 199 |
| 197 // Focus on the host contents when the bubble is first shown. | 200 // Focus on the host contents when the bubble is first shown. |
| 198 host()->host_contents()->Focus(); | 201 host()->host_contents()->Focus(); |
| 199 | 202 |
| 200 if (inspect_with_devtools_) { | 203 if (inspect_with_devtools_) { |
| 201 DevToolsWindow::OpenDevToolsWindow(host()->host_contents(), | 204 DevToolsWindow::OpenDevToolsWindow(host()->host_contents(), |
| 202 DevToolsToggleAction::ShowConsole()); | 205 DevToolsToggleAction::ShowConsole()); |
| 203 } | 206 } |
| 204 } | 207 } |
| OLD | NEW |