| 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 #include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 WebIntentPickerCocoa::~WebIntentPickerCocoa() { | 114 WebIntentPickerCocoa::~WebIntentPickerCocoa() { |
| 115 if (model_ != NULL) | 115 if (model_ != NULL) |
| 116 model_->set_observer(NULL); | 116 model_->set_observer(NULL); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void WebIntentPickerCocoa::OnSheetDidEnd(NSWindow* sheet) { | 119 void WebIntentPickerCocoa::OnSheetDidEnd(NSWindow* sheet) { |
| 120 [sheet orderOut:sheet_controller_]; | 120 [sheet orderOut:sheet_controller_]; |
| 121 if (window_) | 121 if (window_) |
| 122 window_->CloseConstrainedWindow(); | 122 window_->CloseConstrainedWindow(); |
| 123 delegate_->OnClosing(); | 123 if (delegate_) |
| 124 delegate_->OnClosing(); |
| 124 } | 125 } |
| 125 | 126 |
| 126 void WebIntentPickerCocoa::Close() { | 127 void WebIntentPickerCocoa::Close() { |
| 127 DCHECK(sheet_controller_); | 128 DCHECK(sheet_controller_); |
| 128 [sheet_controller_ closeSheet]; | 129 [sheet_controller_ closeSheet]; |
| 129 | 130 |
| 130 if (inline_disposition_tab_contents_.get()) | 131 if (inline_disposition_tab_contents_.get()) |
| 131 inline_disposition_tab_contents_->web_contents()->OnCloseStarted(); | 132 inline_disposition_tab_contents_->web_contents()->OnCloseStarted(); |
| 132 } | 133 } |
| 133 | 134 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 157 | 158 |
| 158 void WebIntentPickerCocoa::OnExtensionIconChanged( | 159 void WebIntentPickerCocoa::OnExtensionIconChanged( |
| 159 WebIntentPickerModel* model, | 160 WebIntentPickerModel* model, |
| 160 const std::string& extension_id) { | 161 const std::string& extension_id) { |
| 161 // We don't handle individual icon changes - just redo the whole model. | 162 // We don't handle individual icon changes - just redo the whole model. |
| 162 PerformLayout(); | 163 PerformLayout(); |
| 163 } | 164 } |
| 164 | 165 |
| 165 void WebIntentPickerCocoa::OnInlineDisposition(const string16& title, | 166 void WebIntentPickerCocoa::OnInlineDisposition(const string16& title, |
| 166 const GURL& url) { | 167 const GURL& url) { |
| 167 | 168 DCHECK(delegate_); |
| 168 content::WebContents* web_contents = | 169 content::WebContents* web_contents = |
| 169 delegate_->CreateWebContentsForInlineDisposition( | 170 delegate_->CreateWebContentsForInlineDisposition( |
| 170 tab_contents_->profile(), url); | 171 tab_contents_->profile(), url); |
| 171 inline_disposition_tab_contents_.reset( | 172 inline_disposition_tab_contents_.reset( |
| 172 TabContents::Factory::CreateTabContents(web_contents)); | 173 TabContents::Factory::CreateTabContents(web_contents)); |
| 173 Browser* browser = browser::FindBrowserWithWebContents( | 174 Browser* browser = browser::FindBrowserWithWebContents( |
| 174 tab_contents_->web_contents()); | 175 tab_contents_->web_contents()); |
| 175 inline_disposition_delegate_.reset( | 176 inline_disposition_delegate_.reset( |
| 176 new WebIntentInlineDispositionDelegate(this, web_contents, browser)); | 177 new WebIntentInlineDispositionDelegate(this, web_contents, browser)); |
| 177 | 178 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 200 const WebIntentPickerModel::InstalledService& installed_service = | 201 const WebIntentPickerModel::InstalledService& installed_service = |
| 201 model_->GetInstalledServiceAt(index); | 202 model_->GetInstalledServiceAt(index); |
| 202 service_invoked = true; | 203 service_invoked = true; |
| 203 delegate_->OnServiceChosen(installed_service.url, | 204 delegate_->OnServiceChosen(installed_service.url, |
| 204 installed_service.disposition, | 205 installed_service.disposition, |
| 205 WebIntentPickerDelegate::kEnableDefaults); | 206 WebIntentPickerDelegate::kEnableDefaults); |
| 206 } | 207 } |
| 207 | 208 |
| 208 void WebIntentPickerCocoa::OnExtensionInstallRequested( | 209 void WebIntentPickerCocoa::OnExtensionInstallRequested( |
| 209 const std::string& extension_id) { | 210 const std::string& extension_id) { |
| 211 DCHECK(delegate_); |
| 210 delegate_->OnExtensionInstallRequested(extension_id); | 212 delegate_->OnExtensionInstallRequested(extension_id); |
| 211 } | 213 } |
| 212 | 214 |
| 213 void WebIntentPickerCocoa::OnExtensionInstallSuccess(const std::string& id) { | 215 void WebIntentPickerCocoa::OnExtensionInstallSuccess(const std::string& id) { |
| 214 DCHECK(sheet_controller_); | 216 DCHECK(sheet_controller_); |
| 215 [sheet_controller_ stopThrobber]; | 217 [sheet_controller_ stopThrobber]; |
| 216 } | 218 } |
| 217 | 219 |
| 218 void WebIntentPickerCocoa::OnExtensionInstallFailure(const std::string& id) { | 220 void WebIntentPickerCocoa::OnExtensionInstallFailure(const std::string& id) { |
| 219 // TODO(groby): What to do on failure? (See also binji for views/gtk) | 221 // TODO(groby): What to do on failure? (See also binji for views/gtk) |
| 220 DCHECK(sheet_controller_); | 222 DCHECK(sheet_controller_); |
| 221 [sheet_controller_ stopThrobber]; | 223 [sheet_controller_ stopThrobber]; |
| 222 } | 224 } |
| 223 | 225 |
| 224 void WebIntentPickerCocoa::OnInlineDispositionAutoResize( | 226 void WebIntentPickerCocoa::OnInlineDispositionAutoResize( |
| 225 const gfx::Size& size) { | 227 const gfx::Size& size) { |
| 226 DCHECK(sheet_controller_); | 228 DCHECK(sheet_controller_); |
| 227 NSSize inline_content_size = NSMakeSize(size.width(), size.height()); | 229 NSSize inline_content_size = NSMakeSize(size.width(), size.height()); |
| 228 [sheet_controller_ setInlineDispositionFrameSize:inline_content_size]; | 230 [sheet_controller_ setInlineDispositionFrameSize:inline_content_size]; |
| 229 } | 231 } |
| 230 | 232 |
| 231 void WebIntentPickerCocoa::OnPendingAsyncCompleted() { | 233 void WebIntentPickerCocoa::OnPendingAsyncCompleted() { |
| 232 } | 234 } |
| 233 | 235 |
| 236 void WebIntentPickerCocoa::InvalidateDelegate() { |
| 237 delegate_ = NULL; |
| 238 } |
| 239 |
| 234 void WebIntentPickerCocoa::OnExtensionLinkClicked( | 240 void WebIntentPickerCocoa::OnExtensionLinkClicked( |
| 235 const std::string& id, | 241 const std::string& id, |
| 236 WindowOpenDisposition disposition) { | 242 WindowOpenDisposition disposition) { |
| 237 DCHECK(delegate_); | 243 DCHECK(delegate_); |
| 238 delegate_->OnExtensionLinkClicked(id, disposition); | 244 delegate_->OnExtensionLinkClicked(id, disposition); |
| 239 } | 245 } |
| 240 | 246 |
| 241 void WebIntentPickerCocoa::OnSuggestionsLinkClicked( | 247 void WebIntentPickerCocoa::OnSuggestionsLinkClicked( |
| 242 WindowOpenDisposition disposition) { | 248 WindowOpenDisposition disposition) { |
| 243 DCHECK(delegate_); | 249 DCHECK(delegate_); |
| 244 delegate_->OnSuggestionsLinkClicked(disposition); | 250 delegate_->OnSuggestionsLinkClicked(disposition); |
| 245 } | 251 } |
| 246 | 252 |
| 247 void WebIntentPickerCocoa::OnChooseAnotherService() { | 253 void WebIntentPickerCocoa::OnChooseAnotherService() { |
| 248 DCHECK(delegate_); | 254 DCHECK(delegate_); |
| 249 delegate_->OnChooseAnotherService(); | 255 delegate_->OnChooseAnotherService(); |
| 250 inline_disposition_tab_contents_.reset(); | 256 inline_disposition_tab_contents_.reset(); |
| 251 inline_disposition_delegate_.reset(); | 257 inline_disposition_delegate_.reset(); |
| 252 [sheet_controller_ setInlineDispositionTabContents:NULL]; | 258 [sheet_controller_ setInlineDispositionTabContents:NULL]; |
| 253 PerformLayout(); | 259 PerformLayout(); |
| 254 } | 260 } |
| OLD | NEW |