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 "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
42 #include "ipc/ipc_message.h" | 42 #include "ipc/ipc_message.h" |
43 #include "net/base/load_flags.h" | 43 #include "net/base/load_flags.h" |
44 #include "net/url_request/url_fetcher.h" | 44 #include "net/url_request/url_fetcher.h" |
45 #include "net/url_request/url_fetcher_delegate.h" | 45 #include "net/url_request/url_fetcher_delegate.h" |
46 #include "skia/ext/image_operations.h" | 46 #include "skia/ext/image_operations.h" |
47 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
48 #include "ui/gfx/codec/png_codec.h" | 48 #include "ui/gfx/codec/png_codec.h" |
49 #include "ui/gfx/favicon_size.h" | 49 #include "ui/gfx/favicon_size.h" |
50 #include "ui/gfx/image/image.h" | 50 #include "ui/gfx/image/image.h" |
51 #include "webkit/glue/web_intent_service_data.h" | |
52 | 51 |
53 using extensions::WebstoreInstaller; | 52 using extensions::WebstoreInstaller; |
54 | 53 |
55 namespace { | 54 namespace { |
56 | 55 |
57 const char kShareActionURL[] = "http://webintents.org/share"; | 56 const char kShareActionURL[] = "http://webintents.org/share"; |
58 const char kEditActionURL[] = "http://webintents.org/edit"; | 57 const char kEditActionURL[] = "http://webintents.org/edit"; |
59 const char kViewActionURL[] = "http://webintents.org/view"; | 58 const char kViewActionURL[] = "http://webintents.org/view"; |
60 const char kPickActionURL[] = "http://webintents.org/pick"; | 59 const char kPickActionURL[] = "http://webintents.org/pick"; |
61 const char kSubscribeActionURL[] = "http://webintents.org/subscribe"; | 60 const char kSubscribeActionURL[] = "http://webintents.org/subscribe"; |
(...skipping 14 matching lines...) Expand all Loading... |
76 // Gets the web intents registry for the profile in |tab_contents|. | 75 // Gets the web intents registry for the profile in |tab_contents|. |
77 WebIntentsRegistry* GetWebIntentsRegistry(TabContents* tab_contents) { | 76 WebIntentsRegistry* GetWebIntentsRegistry(TabContents* tab_contents) { |
78 return WebIntentsRegistryFactory::GetForProfile(tab_contents->profile()); | 77 return WebIntentsRegistryFactory::GetForProfile(tab_contents->profile()); |
79 } | 78 } |
80 | 79 |
81 // Gets the Chrome web store intents registry for the profile in |tab_contents|. | 80 // Gets the Chrome web store intents registry for the profile in |tab_contents|. |
82 CWSIntentsRegistry* GetCWSIntentsRegistry(TabContents* tab_contents) { | 81 CWSIntentsRegistry* GetCWSIntentsRegistry(TabContents* tab_contents) { |
83 return CWSIntentsRegistryFactory::GetForProfile(tab_contents->profile()); | 82 return CWSIntentsRegistryFactory::GetForProfile(tab_contents->profile()); |
84 } | 83 } |
85 | 84 |
86 WebIntentPickerModel::Disposition ConvertDisposition( | |
87 webkit_glue::WebIntentServiceData::Disposition disposition) { | |
88 switch (disposition) { | |
89 case webkit_glue::WebIntentServiceData::DISPOSITION_INLINE: | |
90 return WebIntentPickerModel::DISPOSITION_INLINE; | |
91 case webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW: | |
92 return WebIntentPickerModel::DISPOSITION_WINDOW; | |
93 default: | |
94 NOTREACHED(); | |
95 return WebIntentPickerModel::DISPOSITION_WINDOW; | |
96 } | |
97 } | |
98 | |
99 // Returns the action-specific string for |action|. | 85 // Returns the action-specific string for |action|. |
100 string16 GetIntentActionString(const std::string& action) { | 86 string16 GetIntentActionString(const std::string& action) { |
101 if (!action.compare(kShareActionURL)) | 87 if (!action.compare(kShareActionURL)) |
102 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_SHARE); | 88 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_SHARE); |
103 else if (!action.compare(kEditActionURL)) | 89 else if (!action.compare(kEditActionURL)) |
104 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_EDIT); | 90 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_EDIT); |
105 else if (!action.compare(kViewActionURL)) | 91 else if (!action.compare(kViewActionURL)) |
106 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_VIEW); | 92 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_VIEW); |
107 else if (!action.compare(kPickActionURL)) | 93 else if (!action.compare(kPickActionURL)) |
108 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_PICK); | 94 return l10n_util::GetStringUTF16(IDS_WEB_INTENTS_ACTION_PICK); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 277 |
292 void WebIntentPickerController::Observe( | 278 void WebIntentPickerController::Observe( |
293 int type, | 279 int type, |
294 const content::NotificationSource& source, | 280 const content::NotificationSource& source, |
295 const content::NotificationDetails& details) { | 281 const content::NotificationDetails& details) { |
296 DCHECK(type == content::NOTIFICATION_LOAD_START || | 282 DCHECK(type == content::NOTIFICATION_LOAD_START || |
297 type == chrome::NOTIFICATION_TAB_CLOSING); | 283 type == chrome::NOTIFICATION_TAB_CLOSING); |
298 ClosePicker(); | 284 ClosePicker(); |
299 } | 285 } |
300 | 286 |
301 void WebIntentPickerController::OnServiceChosen(const GURL& url, | 287 void WebIntentPickerController::OnServiceChosen( |
302 Disposition disposition) { | 288 const GURL& url, |
| 289 webkit_glue::WebIntentServiceData::Disposition disposition) { |
303 ExtensionService* service = tab_contents_->profile()->GetExtensionService(); | 290 ExtensionService* service = tab_contents_->profile()->GetExtensionService(); |
304 DCHECK(service); | 291 DCHECK(service); |
305 const extensions::Extension* extension = service->GetInstalledApp(url); | 292 const extensions::Extension* extension = service->GetInstalledApp(url); |
306 if (extension && extension->is_platform_app()) { | 293 if (extension && extension->is_platform_app()) { |
307 extensions::LaunchPlatformAppWithWebIntent(tab_contents_->profile(), | 294 extensions::LaunchPlatformAppWithWebIntent(tab_contents_->profile(), |
308 extension, intents_dispatcher_->GetIntent()); | 295 extension, intents_dispatcher_->GetIntent()); |
309 // TODO(benwells): hook up return pathway to allow platform app to post | 296 // TODO(benwells): hook up return pathway to allow platform app to post |
310 // success or failure. | 297 // success or failure. |
311 intents_dispatcher_->SendReplyMessage( | 298 intents_dispatcher_->SendReplyMessage( |
312 webkit_glue::WEB_INTENT_REPLY_SUCCESS, string16()); | 299 webkit_glue::WEB_INTENT_REPLY_SUCCESS, string16()); |
313 ClosePicker(); | 300 ClosePicker(); |
314 return; | 301 return; |
315 } | 302 } |
316 | 303 |
317 switch (disposition) { | 304 switch (disposition) { |
318 case WebIntentPickerModel::DISPOSITION_INLINE: | 305 case webkit_glue::WebIntentServiceData::DISPOSITION_INLINE: |
319 // Set the model to inline disposition. It will notify the picker which | 306 // Set the model to inline disposition. It will notify the picker which |
320 // will respond (via OnInlineDispositionWebContentsCreated) with the | 307 // will respond (via OnInlineDispositionWebContentsCreated) with the |
321 // WebContents to dispatch the intent to. | 308 // WebContents to dispatch the intent to. |
322 picker_model_->SetInlineDisposition(url); | 309 picker_model_->SetInlineDisposition(url); |
323 break; | 310 break; |
324 | 311 |
325 case WebIntentPickerModel::DISPOSITION_WINDOW: { | 312 case webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW: { |
326 Browser* browser = browser::FindBrowserWithWebContents( | 313 Browser* browser = browser::FindBrowserWithWebContents( |
327 tab_contents_->web_contents()); | 314 tab_contents_->web_contents()); |
328 TabContents* contents = chrome::TabContentsFactory( | 315 TabContents* contents = chrome::TabContentsFactory( |
329 tab_contents_->profile(), | 316 tab_contents_->profile(), |
330 tab_util::GetSiteInstanceForNewTab( | 317 tab_util::GetSiteInstanceForNewTab( |
331 tab_contents_->profile(), url), | 318 tab_contents_->profile(), url), |
332 MSG_ROUTING_NONE, NULL); | 319 MSG_ROUTING_NONE, NULL); |
333 | 320 |
334 // Let the controller for the target TabContents know that it is hosting a | 321 // Let the controller for the target TabContents know that it is hosting a |
335 // web intents service. | 322 // web intents service. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 | 445 |
459 // Extension must be registered with registry by now. | 446 // Extension must be registered with registry by now. |
460 DCHECK(services.size() > 0); | 447 DCHECK(services.size() > 0); |
461 | 448 |
462 // TODO(binji): We're going to need to disambiguate if there are multiple | 449 // TODO(binji): We're going to need to disambiguate if there are multiple |
463 // services. For now, just choose the first. | 450 // services. For now, just choose the first. |
464 const webkit_glue::WebIntentServiceData& service_data = services[0]; | 451 const webkit_glue::WebIntentServiceData& service_data = services[0]; |
465 | 452 |
466 picker_model_->AddInstalledService( | 453 picker_model_->AddInstalledService( |
467 service_data.title, service_data.service_url, | 454 service_data.title, service_data.service_url, |
468 ConvertDisposition(service_data.disposition)); | 455 service_data.disposition); |
469 OnServiceChosen( | 456 OnServiceChosen(service_data.service_url, service_data.disposition); |
470 service_data.service_url, | |
471 ConvertDisposition(service_data.disposition)); | |
472 AsyncOperationFinished(); | 457 AsyncOperationFinished(); |
473 } | 458 } |
474 | 459 |
475 void WebIntentPickerController::OnExtensionInstallFailure( | 460 void WebIntentPickerController::OnExtensionInstallFailure( |
476 const std::string& id, | 461 const std::string& id, |
477 const std::string& error) { | 462 const std::string& error) { |
478 picker_->OnExtensionInstallFailure(id); | 463 picker_->OnExtensionInstallFailure(id); |
479 AsyncOperationFinished(); | 464 AsyncOperationFinished(); |
480 } | 465 } |
481 | 466 |
(...skipping 25 matching lines...) Expand all Loading... |
507 intents_dispatcher_ = NULL; | 492 intents_dispatcher_ = NULL; |
508 } | 493 } |
509 | 494 |
510 void WebIntentPickerController::AddServiceToModel( | 495 void WebIntentPickerController::AddServiceToModel( |
511 const webkit_glue::WebIntentServiceData& service) { | 496 const webkit_glue::WebIntentServiceData& service) { |
512 FaviconService* favicon_service = GetFaviconService(tab_contents_); | 497 FaviconService* favicon_service = GetFaviconService(tab_contents_); |
513 | 498 |
514 picker_model_->AddInstalledService( | 499 picker_model_->AddInstalledService( |
515 service.title, | 500 service.title, |
516 service.service_url, | 501 service.service_url, |
517 ConvertDisposition(service.disposition)); | 502 service.disposition); |
518 | 503 |
519 pending_async_count_++; | 504 pending_async_count_++; |
520 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 505 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
521 service.service_url, | 506 service.service_url, |
522 history::FAVICON, | 507 history::FAVICON, |
523 &favicon_consumer_, | 508 &favicon_consumer_, |
524 base::Bind( | 509 base::Bind( |
525 &WebIntentPickerController::OnFaviconDataAvailable, | 510 &WebIntentPickerController::OnFaviconDataAvailable, |
526 weak_ptr_factory_.GetWeakPtr())); | 511 weak_ptr_factory_.GetWeakPtr())); |
527 favicon_consumer_.SetClientData( | 512 favicon_consumer_.SetClientData( |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 void WebIntentPickerController::AsyncOperationFinished() { | 803 void WebIntentPickerController::AsyncOperationFinished() { |
819 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 804 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
820 if (--pending_async_count_ == 0) { | 805 if (--pending_async_count_ == 0) { |
821 if (picker_) | 806 if (picker_) |
822 picker_->OnPendingAsyncCompleted(); | 807 picker_->OnPendingAsyncCompleted(); |
823 } | 808 } |
824 } | 809 } |
825 | 810 |
826 void WebIntentPickerController::InvokeService( | 811 void WebIntentPickerController::InvokeService( |
827 const WebIntentPickerModel::InstalledService& service) { | 812 const WebIntentPickerModel::InstalledService& service) { |
828 if (service.disposition == WebIntentPickerModel::DISPOSITION_INLINE) { | 813 if (service.disposition == |
| 814 webkit_glue::WebIntentServiceData::DISPOSITION_INLINE) { |
829 SetDialogState(kPickerMain); | 815 SetDialogState(kPickerMain); |
830 } | 816 } |
831 OnServiceChosen(service.url, service.disposition); | 817 OnServiceChosen(service.url, service.disposition); |
832 } | 818 } |
833 | 819 |
834 void WebIntentPickerController::SetDialogState(WebIntentPickerState state) { | 820 void WebIntentPickerController::SetDialogState(WebIntentPickerState state) { |
835 // Ignore events that don't change state. | 821 // Ignore events that don't change state. |
836 if (state == dialog_state_) | 822 if (state == dialog_state_) |
837 return; | 823 return; |
838 | 824 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 picker_->SetActionString(GetIntentActionString( | 881 picker_->SetActionString(GetIntentActionString( |
896 UTF16ToUTF8(picker_model_->action()))); | 882 UTF16ToUTF8(picker_model_->action()))); |
897 picker_shown_ = true; | 883 picker_shown_ = true; |
898 } | 884 } |
899 | 885 |
900 void WebIntentPickerController::ClosePicker() { | 886 void WebIntentPickerController::ClosePicker() { |
901 SetDialogState(kPickerHidden); | 887 SetDialogState(kPickerHidden); |
902 if (picker_) | 888 if (picker_) |
903 picker_->Close(); | 889 picker_->Close(); |
904 } | 890 } |
OLD | NEW |