| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/tab_contents_controller.h" | 5 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
| 8 #include "content/browser/renderer_host/render_view_host.h" | 8 #include "content/browser/renderer_host/render_view_host.h" |
| 9 #include "content/browser/renderer_host/render_widget_host_view.h" | 9 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 10 #include "content/browser/tab_contents/navigation_controller.h" | 10 #include "content/browser/tab_contents/navigation_controller.h" |
| 11 #include "content/browser/tab_contents/tab_contents.h" | 11 #include "content/browser/tab_contents/tab_contents.h" |
| 12 #include "content/common/content_notification_types.h" |
| 12 #include "content/common/notification_details.h" | 13 #include "content/common/notification_details.h" |
| 13 #include "content/common/notification_observer.h" | 14 #include "content/common/notification_observer.h" |
| 14 #include "content/common/notification_registrar.h" | 15 #include "content/common/notification_registrar.h" |
| 15 #include "content/common/notification_source.h" | 16 #include "content/common/notification_source.h" |
| 16 #include "content/common/notification_type.h" | |
| 17 | 17 |
| 18 @interface TabContentsController(Private) | 18 @interface TabContentsController(Private) |
| 19 // Forwards frame update to |delegate_| (ResizeNotificationView calls it). | 19 // Forwards frame update to |delegate_| (ResizeNotificationView calls it). |
| 20 - (void)tabContentsViewFrameWillChange:(NSRect)frameRect; | 20 - (void)tabContentsViewFrameWillChange:(NSRect)frameRect; |
| 21 // Notification from TabContents (forwarded by TabContentsNotificationBridge). | 21 // Notification from TabContents (forwarded by TabContentsNotificationBridge). |
| 22 - (void)tabContentsRenderViewHostChanged:(RenderViewHost*)oldHost | 22 - (void)tabContentsRenderViewHostChanged:(RenderViewHost*)oldHost |
| 23 newHost:(RenderViewHost*)newHost; | 23 newHost:(RenderViewHost*)newHost; |
| 24 @end | 24 @end |
| 25 | 25 |
| 26 | 26 |
| 27 // A supporting C++ bridge object to register for TabContents notifications. | 27 // A supporting C++ bridge object to register for TabContents notifications. |
| 28 | 28 |
| 29 class TabContentsNotificationBridge : public NotificationObserver { | 29 class TabContentsNotificationBridge : public NotificationObserver { |
| 30 public: | 30 public: |
| 31 explicit TabContentsNotificationBridge(TabContentsController* controller); | 31 explicit TabContentsNotificationBridge(TabContentsController* controller); |
| 32 | 32 |
| 33 // Overriden from NotificationObserver. | 33 // Overriden from NotificationObserver. |
| 34 virtual void Observe(NotificationType type, | 34 virtual void Observe(int type, |
| 35 const NotificationSource& source, | 35 const NotificationSource& source, |
| 36 const NotificationDetails& details); | 36 const NotificationDetails& details); |
| 37 // Register for |contents|'s notifications, remove all prior registrations. | 37 // Register for |contents|'s notifications, remove all prior registrations. |
| 38 void ChangeTabContents(TabContents* contents); | 38 void ChangeTabContents(TabContents* contents); |
| 39 private: | 39 private: |
| 40 NotificationRegistrar registrar_; | 40 NotificationRegistrar registrar_; |
| 41 TabContentsController* controller_; // weak, owns us | 41 TabContentsController* controller_; // weak, owns us |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 TabContentsNotificationBridge::TabContentsNotificationBridge( | 44 TabContentsNotificationBridge::TabContentsNotificationBridge( |
| 45 TabContentsController* controller) | 45 TabContentsController* controller) |
| 46 : controller_(controller) { | 46 : controller_(controller) { |
| 47 } | 47 } |
| 48 | 48 |
| 49 void TabContentsNotificationBridge::Observe( | 49 void TabContentsNotificationBridge::Observe( |
| 50 NotificationType type, | 50 int type, |
| 51 const NotificationSource& source, | 51 const NotificationSource& source, |
| 52 const NotificationDetails& details) { | 52 const NotificationDetails& details) { |
| 53 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { | 53 if (type == chrome::RENDER_VIEW_HOST_CHANGED) { |
| 54 RenderViewHostSwitchedDetails* switched_details = | 54 RenderViewHostSwitchedDetails* switched_details = |
| 55 Details<RenderViewHostSwitchedDetails>(details).ptr(); | 55 Details<RenderViewHostSwitchedDetails>(details).ptr(); |
| 56 [controller_ tabContentsRenderViewHostChanged:switched_details->old_host | 56 [controller_ tabContentsRenderViewHostChanged:switched_details->old_host |
| 57 newHost:switched_details->new_host]; | 57 newHost:switched_details->new_host]; |
| 58 } else { | 58 } else { |
| 59 NOTREACHED(); | 59 NOTREACHED(); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 void TabContentsNotificationBridge::ChangeTabContents(TabContents* contents) { | 63 void TabContentsNotificationBridge::ChangeTabContents(TabContents* contents) { |
| 64 registrar_.RemoveAll(); | 64 registrar_.RemoveAll(); |
| 65 if (contents) { | 65 if (contents) { |
| 66 registrar_.Add(this, | 66 registrar_.Add(this, |
| 67 NotificationType::RENDER_VIEW_HOST_CHANGED, | 67 chrome::RENDER_VIEW_HOST_CHANGED, |
| 68 Source<NavigationController>(&contents->controller())); | 68 Source<NavigationController>(&contents->controller())); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 | 72 |
| 73 // A custom view that notifies |controller| that view's frame is changing. | 73 // A custom view that notifies |controller| that view's frame is changing. |
| 74 | 74 |
| 75 @interface ResizeNotificationView : NSView { | 75 @interface ResizeNotificationView : NSView { |
| 76 TabContentsController* controller_; | 76 TabContentsController* controller_; |
| 77 } | 77 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // the view may have, so avoid changing the view hierarchy unless | 201 // the view may have, so avoid changing the view hierarchy unless |
| 202 // the view is different. | 202 // the view is different. |
| 203 if ([self tabContents] != updatedContents) { | 203 if ([self tabContents] != updatedContents) { |
| 204 [self changeTabContents:updatedContents]; | 204 [self changeTabContents:updatedContents]; |
| 205 if ([self tabContents]) | 205 if ([self tabContents]) |
| 206 [self ensureContentsVisible]; | 206 [self ensureContentsVisible]; |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 | 209 |
| 210 @end | 210 @end |
| OLD | NEW |