| 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/browser/page_navigator.h" |
| 25 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/common/ssl_status.h" | 26 #include "content/public/common/ssl_status.h" |
| 26 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 27 #include "grit/locale_settings.h" | 28 #include "grit/locale_settings.h" |
| 28 #include "net/base/cert_status_flags.h" | 29 #include "net/base/cert_status_flags.h" |
| 29 #include "net/base/x509_certificate.h" | 30 #include "net/base/x509_certificate.h" |
| 30 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 31 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/l10n/l10n_util_mac.h" | 33 #include "ui/base/l10n/l10n_util_mac.h" |
| 33 #include "ui/gfx/image/image.h" | 34 #include "ui/gfx/image/image.h" |
| 34 | 35 |
| 35 using content::OpenURLParams; | 36 using content::OpenURLParams; |
| 36 using content::Referrer; | 37 using content::Referrer; |
| 37 using content::SSLStatus; | 38 using content::SSLStatus; |
| 39 using content::WebContents; |
| 38 | 40 |
| 39 @interface PageInfoBubbleController (Private) | 41 @interface PageInfoBubbleController (Private) |
| 40 - (PageInfoModel*)model; | 42 - (PageInfoModel*)model; |
| 41 - (NSButton*)certificateButtonWithFrame:(NSRect)frame; | 43 - (NSButton*)certificateButtonWithFrame:(NSRect)frame; |
| 42 - (void)configureTextFieldAsLabel:(NSTextField*)textField; | 44 - (void)configureTextFieldAsLabel:(NSTextField*)textField; |
| 43 - (CGFloat)addHeadlineViewForInfo:(const PageInfoModel::SectionInfo&)info | 45 - (CGFloat)addHeadlineViewForInfo:(const PageInfoModel::SectionInfo&)info |
| 44 toSubviews:(NSMutableArray*)subviews | 46 toSubviews:(NSMutableArray*)subviews |
| 45 atPoint:(NSPoint)point; | 47 atPoint:(NSPoint)point; |
| 46 - (CGFloat)addDescriptionViewForInfo:(const PageInfoModel::SectionInfo&)info | 48 - (CGFloat)addDescriptionViewForInfo:(const PageInfoModel::SectionInfo&)info |
| 47 toSubviews:(NSMutableArray*)subviews | 49 toSubviews:(NSMutableArray*)subviews |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 base::WeakPtrFactory<PageInfoModelBubbleBridge> weak_ptr_factory_; | 151 base::WeakPtrFactory<PageInfoModelBubbleBridge> weak_ptr_factory_; |
| 150 | 152 |
| 151 DISALLOW_COPY_AND_ASSIGN(PageInfoModelBubbleBridge); | 153 DISALLOW_COPY_AND_ASSIGN(PageInfoModelBubbleBridge); |
| 152 }; | 154 }; |
| 153 | 155 |
| 154 } // namespace | 156 } // namespace |
| 155 | 157 |
| 156 namespace browser { | 158 namespace browser { |
| 157 | 159 |
| 158 void ShowPageInfoBubble(gfx::NativeWindow parent, | 160 void ShowPageInfoBubble(gfx::NativeWindow parent, |
| 159 Profile* profile, | 161 WebContents* web_contents, |
| 160 const GURL& url, | 162 const GURL& url, |
| 161 const SSLStatus& ssl, | 163 const SSLStatus& ssl, |
| 162 bool show_history, | 164 bool show_history, |
| 163 content::PageNavigator* navigator) { | 165 content::PageNavigator* navigator) { |
| 164 PageInfoModelBubbleBridge* bridge = new PageInfoModelBubbleBridge(); | 166 PageInfoModelBubbleBridge* bridge = new PageInfoModelBubbleBridge(); |
| 165 PageInfoModel* model = | 167 PageInfoModel* model = new PageInfoModel( |
| 166 new PageInfoModel(profile, url, ssl, show_history, bridge); | 168 Profile::FromBrowserContext(web_contents->GetBrowserContext()), url, ssl, |
| 169 show_history, bridge); |
| 167 PageInfoBubbleController* controller = | 170 PageInfoBubbleController* controller = |
| 168 [[PageInfoBubbleController alloc] initWithPageInfoModel:model | 171 [[PageInfoBubbleController alloc] initWithPageInfoModel:model |
| 169 modelObserver:bridge | 172 modelObserver:bridge |
| 170 parentWindow:parent | 173 parentWindow:parent |
| 174 webContents:web_contents |
| 171 navigator:navigator]; | 175 navigator:navigator]; |
| 172 bridge->set_controller(controller); | 176 bridge->set_controller(controller); |
| 173 [controller setCertID:ssl.cert_id]; | 177 [controller setCertID:ssl.cert_id]; |
| 174 [controller showWindow:nil]; | 178 [controller showWindow:nil]; |
| 175 } | 179 } |
| 176 | 180 |
| 177 } // namespace browser | 181 } // namespace browser |
| 178 | 182 |
| 179 @implementation PageInfoBubbleController | 183 @implementation PageInfoBubbleController |
| 180 | 184 |
| 181 @synthesize certID = certID_; | 185 @synthesize certID = certID_; |
| 182 | 186 |
| 183 - (id)initWithPageInfoModel:(PageInfoModel*)model | 187 - (id)initWithPageInfoModel:(PageInfoModel*)model |
| 184 modelObserver:(PageInfoModelObserver*)bridge | 188 modelObserver:(PageInfoModelObserver*)bridge |
| 185 parentWindow:(NSWindow*)parentWindow | 189 parentWindow:(NSWindow*)parentWindow |
| 190 webContents:(WebContents*)webContents |
| 186 navigator:(content::PageNavigator*)navigator { | 191 navigator:(content::PageNavigator*)navigator { |
| 187 DCHECK(parentWindow); | 192 DCHECK(parentWindow); |
| 188 | 193 |
| 189 // Use an arbitrary height because it will be changed by the bridge. | 194 // Use an arbitrary height because it will be changed by the bridge. |
| 190 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 1); | 195 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 1); |
| 191 // Create an empty window into which content is placed. | 196 // Create an empty window into which content is placed. |
| 192 scoped_nsobject<InfoBubbleWindow> window( | 197 scoped_nsobject<InfoBubbleWindow> window( |
| 193 [[InfoBubbleWindow alloc] initWithContentRect:contentRect | 198 [[InfoBubbleWindow alloc] initWithContentRect:contentRect |
| 194 styleMask:NSBorderlessWindowMask | 199 styleMask:NSBorderlessWindowMask |
| 195 backing:NSBackingStoreBuffered | 200 backing:NSBackingStoreBuffered |
| 196 defer:NO]); | 201 defer:NO]); |
| 197 | 202 |
| 198 if ((self = [super initWithWindow:window.get() | 203 if ((self = [super initWithWindow:window.get() |
| 199 parentWindow:parentWindow | 204 parentWindow:parentWindow |
| 200 anchoredAt:NSZeroPoint])) { | 205 anchoredAt:NSZeroPoint])) { |
| 201 model_.reset(model); | 206 model_.reset(model); |
| 202 bridge_.reset(bridge); | 207 bridge_.reset(bridge); |
| 208 webContents_ = webContents; |
| 203 navigator_ = navigator; | 209 navigator_ = navigator; |
| 204 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; | 210 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; |
| 205 [self performLayout]; | 211 [self performLayout]; |
| 206 } | 212 } |
| 207 return self; | 213 return self; |
| 208 } | 214 } |
| 209 | 215 |
| 210 - (PageInfoModel*)model { | 216 - (PageInfoModel*)model { |
| 211 return model_.get(); | 217 return model_.get(); |
| 212 } | 218 } |
| 213 | 219 |
| 214 - (IBAction)showCertWindow:(id)sender { | 220 - (IBAction)showCertWindow:(id)sender { |
| 215 DCHECK(certID_ != 0); | 221 DCHECK(certID_ != 0); |
| 216 ShowCertificateViewerByID([self parentWindow], certID_); | 222 ShowCertificateViewerByID(webContents_, [self parentWindow], certID_); |
| 217 } | 223 } |
| 218 | 224 |
| 219 - (IBAction)showHelpPage:(id)sender { | 225 - (IBAction)showHelpPage:(id)sender { |
| 220 navigator_->OpenURL(OpenURLParams(GURL(chrome::kPageInfoHelpCenterURL), | 226 navigator_->OpenURL(OpenURLParams(GURL(chrome::kPageInfoHelpCenterURL), |
| 221 Referrer(), | 227 Referrer(), |
| 222 NEW_FOREGROUND_TAB, | 228 NEW_FOREGROUND_TAB, |
| 223 content::PAGE_TRANSITION_LINK, | 229 content::PAGE_TRANSITION_LINK, |
| 224 false)); | 230 false)); |
| 225 } | 231 } |
| 226 | 232 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 LocationBarViewMac* locationBar = [controller locationBarBridge]; | 486 LocationBarViewMac* locationBar = [controller locationBarBridge]; |
| 481 if (locationBar) { | 487 if (locationBar) { |
| 482 NSPoint bubblePoint = locationBar->GetPageInfoBubblePoint(); | 488 NSPoint bubblePoint = locationBar->GetPageInfoBubblePoint(); |
| 483 origin = [parent convertBaseToScreen:bubblePoint]; | 489 origin = [parent convertBaseToScreen:bubblePoint]; |
| 484 } | 490 } |
| 485 } | 491 } |
| 486 return origin; | 492 return origin; |
| 487 } | 493 } |
| 488 | 494 |
| 489 @end | 495 @end |
| OLD | NEW |