Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.mm

Issue 9015022: Replace most of Browser::GetSelectedTabContents calls into Browser::GetSelectedWebContents. I've ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h" 13 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/notification_details.h" 14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
16 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
17 17
18 using content::WebContents;
19
18 @interface TabContentsController(Private) 20 @interface TabContentsController(Private)
19 // Forwards frame update to |delegate_| (ResizeNotificationView calls it). 21 // Forwards frame update to |delegate_| (ResizeNotificationView calls it).
20 - (void)tabContentsViewFrameWillChange:(NSRect)frameRect; 22 - (void)tabContentsViewFrameWillChange:(NSRect)frameRect;
21 // Notification from TabContents (forwarded by TabContentsNotificationBridge). 23 // Notification from TabContents (forwarded by TabContentsNotificationBridge).
22 - (void)tabContentsRenderViewHostChanged:(RenderViewHost*)oldHost 24 - (void)tabContentsRenderViewHostChanged:(RenderViewHost*)oldHost
23 newHost:(RenderViewHost*)newHost; 25 newHost:(RenderViewHost*)newHost;
24 @end 26 @end
25 27
26 28
27 // A supporting C++ bridge object to register for TabContents notifications. 29 // A supporting C++ bridge object to register for TabContents notifications.
28 30
29 class TabContentsNotificationBridge : public content::NotificationObserver { 31 class TabContentsNotificationBridge : public content::NotificationObserver {
30 public: 32 public:
31 explicit TabContentsNotificationBridge(TabContentsController* controller); 33 explicit TabContentsNotificationBridge(TabContentsController* controller);
32 34
33 // Overriden from content::NotificationObserver. 35 // Overriden from content::NotificationObserver.
34 virtual void Observe(int type, 36 virtual void Observe(int type,
35 const content::NotificationSource& source, 37 const content::NotificationSource& source,
36 const content::NotificationDetails& details); 38 const content::NotificationDetails& details);
37 // Register for |contents|'s notifications, remove all prior registrations. 39 // Register for |contents|'s notifications, remove all prior registrations.
38 void ChangeTabContents(TabContents* contents); 40 void ChangeWebContents(WebContents* contents);
39 private: 41 private:
40 content::NotificationRegistrar registrar_; 42 content::NotificationRegistrar registrar_;
41 TabContentsController* controller_; // weak, owns us 43 TabContentsController* controller_; // weak, owns us
42 }; 44 };
43 45
44 TabContentsNotificationBridge::TabContentsNotificationBridge( 46 TabContentsNotificationBridge::TabContentsNotificationBridge(
45 TabContentsController* controller) 47 TabContentsController* controller)
46 : controller_(controller) { 48 : controller_(controller) {
47 } 49 }
48 50
49 void TabContentsNotificationBridge::Observe( 51 void TabContentsNotificationBridge::Observe(
50 int type, 52 int type,
51 const content::NotificationSource& source, 53 const content::NotificationSource& source,
52 const content::NotificationDetails& details) { 54 const content::NotificationDetails& details) {
53 if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) { 55 if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) {
54 RenderViewHostSwitchedDetails* switched_details = 56 RenderViewHostSwitchedDetails* switched_details =
55 content::Details<RenderViewHostSwitchedDetails>(details).ptr(); 57 content::Details<RenderViewHostSwitchedDetails>(details).ptr();
56 [controller_ tabContentsRenderViewHostChanged:switched_details->old_host 58 [controller_ tabContentsRenderViewHostChanged:switched_details->old_host
57 newHost:switched_details->new_host]; 59 newHost:switched_details->new_host];
58 } else { 60 } else {
59 NOTREACHED(); 61 NOTREACHED();
60 } 62 }
61 } 63 }
62 64
63 void TabContentsNotificationBridge::ChangeTabContents(TabContents* contents) { 65 void TabContentsNotificationBridge::ChangeWebContents(WebContents* contents) {
64 registrar_.RemoveAll(); 66 registrar_.RemoveAll();
65 if (contents) { 67 if (contents) {
66 registrar_.Add( 68 registrar_.Add(
67 this, 69 this,
68 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 70 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
69 content::Source<NavigationController>(&contents->GetController())); 71 content::Source<NavigationController>(&contents->GetController()));
70 } 72 }
71 } 73 }
72 74
73 75
(...skipping 24 matching lines...) Expand all
98 100
99 @implementation TabContentsController 101 @implementation TabContentsController
100 @synthesize tabContents = contents_; 102 @synthesize tabContents = contents_;
101 103
102 - (id)initWithContents:(TabContents*)contents 104 - (id)initWithContents:(TabContents*)contents
103 delegate:(id<TabContentsControllerDelegate>)delegate { 105 delegate:(id<TabContentsControllerDelegate>)delegate {
104 if ((self = [super initWithNibName:nil bundle:nil])) { 106 if ((self = [super initWithNibName:nil bundle:nil])) {
105 contents_ = contents; 107 contents_ = contents;
106 delegate_ = delegate; 108 delegate_ = delegate;
107 tabContentsBridge_.reset(new TabContentsNotificationBridge(self)); 109 tabContentsBridge_.reset(new TabContentsNotificationBridge(self));
108 tabContentsBridge_->ChangeTabContents(contents); 110 tabContentsBridge_->ChangeWebContents(contents);
109 } 111 }
110 return self; 112 return self;
111 } 113 }
112 114
113 - (void)dealloc { 115 - (void)dealloc {
114 // make sure our contents have been removed from the window 116 // make sure our contents have been removed from the window
115 [[self view] removeFromSuperview]; 117 [[self view] removeFromSuperview];
116 [super dealloc]; 118 [super dealloc];
117 } 119 }
118 120
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 with:contentsNativeView]; 159 with:contentsNativeView];
158 } 160 }
159 // Restore autoresizing properties possibly stripped by 161 // Restore autoresizing properties possibly stripped by
160 // ensureContentsSizeDoesNotChange call. 162 // ensureContentsSizeDoesNotChange call.
161 [contentsNativeView setAutoresizingMask:NSViewWidthSizable| 163 [contentsNativeView setAutoresizingMask:NSViewWidthSizable|
162 NSViewHeightSizable]; 164 NSViewHeightSizable];
163 } 165 }
164 166
165 - (void)changeTabContents:(TabContents*)newContents { 167 - (void)changeTabContents:(TabContents*)newContents {
166 contents_ = newContents; 168 contents_ = newContents;
167 tabContentsBridge_->ChangeTabContents(contents_); 169 tabContentsBridge_->ChangeWebContents(contents_);
168 } 170 }
169 171
170 - (void)tabContentsViewFrameWillChange:(NSRect)frameRect { 172 - (void)tabContentsViewFrameWillChange:(NSRect)frameRect {
171 [delegate_ tabContentsViewFrameWillChange:self frameRect:frameRect]; 173 [delegate_ tabContentsViewFrameWillChange:self frameRect:frameRect];
172 } 174 }
173 175
174 - (void)tabContentsRenderViewHostChanged:(RenderViewHost*)oldHost 176 - (void)tabContentsRenderViewHostChanged:(RenderViewHost*)oldHost
175 newHost:(RenderViewHost*)newHost { 177 newHost:(RenderViewHost*)newHost {
176 if (oldHost && newHost && oldHost->view() && newHost->view()) { 178 if (oldHost && newHost && oldHost->view() && newHost->view()) {
177 newHost->view()->set_reserved_contents_rect( 179 newHost->view()->set_reserved_contents_rect(
(...skipping 24 matching lines...) Expand all
202 // the view may have, so avoid changing the view hierarchy unless 204 // the view may have, so avoid changing the view hierarchy unless
203 // the view is different. 205 // the view is different.
204 if ([self tabContents] != updatedContents) { 206 if ([self tabContents] != updatedContents) {
205 [self changeTabContents:updatedContents]; 207 [self changeTabContents:updatedContents];
206 if ([self tabContents]) 208 if ([self tabContents])
207 [self ensureContentsVisible]; 209 [self ensureContentsVisible];
208 } 210 }
209 } 211 }
210 212
211 @end 213 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h ('k') | chrome/browser/ui/cocoa/tabpose_window.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698