| 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/intents/web_intent_picker_controller.h" | 5 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/extensions/webstore_installer.h" | 13 #include "chrome/browser/extensions/webstore_installer.h" |
| 14 #include "chrome/browser/favicon/favicon_service.h" | 14 #include "chrome/browser/favicon/favicon_service.h" |
| 15 #include "chrome/browser/intents/cws_intents_registry_factory.h" | 15 #include "chrome/browser/intents/cws_intents_registry_factory.h" |
| 16 #include "chrome/browser/intents/default_web_intent_service.h" | 16 #include "chrome/browser/intents/default_web_intent_service.h" |
| 17 #include "chrome/browser/intents/web_intents_registry_factory.h" | 17 #include "chrome/browser/intents/web_intents_registry_factory.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/tab_contents/tab_util.h" | 19 #include "chrome/browser/tab_contents/tab_util.h" |
| 20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_finder.h" |
| 21 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 22 #include "chrome/browser/ui/browser_navigator.h" | 23 #include "chrome/browser/ui/browser_navigator.h" |
| 23 #include "chrome/browser/ui/intents/web_intent_picker.h" | 24 #include "chrome/browser/ui/intents/web_intent_picker.h" |
| 24 #include "chrome/browser/ui/intents/web_intent_picker_model.h" | 25 #include "chrome/browser/ui/intents/web_intent_picker_model.h" |
| 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 27 #include "chrome/browser/webdata/web_data_service.h" | 28 #include "chrome/browser/webdata/web_data_service.h" |
| 28 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 switch (disposition) { | 257 switch (disposition) { |
| 257 case WebIntentPickerModel::DISPOSITION_INLINE: | 258 case WebIntentPickerModel::DISPOSITION_INLINE: |
| 258 // Set the model to inline disposition. It will notify the picker which | 259 // Set the model to inline disposition. It will notify the picker which |
| 259 // will respond (via OnInlineDispositionWebContentsCreated) with the | 260 // will respond (via OnInlineDispositionWebContentsCreated) with the |
| 260 // WebContents to dispatch the intent to. | 261 // WebContents to dispatch the intent to. |
| 261 picker_model_->SetInlineDisposition(url); | 262 picker_model_->SetInlineDisposition(url); |
| 262 break; | 263 break; |
| 263 | 264 |
| 264 case WebIntentPickerModel::DISPOSITION_WINDOW: { | 265 case WebIntentPickerModel::DISPOSITION_WINDOW: { |
| 265 int index = TabStripModel::kNoTab; | 266 int index = TabStripModel::kNoTab; |
| 266 Browser* browser = Browser::GetBrowserForController( | 267 Browser* browser = browser::FindBrowserForController( |
| 267 &wrapper_->web_contents()->GetController(), &index); | 268 &wrapper_->web_contents()->GetController(), &index); |
| 268 TabContentsWrapper* contents = Browser::TabContentsFactory( | 269 TabContentsWrapper* contents = Browser::TabContentsFactory( |
| 269 wrapper_->profile(), | 270 wrapper_->profile(), |
| 270 tab_util::GetSiteInstanceForNewTab( | 271 tab_util::GetSiteInstanceForNewTab( |
| 271 wrapper_->profile(), url), | 272 wrapper_->profile(), url), |
| 272 MSG_ROUTING_NONE, NULL, NULL); | 273 MSG_ROUTING_NONE, NULL, NULL); |
| 273 | 274 |
| 274 intents_dispatcher_->DispatchIntent(contents->web_contents()); | 275 intents_dispatcher_->DispatchIntent(contents->web_contents()); |
| 275 service_tab_ = contents->web_contents(); | 276 service_tab_ = contents->web_contents(); |
| 276 | 277 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 scoped_ptr<WebstoreInstaller::Approval>(NULL), | 313 scoped_ptr<WebstoreInstaller::Approval>(NULL), |
| 313 WebstoreInstaller::FLAG_INLINE_INSTALL); | 314 WebstoreInstaller::FLAG_INLINE_INSTALL); |
| 314 | 315 |
| 315 pending_async_count_++; | 316 pending_async_count_++; |
| 316 installer->Start(); | 317 installer->Start(); |
| 317 } | 318 } |
| 318 | 319 |
| 319 void WebIntentPickerController::OnExtensionLinkClicked(const std::string& id) { | 320 void WebIntentPickerController::OnExtensionLinkClicked(const std::string& id) { |
| 320 // Navigate from source tab. | 321 // Navigate from source tab. |
| 321 Browser* browser = | 322 Browser* browser = |
| 322 BrowserList::FindBrowserWithWebContents(wrapper_->web_contents()); | 323 browser::FindBrowserWithWebContents(wrapper_->web_contents()); |
| 323 GURL extension_url(extension_urls::GetWebstoreItemDetailURLPrefix() + id); | 324 GURL extension_url(extension_urls::GetWebstoreItemDetailURLPrefix() + id); |
| 324 browser::NavigateParams params(browser, extension_url, | 325 browser::NavigateParams params(browser, extension_url, |
| 325 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 326 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 326 params.disposition = NEW_FOREGROUND_TAB; | 327 params.disposition = NEW_FOREGROUND_TAB; |
| 327 browser::Navigate(¶ms); | 328 browser::Navigate(¶ms); |
| 328 } | 329 } |
| 329 | 330 |
| 330 void WebIntentPickerController::OnSuggestionsLinkClicked() { | 331 void WebIntentPickerController::OnSuggestionsLinkClicked() { |
| 331 // Navigate from source tab. | 332 // Navigate from source tab. |
| 332 Browser* browser = | 333 Browser* browser = |
| 333 BrowserList::FindBrowserWithWebContents(wrapper_->web_contents()); | 334 browser::FindBrowserWithWebContents(wrapper_->web_contents()); |
| 334 GURL query_url = extension_urls::GetWebstoreIntentQueryURL( | 335 GURL query_url = extension_urls::GetWebstoreIntentQueryURL( |
| 335 UTF16ToUTF8(picker_model_->action()), | 336 UTF16ToUTF8(picker_model_->action()), |
| 336 UTF16ToUTF8(picker_model_->mimetype())); | 337 UTF16ToUTF8(picker_model_->mimetype())); |
| 337 browser::NavigateParams params(browser, query_url, | 338 browser::NavigateParams params(browser, query_url, |
| 338 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 339 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 339 params.disposition = NEW_FOREGROUND_TAB; | 340 params.disposition = NEW_FOREGROUND_TAB; |
| 340 browser::Navigate(¶ms); | 341 browser::Navigate(¶ms); |
| 341 } | 342 } |
| 342 | 343 |
| 343 void WebIntentPickerController::OnPickerClosed() { | 344 void WebIntentPickerController::OnPickerClosed() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 AsyncOperationFinished(); | 389 AsyncOperationFinished(); |
| 389 } | 390 } |
| 390 | 391 |
| 391 void WebIntentPickerController::OnSendReturnMessage( | 392 void WebIntentPickerController::OnSendReturnMessage( |
| 392 webkit_glue::WebIntentReplyType reply_type) { | 393 webkit_glue::WebIntentReplyType reply_type) { |
| 393 ClosePicker(); | 394 ClosePicker(); |
| 394 | 395 |
| 395 if (service_tab_ && | 396 if (service_tab_ && |
| 396 reply_type != webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED) { | 397 reply_type != webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED) { |
| 397 int index = TabStripModel::kNoTab; | 398 int index = TabStripModel::kNoTab; |
| 398 Browser* browser = Browser::GetBrowserForController( | 399 Browser* browser = browser::FindBrowserForController( |
| 399 &service_tab_->GetController(), &index); | 400 &service_tab_->GetController(), &index); |
| 400 if (browser) { | 401 if (browser) { |
| 401 browser->tab_strip_model()->CloseTabContentsAt( | 402 browser->tab_strip_model()->CloseTabContentsAt( |
| 402 index, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); | 403 index, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); |
| 403 | 404 |
| 404 // Activate source tab. | 405 // Activate source tab. |
| 405 Browser* source_browser = | 406 Browser* source_browser = |
| 406 BrowserList::FindBrowserWithWebContents(wrapper_->web_contents()); | 407 browser::FindBrowserWithWebContents(wrapper_->web_contents()); |
| 407 if (source_browser) { | 408 if (source_browser) { |
| 408 int source_index = | 409 int source_index = |
| 409 source_browser->tab_strip_model()->GetIndexOfTabContents(wrapper_); | 410 source_browser->tab_strip_model()->GetIndexOfTabContents(wrapper_); |
| 410 source_browser->ActivateTabAt(source_index, false); | 411 source_browser->ActivateTabAt(source_index, false); |
| 411 } | 412 } |
| 412 } | 413 } |
| 413 service_tab_ = NULL; | 414 service_tab_ = NULL; |
| 414 } | 415 } |
| 415 | 416 |
| 416 intents_dispatcher_ = NULL; | 417 intents_dispatcher_ = NULL; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 // If picker is non-NULL, it was set by a test. | 685 // If picker is non-NULL, it was set by a test. |
| 685 if (picker_ == NULL) | 686 if (picker_ == NULL) |
| 686 picker_ = WebIntentPicker::Create(wrapper_, this, picker_model_.get()); | 687 picker_ = WebIntentPicker::Create(wrapper_, this, picker_model_.get()); |
| 687 picker_shown_ = true; | 688 picker_shown_ = true; |
| 688 } | 689 } |
| 689 | 690 |
| 690 void WebIntentPickerController::ClosePicker() { | 691 void WebIntentPickerController::ClosePicker() { |
| 691 if (picker_) | 692 if (picker_) |
| 692 picker_->Close(); | 693 picker_->Close(); |
| 693 } | 694 } |
| OLD | NEW |