Chromium Code Reviews| 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 30 matching lines...) Expand all Loading... | |
| 41 #include "ipc/ipc_message.h" | 41 #include "ipc/ipc_message.h" |
| 42 #include "net/base/load_flags.h" | 42 #include "net/base/load_flags.h" |
| 43 #include "net/url_request/url_fetcher.h" | 43 #include "net/url_request/url_fetcher.h" |
| 44 #include "net/url_request/url_fetcher_delegate.h" | 44 #include "net/url_request/url_fetcher_delegate.h" |
| 45 #include "skia/ext/image_operations.h" | 45 #include "skia/ext/image_operations.h" |
| 46 #include "ui/base/l10n/l10n_util.h" | 46 #include "ui/base/l10n/l10n_util.h" |
| 47 #include "ui/gfx/codec/png_codec.h" | 47 #include "ui/gfx/codec/png_codec.h" |
| 48 #include "ui/gfx/favicon_size.h" | 48 #include "ui/gfx/favicon_size.h" |
| 49 #include "ui/gfx/image/image.h" | 49 #include "ui/gfx/image/image.h" |
| 50 #include "webkit/glue/web_intent_service_data.h" | 50 #include "webkit/glue/web_intent_service_data.h" |
| 51 | 51 |
|
groby-ooo-7-16
2012/08/10 18:36:31
#include "webkit/glue/web_intent_service_data.h"
Greg Billock
2012/08/15 18:16:37
Was here one line up, but moving to .h file.
| |
| 52 using extensions::WebstoreInstaller; | 52 using extensions::WebstoreInstaller; |
| 53 | 53 |
| 54 namespace { | 54 namespace { |
| 55 | 55 |
| 56 const char kShareActionURL[] = "http://webintents.org/share"; | 56 const char kShareActionURL[] = "http://webintents.org/share"; |
| 57 const char kEditActionURL[] = "http://webintents.org/edit"; | 57 const char kEditActionURL[] = "http://webintents.org/edit"; |
| 58 const char kViewActionURL[] = "http://webintents.org/view"; | 58 const char kViewActionURL[] = "http://webintents.org/view"; |
| 59 const char kPickActionURL[] = "http://webintents.org/pick"; | 59 const char kPickActionURL[] = "http://webintents.org/pick"; |
| 60 const char kSubscribeActionURL[] = "http://webintents.org/subscribe"; | 60 const char kSubscribeActionURL[] = "http://webintents.org/subscribe"; |
| 61 const char kSaveActionURL[] = "http://webintents.org/save"; | 61 const char kSaveActionURL[] = "http://webintents.org/save"; |
| 62 | 62 |
| 63 // Gets the favicon service for the profile in |tab_contents|. | 63 // Gets the favicon service for the profile in |tab_contents|. |
| 64 FaviconService* GetFaviconService(TabContents* tab_contents) { | 64 FaviconService* GetFaviconService(TabContents* tab_contents) { |
| 65 return tab_contents->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); | 65 return tab_contents->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Gets the web intents registry for the profile in |tab_contents|. | 68 // Gets the web intents registry for the profile in |tab_contents|. |
| 69 WebIntentsRegistry* GetWebIntentsRegistry(TabContents* tab_contents) { | 69 WebIntentsRegistry* GetWebIntentsRegistry(TabContents* tab_contents) { |
| 70 return WebIntentsRegistryFactory::GetForProfile(tab_contents->profile()); | 70 return WebIntentsRegistryFactory::GetForProfile(tab_contents->profile()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Gets the Chrome web store intents registry for the profile in |tab_contents|. | 73 // Gets the Chrome web store intents registry for the profile in |tab_contents|. |
| 74 CWSIntentsRegistry* GetCWSIntentsRegistry(TabContents* tab_contents) { | 74 CWSIntentsRegistry* GetCWSIntentsRegistry(TabContents* tab_contents) { |
| 75 return CWSIntentsRegistryFactory::GetForProfile(tab_contents->profile()); | 75 return CWSIntentsRegistryFactory::GetForProfile(tab_contents->profile()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 WebIntentPickerModel::Disposition ConvertDisposition( | |
| 79 webkit_glue::WebIntentServiceData::Disposition disposition) { | |
| 80 switch (disposition) { | |
| 81 case webkit_glue::WebIntentServiceData::DISPOSITION_INLINE: | |
| 82 return WebIntentPickerModel::DISPOSITION_INLINE; | |
| 83 case webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW: | |
| 84 return WebIntentPickerModel::DISPOSITION_WINDOW; | |
| 85 default: | |
| 86 NOTREACHED(); | |
| 87 return WebIntentPickerModel::DISPOSITION_WINDOW; | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 // Returns the action-specific string for |action|. | 78 // Returns the action-specific string for |action|. |
| 92 string16 GetIntentActionString(const std::string& action) { | 79 string16 GetIntentActionString(const std::string& action) { |
| 93 if (!action.compare(kShareActionURL)) | 80 if (!action.compare(kShareActionURL)) |
| 94 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_SHARE); | 81 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_SHARE); |
| 95 else if (!action.compare(kEditActionURL)) | 82 else if (!action.compare(kEditActionURL)) |
| 96 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_EDIT); | 83 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_EDIT); |
| 97 else if (!action.compare(kViewActionURL)) | 84 else if (!action.compare(kViewActionURL)) |
| 98 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_VIEW); | 85 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_VIEW); |
| 99 else if (!action.compare(kPickActionURL)) | 86 else if (!action.compare(kPickActionURL)) |
| 100 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_PICK); | 87 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_PICK); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 | 260 |
| 274 void WebIntentPickerController::Observe( | 261 void WebIntentPickerController::Observe( |
| 275 int type, | 262 int type, |
| 276 const content::NotificationSource& source, | 263 const content::NotificationSource& source, |
| 277 const content::NotificationDetails& details) { | 264 const content::NotificationDetails& details) { |
| 278 DCHECK(type == content::NOTIFICATION_LOAD_START || | 265 DCHECK(type == content::NOTIFICATION_LOAD_START || |
| 279 type == chrome::NOTIFICATION_TAB_CLOSING); | 266 type == chrome::NOTIFICATION_TAB_CLOSING); |
| 280 ClosePicker(); | 267 ClosePicker(); |
| 281 } | 268 } |
| 282 | 269 |
| 283 void WebIntentPickerController::OnServiceChosen(const GURL& url, | 270 void WebIntentPickerController::OnServiceChosen( |
| 284 Disposition disposition) { | 271 const GURL& url, |
| 272 webkit_glue::WebIntentServiceData::Disposition disposition) { | |
| 285 ExtensionService* service = tab_contents_->profile()->GetExtensionService(); | 273 ExtensionService* service = tab_contents_->profile()->GetExtensionService(); |
| 286 DCHECK(service); | 274 DCHECK(service); |
| 287 const extensions::Extension* extension = service->GetInstalledApp(url); | 275 const extensions::Extension* extension = service->GetInstalledApp(url); |
| 288 if (extension && extension->is_platform_app()) { | 276 if (extension && extension->is_platform_app()) { |
| 289 extensions::LaunchPlatformAppWithWebIntent(tab_contents_->profile(), | 277 extensions::LaunchPlatformAppWithWebIntent(tab_contents_->profile(), |
| 290 extension, intents_dispatcher_->GetIntent()); | 278 extension, intents_dispatcher_->GetIntent()); |
| 291 // TODO(benwells): hook up return pathway to allow platform app to post | 279 // TODO(benwells): hook up return pathway to allow platform app to post |
| 292 // success or failure. | 280 // success or failure. |
| 293 intents_dispatcher_->SendReplyMessage( | 281 intents_dispatcher_->SendReplyMessage( |
| 294 webkit_glue::WEB_INTENT_REPLY_SUCCESS, string16()); | 282 webkit_glue::WEB_INTENT_REPLY_SUCCESS, string16()); |
| 295 ClosePicker(); | 283 ClosePicker(); |
| 296 return; | 284 return; |
| 297 } | 285 } |
| 298 | 286 |
| 299 switch (disposition) { | 287 switch (disposition) { |
| 300 case WebIntentPickerModel::DISPOSITION_INLINE: | 288 case webkit_glue::WebIntentServiceData::DISPOSITION_INLINE: |
| 301 // Set the model to inline disposition. It will notify the picker which | 289 // Set the model to inline disposition. It will notify the picker which |
| 302 // will respond (via OnInlineDispositionWebContentsCreated) with the | 290 // will respond (via OnInlineDispositionWebContentsCreated) with the |
| 303 // WebContents to dispatch the intent to. | 291 // WebContents to dispatch the intent to. |
| 304 picker_model_->SetInlineDisposition(url); | 292 picker_model_->SetInlineDisposition(url); |
| 305 break; | 293 break; |
| 306 | 294 |
| 307 case WebIntentPickerModel::DISPOSITION_WINDOW: { | 295 case webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW: { |
| 308 Browser* browser = browser::FindBrowserWithWebContents( | 296 Browser* browser = browser::FindBrowserWithWebContents( |
| 309 tab_contents_->web_contents()); | 297 tab_contents_->web_contents()); |
| 310 TabContents* contents = chrome::TabContentsFactory( | 298 TabContents* contents = chrome::TabContentsFactory( |
| 311 tab_contents_->profile(), | 299 tab_contents_->profile(), |
| 312 tab_util::GetSiteInstanceForNewTab( | 300 tab_util::GetSiteInstanceForNewTab( |
| 313 tab_contents_->profile(), url), | 301 tab_contents_->profile(), url), |
| 314 MSG_ROUTING_NONE, NULL, NULL); | 302 MSG_ROUTING_NONE, NULL, NULL); |
| 315 | 303 |
| 316 // Let the controller for the target TabContents know that it is hosting a | 304 // Let the controller for the target TabContents know that it is hosting a |
| 317 // web intents service. | 305 // web intents service. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 // Extension must be registered with registry by now. | 429 // Extension must be registered with registry by now. |
| 442 DCHECK(services.size() > 0); | 430 DCHECK(services.size() > 0); |
| 443 | 431 |
| 444 // TODO(binji): We're going to need to disambiguate if there are multiple | 432 // TODO(binji): We're going to need to disambiguate if there are multiple |
| 445 // services. For now, just choose the first. | 433 // services. For now, just choose the first. |
| 446 const webkit_glue::WebIntentServiceData& service_data = services[0]; | 434 const webkit_glue::WebIntentServiceData& service_data = services[0]; |
| 447 | 435 |
| 448 picker_model_->AddInstalledService( | 436 picker_model_->AddInstalledService( |
| 449 service_data.title, service_data.service_url, | 437 service_data.title, service_data.service_url, |
| 450 ConvertDisposition(service_data.disposition)); | 438 ConvertDisposition(service_data.disposition)); |
| 451 OnServiceChosen( | 439 OnServiceChosen(service_data.service_url, service_data.disposition); |
| 452 service_data.service_url, | |
| 453 ConvertDisposition(service_data.disposition)); | |
| 454 AsyncOperationFinished(); | 440 AsyncOperationFinished(); |
| 455 } | 441 } |
| 456 | 442 |
| 457 void WebIntentPickerController::OnExtensionInstallFailure( | 443 void WebIntentPickerController::OnExtensionInstallFailure( |
| 458 const std::string& id, | 444 const std::string& id, |
| 459 const std::string& error) { | 445 const std::string& error) { |
| 460 picker_->OnExtensionInstallFailure(id); | 446 picker_->OnExtensionInstallFailure(id); |
| 461 AsyncOperationFinished(); | 447 AsyncOperationFinished(); |
| 462 } | 448 } |
| 463 | 449 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 489 intents_dispatcher_ = NULL; | 475 intents_dispatcher_ = NULL; |
| 490 } | 476 } |
| 491 | 477 |
| 492 void WebIntentPickerController::AddServiceToModel( | 478 void WebIntentPickerController::AddServiceToModel( |
| 493 const webkit_glue::WebIntentServiceData& service) { | 479 const webkit_glue::WebIntentServiceData& service) { |
| 494 FaviconService* favicon_service = GetFaviconService(tab_contents_); | 480 FaviconService* favicon_service = GetFaviconService(tab_contents_); |
| 495 | 481 |
| 496 picker_model_->AddInstalledService( | 482 picker_model_->AddInstalledService( |
| 497 service.title, | 483 service.title, |
| 498 service.service_url, | 484 service.service_url, |
| 499 ConvertDisposition(service.disposition)); | 485 service.disposition); |
| 500 | 486 |
| 501 pending_async_count_++; | 487 pending_async_count_++; |
| 502 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 488 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
| 503 service.service_url, | 489 service.service_url, |
| 504 history::FAVICON, | 490 history::FAVICON, |
| 505 &favicon_consumer_, | 491 &favicon_consumer_, |
| 506 base::Bind( | 492 base::Bind( |
| 507 &WebIntentPickerController::OnFaviconDataAvailable, | 493 &WebIntentPickerController::OnFaviconDataAvailable, |
| 508 weak_ptr_factory_.GetWeakPtr())); | 494 weak_ptr_factory_.GetWeakPtr())); |
| 509 favicon_consumer_.SetClientData( | 495 favicon_consumer_.SetClientData( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 525 DCHECK(intents_dispatcher_->GetIntent().service.is_valid()); | 511 DCHECK(intents_dispatcher_->GetIntent().service.is_valid()); |
| 526 for (size_t i = 0; i < services.size(); ++i) { | 512 for (size_t i = 0; i < services.size(); ++i) { |
| 527 if (services[i].service_url != intents_dispatcher_->GetIntent().service) | 513 if (services[i].service_url != intents_dispatcher_->GetIntent().service) |
| 528 continue; | 514 continue; |
| 529 | 515 |
| 530 AddServiceToModel(services[i]); | 516 AddServiceToModel(services[i]); |
| 531 | 517 |
| 532 if (services[i].disposition == | 518 if (services[i].disposition == |
| 533 webkit_glue::WebIntentServiceData::DISPOSITION_INLINE) | 519 webkit_glue::WebIntentServiceData::DISPOSITION_INLINE) |
| 534 CreatePicker(); | 520 CreatePicker(); |
| 535 OnServiceChosen(services[i].service_url, | 521 OnServiceChosen(services[i].service_url, services[i].disposition); |
| 536 ConvertDisposition(services[i].disposition)); | |
| 537 AsyncOperationFinished(); | 522 AsyncOperationFinished(); |
| 538 return; | 523 return; |
| 539 } | 524 } |
| 540 | 525 |
| 541 // No acceptable extension. The intent cannot be dispatched. | 526 // No acceptable extension. The intent cannot be dispatched. |
| 542 intents_dispatcher_->SendReplyMessage( | 527 intents_dispatcher_->SendReplyMessage( |
| 543 webkit_glue::WEB_INTENT_REPLY_FAILURE, ASCIIToUTF16( | 528 webkit_glue::WEB_INTENT_REPLY_FAILURE, ASCIIToUTF16( |
| 544 "Explicit extension URL is not available.")); | 529 "Explicit extension URL is not available.")); |
| 545 | 530 |
| 546 AsyncOperationFinished(); | 531 AsyncOperationFinished(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 563 | 548 |
| 564 if (picker_model_->default_service_url().is_valid()) { | 549 if (picker_model_->default_service_url().is_valid()) { |
| 565 // If there's a default service, dispatch to it immediately | 550 // If there's a default service, dispatch to it immediately |
| 566 // without showing the picker. | 551 // without showing the picker. |
| 567 const WebIntentPickerModel::InstalledService* default_service = | 552 const WebIntentPickerModel::InstalledService* default_service = |
| 568 picker_model_->GetInstalledServiceWithURL( | 553 picker_model_->GetInstalledServiceWithURL( |
| 569 GURL(picker_model_->default_service_url())); | 554 GURL(picker_model_->default_service_url())); |
| 570 | 555 |
| 571 if (default_service != NULL) { | 556 if (default_service != NULL) { |
| 572 if (default_service->disposition == | 557 if (default_service->disposition == |
| 573 WebIntentPickerModel::DISPOSITION_INLINE) | 558 webkit_glue::WebIntentServiceData::DISPOSITION_INLINE) |
| 574 CreatePicker(); | 559 CreatePicker(); |
| 575 | 560 |
| 576 OnServiceChosen(default_service->url, default_service->disposition); | 561 OnServiceChosen(default_service->url, default_service->disposition); |
| 577 return; | 562 return; |
| 578 } | 563 } |
| 579 } | 564 } |
| 580 | 565 |
| 581 CreatePicker(); | 566 CreatePicker(); |
| 582 picker_->SetActionString(GetIntentActionString( | 567 picker_->SetActionString(GetIntentActionString( |
| 583 UTF16ToUTF8(picker_model_->action()))); | 568 UTF16ToUTF8(picker_model_->action()))); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 // If picker is non-NULL, it was set by a test. | 751 // If picker is non-NULL, it was set by a test. |
| 767 if (picker_ == NULL) | 752 if (picker_ == NULL) |
| 768 picker_ = WebIntentPicker::Create(tab_contents_, this, picker_model_.get()); | 753 picker_ = WebIntentPicker::Create(tab_contents_, this, picker_model_.get()); |
| 769 picker_shown_ = true; | 754 picker_shown_ = true; |
| 770 } | 755 } |
| 771 | 756 |
| 772 void WebIntentPickerController::ClosePicker() { | 757 void WebIntentPickerController::ClosePicker() { |
| 773 if (picker_) | 758 if (picker_) |
| 774 picker_->Close(); | 759 picker_->Close(); |
| 775 } | 760 } |
| OLD | NEW |