| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "chrome/browser/devtools/devtools_window.h" | 12 #include "chrome/browser/devtools/devtools_window.h" |
| 13 #include "chrome/browser/extensions/extension_view_host.h" | 13 #include "chrome/browser/extensions/extension_view_host.h" |
| 14 #include "chrome/browser/extensions/extension_view_host_factory.h" | 14 #include "chrome/browser/extensions/extension_view_host_factory.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 16 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 17 #import "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 17 #import "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
| 18 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 18 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 20 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 20 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 21 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.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_agent_host_observer.h" |
| 23 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
| 24 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
| 25 #include "extensions/browser/notification_types.h" | 26 #include "extensions/browser/notification_types.h" |
| 26 #include "ui/base/cocoa/cocoa_base_utils.h" | 27 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 27 #include "ui/base/cocoa/window_size_constants.h" | 28 #include "ui/base/cocoa/window_size_constants.h" |
| 28 | 29 |
| 29 using content::BrowserContext; | 30 using content::BrowserContext; |
| 30 using content::RenderViewHost; | 31 using content::RenderViewHost; |
| 31 using content::WebContents; | 32 using content::WebContents; |
| 32 using extensions::ExtensionViewHost; | 33 using extensions::ExtensionViewHost; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 84 } |
| 84 | 85 |
| 85 void OnExtensionViewDidShow(ExtensionViewMac* view) override { | 86 void OnExtensionViewDidShow(ExtensionViewMac* view) override { |
| 86 [controller_ onViewDidShow]; | 87 [controller_ onViewDidShow]; |
| 87 } | 88 } |
| 88 | 89 |
| 89 private: | 90 private: |
| 90 ExtensionPopupController* controller_; // Weak; owns this. | 91 ExtensionPopupController* controller_; // Weak; owns this. |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 class ExtensionPopupNotificationBridge : public content::NotificationObserver { | 94 class ExtensionPopupNotificationBridge : |
| 95 public content::NotificationObserver, |
| 96 public content::DevToolsAgentHostObserver { |
| 94 public: | 97 public: |
| 95 ExtensionPopupNotificationBridge(ExtensionPopupController* controller, | 98 ExtensionPopupNotificationBridge(ExtensionPopupController* controller, |
| 96 ExtensionViewHost* view_host) | 99 ExtensionViewHost* view_host) |
| 97 : controller_(controller), | 100 : controller_(controller), |
| 98 view_host_(view_host), | 101 view_host_(view_host), |
| 99 web_contents_(view_host_->host_contents()), | 102 web_contents_(view_host_->host_contents()) { |
| 100 devtools_callback_(base::Bind( | 103 content::DevToolsAgentHost::AddObserver(this); |
| 101 &ExtensionPopupNotificationBridge::OnDevToolsStateChanged, | |
| 102 base::Unretained(this))) { | |
| 103 content::DevToolsAgentHost::AddAgentStateCallback(devtools_callback_); | |
| 104 } | 104 } |
| 105 | 105 |
| 106 ~ExtensionPopupNotificationBridge() override { | 106 ~ExtensionPopupNotificationBridge() override { |
| 107 content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_); | 107 content::DevToolsAgentHost::RemoveObserver(this); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void OnDevToolsStateChanged(content::DevToolsAgentHost* agent_host, | 110 void DevToolsAgentHostAttached( |
| 111 bool attached) { | 111 content::DevToolsAgentHost* agent_host) override { |
| 112 if (agent_host->GetWebContents() != web_contents_) | 112 if (agent_host->GetWebContents() != web_contents_) |
| 113 return; | 113 return; |
| 114 // Set the flag on the controller so the popup is not hidden when |
| 115 // the dev tools get focus. |
| 116 [controller_ setBeingInspected:YES]; |
| 117 } |
| 114 | 118 |
| 115 if (attached) { | 119 void DevToolsAgentHostDetached( |
| 116 // Set the flag on the controller so the popup is not hidden when | 120 content::DevToolsAgentHost* agent_host) override { |
| 117 // the dev tools get focus. | 121 if (agent_host->GetWebContents() != web_contents_) |
| 118 [controller_ setBeingInspected:YES]; | 122 return; |
| 119 } else { | 123 // Allow the devtools to finish detaching before we close the popup. |
| 120 // Allow the devtools to finish detaching before we close the popup. | 124 [controller_ performSelector:@selector(close) |
| 121 [controller_ performSelector:@selector(close) | 125 withObject:nil |
| 122 withObject:nil | 126 afterDelay:0.0]; |
| 123 afterDelay:0.0]; | |
| 124 } | |
| 125 } | 127 } |
| 126 | 128 |
| 127 void Observe(int type, | 129 void Observe(int type, |
| 128 const content::NotificationSource& source, | 130 const content::NotificationSource& source, |
| 129 const content::NotificationDetails& details) override { | 131 const content::NotificationDetails& details) override { |
| 130 switch (type) { | 132 switch (type) { |
| 131 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD: | 133 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD: |
| 132 if (content::Details<ExtensionViewHost>(view_host_) == details) | 134 if (content::Details<ExtensionViewHost>(view_host_) == details) |
| 133 [controller_ showDevTools]; | 135 [controller_ showDevTools]; |
| 134 break; | 136 break; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 146 | 148 |
| 147 private: | 149 private: |
| 148 ExtensionPopupController* controller_; | 150 ExtensionPopupController* controller_; |
| 149 | 151 |
| 150 extensions::ExtensionViewHost* view_host_; | 152 extensions::ExtensionViewHost* view_host_; |
| 151 | 153 |
| 152 // WebContents for controller. Hold onto this separately because we need to | 154 // WebContents for controller. Hold onto this separately because we need to |
| 153 // know what it is for notifications, but our ExtensionViewHost may not be | 155 // know what it is for notifications, but our ExtensionViewHost may not be |
| 154 // valid. | 156 // valid. |
| 155 WebContents* web_contents_; | 157 WebContents* web_contents_; |
| 156 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; | |
| 157 | 158 |
| 158 DISALLOW_COPY_AND_ASSIGN(ExtensionPopupNotificationBridge); | 159 DISALLOW_COPY_AND_ASSIGN(ExtensionPopupNotificationBridge); |
| 159 }; | 160 }; |
| 160 | 161 |
| 161 @implementation ExtensionPopupController | 162 @implementation ExtensionPopupController |
| 162 | 163 |
| 163 @synthesize extensionId = extensionId_; | 164 @synthesize extensionId = extensionId_; |
| 164 | 165 |
| 165 - (id)initWithParentWindow:(NSWindow*)parentWindow | 166 - (id)initWithParentWindow:(NSWindow*)parentWindow |
| 166 anchoredAt:(NSPoint)anchoredAt | 167 anchoredAt:(NSPoint)anchoredAt |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 return minSize; | 420 return minSize; |
| 420 } | 421 } |
| 421 | 422 |
| 422 // Private (TestingAPI) | 423 // Private (TestingAPI) |
| 423 + (NSSize)maxPopupSize { | 424 + (NSSize)maxPopupSize { |
| 424 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; | 425 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; |
| 425 return maxSize; | 426 return maxSize; |
| 426 } | 427 } |
| 427 | 428 |
| 428 @end | 429 @end |
| OLD | NEW |