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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 - (void)onWindowChanged; | 66 - (void)onWindowChanged; |
67 | 67 |
68 @end | 68 @end |
69 | 69 |
70 class ExtensionPopupContainer : public ExtensionViewMac::Container { | 70 class ExtensionPopupContainer : public ExtensionViewMac::Container { |
71 public: | 71 public: |
72 explicit ExtensionPopupContainer(ExtensionPopupController* controller) | 72 explicit ExtensionPopupContainer(ExtensionPopupController* controller) |
73 : controller_(controller) { | 73 : controller_(controller) { |
74 } | 74 } |
75 | 75 |
76 virtual void OnExtensionSizeChanged( | 76 void OnExtensionSizeChanged(ExtensionViewMac* view, |
77 ExtensionViewMac* view, | 77 const gfx::Size& new_size) override { |
78 const gfx::Size& new_size) override { | |
79 [controller_ onSizeChanged: | 78 [controller_ onSizeChanged: |
80 NSMakeSize(new_size.width(), new_size.height())]; | 79 NSMakeSize(new_size.width(), new_size.height())]; |
81 } | 80 } |
82 | 81 |
83 virtual void OnExtensionViewDidShow(ExtensionViewMac* view) override { | 82 void OnExtensionViewDidShow(ExtensionViewMac* view) override { |
84 [controller_ onViewDidShow]; | 83 [controller_ onViewDidShow]; |
85 } | 84 } |
86 | 85 |
87 private: | 86 private: |
88 ExtensionPopupController* controller_; // Weak; owns this. | 87 ExtensionPopupController* controller_; // Weak; owns this. |
89 }; | 88 }; |
90 | 89 |
91 class DevtoolsNotificationBridge : public content::NotificationObserver { | 90 class DevtoolsNotificationBridge : public content::NotificationObserver { |
92 public: | 91 public: |
93 explicit DevtoolsNotificationBridge(ExtensionPopupController* controller) | 92 explicit DevtoolsNotificationBridge(ExtensionPopupController* controller) |
94 : controller_(controller), | 93 : controller_(controller), |
95 web_contents_([controller_ extensionViewHost]->host_contents()), | 94 web_contents_([controller_ extensionViewHost]->host_contents()), |
96 devtools_callback_(base::Bind( | 95 devtools_callback_(base::Bind( |
97 &DevtoolsNotificationBridge::OnDevToolsStateChanged, | 96 &DevtoolsNotificationBridge::OnDevToolsStateChanged, |
98 base::Unretained(this))) { | 97 base::Unretained(this))) { |
99 content::DevToolsAgentHost::AddAgentStateCallback(devtools_callback_); | 98 content::DevToolsAgentHost::AddAgentStateCallback(devtools_callback_); |
100 } | 99 } |
101 | 100 |
102 virtual ~DevtoolsNotificationBridge() { | 101 ~DevtoolsNotificationBridge() override { |
103 content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_); | 102 content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_); |
104 } | 103 } |
105 | 104 |
106 void OnDevToolsStateChanged(content::DevToolsAgentHost* agent_host, | 105 void OnDevToolsStateChanged(content::DevToolsAgentHost* agent_host, |
107 bool attached) { | 106 bool attached) { |
108 if (agent_host->GetWebContents() != web_contents_) | 107 if (agent_host->GetWebContents() != web_contents_) |
109 return; | 108 return; |
110 | 109 |
111 if (attached) { | 110 if (attached) { |
112 // Set the flag on the controller so the popup is not hidden when | 111 // Set the flag on the controller so the popup is not hidden when |
113 // the dev tools get focus. | 112 // the dev tools get focus. |
114 [controller_ setBeingInspected:YES]; | 113 [controller_ setBeingInspected:YES]; |
115 } else { | 114 } else { |
116 // Allow the devtools to finish detaching before we close the popup. | 115 // Allow the devtools to finish detaching before we close the popup. |
117 [controller_ performSelector:@selector(close) | 116 [controller_ performSelector:@selector(close) |
118 withObject:nil | 117 withObject:nil |
119 afterDelay:0.0]; | 118 afterDelay:0.0]; |
120 } | 119 } |
121 } | 120 } |
122 | 121 |
123 virtual void Observe( | 122 void Observe(int type, |
124 int type, | 123 const content::NotificationSource& source, |
125 const content::NotificationSource& source, | 124 const content::NotificationDetails& details) override { |
126 const content::NotificationDetails& details) override { | |
127 switch (type) { | 125 switch (type) { |
128 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | 126 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { |
129 if (content::Details<extensions::ExtensionViewHost>( | 127 if (content::Details<extensions::ExtensionViewHost>( |
130 [controller_ extensionViewHost]) == details) { | 128 [controller_ extensionViewHost]) == details) { |
131 [controller_ showDevTools]; | 129 [controller_ showDevTools]; |
132 } | 130 } |
133 break; | 131 break; |
134 } | 132 } |
135 default: { | 133 default: { |
136 NOTREACHED() << "Received unexpected notification"; | 134 NOTREACHED() << "Received unexpected notification"; |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 return minSize; | 432 return minSize; |
435 } | 433 } |
436 | 434 |
437 // Private (TestingAPI) | 435 // Private (TestingAPI) |
438 + (NSSize)maxPopupSize { | 436 + (NSSize)maxPopupSize { |
439 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; | 437 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; |
440 return maxSize; | 438 return maxSize; |
441 } | 439 } |
442 | 440 |
443 @end | 441 @end |
OLD | NEW |