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 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 } | 683 } |
684 | 684 |
685 void WebIntentPickerController::OnIntentDataArrived() { | 685 void WebIntentPickerController::OnIntentDataArrived() { |
686 DCHECK(picker_model_.get()); | 686 DCHECK(picker_model_.get()); |
687 | 687 |
688 if (!pending_cws_request_ && | 688 if (!pending_cws_request_ && |
689 pending_registry_calls_count_ == 0) | 689 pending_registry_calls_count_ == 0) |
690 OnPickerEvent(kPickerEventAsyncDataComplete); | 690 OnPickerEvent(kPickerEventAsyncDataComplete); |
691 } | 691 } |
692 | 692 |
| 693 void WebIntentPickerController::Reset() { |
| 694 // Abandon all callbacks. |
| 695 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 696 timer_factory_.InvalidateWeakPtrs(); |
| 697 |
| 698 // Reset state associated with callbacks. |
| 699 pending_async_count_ = 0; |
| 700 pending_registry_calls_count_ = 0; |
| 701 pending_cws_request_ = false; |
| 702 |
| 703 // Reset picker. |
| 704 picker_model_.reset(new WebIntentPickerModel()); |
| 705 picker_shown_ = false; |
| 706 |
| 707 DCHECK(tab_contents_); |
| 708 tab_contents_->constrained_window_tab_helper()->BlockTabContent(false); |
| 709 } |
| 710 |
693 // static | 711 // static |
694 void WebIntentPickerController::DecodeExtensionIconAndResize( | 712 void WebIntentPickerController::DecodeExtensionIconAndResize( |
695 scoped_ptr<std::string> icon_response, | 713 scoped_ptr<std::string> icon_response, |
696 const ExtensionIconAvailableCallback& callback, | 714 const ExtensionIconAvailableCallback& callback, |
697 const base::Closure& unavailable_callback) { | 715 const base::Closure& unavailable_callback) { |
698 SkBitmap icon_bitmap; | 716 SkBitmap icon_bitmap; |
699 if (gfx::PNGCodec::Decode( | 717 if (gfx::PNGCodec::Decode( |
700 reinterpret_cast<const unsigned char*>(icon_response->data()), | 718 reinterpret_cast<const unsigned char*>(icon_response->data()), |
701 icon_response->length(), | 719 icon_response->length(), |
702 &icon_bitmap)) { | 720 &icon_bitmap)) { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 DCHECK(dialog_state_ == kPickerWaiting); | 873 DCHECK(dialog_state_ == kPickerWaiting); |
856 break; | 874 break; |
857 | 875 |
858 case kPickerMain: | 876 case kPickerMain: |
859 // No DCHECK - main state can be reached from any state. | 877 // No DCHECK - main state can be reached from any state. |
860 // Ready to display data. | 878 // Ready to display data. |
861 picker_model_->SetWaitingForSuggestions(false); | 879 picker_model_->SetWaitingForSuggestions(false); |
862 break; | 880 break; |
863 | 881 |
864 case kPickerHidden: | 882 case kPickerHidden: |
865 // Once the picker dialog is closed, abandon all pending callbacks. | 883 Reset(); |
866 weak_ptr_factory_.InvalidateWeakPtrs(); | |
867 break; | 884 break; |
868 | 885 |
869 default: | 886 default: |
870 NOTREACHED(); | 887 NOTREACHED(); |
871 break; | 888 break; |
872 | 889 |
873 } | 890 } |
874 | 891 |
875 dialog_state_ = state; | 892 dialog_state_ = state; |
876 | 893 |
(...skipping 10 matching lines...) Expand all Loading... |
887 picker_->SetActionString(GetIntentActionString( | 904 picker_->SetActionString(GetIntentActionString( |
888 UTF16ToUTF8(picker_model_->action()))); | 905 UTF16ToUTF8(picker_model_->action()))); |
889 picker_shown_ = true; | 906 picker_shown_ = true; |
890 } | 907 } |
891 | 908 |
892 void WebIntentPickerController::ClosePicker() { | 909 void WebIntentPickerController::ClosePicker() { |
893 SetDialogState(kPickerHidden); | 910 SetDialogState(kPickerHidden); |
894 if (picker_) | 911 if (picker_) |
895 picker_->Close(); | 912 picker_->Close(); |
896 } | 913 } |
OLD | NEW |