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

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: rebase for r281699 (unused hwnd_util.h) 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"
11 #include "chrome/browser/extensions/extension_view_host_factory.h" 11 #include "chrome/browser/extensions/extension_view_host_factory.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "content/public/browser/devtools_agent_host.h" 14 #include "content/public/browser/devtools_agent_host.h"
15 #include "content/public/browser/devtools_manager.h" 15 #include "content/public/browser/devtools_manager.h"
16 #include "content/public/browser/notification_details.h" 16 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_source.h" 17 #include "content/public/browser/notification_source.h"
18 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
21 #include "ui/gfx/insets.h" 21 #include "ui/gfx/insets.h"
22 #include "ui/views/layout/fill_layout.h" 22 #include "ui/views/layout/fill_layout.h"
23 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
24 #include "ui/wm/core/window_animations.h" 24 #include "ui/wm/core/window_animations.h"
25 #include "ui/wm/core/window_util.h" 25 #include "ui/wm/core/window_util.h"
26 #include "ui/wm/public/activation_client.h" 26 #include "ui/wm/public/activation_client.h"
27 27
28 namespace {
29
30 ExtensionViewViews* GetExtensionView(extensions::ExtensionViewHost* host) {
31 return static_cast<ExtensionViewViews*>(host->view());
32 }
33
34 } // namespace
35
28 // The minimum/maximum dimensions of the popup. 36 // The minimum/maximum dimensions of the popup.
29 // The minimum is just a little larger than the size of the button itself. 37 // The minimum is just a little larger than the size of the button itself.
30 // The maximum is an arbitrary number that should be smaller than most screens. 38 // The maximum is an arbitrary number that should be smaller than most screens.
31 const int ExtensionPopup::kMinWidth = 25; 39 const int ExtensionPopup::kMinWidth = 25;
32 const int ExtensionPopup::kMinHeight = 25; 40 const int ExtensionPopup::kMinHeight = 25;
33 const int ExtensionPopup::kMaxWidth = 800; 41 const int ExtensionPopup::kMaxWidth = 800;
34 const int ExtensionPopup::kMaxHeight = 600; 42 const int ExtensionPopup::kMaxHeight = 600;
35 43
36 ExtensionPopup::ExtensionPopup(extensions::ExtensionViewHost* host, 44 ExtensionPopup::ExtensionPopup(extensions::ExtensionViewHost* host,
37 views::View* anchor_view, 45 views::View* anchor_view,
38 views::BubbleBorder::Arrow arrow, 46 views::BubbleBorder::Arrow arrow,
39 ShowAction show_action) 47 ShowAction show_action)
40 : BubbleDelegateView(anchor_view, arrow), 48 : BubbleDelegateView(anchor_view, arrow),
41 host_(host), 49 host_(host),
42 devtools_callback_(base::Bind( 50 devtools_callback_(base::Bind(
43 &ExtensionPopup::OnDevToolsStateChanged, base::Unretained(this))), 51 &ExtensionPopup::OnDevToolsStateChanged, base::Unretained(this))),
44 widget_initialized_(false) { 52 widget_initialized_(false) {
45 inspect_with_devtools_ = show_action == SHOW_AND_INSPECT; 53 inspect_with_devtools_ = show_action == SHOW_AND_INSPECT;
46 // Adjust the margin so that contents fit better. 54 // Adjust the margin so that contents fit better.
47 const int margin = views::BubbleBorder::GetCornerRadius() / 2; 55 const int margin = views::BubbleBorder::GetCornerRadius() / 2;
48 set_margins(gfx::Insets(margin, margin, margin, margin)); 56 set_margins(gfx::Insets(margin, margin, margin, margin));
49 SetLayoutManager(new views::FillLayout()); 57 SetLayoutManager(new views::FillLayout());
50 AddChildView(host->view()); 58 AddChildView(GetExtensionView(host));
51 host->view()->set_container(this); 59 GetExtensionView(host)->set_container(this);
52 // ExtensionPopup closes itself on very specific de-activation conditions. 60 // ExtensionPopup closes itself on very specific de-activation conditions.
53 set_close_on_deactivate(false); 61 set_close_on_deactivate(false);
54 62
55 // Wait to show the popup until the contained host finishes loading. 63 // Wait to show the popup until the contained host finishes loading.
56 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 64 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
57 content::Source<content::WebContents>(host->host_contents())); 65 content::Source<content::WebContents>(host->host_contents()));
58 66
59 // Listen for the containing view calling window.close(); 67 // Listen for the containing view calling window.close();
60 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 68 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
61 content::Source<content::BrowserContext>(host->browser_context())); 69 content::Source<content::BrowserContext>(host->browser_context()));
62 content::DevToolsManager::GetInstance()->AddAgentStateCallback( 70 content::DevToolsManager::GetInstance()->AddAgentStateCallback(
63 devtools_callback_); 71 devtools_callback_);
64 72
65 host_->view()->browser()->tab_strip_model()->AddObserver(this); 73 GetExtensionView(host)->GetBrowser()->tab_strip_model()->AddObserver(this);
66 } 74 }
67 75
68 ExtensionPopup::~ExtensionPopup() { 76 ExtensionPopup::~ExtensionPopup() {
69 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( 77 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback(
70 devtools_callback_); 78 devtools_callback_);
71 79
72 host_->view()->browser()->tab_strip_model()->RemoveObserver(this); 80 GetExtensionView(
81 host_.get())->GetBrowser()->tab_strip_model()->RemoveObserver(this);
73 } 82 }
74 83
75 void ExtensionPopup::Observe(int type, 84 void ExtensionPopup::Observe(int type,
76 const content::NotificationSource& source, 85 const content::NotificationSource& source,
77 const content::NotificationDetails& details) { 86 const content::NotificationDetails& details) {
78 switch (type) { 87 switch (type) {
79 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: 88 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME:
80 DCHECK_EQ(host()->host_contents(), 89 DCHECK_EQ(host()->host_contents(),
81 content::Source<content::WebContents>(source).ptr()); 90 content::Source<content::WebContents>(source).ptr());
82 // Show when the content finishes loading and its width is computed. 91 // Show when the content finishes loading and its width is computed.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 GetWidget()->Show(); 220 GetWidget()->Show();
212 221
213 // Focus on the host contents when the bubble is first shown. 222 // Focus on the host contents when the bubble is first shown.
214 host()->host_contents()->Focus(); 223 host()->host_contents()->Focus();
215 224
216 if (inspect_with_devtools_) { 225 if (inspect_with_devtools_) {
217 DevToolsWindow::OpenDevToolsWindow(host()->render_view_host(), 226 DevToolsWindow::OpenDevToolsWindow(host()->render_view_host(),
218 DevToolsToggleAction::ShowConsole()); 227 DevToolsToggleAction::ShowConsole());
219 } 228 }
220 } 229 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_dialog.cc ('k') | chrome/browser/ui/views/extensions/extension_view_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698