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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_popup.cc

Issue 363233002: Abstract base 'ExtensionView' to Fix DEPS violation in extension_view_host.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Init() must be done after assigning Created 6 years, 5 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 | Annotate | Revision Log
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/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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 : BubbleDelegateView(anchor_view, arrow), 44 : BubbleDelegateView(anchor_view, arrow),
45 host_(host), 45 host_(host),
46 devtools_callback_(base::Bind( 46 devtools_callback_(base::Bind(
47 &ExtensionPopup::OnDevToolsStateChanged, base::Unretained(this))), 47 &ExtensionPopup::OnDevToolsStateChanged, base::Unretained(this))),
48 widget_initialized_(false) { 48 widget_initialized_(false) {
49 inspect_with_devtools_ = show_action == SHOW_AND_INSPECT; 49 inspect_with_devtools_ = show_action == SHOW_AND_INSPECT;
50 // Adjust the margin so that contents fit better. 50 // Adjust the margin so that contents fit better.
51 const int margin = views::BubbleBorder::GetCornerRadius() / 2; 51 const int margin = views::BubbleBorder::GetCornerRadius() / 2;
52 set_margins(gfx::Insets(margin, margin, margin, margin)); 52 set_margins(gfx::Insets(margin, margin, margin, margin));
53 SetLayoutManager(new views::FillLayout()); 53 SetLayoutManager(new views::FillLayout());
54 AddChildView(host->view()); 54 AddChildView(GetExtensionView());
55 host->view()->set_container(this); 55 GetExtensionView()->set_container(this);
56 // ExtensionPopup closes itself on very specific de-activation conditions. 56 // ExtensionPopup closes itself on very specific de-activation conditions.
57 set_close_on_deactivate(false); 57 set_close_on_deactivate(false);
58 58
59 // Wait to show the popup until the contained host finishes loading. 59 // Wait to show the popup until the contained host finishes loading.
60 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 60 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
61 content::Source<content::WebContents>(host->host_contents())); 61 content::Source<content::WebContents>(host->host_contents()));
62 62
63 // Listen for the containing view calling window.close(); 63 // Listen for the containing view calling window.close();
64 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 64 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
65 content::Source<content::BrowserContext>(host->browser_context())); 65 content::Source<content::BrowserContext>(host->browser_context()));
66 content::DevToolsManager::GetInstance()->AddAgentStateCallback( 66 content::DevToolsManager::GetInstance()->AddAgentStateCallback(
67 devtools_callback_); 67 devtools_callback_);
68 68
69 host_->view()->browser()->tab_strip_model()->AddObserver(this); 69 GetExtensionView()->GetBrowser()->tab_strip_model()->AddObserver(this);
70 } 70 }
71 71
72 ExtensionPopup::~ExtensionPopup() { 72 ExtensionPopup::~ExtensionPopup() {
73 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( 73 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback(
74 devtools_callback_); 74 devtools_callback_);
75 75
76 host_->view()->browser()->tab_strip_model()->RemoveObserver(this); 76 GetExtensionView()->GetBrowser()->tab_strip_model()->RemoveObserver(this);
77 } 77 }
78 78
79 void ExtensionPopup::Observe(int type, 79 void ExtensionPopup::Observe(int type,
80 const content::NotificationSource& source, 80 const content::NotificationSource& source,
81 const content::NotificationDetails& details) { 81 const content::NotificationDetails& details) {
82 switch (type) { 82 switch (type) {
83 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: 83 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME:
84 DCHECK_EQ(host()->host_contents(), 84 DCHECK_EQ(host()->host_contents(),
85 content::Source<content::WebContents>(source).ptr()); 85 content::Source<content::WebContents>(source).ptr());
86 // Show when the content finishes loading and its width is computed. 86 // Show when the content finishes loading and its width is computed.
(...skipping 20 matching lines...) Expand all
107 // Set inspect_with_devtools_ so the popup will be kept open while 107 // Set inspect_with_devtools_ so the popup will be kept open while
108 // the devtools are open. 108 // the devtools are open.
109 inspect_with_devtools_ = true; 109 inspect_with_devtools_ = true;
110 } else { 110 } else {
111 // Widget::Close posts a task, which should give the devtools window a 111 // Widget::Close posts a task, which should give the devtools window a
112 // chance to finish detaching from the inspected RenderViewHost. 112 // chance to finish detaching from the inspected RenderViewHost.
113 GetWidget()->Close(); 113 GetWidget()->Close();
114 } 114 }
115 } 115 }
116 116
117 ExtensionViewViews* ExtensionPopup::GetExtensionView() {
118 return static_cast<ExtensionViewViews*>(host()->view());
119 }
120
117 void ExtensionPopup::OnExtensionSizeChanged(ExtensionViewViews* view) { 121 void ExtensionPopup::OnExtensionSizeChanged(ExtensionViewViews* view) {
118 SizeToContents(); 122 SizeToContents();
119 } 123 }
120 124
121 gfx::Size ExtensionPopup::GetPreferredSize() const { 125 gfx::Size ExtensionPopup::GetPreferredSize() const {
122 // Constrain the size to popup min/max. 126 // Constrain the size to popup min/max.
123 gfx::Size sz = views::View::GetPreferredSize(); 127 gfx::Size sz = views::View::GetPreferredSize();
124 sz.set_width(std::max(kMinWidth, std::min(kMaxWidth, sz.width()))); 128 sz.set_width(std::max(kMinWidth, std::min(kMaxWidth, sz.width())));
125 sz.set_height(std::max(kMinHeight, std::min(kMaxHeight, sz.height()))); 129 sz.set_height(std::max(kMinHeight, std::min(kMaxHeight, sz.height())));
126 return sz; 130 return sz;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 GetWidget()->Show(); 219 GetWidget()->Show();
216 220
217 // Focus on the host contents when the bubble is first shown. 221 // Focus on the host contents when the bubble is first shown.
218 host()->host_contents()->Focus(); 222 host()->host_contents()->Focus();
219 223
220 if (inspect_with_devtools_) { 224 if (inspect_with_devtools_) {
221 DevToolsWindow::OpenDevToolsWindow(host()->render_view_host(), 225 DevToolsWindow::OpenDevToolsWindow(host()->render_view_host(),
222 DevToolsToggleAction::ShowConsole()); 226 DevToolsToggleAction::ShowConsole());
223 } 227 }
224 } 228 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698