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 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 5 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "components/web_modal/popup_manager.h" | 21 #include "components/web_modal/popup_manager.h" |
22 #include "content/public/browser/devtools_agent_host.h" | 22 #include "content/public/browser/devtools_agent_host.h" |
23 #include "content/public/browser/devtools_manager.h" | 23 #include "content/public/browser/devtools_manager.h" |
24 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
25 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
26 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
27 #include "ui/base/cocoa/window_size_constants.h" | 27 #include "ui/base/cocoa/window_size_constants.h" |
28 | 28 |
29 using content::BrowserContext; | 29 using content::BrowserContext; |
30 using content::RenderViewHost; | 30 using content::RenderViewHost; |
| 31 using content::WebContents; |
31 | 32 |
32 namespace { | 33 namespace { |
33 // The duration for any animations that might be invoked by this controller. | 34 // The duration for any animations that might be invoked by this controller. |
34 const NSTimeInterval kAnimationDuration = 0.2; | 35 const NSTimeInterval kAnimationDuration = 0.2; |
35 | 36 |
36 // There should only be one extension popup showing at one time. Keep a | 37 // There should only be one extension popup showing at one time. Keep a |
37 // reference to it here. | 38 // reference to it here. |
38 static ExtensionPopupController* gPopup; | 39 static ExtensionPopupController* gPopup; |
39 | 40 |
40 // Given a value and a rage, clamp the value into the range. | 41 // Given a value and a rage, clamp the value into the range. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 86 } |
86 | 87 |
87 private: | 88 private: |
88 ExtensionPopupController* controller_; // Weak; owns this. | 89 ExtensionPopupController* controller_; // Weak; owns this. |
89 }; | 90 }; |
90 | 91 |
91 class DevtoolsNotificationBridge : public content::NotificationObserver { | 92 class DevtoolsNotificationBridge : public content::NotificationObserver { |
92 public: | 93 public: |
93 explicit DevtoolsNotificationBridge(ExtensionPopupController* controller) | 94 explicit DevtoolsNotificationBridge(ExtensionPopupController* controller) |
94 : controller_(controller), | 95 : controller_(controller), |
95 render_view_host_([controller_ extensionViewHost]->render_view_host()), | 96 web_contents_([controller_ extensionViewHost]->host_contents()), |
96 devtools_callback_(base::Bind( | 97 devtools_callback_(base::Bind( |
97 &DevtoolsNotificationBridge::OnDevToolsStateChanged, | 98 &DevtoolsNotificationBridge::OnDevToolsStateChanged, |
98 base::Unretained(this))) { | 99 base::Unretained(this))) { |
99 content::DevToolsManager::GetInstance()->AddAgentStateCallback( | 100 content::DevToolsManager::GetInstance()->AddAgentStateCallback( |
100 devtools_callback_); | 101 devtools_callback_); |
101 } | 102 } |
102 | 103 |
103 virtual ~DevtoolsNotificationBridge() { | 104 virtual ~DevtoolsNotificationBridge() { |
104 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( | 105 content::DevToolsManager::GetInstance()->RemoveAgentStateCallback( |
105 devtools_callback_); | 106 devtools_callback_); |
106 } | 107 } |
107 | 108 |
108 void OnDevToolsStateChanged(content::DevToolsAgentHost* agent_host, | 109 void OnDevToolsStateChanged(content::DevToolsAgentHost* agent_host, |
109 bool attached) { | 110 bool attached) { |
110 if (agent_host->GetRenderViewHost() != render_view_host_) | 111 if (agent_host->GetWebContents() != web_contents_) |
111 return; | 112 return; |
112 | 113 |
113 if (attached) { | 114 if (attached) { |
114 // Set the flag on the controller so the popup is not hidden when | 115 // Set the flag on the controller so the popup is not hidden when |
115 // the dev tools get focus. | 116 // the dev tools get focus. |
116 [controller_ setBeingInspected:YES]; | 117 [controller_ setBeingInspected:YES]; |
117 } else { | 118 } else { |
118 // Allow the devtools to finish detaching before we close the popup. | 119 // Allow the devtools to finish detaching before we close the popup. |
119 [controller_ performSelector:@selector(close) | 120 [controller_ performSelector:@selector(close) |
120 withObject:nil | 121 withObject:nil |
(...skipping 15 matching lines...) Expand all Loading... |
136 } | 137 } |
137 default: { | 138 default: { |
138 NOTREACHED() << "Received unexpected notification"; | 139 NOTREACHED() << "Received unexpected notification"; |
139 break; | 140 break; |
140 } | 141 } |
141 }; | 142 }; |
142 } | 143 } |
143 | 144 |
144 private: | 145 private: |
145 ExtensionPopupController* controller_; | 146 ExtensionPopupController* controller_; |
146 // RenderViewHost for controller. Hold onto this separately because we need to | 147 // WebContents for controller. Hold onto this separately because we need to |
147 // know what it is for notifications, but our ExtensionViewHost may not be | 148 // know what it is for notifications, but our ExtensionViewHost may not be |
148 // valid. | 149 // valid. |
149 RenderViewHost* render_view_host_; | 150 WebContents* web_contents_; |
150 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; | 151 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; |
151 }; | 152 }; |
152 | 153 |
153 @implementation ExtensionPopupController | 154 @implementation ExtensionPopupController |
154 | 155 |
155 - (id)initWithHost:(extensions::ExtensionViewHost*)host | 156 - (id)initWithHost:(extensions::ExtensionViewHost*)host |
156 parentWindow:(NSWindow*)parentWindow | 157 parentWindow:(NSWindow*)parentWindow |
157 anchoredAt:(NSPoint)anchoredAt | 158 anchoredAt:(NSPoint)anchoredAt |
158 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation | 159 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation |
159 devMode:(BOOL)devMode { | 160 devMode:(BOOL)devMode { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 202 } |
202 return self; | 203 return self; |
203 } | 204 } |
204 | 205 |
205 - (void)dealloc { | 206 - (void)dealloc { |
206 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 207 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
207 [super dealloc]; | 208 [super dealloc]; |
208 } | 209 } |
209 | 210 |
210 - (void)showDevTools { | 211 - (void)showDevTools { |
211 DevToolsWindow::OpenDevToolsWindow(host_->render_view_host()); | 212 DevToolsWindow::OpenDevToolsWindow(host_->host_contents()); |
212 } | 213 } |
213 | 214 |
214 - (void)close { | 215 - (void)close { |
215 // |windowWillClose:| could have already been called. http://crbug.com/279505 | 216 // |windowWillClose:| could have already been called. http://crbug.com/279505 |
216 if (host_) { | 217 if (host_) { |
217 // TODO(gbillock): Change this API to say directly if the current popup | 218 // TODO(gbillock): Change this API to say directly if the current popup |
218 // should block tab close? This is a bit over-reaching. | 219 // should block tab close? This is a bit over-reaching. |
219 web_modal::PopupManager* popup_manager = | 220 web_modal::PopupManager* popup_manager = |
220 web_modal::PopupManager::FromWebContents(host_->host_contents()); | 221 web_modal::PopupManager::FromWebContents(host_->host_contents()); |
221 if (popup_manager && popup_manager->IsWebModalDialogActive( | 222 if (popup_manager && popup_manager->IsWebModalDialogActive( |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 return minSize; | 432 return minSize; |
432 } | 433 } |
433 | 434 |
434 // Private (TestingAPI) | 435 // Private (TestingAPI) |
435 + (NSSize)maxPopupSize { | 436 + (NSSize)maxPopupSize { |
436 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; | 437 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; |
437 return maxSize; | 438 return maxSize; |
438 } | 439 } |
439 | 440 |
440 @end | 441 @end |
OLD | NEW |