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/page_info_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/page_info_bubble_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "chrome/browser/certificate_viewer.h" | 12 #include "chrome/browser/certificate_viewer.h" |
13 #include "chrome/browser/page_info_model.h" | 13 #include "chrome/browser/page_info_model.h" |
14 #include "chrome/browser/page_info_model_observer.h" | 14 #include "chrome/browser/page_info_model_observer.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
18 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" | 18 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" |
19 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 19 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
20 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 20 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
21 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 21 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
23 #include "content/public/browser/cert_store.h" | 23 #include "content/public/browser/cert_store.h" |
24 #include "content/public/browser/page_navigator.h" | |
24 #include "content/public/common/ssl_status.h" | 25 #include "content/public/common/ssl_status.h" |
25 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
26 #include "grit/locale_settings.h" | 27 #include "grit/locale_settings.h" |
27 #include "net/base/cert_status_flags.h" | 28 #include "net/base/cert_status_flags.h" |
28 #include "net/base/x509_certificate.h" | 29 #include "net/base/x509_certificate.h" |
29 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 30 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
30 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/base/l10n/l10n_util_mac.h" | 32 #include "ui/base/l10n/l10n_util_mac.h" |
32 #include "ui/gfx/image/image.h" | 33 #include "ui/gfx/image/image.h" |
33 | 34 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 }; | 152 }; |
152 | 153 |
153 } // namespace | 154 } // namespace |
154 | 155 |
155 namespace browser { | 156 namespace browser { |
156 | 157 |
157 void ShowPageInfoBubble(gfx::NativeWindow parent, | 158 void ShowPageInfoBubble(gfx::NativeWindow parent, |
158 Profile* profile, | 159 Profile* profile, |
159 const GURL& url, | 160 const GURL& url, |
160 const SSLStatus& ssl, | 161 const SSLStatus& ssl, |
161 bool show_history) { | 162 bool show_history, |
163 content::PageNavigator* navigator) { | |
162 PageInfoModelBubbleBridge* bridge = new PageInfoModelBubbleBridge(); | 164 PageInfoModelBubbleBridge* bridge = new PageInfoModelBubbleBridge(); |
163 PageInfoModel* model = | 165 PageInfoModel* model = |
164 new PageInfoModel(profile, url, ssl, show_history, bridge); | 166 new PageInfoModel(profile, url, ssl, show_history, bridge); |
165 PageInfoBubbleController* controller = | 167 PageInfoBubbleController* controller = |
166 [[PageInfoBubbleController alloc] initWithPageInfoModel:model | 168 [[PageInfoBubbleController alloc] initWithPageInfoModel:model |
167 modelObserver:bridge | 169 modelObserver:bridge |
168 parentWindow:parent]; | 170 parentWindow:parent |
171 navigator:navigator]; | |
169 bridge->set_controller(controller); | 172 bridge->set_controller(controller); |
170 [controller setCertID:ssl.cert_id]; | 173 [controller setCertID:ssl.cert_id]; |
171 [controller showWindow:nil]; | 174 [controller showWindow:nil]; |
172 } | 175 } |
173 | 176 |
174 } // namespace browser | 177 } // namespace browser |
175 | 178 |
176 @implementation PageInfoBubbleController | 179 @implementation PageInfoBubbleController |
177 | 180 |
178 @synthesize certID = certID_; | 181 @synthesize certID = certID_; |
179 | 182 |
180 - (id)initWithPageInfoModel:(PageInfoModel*)model | 183 - (id)initWithPageInfoModel:(PageInfoModel*)model |
181 modelObserver:(PageInfoModelObserver*)bridge | 184 modelObserver:(PageInfoModelObserver*)bridge |
182 parentWindow:(NSWindow*)parentWindow { | 185 parentWindow:(NSWindow*)parentWindow |
186 navigator:(content::PageNavigator*)navigator{ | |
Finnur
2012/05/23 16:33:25
nit: space before {
| |
183 DCHECK(parentWindow); | 187 DCHECK(parentWindow); |
184 | 188 |
185 // Use an arbitrary height because it will be changed by the bridge. | 189 // Use an arbitrary height because it will be changed by the bridge. |
186 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 1); | 190 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 1); |
187 // Create an empty window into which content is placed. | 191 // Create an empty window into which content is placed. |
188 scoped_nsobject<InfoBubbleWindow> window( | 192 scoped_nsobject<InfoBubbleWindow> window( |
189 [[InfoBubbleWindow alloc] initWithContentRect:contentRect | 193 [[InfoBubbleWindow alloc] initWithContentRect:contentRect |
190 styleMask:NSBorderlessWindowMask | 194 styleMask:NSBorderlessWindowMask |
191 backing:NSBackingStoreBuffered | 195 backing:NSBackingStoreBuffered |
192 defer:NO]); | 196 defer:NO]); |
193 | 197 |
194 if ((self = [super initWithWindow:window.get() | 198 if ((self = [super initWithWindow:window.get() |
195 parentWindow:parentWindow | 199 parentWindow:parentWindow |
196 anchoredAt:NSZeroPoint])) { | 200 anchoredAt:NSZeroPoint])) { |
197 model_.reset(model); | 201 model_.reset(model); |
198 bridge_.reset(bridge); | 202 bridge_.reset(bridge); |
203 navigator_ = navigator; | |
199 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; | 204 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; |
200 [self performLayout]; | 205 [self performLayout]; |
201 } | 206 } |
202 return self; | 207 return self; |
203 } | 208 } |
204 | 209 |
205 - (PageInfoModel*)model { | 210 - (PageInfoModel*)model { |
206 return model_.get(); | 211 return model_.get(); |
207 } | 212 } |
208 | 213 |
209 - (IBAction)showCertWindow:(id)sender { | 214 - (IBAction)showCertWindow:(id)sender { |
210 DCHECK(certID_ != 0); | 215 DCHECK(certID_ != 0); |
211 ShowCertificateViewerByID([self parentWindow], certID_); | 216 ShowCertificateViewerByID([self parentWindow], certID_); |
212 } | 217 } |
213 | 218 |
214 - (IBAction)showHelpPage:(id)sender { | 219 - (IBAction)showHelpPage:(id)sender { |
215 Browser* browser = BrowserList::GetLastActive(); | 220 navigator_->OpenURL(OpenURLParams(GURL(chrome::kPageInfoHelpCenterURL), |
216 OpenURLParams params( | 221 Referrer(), |
217 GURL(chrome::kPageInfoHelpCenterURL), Referrer(), NEW_FOREGROUND_TAB, | 222 NEW_FOREGROUND_TAB, |
218 content::PAGE_TRANSITION_LINK, false); | 223 content::PAGE_TRANSITION_LINK, |
219 browser->OpenURL(params); | 224 false)); |
220 } | 225 } |
221 | 226 |
222 // This will create the subviews for the page info window. The general layout | 227 // This will create the subviews for the page info window. The general layout |
223 // is 2 or 3 boxed and titled sections, each of which has a status image to | 228 // is 2 or 3 boxed and titled sections, each of which has a status image to |
224 // provide visual feedback and a description that explains it. The description | 229 // provide visual feedback and a description that explains it. The description |
225 // text is usually only 1 or 2 lines, but can be much longer. At the bottom of | 230 // text is usually only 1 or 2 lines, but can be much longer. At the bottom of |
226 // the window is a button to view the SSL certificate, which is disabled if | 231 // the window is a button to view the SSL certificate, which is disabled if |
227 // not using HTTPS. | 232 // not using HTTPS. |
228 - (void)performLayout { | 233 - (void)performLayout { |
229 // |offset| is the Y position that should be drawn at next. | 234 // |offset| is the Y position that should be drawn at next. |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 LocationBarViewMac* locationBar = [controller locationBarBridge]; | 480 LocationBarViewMac* locationBar = [controller locationBarBridge]; |
476 if (locationBar) { | 481 if (locationBar) { |
477 NSPoint bubblePoint = locationBar->GetPageInfoBubblePoint(); | 482 NSPoint bubblePoint = locationBar->GetPageInfoBubblePoint(); |
478 origin = [parent convertBaseToScreen:bubblePoint]; | 483 origin = [parent convertBaseToScreen:bubblePoint]; |
479 } | 484 } |
480 } | 485 } |
481 return origin; | 486 return origin; |
482 } | 487 } |
483 | 488 |
484 @end | 489 @end |
OLD | NEW |