| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/extensions/extension_popup_controller.h" | 5 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #import "chrome/browser/cocoa/browser_window_cocoa.h" | 10 #import "chrome/browser/cocoa/browser_window_cocoa.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 class DevtoolsNotificationBridge : public NotificationObserver { | 35 class DevtoolsNotificationBridge : public NotificationObserver { |
| 36 public: | 36 public: |
| 37 explicit DevtoolsNotificationBridge(ExtensionPopupController* controller) | 37 explicit DevtoolsNotificationBridge(ExtensionPopupController* controller) |
| 38 : controller_(controller) {} | 38 : controller_(controller) {} |
| 39 | 39 |
| 40 void Observe(NotificationType type, | 40 void Observe(NotificationType type, |
| 41 const NotificationSource& source, | 41 const NotificationSource& source, |
| 42 const NotificationDetails& details) { | 42 const NotificationDetails& details) { |
| 43 switch (type.value) { | 43 switch (type.value) { |
| 44 case NotificationType::EXTENSION_HOST_DID_STOP_LOADING: { | 44 case NotificationType::EXTENSION_HOST_DID_STOP_LOADING: { |
| 45 if (Details<ExtensionHost>([controller_ extensionHost]) == | 45 if (Details<ExtensionHost>([controller_ extensionHost]) == details) |
| 46 details) | |
| 47 [controller_ showDevTools]; | 46 [controller_ showDevTools]; |
| 48 break; | 47 break; |
| 49 } | 48 } |
| 50 case NotificationType::DEVTOOLS_WINDOW_CLOSING: { | 49 case NotificationType::DEVTOOLS_WINDOW_CLOSING: { |
| 51 RenderViewHost* rvh = | 50 RenderViewHost* rvh = [controller_ extensionHost]->render_view_host(); |
| 52 [controller_ extensionHost]->render_view_host(); | |
| 53 if (Details<RenderViewHost>(rvh) == details) | 51 if (Details<RenderViewHost>(rvh) == details) |
| 54 // Allow the devtools to finish detaching before we close the popup | 52 // Allow the devtools to finish detaching before we close the popup |
| 55 [controller_ performSelector:@selector(close) | 53 [controller_ performSelector:@selector(close) |
| 56 withObject:nil | 54 withObject:nil |
| 57 afterDelay:0.0]; | 55 afterDelay:0.0]; |
| 58 break; | 56 break; |
| 59 } | 57 } |
| 60 default: { | 58 default: { |
| 61 NOTREACHED() << "Received unexpected notification"; | 59 NOTREACHED() << "Received unexpected notification"; |
| 62 break; | 60 break; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 85 | 83 |
| 86 - (id)initWithHost:(ExtensionHost*)host | 84 - (id)initWithHost:(ExtensionHost*)host |
| 87 parentWindow:(NSWindow*)parentWindow | 85 parentWindow:(NSWindow*)parentWindow |
| 88 anchoredAt:(NSPoint)anchoredAt | 86 anchoredAt:(NSPoint)anchoredAt |
| 89 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation | 87 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation |
| 90 devMode:(BOOL)devMode { | 88 devMode:(BOOL)devMode { |
| 91 | 89 |
| 92 parentWindow_ = parentWindow; | 90 parentWindow_ = parentWindow; |
| 93 anchor_ = [parentWindow convertBaseToScreen:anchoredAt]; | 91 anchor_ = [parentWindow convertBaseToScreen:anchoredAt]; |
| 94 host_.reset(host); | 92 host_.reset(host); |
| 93 beingInspected_ = devMode; |
| 95 | 94 |
| 96 scoped_nsobject<InfoBubbleView> view([[InfoBubbleView alloc] init]); | 95 scoped_nsobject<InfoBubbleView> view([[InfoBubbleView alloc] init]); |
| 97 if (!view.get()) | 96 if (!view.get()) |
| 98 return nil; | 97 return nil; |
| 99 [view setArrowLocation:arrowLocation]; | 98 [view setArrowLocation:arrowLocation]; |
| 100 [view setBubbleType:info_bubble::kWhiteInfoBubble]; | 99 [view setBubbleType:info_bubble::kWhiteInfoBubble]; |
| 101 | 100 |
| 102 host->view()->set_is_toolstrip(NO); | 101 host->view()->set_is_toolstrip(NO); |
| 103 | 102 |
| 104 extensionView_ = host->view()->native_view(); | 103 extensionView_ = host->view()->native_view(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 120 initWithContentRect:NSZeroRect | 119 initWithContentRect:NSZeroRect |
| 121 styleMask:NSBorderlessWindowMask | 120 styleMask:NSBorderlessWindowMask |
| 122 backing:NSBackingStoreBuffered | 121 backing:NSBackingStoreBuffered |
| 123 defer:YES]); | 122 defer:YES]); |
| 124 if (!window.get()) | 123 if (!window.get()) |
| 125 return nil; | 124 return nil; |
| 126 | 125 |
| 127 [window setDelegate:self]; | 126 [window setDelegate:self]; |
| 128 [window setContentView:view]; | 127 [window setContentView:view]; |
| 129 self = [super initWithWindow:window]; | 128 self = [super initWithWindow:window]; |
| 130 if (devMode) { | 129 if (beingInspected_) { |
| 131 beingInspected_ = true; | |
| 132 // Listen for the the devtools window closing. | 130 // Listen for the the devtools window closing. |
| 133 notificationBridge_.reset(new DevtoolsNotificationBridge(self)); | 131 notificationBridge_.reset(new DevtoolsNotificationBridge(self)); |
| 134 registrar_.reset(new NotificationRegistrar); | 132 registrar_.reset(new NotificationRegistrar); |
| 135 registrar_->Add(notificationBridge_.get(), | 133 registrar_->Add(notificationBridge_.get(), |
| 136 NotificationType::DEVTOOLS_WINDOW_CLOSING, | 134 NotificationType::DEVTOOLS_WINDOW_CLOSING, |
| 137 Source<Profile>(host->profile())); | 135 Source<Profile>(host->profile())); |
| 138 registrar_->Add(notificationBridge_.get(), | 136 registrar_->Add(notificationBridge_.get(), |
| 139 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, | 137 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, |
| 140 Source<Profile>(host->profile())); | 138 Source<Profile>(host->profile())); |
| 141 } else { | |
| 142 beingInspected_ = false; | |
| 143 } | 139 } |
| 144 return self; | 140 return self; |
| 145 } | 141 } |
| 146 | 142 |
| 147 - (void)showDevTools { | 143 - (void)showDevTools { |
| 148 DevToolsManager::GetInstance()->OpenDevToolsWindow( | 144 DevToolsManager::GetInstance()->OpenDevToolsWindow(host_->render_view_host()); |
| 149 host_->render_view_host()); | |
| 150 } | 145 } |
| 151 | 146 |
| 152 - (void)dealloc { | 147 - (void)dealloc { |
| 153 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 148 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 154 [super dealloc]; | 149 [super dealloc]; |
| 155 } | 150 } |
| 156 | 151 |
| 157 - (void)parentWindowWillClose:(NSNotification*)notification { | 152 - (void)parentWindowWillClose:(NSNotification*)notification { |
| 158 [self close]; | 153 [self close]; |
| 159 } | 154 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 return minSize; | 329 return minSize; |
| 335 } | 330 } |
| 336 | 331 |
| 337 // Private (TestingAPI) | 332 // Private (TestingAPI) |
| 338 + (NSSize)maxPopupSize { | 333 + (NSSize)maxPopupSize { |
| 339 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; | 334 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; |
| 340 return maxSize; | 335 return maxSize; |
| 341 } | 336 } |
| 342 | 337 |
| 343 @end | 338 @end |
| OLD | NEW |