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 "chrome/browser/devtools/devtools_window.h" | 9 #include "chrome/browser/devtools/devtools_window.h" |
10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 [controller_ onViewDidShow]; | 74 [controller_ onViewDidShow]; |
75 } | 75 } |
76 | 76 |
77 private: | 77 private: |
78 ExtensionPopupController* controller_; // Weak; owns this. | 78 ExtensionPopupController* controller_; // Weak; owns this. |
79 }; | 79 }; |
80 | 80 |
81 class DevtoolsNotificationBridge : public content::NotificationObserver { | 81 class DevtoolsNotificationBridge : public content::NotificationObserver { |
82 public: | 82 public: |
83 explicit DevtoolsNotificationBridge(ExtensionPopupController* controller) | 83 explicit DevtoolsNotificationBridge(ExtensionPopupController* controller) |
84 : controller_(controller) {} | 84 : controller_(controller), |
85 rvh_([controller_ extensionHost]->render_view_host()) {} | |
85 | 86 |
86 virtual void Observe( | 87 virtual void Observe( |
87 int type, | 88 int type, |
88 const content::NotificationSource& source, | 89 const content::NotificationSource& source, |
89 const content::NotificationDetails& details) OVERRIDE { | 90 const content::NotificationDetails& details) OVERRIDE { |
90 switch (type) { | 91 switch (type) { |
91 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | 92 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { |
92 if (content::Details<extensions::ExtensionHost>( | 93 if (content::Details<extensions::ExtensionHost>( |
93 [controller_ extensionHost]) == details) { | 94 [controller_ extensionHost]) == details) { |
94 [controller_ showDevTools]; | 95 [controller_ showDevTools]; |
95 } | 96 } |
96 break; | 97 break; |
97 } | 98 } |
98 case content::NOTIFICATION_DEVTOOLS_AGENT_ATTACHED: { | 99 case content::NOTIFICATION_DEVTOOLS_AGENT_ATTACHED: { |
99 RenderViewHost* rvh = [controller_ extensionHost]->render_view_host(); | 100 if (content::Details<RenderViewHost>(rvh_) == details) |
100 if (content::Details<RenderViewHost>(rvh) == details) | |
101 // Set the flag on the controller so the popup is not hidden when | 101 // Set the flag on the controller so the popup is not hidden when |
102 // the dev tools get focus. | 102 // the dev tools get focus. |
103 [controller_ setBeingInspected:YES]; | 103 [controller_ setBeingInspected:YES]; |
104 break; | 104 break; |
105 } | 105 } |
106 case content::NOTIFICATION_DEVTOOLS_AGENT_DETACHED: { | 106 case content::NOTIFICATION_DEVTOOLS_AGENT_DETACHED: { |
107 RenderViewHost* rvh = [controller_ extensionHost]->render_view_host(); | 107 if (content::Details<RenderViewHost>(rvh_) == details) |
108 if (content::Details<RenderViewHost>(rvh) == details) | |
109 // Allow the devtools to finish detaching before we close the popup | 108 // Allow the devtools to finish detaching before we close the popup |
110 [controller_ performSelector:@selector(close) | 109 [controller_ performSelector:@selector(close) |
111 withObject:nil | 110 withObject:nil |
112 afterDelay:0.0]; | 111 afterDelay:0.0]; |
113 break; | 112 break; |
114 } | 113 } |
115 default: { | 114 default: { |
116 NOTREACHED() << "Received unexpected notification"; | 115 NOTREACHED() << "Received unexpected notification"; |
117 break; | 116 break; |
118 } | 117 } |
119 }; | 118 }; |
120 } | 119 } |
121 | 120 |
122 private: | 121 private: |
123 ExtensionPopupController* controller_; | 122 ExtensionPopupController* controller_; |
123 // RenderViewHost for controller. Hold onto this separately because we need | |
124 // to know what it is when our ExtensionHost may no longer be valid. | |
125 RenderViewHost* rvh_; | |
Matt Perry
2013/03/15 22:55:46
nit: don't abbrev member vars
not at google - send to devlin
2013/03/15 23:49:53
Done.
| |
124 }; | 126 }; |
125 | 127 |
126 @implementation ExtensionPopupController | 128 @implementation ExtensionPopupController |
127 | 129 |
128 - (id)initWithHost:(extensions::ExtensionHost*)host | 130 - (id)initWithHost:(extensions::ExtensionHost*)host |
129 parentWindow:(NSWindow*)parentWindow | 131 parentWindow:(NSWindow*)parentWindow |
130 anchoredAt:(NSPoint)anchoredAt | 132 anchoredAt:(NSPoint)anchoredAt |
131 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation | 133 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation |
132 devMode:(BOOL)devMode { | 134 devMode:(BOOL)devMode { |
133 scoped_nsobject<InfoBubbleWindow> window( | 135 scoped_nsobject<InfoBubbleWindow> window( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 [super dealloc]; | 194 [super dealloc]; |
193 } | 195 } |
194 | 196 |
195 - (void)showDevTools { | 197 - (void)showDevTools { |
196 DevToolsWindow::OpenDevToolsWindow(host_->render_view_host()); | 198 DevToolsWindow::OpenDevToolsWindow(host_->render_view_host()); |
197 } | 199 } |
198 | 200 |
199 - (void)windowWillClose:(NSNotification *)notification { | 201 - (void)windowWillClose:(NSNotification *)notification { |
200 [super windowWillClose:notification]; | 202 [super windowWillClose:notification]; |
201 gPopup = nil; | 203 gPopup = nil; |
202 if (host_->view()) { | 204 if (host_->view()) |
203 host_->view()->set_container(NULL); | 205 host_->view()->set_container(NULL); |
204 host_.reset(); | |
205 } | |
206 } | 206 } |
207 | 207 |
208 - (void)windowDidResignKey:(NSNotification*)notification { | 208 - (void)windowDidResignKey:(NSNotification*)notification { |
209 if (!beingInspected_) | 209 if (!beingInspected_) |
210 [super windowDidResignKey:notification]; | 210 [super windowDidResignKey:notification]; |
211 } | 211 } |
212 | 212 |
213 - (BOOL)isClosing { | 213 - (BOOL)isClosing { |
214 return [static_cast<InfoBubbleWindow*>([self window]) isClosing]; | 214 return [static_cast<InfoBubbleWindow*>([self window]) isClosing]; |
215 } | 215 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 return minSize; | 374 return minSize; |
375 } | 375 } |
376 | 376 |
377 // Private (TestingAPI) | 377 // Private (TestingAPI) |
378 + (NSSize)maxPopupSize { | 378 + (NSSize)maxPopupSize { |
379 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; | 379 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; |
380 return maxSize; | 380 return maxSize; |
381 } | 381 } |
382 | 382 |
383 @end | 383 @end |
OLD | NEW |