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

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

Issue 119633002: Close ExtensionPopup on tab switches; add test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Close ExtensionPopup on tab switches; add test. Created 7 years 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
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_popup.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/devtools/devtools_window.h" 10 #include "chrome/browser/devtools/devtools_window.h"
11 #include "chrome/browser/extensions/extension_view_host.h" 11 #include "chrome/browser/extensions/extension_view_host.h"
12 #include "chrome/browser/extensions/extension_view_host_factory.h" 12 #include "chrome/browser/extensions/extension_view_host_factory.h"
13 #include "chrome/browser/platform_util.h" 13 #include "chrome/browser/platform_util.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
17 #include "chrome/browser/ui/host_desktop.h" 17 #include "chrome/browser/ui/host_desktop.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/browser/ui/views/frame/browser_view.h" 19 #include "chrome/browser/ui/views/frame/browser_view.h"
19 #include "content/public/browser/devtools_agent_host.h" 20 #include "content/public/browser/devtools_agent_host.h"
20 #include "content/public/browser/devtools_manager.h" 21 #include "content/public/browser/devtools_manager.h"
21 #include "content/public/browser/notification_details.h" 22 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
23 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_contents_view.h" 26 #include "content/public/browser/web_contents_view.h"
26 #include "ui/gfx/insets.h" 27 #include "ui/gfx/insets.h"
27 #include "ui/views/layout/fill_layout.h" 28 #include "ui/views/layout/fill_layout.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 88
88 // Wait to show the popup until the contained host finishes loading. 89 // Wait to show the popup until the contained host finishes loading.
89 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 90 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
90 content::Source<WebContents>(host->host_contents())); 91 content::Source<WebContents>(host->host_contents()));
91 92
92 // Listen for the containing view calling window.close(); 93 // Listen for the containing view calling window.close();
93 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 94 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
94 content::Source<BrowserContext>(host->browser_context())); 95 content::Source<BrowserContext>(host->browser_context()));
95 content::DevToolsManager::GetInstance()->AddAgentStateCallback( 96 content::DevToolsManager::GetInstance()->AddAgentStateCallback(
96 devtools_callback_); 97 devtools_callback_);
98
99 Browser* browser = host_->view()->browser();
100 if (browser && browser->tab_strip_model())
sky 2013/12/20 00:14:51 Can browser really be NULL here? browser->tab_stri
msw 2013/12/20 00:46:28 Done, I removed both checks. I tracked down that t
101 browser->tab_strip_model()->AddObserver(this);
97 } 102 }
98 103
99 ExtensionPopup::~ExtensionPopup() { 104 ExtensionPopup::~ExtensionPopup() {
100 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( 105 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback(
101 devtools_callback_); 106 devtools_callback_);
107
108 Browser* browser = host_->view()->browser();
109 if (browser && browser->tab_strip_model())
110 browser->tab_strip_model()->RemoveObserver(this);
102 } 111 }
103 112
104 void ExtensionPopup::Observe(int type, 113 void ExtensionPopup::Observe(int type,
105 const content::NotificationSource& source, 114 const content::NotificationSource& source,
106 const content::NotificationDetails& details) { 115 const content::NotificationDetails& details) {
107 switch (type) { 116 switch (type) {
108 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: 117 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME:
109 DCHECK(content::Source<WebContents>(host()->host_contents()) == source); 118 DCHECK(content::Source<WebContents>(host()->host_contents()) == source);
110 // Show when the content finishes loading and its width is computed. 119 // Show when the content finishes loading and its width is computed.
111 ShowBubble(); 120 ShowBubble();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 chrome::HostDesktopType host_desktop_type = 194 chrome::HostDesktopType host_desktop_type =
186 chrome::GetHostDesktopTypeForNativeWindow(this_window); 195 chrome::GetHostDesktopTypeForNativeWindow(this_window);
187 if (!inspect_with_devtools_ && anchor_window == gained_active && 196 if (!inspect_with_devtools_ && anchor_window == gained_active &&
188 host_desktop_type != chrome::HOST_DESKTOP_TYPE_ASH && 197 host_desktop_type != chrome::HOST_DESKTOP_TYPE_ASH &&
189 this_window->GetRootWindow() == anchor_window->GetRootWindow() && 198 this_window->GetRootWindow() == anchor_window->GetRootWindow() &&
190 gained_active->transient_parent() != this_window) 199 gained_active->transient_parent() != this_window)
191 GetWidget()->Close(); 200 GetWidget()->Close();
192 } 201 }
193 #endif 202 #endif
194 203
204 void ExtensionPopup::ActiveTabChanged(content::WebContents* old_contents,
205 content::WebContents* new_contents,
206 int index,
207 int reason) {
208 GetWidget()->Close();
209 }
210
195 // static 211 // static
196 ExtensionPopup* ExtensionPopup::ShowPopup(const GURL& url, 212 ExtensionPopup* ExtensionPopup::ShowPopup(const GURL& url,
197 Browser* browser, 213 Browser* browser,
198 views::View* anchor_view, 214 views::View* anchor_view,
199 views::BubbleBorder::Arrow arrow, 215 views::BubbleBorder::Arrow arrow,
200 ShowAction show_action) { 216 ShowAction show_action) {
201 extensions::ExtensionViewHost* host = 217 extensions::ExtensionViewHost* host =
202 extensions::ExtensionViewHostFactory::CreatePopupHost(url, browser); 218 extensions::ExtensionViewHostFactory::CreatePopupHost(url, browser);
203 ExtensionPopup* popup = new ExtensionPopup(host, anchor_view, arrow, 219 ExtensionPopup* popup = new ExtensionPopup(host, anchor_view, arrow,
204 show_action); 220 show_action);
(...skipping 29 matching lines...) Expand all
234 250
235 // Focus on the host contents when the bubble is first shown. 251 // Focus on the host contents when the bubble is first shown.
236 host()->host_contents()->GetView()->Focus(); 252 host()->host_contents()->GetView()->Focus();
237 253
238 if (inspect_with_devtools_) { 254 if (inspect_with_devtools_) {
239 DevToolsWindow::ToggleDevToolsWindow(host()->render_view_host(), 255 DevToolsWindow::ToggleDevToolsWindow(host()->render_view_host(),
240 true, 256 true,
241 DevToolsToggleAction::ShowConsole()); 257 DevToolsToggleAction::ShowConsole());
242 } 258 }
243 } 259 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_popup.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698