| 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" | 
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 131 } | 131 } | 
| 132 | 132 | 
| 133 }  // namespace | 133 }  // namespace | 
| 134 | 134 | 
| 135 WebIntentPickerController::WebIntentPickerController( | 135 WebIntentPickerController::WebIntentPickerController( | 
| 136     TabContentsWrapper* wrapper) | 136     TabContentsWrapper* wrapper) | 
| 137     : wrapper_(wrapper), | 137     : wrapper_(wrapper), | 
| 138       picker_(NULL), | 138       picker_(NULL), | 
| 139       picker_model_(new WebIntentPickerModel()), | 139       picker_model_(new WebIntentPickerModel()), | 
| 140       pending_async_count_(0), | 140       pending_async_count_(0), | 
|  | 141       pending_registry_calls_count_(0), | 
| 141       picker_shown_(false), | 142       picker_shown_(false), | 
| 142       intents_dispatcher_(NULL), | 143       intents_dispatcher_(NULL), | 
| 143       service_tab_(NULL), | 144       service_tab_(NULL), | 
| 144       weak_ptr_factory_(this) { | 145       weak_ptr_factory_(this) { | 
| 145   content::NavigationController* controller = | 146   content::NavigationController* controller = | 
| 146       &wrapper->web_contents()->GetController(); | 147       &wrapper->web_contents()->GetController(); | 
| 147   registrar_.Add(this, content::NOTIFICATION_LOAD_START, | 148   registrar_.Add(this, content::NOTIFICATION_LOAD_START, | 
| 148                  content::Source<content::NavigationController>(controller)); | 149                  content::Source<content::NavigationController>(controller)); | 
| 149   registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, | 150   registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, | 
| 150                  content::Source<content::NavigationController>(controller)); | 151                  content::Source<content::NavigationController>(controller)); | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 210       // required to find disposition set by service.) | 211       // required to find disposition set by service.) | 
| 211       pending_async_count_++; | 212       pending_async_count_++; | 
| 212       GetWebIntentsRegistry(wrapper_)->GetIntentServices( | 213       GetWebIntentsRegistry(wrapper_)->GetIntentServices( | 
| 213           action, type, base::Bind( | 214           action, type, base::Bind( | 
| 214               &WebIntentPickerController::WebIntentServicesForExplicitIntent, | 215               &WebIntentPickerController::WebIntentServicesForExplicitIntent, | 
| 215               weak_ptr_factory_.GetWeakPtr())); | 216               weak_ptr_factory_.GetWeakPtr())); | 
| 216       return; | 217       return; | 
| 217     } | 218     } | 
| 218   } | 219   } | 
| 219 | 220 | 
| 220   pending_async_count_+= 2; | 221   pending_async_count_ += 2; | 
|  | 222   pending_registry_calls_count_ += 1; | 
|  | 223 | 
| 221   GetWebIntentsRegistry(wrapper_)->GetIntentServices( | 224   GetWebIntentsRegistry(wrapper_)->GetIntentServices( | 
| 222       action, type, | 225       action, type, | 
| 223           base::Bind(&WebIntentPickerController::OnWebIntentServicesAvailable, | 226           base::Bind(&WebIntentPickerController::OnWebIntentServicesAvailable, | 
| 224               weak_ptr_factory_.GetWeakPtr())); | 227               weak_ptr_factory_.GetWeakPtr())); | 
|  | 228 | 
|  | 229   GURL invoking_url = wrapper_->web_contents()->GetURL(); | 
|  | 230   if (invoking_url.is_valid()) { | 
|  | 231     pending_async_count_++; | 
|  | 232     pending_registry_calls_count_++; | 
|  | 233     GetWebIntentsRegistry(wrapper_)->GetDefaultIntentService( | 
|  | 234         action, type, invoking_url, | 
|  | 235         base::Bind(&WebIntentPickerController::OnWebIntentDefaultsAvailable, | 
|  | 236                    weak_ptr_factory_.GetWeakPtr())); | 
|  | 237   } | 
|  | 238 | 
| 225   GetCWSIntentsRegistry(wrapper_)->GetIntentServices( | 239   GetCWSIntentsRegistry(wrapper_)->GetIntentServices( | 
| 226       action, type, | 240       action, type, | 
| 227       base::Bind(&WebIntentPickerController::OnCWSIntentServicesAvailable, | 241       base::Bind(&WebIntentPickerController::OnCWSIntentServicesAvailable, | 
| 228                  weak_ptr_factory_.GetWeakPtr())); | 242                  weak_ptr_factory_.GetWeakPtr())); | 
| 229 } | 243 } | 
| 230 | 244 | 
| 231 void WebIntentPickerController::Observe( | 245 void WebIntentPickerController::Observe( | 
| 232     int type, | 246     int type, | 
| 233     const content::NotificationSource& source, | 247     const content::NotificationSource& source, | 
| 234     const content::NotificationDetails& details) { | 248     const content::NotificationDetails& details) { | 
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 406     FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 420     FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 
| 407         services[i].service_url, | 421         services[i].service_url, | 
| 408         history::FAVICON, | 422         history::FAVICON, | 
| 409         &favicon_consumer_, | 423         &favicon_consumer_, | 
| 410         base::Bind( | 424         base::Bind( | 
| 411             &WebIntentPickerController::OnFaviconDataAvailable, | 425             &WebIntentPickerController::OnFaviconDataAvailable, | 
| 412             weak_ptr_factory_.GetWeakPtr())); | 426             weak_ptr_factory_.GetWeakPtr())); | 
| 413     favicon_consumer_.SetClientData(favicon_service, handle, i); | 427     favicon_consumer_.SetClientData(favicon_service, handle, i); | 
| 414   } | 428   } | 
| 415 | 429 | 
|  | 430   RegistryCallsCompleted(); | 
| 416   AsyncOperationFinished(); | 431   AsyncOperationFinished(); | 
| 417 |  | 
| 418   CreatePicker(); |  | 
| 419   picker_->SetActionString(GetIntentActionString( |  | 
| 420       UTF16ToUTF8(picker_model_->action()))); |  | 
| 421 } | 432 } | 
| 422 | 433 | 
| 423 void WebIntentPickerController::WebIntentServicesForExplicitIntent( | 434 void WebIntentPickerController::WebIntentServicesForExplicitIntent( | 
| 424     const std::vector<webkit_glue::WebIntentServiceData>& services) { | 435     const std::vector<webkit_glue::WebIntentServiceData>& services) { | 
| 425   DCHECK(intents_dispatcher_); | 436   DCHECK(intents_dispatcher_); | 
| 426   DCHECK(intents_dispatcher_->GetIntent().service.is_valid()); | 437   DCHECK(intents_dispatcher_->GetIntent().service.is_valid()); | 
| 427   for (size_t i = 0; i < services.size(); ++i) { | 438   for (size_t i = 0; i < services.size(); ++i) { | 
| 428     if (services[i].service_url != intents_dispatcher_->GetIntent().service) | 439     if (services[i].service_url != intents_dispatcher_->GetIntent().service) | 
| 429       continue; | 440       continue; | 
| 430 | 441 | 
| 431     if (services[i].disposition == | 442     if (services[i].disposition == | 
| 432         webkit_glue::WebIntentServiceData::DISPOSITION_INLINE) | 443         webkit_glue::WebIntentServiceData::DISPOSITION_INLINE) | 
| 433       CreatePicker(); | 444       CreatePicker(); | 
| 434     OnServiceChosen(services[i].service_url, | 445     OnServiceChosen(services[i].service_url, | 
| 435                     ConvertDisposition(services[i].disposition)); | 446                     ConvertDisposition(services[i].disposition)); | 
| 436     AsyncOperationFinished(); | 447     AsyncOperationFinished(); | 
| 437     return; | 448     return; | 
| 438   } | 449   } | 
| 439 | 450 | 
| 440   // No acceptable extension. The intent cannot be dispatched. | 451   // No acceptable extension. The intent cannot be dispatched. | 
| 441   intents_dispatcher_->SendReplyMessage( | 452   intents_dispatcher_->SendReplyMessage( | 
| 442       webkit_glue::WEB_INTENT_REPLY_FAILURE,  ASCIIToUTF16( | 453       webkit_glue::WEB_INTENT_REPLY_FAILURE,  ASCIIToUTF16( | 
| 443           "Explicit extension URL is not available.")); | 454           "Explicit extension URL is not available.")); | 
| 444 | 455 | 
| 445   AsyncOperationFinished(); | 456   AsyncOperationFinished(); | 
| 446 } | 457 } | 
| 447 | 458 | 
|  | 459 void WebIntentPickerController::OnWebIntentDefaultsAvailable( | 
|  | 460     const DefaultWebIntentService& default_service) { | 
|  | 461   if (!default_service.service_url.empty()) { | 
|  | 462     DCHECK(default_service.suppression == 0); | 
|  | 463     picker_model_->set_default_service_url(GURL(default_service.service_url)); | 
|  | 464   } | 
|  | 465 | 
|  | 466   RegistryCallsCompleted(); | 
|  | 467   AsyncOperationFinished(); | 
|  | 468 } | 
|  | 469 | 
|  | 470 void WebIntentPickerController::RegistryCallsCompleted() { | 
|  | 471   pending_registry_calls_count_--; | 
|  | 472   if (pending_registry_calls_count_ != 0) return; | 
|  | 473 | 
|  | 474   if (picker_model_->default_service_url().is_valid()) { | 
|  | 475     // If there's a default service, dispatch to it immediately | 
|  | 476     // without showing the picker. | 
|  | 477     const WebIntentPickerModel::InstalledService* default_service = | 
|  | 478         picker_model_->GetInstalledServiceWithURL( | 
|  | 479             GURL(picker_model_->default_service_url())); | 
|  | 480 | 
|  | 481     if (default_service != NULL) { | 
|  | 482       if (default_service->disposition == | 
|  | 483           WebIntentPickerModel::DISPOSITION_INLINE) | 
|  | 484         CreatePicker(); | 
|  | 485 | 
|  | 486       OnServiceChosen(default_service->url, default_service->disposition); | 
|  | 487       return; | 
|  | 488     } | 
|  | 489   } | 
|  | 490 | 
|  | 491   CreatePicker(); | 
|  | 492   picker_->SetActionString(GetIntentActionString( | 
|  | 493       UTF16ToUTF8(picker_model_->action()))); | 
|  | 494 } | 
|  | 495 | 
| 448 void WebIntentPickerController::OnFaviconDataAvailable( | 496 void WebIntentPickerController::OnFaviconDataAvailable( | 
| 449     FaviconService::Handle handle, history::FaviconData favicon_data) { | 497     FaviconService::Handle handle, history::FaviconData favicon_data) { | 
| 450   size_t index = favicon_consumer_.GetClientDataForCurrentRequest(); | 498   size_t index = favicon_consumer_.GetClientDataForCurrentRequest(); | 
| 451   if (favicon_data.is_valid()) { | 499   if (favicon_data.is_valid()) { | 
| 452     SkBitmap icon_bitmap; | 500     SkBitmap icon_bitmap; | 
| 453 | 501 | 
| 454     if (gfx::PNGCodec::Decode(favicon_data.image_data->front(), | 502     if (gfx::PNGCodec::Decode(favicon_data.image_data->front(), | 
| 455                               favicon_data.image_data->size(), | 503                               favicon_data.image_data->size(), | 
| 456                               &icon_bitmap)) { | 504                               &icon_bitmap)) { | 
| 457       gfx::Image icon_image(new SkBitmap(icon_bitmap)); | 505       gfx::Image icon_image(new SkBitmap(icon_bitmap)); | 
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 609   // If picker is non-NULL, it was set by a test. | 657   // If picker is non-NULL, it was set by a test. | 
| 610   if (picker_ == NULL) | 658   if (picker_ == NULL) | 
| 611     picker_ = WebIntentPicker::Create(wrapper_, this, picker_model_.get()); | 659     picker_ = WebIntentPicker::Create(wrapper_, this, picker_model_.get()); | 
| 612   picker_shown_ = true; | 660   picker_shown_ = true; | 
| 613 } | 661 } | 
| 614 | 662 | 
| 615 void WebIntentPickerController::ClosePicker() { | 663 void WebIntentPickerController::ClosePicker() { | 
| 616   if (picker_) | 664   if (picker_) | 
| 617     picker_->Close(); | 665     picker_->Close(); | 
| 618 } | 666 } | 
| OLD | NEW | 
|---|