| 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/debugger/devtools_window.h" | 9 #include "chrome/browser/debugger/devtools_window.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
| 11 #include "chrome/browser/extensions/extension_process_manager.h" | 11 #include "chrome/browser/extensions/extension_process_manager.h" |
| 12 #include "chrome/browser/extensions/extension_view_container.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 14 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 15 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 15 #import "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 16 #import "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
| 16 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 17 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
| 20 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 21 #include "ui/base/cocoa/window_size_constants.h" | 22 #include "ui/base/cocoa/window_size_constants.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 49 // Called when the extension's hosted NSView has been resized. | 50 // Called when the extension's hosted NSView has been resized. |
| 50 - (void)extensionViewFrameChanged; | 51 - (void)extensionViewFrameChanged; |
| 51 | 52 |
| 52 // Called when the extension's size changes. | 53 // Called when the extension's size changes. |
| 53 - (void)onSizeChanged:(NSSize)newSize; | 54 - (void)onSizeChanged:(NSSize)newSize; |
| 54 | 55 |
| 55 // Called when the extension view is shown. | 56 // Called when the extension view is shown. |
| 56 - (void)onViewDidShow; | 57 - (void)onViewDidShow; |
| 57 @end | 58 @end |
| 58 | 59 |
| 59 class ExtensionPopupContainer : public ExtensionViewMac::Container { | 60 class ExtensionPopupContainer : public ExtensionViewContainer { |
| 60 public: | 61 public: |
| 61 explicit ExtensionPopupContainer(ExtensionPopupController* controller) | 62 explicit ExtensionPopupContainer(ExtensionPopupController* controller) |
| 62 : controller_(controller) { | 63 : controller_(controller) { |
| 63 } | 64 } |
| 64 | 65 |
| 65 virtual void OnExtensionSizeChanged( | 66 virtual void OnExtensionSizeChanged(ExtensionView* view, |
| 66 ExtensionViewMac* view, | 67 const gfx::Size& new_size) OVERRIDE { |
| 67 const gfx::Size& new_size) OVERRIDE { | |
| 68 [controller_ onSizeChanged: | 68 [controller_ onSizeChanged: |
| 69 NSMakeSize(new_size.width(), new_size.height())]; | 69 NSMakeSize(new_size.width(), new_size.height())]; |
| 70 } | 70 } |
| 71 | 71 |
| 72 virtual void OnExtensionViewDidShow(ExtensionViewMac* view) OVERRIDE { | 72 virtual void OnExtensionViewDidShow(ExtensionView* view) OVERRIDE { |
| 73 [controller_ onViewDidShow]; | 73 [controller_ onViewDidShow]; |
| 74 } | 74 } |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 ExtensionPopupController* controller_; // Weak; owns this. | 77 ExtensionPopupController* controller_; // Weak; owns this. |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 class DevtoolsNotificationBridge : public content::NotificationObserver { | 80 class DevtoolsNotificationBridge : public content::NotificationObserver { |
| 81 public: | 81 public: |
| 82 explicit DevtoolsNotificationBridge(ExtensionPopupController* controller) | 82 explicit DevtoolsNotificationBridge(ExtensionPopupController* controller) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 anchoredAt = [parentWindow convertBaseToScreen:anchoredAt]; | 140 anchoredAt = [parentWindow convertBaseToScreen:anchoredAt]; |
| 141 if ((self = [super initWithWindow:window | 141 if ((self = [super initWithWindow:window |
| 142 parentWindow:parentWindow | 142 parentWindow:parentWindow |
| 143 anchoredAt:anchoredAt])) { | 143 anchoredAt:anchoredAt])) { |
| 144 host_.reset(host); | 144 host_.reset(host); |
| 145 beingInspected_ = devMode; | 145 beingInspected_ = devMode; |
| 146 | 146 |
| 147 InfoBubbleView* view = self.bubble; | 147 InfoBubbleView* view = self.bubble; |
| 148 [view setArrowLocation:arrowLocation]; | 148 [view setArrowLocation:arrowLocation]; |
| 149 | 149 |
| 150 extensionView_ = host->view()->native_view(); | 150 extensionView_ = host->GetExtensionView()->GetNativeView(); |
| 151 container_.reset(new ExtensionPopupContainer(self)); | 151 container_.reset(new ExtensionPopupContainer(self)); |
| 152 host->view()->set_container(container_.get()); | 152 host->GetExtensionView()->SetContainer(container_.get()); |
| 153 | 153 |
| 154 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 154 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 155 [center addObserver:self | 155 [center addObserver:self |
| 156 selector:@selector(extensionViewFrameChanged) | 156 selector:@selector(extensionViewFrameChanged) |
| 157 name:NSViewFrameDidChangeNotification | 157 name:NSViewFrameDidChangeNotification |
| 158 object:extensionView_]; | 158 object:extensionView_]; |
| 159 | 159 |
| 160 [view addSubview:extensionView_]; | 160 [view addSubview:extensionView_]; |
| 161 | 161 |
| 162 notificationBridge_.reset(new DevtoolsNotificationBridge(self)); | 162 notificationBridge_.reset(new DevtoolsNotificationBridge(self)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 190 [super dealloc]; | 190 [super dealloc]; |
| 191 } | 191 } |
| 192 | 192 |
| 193 - (void)showDevTools { | 193 - (void)showDevTools { |
| 194 DevToolsWindow::OpenDevToolsWindow(host_->render_view_host()); | 194 DevToolsWindow::OpenDevToolsWindow(host_->render_view_host()); |
| 195 } | 195 } |
| 196 | 196 |
| 197 - (void)windowWillClose:(NSNotification *)notification { | 197 - (void)windowWillClose:(NSNotification *)notification { |
| 198 [super windowWillClose:notification]; | 198 [super windowWillClose:notification]; |
| 199 gPopup = nil; | 199 gPopup = nil; |
| 200 if (host_->view()) | 200 if (host_->GetExtensionView()) |
| 201 host_->view()->set_container(NULL); | 201 host_->GetExtensionView()->SetContainer(NULL); |
| 202 } | 202 } |
| 203 | 203 |
| 204 - (void)windowDidResignKey:(NSNotification*)notification { | 204 - (void)windowDidResignKey:(NSNotification*)notification { |
| 205 if (!beingInspected_) | 205 if (!beingInspected_) |
| 206 [super windowDidResignKey:notification]; | 206 [super windowDidResignKey:notification]; |
| 207 } | 207 } |
| 208 | 208 |
| 209 - (BOOL)isClosing { | 209 - (BOOL)isClosing { |
| 210 return [static_cast<InfoBubbleWindow*>([self window]) isClosing]; | 210 return [static_cast<InfoBubbleWindow*>([self window]) isClosing]; |
| 211 } | 211 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 [extensionView_ setFrame:frame]; | 342 [extensionView_ setFrame:frame]; |
| 343 [extensionView_ setNeedsDisplay:YES]; | 343 [extensionView_ setNeedsDisplay:YES]; |
| 344 } | 344 } |
| 345 | 345 |
| 346 - (void)onViewDidShow { | 346 - (void)onViewDidShow { |
| 347 [self onSizeChanged:pendingSize_]; | 347 [self onSizeChanged:pendingSize_]; |
| 348 } | 348 } |
| 349 | 349 |
| 350 - (void)windowDidResize:(NSNotification*)notification { | 350 - (void)windowDidResize:(NSNotification*)notification { |
| 351 // Let the extension view know, so that it can tell plugins. | 351 // Let the extension view know, so that it can tell plugins. |
| 352 if (host_->view()) | 352 if (host_->GetExtensionView()) |
| 353 host_->view()->WindowFrameChanged(); | 353 host_->GetExtensionView()->WindowFrameChanged(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 - (void)windowDidMove:(NSNotification*)notification { | 356 - (void)windowDidMove:(NSNotification*)notification { |
| 357 // Let the extension view know, so that it can tell plugins. | 357 // Let the extension view know, so that it can tell plugins. |
| 358 if (host_->view()) | 358 if (host_->GetExtensionView()) |
| 359 host_->view()->WindowFrameChanged(); | 359 host_->GetExtensionView()->WindowFrameChanged(); |
| 360 } | 360 } |
| 361 | 361 |
| 362 // Private (TestingAPI) | 362 // Private (TestingAPI) |
| 363 - (NSView*)view { | 363 - (NSView*)view { |
| 364 return extensionView_; | 364 return extensionView_; |
| 365 } | 365 } |
| 366 | 366 |
| 367 // Private (TestingAPI) | 367 // Private (TestingAPI) |
| 368 + (NSSize)minPopupSize { | 368 + (NSSize)minPopupSize { |
| 369 NSSize minSize = {ExtensionViewMac::kMinWidth, ExtensionViewMac::kMinHeight}; | 369 NSSize minSize = {ExtensionViewMac::kMinWidth, ExtensionViewMac::kMinHeight}; |
| 370 return minSize; | 370 return minSize; |
| 371 } | 371 } |
| 372 | 372 |
| 373 // Private (TestingAPI) | 373 // Private (TestingAPI) |
| 374 + (NSSize)maxPopupSize { | 374 + (NSSize)maxPopupSize { |
| 375 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; | 375 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; |
| 376 return maxSize; | 376 return maxSize; |
| 377 } | 377 } |
| 378 | 378 |
| 379 @end | 379 @end |
| OLD | NEW |