| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "chrome/browser/tab_contents/tab_util.h" | 10 #include "chrome/browser/tab_contents/tab_util.h" |
| 11 #include "chrome/browser/ui/browser_navigator.h" | 11 #include "chrome/browser/ui/browser_navigator.h" |
| 12 #include "chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h" | 12 #include "chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h" |
| 13 #include "chrome/browser/ui/intents/web_intent_picker.h" | 13 #include "chrome/browser/ui/intents/web_intent_picker.h" |
| 14 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" | 14 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" |
| 15 #include "chrome/browser/ui/intents/web_intent_picker_model.h" | 15 #include "chrome/browser/ui/intents/web_intent_picker_model.h" |
| 16 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" | 16 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 18 #include "chrome/browser/ui/views/constrained_window_views.h" | 18 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 19 #include "chrome/browser/ui/views/frame/browser_view.h" | 19 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 20 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 20 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 21 #include "chrome/browser/ui/views/toolbar_view.h" | 21 #include "chrome/browser/ui/views/toolbar_view.h" |
| 22 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/browser/web_contents_view.h" | 24 #include "content/public/browser/web_contents_view.h" |
| 25 #include "grit/chromium_strings.h" | 25 #include "grit/chromium_strings.h" |
| 26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 27 #include "grit/google_chrome_strings.h" | 27 #include "grit/google_chrome_strings.h" |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 | 654 |
| 655 // Views implementation of WebIntentPicker. | 655 // Views implementation of WebIntentPicker. |
| 656 class WebIntentPickerViews : public views::ButtonListener, | 656 class WebIntentPickerViews : public views::ButtonListener, |
| 657 public views::DialogDelegate, | 657 public views::DialogDelegate, |
| 658 public views::LinkListener, | 658 public views::LinkListener, |
| 659 public WebIntentPicker, | 659 public WebIntentPicker, |
| 660 public WebIntentPickerModelObserver, | 660 public WebIntentPickerModelObserver, |
| 661 public ServiceButtonsView::Delegate, | 661 public ServiceButtonsView::Delegate, |
| 662 public SuggestedExtensionsRowView::Delegate { | 662 public SuggestedExtensionsRowView::Delegate { |
| 663 public: | 663 public: |
| 664 WebIntentPickerViews(TabContentsWrapper* tab_contents, | 664 WebIntentPickerViews(TabContents* tab_contents, |
| 665 WebIntentPickerDelegate* delegate, | 665 WebIntentPickerDelegate* delegate, |
| 666 WebIntentPickerModel* model); | 666 WebIntentPickerModel* model); |
| 667 virtual ~WebIntentPickerViews(); | 667 virtual ~WebIntentPickerViews(); |
| 668 | 668 |
| 669 // views::ButtonListener implementation. | 669 // views::ButtonListener implementation. |
| 670 virtual void ButtonPressed(views::Button* sender, | 670 virtual void ButtonPressed(views::Button* sender, |
| 671 const views::Event& event) OVERRIDE; | 671 const views::Event& event) OVERRIDE; |
| 672 | 672 |
| 673 // views::DialogDelegate implementation. | 673 // views::DialogDelegate implementation. |
| 674 virtual void WindowClosing() OVERRIDE; | 674 virtual void WindowClosing() OVERRIDE; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 // Created locally, owned by Views. | 742 // Created locally, owned by Views. |
| 743 views::Label* suggestions_label_; | 743 views::Label* suggestions_label_; |
| 744 | 744 |
| 745 // A weak pointer to the extensions view. | 745 // A weak pointer to the extensions view. |
| 746 // Created locally, owned by Views. | 746 // Created locally, owned by Views. |
| 747 SuggestedExtensionsView* extensions_; | 747 SuggestedExtensionsView* extensions_; |
| 748 | 748 |
| 749 // Delegate for inline disposition tab contents. | 749 // Delegate for inline disposition tab contents. |
| 750 scoped_ptr<WebIntentInlineDispositionDelegate> inline_disposition_delegate_; | 750 scoped_ptr<WebIntentInlineDispositionDelegate> inline_disposition_delegate_; |
| 751 | 751 |
| 752 // A weak pointer to the wrapper of the WebContents this picker is in. | 752 // A weak pointer to the TabContents this picker is in. |
| 753 TabContentsWrapper* wrapper_; | 753 TabContents* tab_contents_; |
| 754 | 754 |
| 755 // A weak pointer to the WebView that hosts the WebContents being displayed. | 755 // A weak pointer to the WebView that hosts the WebContents being displayed. |
| 756 // Created locally, owned by Views. | 756 // Created locally, owned by Views. |
| 757 views::WebView* webview_; | 757 views::WebView* webview_; |
| 758 | 758 |
| 759 // A weak pointer to the view that contains all other views in the picker. | 759 // A weak pointer to the view that contains all other views in the picker. |
| 760 // Created locally, owned by Views. | 760 // Created locally, owned by Views. |
| 761 views::View* contents_; | 761 views::View* contents_; |
| 762 | 762 |
| 763 // A weak pointer to the constrained window. | 763 // A weak pointer to the constrained window. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 779 // The text for the current action. | 779 // The text for the current action. |
| 780 string16 action_text_; | 780 string16 action_text_; |
| 781 | 781 |
| 782 // Ownership of the WebContents we are displaying in the inline disposition. | 782 // Ownership of the WebContents we are displaying in the inline disposition. |
| 783 scoped_ptr<WebContents> inline_web_contents_; | 783 scoped_ptr<WebContents> inline_web_contents_; |
| 784 | 784 |
| 785 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerViews); | 785 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerViews); |
| 786 }; | 786 }; |
| 787 | 787 |
| 788 // static | 788 // static |
| 789 WebIntentPicker* WebIntentPicker::Create(TabContentsWrapper* wrapper, | 789 WebIntentPicker* WebIntentPicker::Create(TabContents* tab_contents, |
| 790 WebIntentPickerDelegate* delegate, | 790 WebIntentPickerDelegate* delegate, |
| 791 WebIntentPickerModel* model) { | 791 WebIntentPickerModel* model) { |
| 792 return new WebIntentPickerViews(wrapper, delegate, model); | 792 return new WebIntentPickerViews(tab_contents, delegate, model); |
| 793 } | 793 } |
| 794 | 794 |
| 795 WebIntentPickerViews::WebIntentPickerViews(TabContentsWrapper* wrapper, | 795 WebIntentPickerViews::WebIntentPickerViews(TabContents* tab_contents, |
| 796 WebIntentPickerDelegate* delegate, | 796 WebIntentPickerDelegate* delegate, |
| 797 WebIntentPickerModel* model) | 797 WebIntentPickerModel* model) |
| 798 : delegate_(delegate), | 798 : delegate_(delegate), |
| 799 model_(model), | 799 model_(model), |
| 800 service_buttons_(NULL), | 800 service_buttons_(NULL), |
| 801 action_label_(NULL), | 801 action_label_(NULL), |
| 802 suggestions_label_(NULL), | 802 suggestions_label_(NULL), |
| 803 extensions_(NULL), | 803 extensions_(NULL), |
| 804 wrapper_(wrapper), | 804 tab_contents_(tab_contents), |
| 805 webview_(new views::WebView(wrapper->profile())), | 805 webview_(new views::WebView(tab_contents->profile())), |
| 806 contents_(NULL), | 806 contents_(NULL), |
| 807 window_(NULL), | 807 window_(NULL), |
| 808 more_suggestions_link_(NULL), | 808 more_suggestions_link_(NULL), |
| 809 choose_another_service_link_(NULL), | 809 choose_another_service_link_(NULL), |
| 810 displaying_web_contents_(false) { | 810 displaying_web_contents_(false) { |
| 811 model_->set_observer(this); | 811 model_->set_observer(this); |
| 812 InitContents(); | 812 InitContents(); |
| 813 | 813 |
| 814 // Show the dialog. | 814 // Show the dialog. |
| 815 window_ = new ConstrainedWindowViews(wrapper, this); | 815 window_ = new ConstrainedWindowViews(tab_contents, this); |
| 816 } | 816 } |
| 817 | 817 |
| 818 WebIntentPickerViews::~WebIntentPickerViews() { | 818 WebIntentPickerViews::~WebIntentPickerViews() { |
| 819 model_->set_observer(NULL); | 819 model_->set_observer(NULL); |
| 820 } | 820 } |
| 821 | 821 |
| 822 void WebIntentPickerViews::ButtonPressed(views::Button* sender, | 822 void WebIntentPickerViews::ButtonPressed(views::Button* sender, |
| 823 const views::Event& event) { | 823 const views::Event& event) { |
| 824 #if defined(USE_CLOSE_BUTTON) | 824 #if defined(USE_CLOSE_BUTTON) |
| 825 delegate_->OnPickerCancelled(); | 825 delegate_->OnPickerCancelled(); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 WebIntentPickerModel* model, | 981 WebIntentPickerModel* model, |
| 982 const string16& extension_id) { | 982 const string16& extension_id) { |
| 983 extensions_->Update(); | 983 extensions_->Update(); |
| 984 contents_->Layout(); | 984 contents_->Layout(); |
| 985 SizeToContents(); | 985 SizeToContents(); |
| 986 } | 986 } |
| 987 | 987 |
| 988 void WebIntentPickerViews::OnInlineDisposition( | 988 void WebIntentPickerViews::OnInlineDisposition( |
| 989 WebIntentPickerModel* model, const GURL& url) { | 989 WebIntentPickerModel* model, const GURL& url) { |
| 990 if (!webview_) | 990 if (!webview_) |
| 991 webview_ = new views::WebView(wrapper_->profile()); | 991 webview_ = new views::WebView(tab_contents_->profile()); |
| 992 | 992 |
| 993 inline_web_contents_.reset(WebContents::Create( | 993 inline_web_contents_.reset(WebContents::Create( |
| 994 wrapper_->profile(), | 994 tab_contents_->profile(), |
| 995 tab_util::GetSiteInstanceForNewTab(wrapper_->profile(), url), | 995 tab_util::GetSiteInstanceForNewTab(tab_contents_->profile(), url), |
| 996 MSG_ROUTING_NONE, NULL, NULL)); | 996 MSG_ROUTING_NONE, NULL, NULL)); |
| 997 // Does not take ownership, so we keep a scoped_ptr | 997 // Does not take ownership, so we keep a scoped_ptr |
| 998 // for the WebContents locally. | 998 // for the WebContents locally. |
| 999 webview_->SetWebContents(inline_web_contents_.get()); | 999 webview_->SetWebContents(inline_web_contents_.get()); |
| 1000 inline_disposition_delegate_.reset( | 1000 inline_disposition_delegate_.reset( |
| 1001 new WebIntentInlineDispositionDelegate(this, inline_web_contents_.get(), | 1001 new WebIntentInlineDispositionDelegate(this, inline_web_contents_.get(), |
| 1002 wrapper_->profile())); | 1002 tab_contents_->profile())); |
| 1003 content::WebContents* web_contents = webview_->GetWebContents(); | 1003 content::WebContents* web_contents = webview_->GetWebContents(); |
| 1004 | 1004 |
| 1005 const WebIntentPickerModel::InstalledService* service = | 1005 const WebIntentPickerModel::InstalledService* service = |
| 1006 model->GetInstalledServiceWithURL(url); | 1006 model->GetInstalledServiceWithURL(url); |
| 1007 DCHECK(service); | 1007 DCHECK(service); |
| 1008 | 1008 |
| 1009 // Must call this immediately after WebContents creation to avoid race | 1009 // Must call this immediately after WebContents creation to avoid race |
| 1010 // with load. | 1010 // with load. |
| 1011 delegate_->OnInlineDispositionWebContentsCreated(web_contents); | 1011 delegate_->OnInlineDispositionWebContentsCreated(web_contents); |
| 1012 web_contents->GetController().LoadURL( | 1012 web_contents->GetController().LoadURL( |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 views::ImageButton* close_button = new views::ImageButton(this); | 1163 views::ImageButton* close_button = new views::ImageButton(this); |
| 1164 close_button->SetImage(views::CustomButton::BS_NORMAL, | 1164 close_button->SetImage(views::CustomButton::BS_NORMAL, |
| 1165 rb.GetImageSkiaNamed(IDR_CLOSE_BAR)); | 1165 rb.GetImageSkiaNamed(IDR_CLOSE_BAR)); |
| 1166 close_button->SetImage(views::CustomButton::BS_HOT, | 1166 close_button->SetImage(views::CustomButton::BS_HOT, |
| 1167 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_H)); | 1167 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_H)); |
| 1168 close_button->SetImage(views::CustomButton::BS_PUSHED, | 1168 close_button->SetImage(views::CustomButton::BS_PUSHED, |
| 1169 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_P)); | 1169 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_P)); |
| 1170 return close_button; | 1170 return close_button; |
| 1171 } | 1171 } |
| 1172 #endif | 1172 #endif |
| OLD | NEW |