Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome/browser/ui/views/web_intent_picker_views.cc

Issue 9649020: [Web Intents] WebIntentPickerModel uses URL instead of index to reference registered services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mac fix Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/intents/web_intent_picker_model_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_navigator.h" 10 #include "chrome/browser/ui/browser_navigator.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 145
146 // A view that contains all service buttons (i.e. the installed services). 146 // A view that contains all service buttons (i.e. the installed services).
147 class ServiceButtonsView : public views::View, 147 class ServiceButtonsView : public views::View,
148 public views::ButtonListener { 148 public views::ButtonListener {
149 public: 149 public:
150 class Delegate { 150 class Delegate {
151 public: 151 public:
152 // Called when a service button is clicked. |index| is the index of the 152 // Called when a service button is clicked. |index| is the index of the
153 // service button in the model. 153 // service button in the model.
154 virtual void OnServiceButtonClicked( 154 virtual void OnServiceButtonClicked(
155 size_t index,
156 const WebIntentPickerModel::InstalledService& service) = 0; 155 const WebIntentPickerModel::InstalledService& service) = 0;
157 156
158 protected: 157 protected:
159 virtual ~Delegate() {} 158 virtual ~Delegate() {}
160 }; 159 };
161 160
162 ServiceButtonsView(const WebIntentPickerModel* model, Delegate* delegate); 161 ServiceButtonsView(const WebIntentPickerModel* model, Delegate* delegate);
163 virtual ~ServiceButtonsView(); 162 virtual ~ServiceButtonsView();
164 163
165 // Updates the service button view with new model data. 164 // Updates the service button view with new model data.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 217 }
219 218
220 // Add a padding row between the service buttons and the label when there 219 // Add a padding row between the service buttons and the label when there
221 // are service buttons to display. 220 // are service buttons to display.
222 grid_layout->AddPaddingRow(0, kContentAreaSpacing); 221 grid_layout->AddPaddingRow(0, kContentAreaSpacing);
223 } 222 }
224 223
225 void ServiceButtonsView::ButtonPressed(views::Button* sender, 224 void ServiceButtonsView::ButtonPressed(views::Button* sender,
226 const views::Event& event) { 225 const views::Event& event) {
227 size_t index = static_cast<size_t>(sender->tag()); 226 size_t index = static_cast<size_t>(sender->tag());
228 delegate_->OnServiceButtonClicked(index, 227 delegate_->OnServiceButtonClicked(model_->GetInstalledServiceAt(index));
229 model_->GetInstalledServiceAt(index));
230 } 228 }
231 229
232 gfx::Size ServiceButtonsView::GetPreferredSize() { 230 gfx::Size ServiceButtonsView::GetPreferredSize() {
233 // If there are no service buttons, hide this view. 231 // If there are no service buttons, hide this view.
234 if (model_->GetInstalledServiceCount() == 0) 232 if (model_->GetInstalledServiceCount() == 0)
235 return gfx::Size(); 233 return gfx::Size();
236 return GetLayoutManager()->GetPreferredSize(this); 234 return GetLayoutManager()->GetPreferredSize(this);
237 } 235 }
238 236
239 // SuggestedExtensionsView ----------------------------------------------------- 237 // SuggestedExtensionsView -----------------------------------------------------
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 446
449 // WebIntentPicker implementation. 447 // WebIntentPicker implementation.
450 virtual void Close() OVERRIDE; 448 virtual void Close() OVERRIDE;
451 449
452 // WebIntentPickerModelObserver implementation. 450 // WebIntentPickerModelObserver implementation.
453 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE; 451 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE;
454 virtual void OnFaviconChanged(WebIntentPickerModel* model, 452 virtual void OnFaviconChanged(WebIntentPickerModel* model,
455 size_t index) OVERRIDE; 453 size_t index) OVERRIDE;
456 virtual void OnExtensionIconChanged(WebIntentPickerModel* model, 454 virtual void OnExtensionIconChanged(WebIntentPickerModel* model,
457 const string16& extension_id) OVERRIDE; 455 const string16& extension_id) OVERRIDE;
458 virtual void OnInlineDisposition(WebIntentPickerModel* model) OVERRIDE; 456 virtual void OnInlineDisposition(WebIntentPickerModel* model,
457 const GURL& url) OVERRIDE;
459 458
460 // ServiceButtonsView::Delegate implementation. 459 // ServiceButtonsView::Delegate implementation.
461 virtual void OnServiceButtonClicked( 460 virtual void OnServiceButtonClicked(
462 size_t index,
463 const WebIntentPickerModel::InstalledService& service) OVERRIDE; 461 const WebIntentPickerModel::InstalledService& service) OVERRIDE;
464 462
465 // SuggestedExtensionsView::Delegate implementation. 463 // SuggestedExtensionsView::Delegate implementation.
466 virtual void OnExtensionInstallClicked(const string16& extension_id) OVERRIDE; 464 virtual void OnExtensionInstallClicked(const string16& extension_id) OVERRIDE;
467 virtual void OnExtensionLinkClicked(const string16& extension_id) OVERRIDE; 465 virtual void OnExtensionLinkClicked(const string16& extension_id) OVERRIDE;
468 virtual void OnMoreSuggestionsLinkClicked() OVERRIDE; 466 virtual void OnMoreSuggestionsLinkClicked() OVERRIDE;
469 467
470 private: 468 private:
471 // Initialize the contents of the picker. After this call, contents_ will be 469 // Initialize the contents of the picker. After this call, contents_ will be
472 // non-NULL. 470 // non-NULL.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 594
597 void WebIntentPickerViews::OnExtensionIconChanged( 595 void WebIntentPickerViews::OnExtensionIconChanged(
598 WebIntentPickerModel* model, 596 WebIntentPickerModel* model,
599 const string16& extension_id) { 597 const string16& extension_id) {
600 extensions_->Update(); 598 extensions_->Update();
601 contents_->Layout(); 599 contents_->Layout();
602 SizeToContents(); 600 SizeToContents();
603 } 601 }
604 602
605 void WebIntentPickerViews::OnInlineDisposition( 603 void WebIntentPickerViews::OnInlineDisposition(
606 WebIntentPickerModel* model) { 604 WebIntentPickerModel* model, const GURL& url) {
607 const WebIntentPickerModel::InstalledService& installed_service =
608 model->GetInstalledServiceAt(model->inline_disposition_index());
609
610 WebContents* web_contents = WebContents::Create( 605 WebContents* web_contents = WebContents::Create(
611 browser_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); 606 browser_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
612 inline_disposition_delegate_.reset(new WebIntentInlineDispositionDelegate); 607 inline_disposition_delegate_.reset(new WebIntentInlineDispositionDelegate);
613 web_contents->SetDelegate(inline_disposition_delegate_.get()); 608 web_contents->SetDelegate(inline_disposition_delegate_.get());
614 609
615 // Must call this immediately after WebContents creation to avoid race 610 // Must call this immediately after WebContents creation to avoid race
616 // with load. 611 // with load.
617 delegate_->OnInlineDispositionWebContentsCreated(web_contents); 612 delegate_->OnInlineDispositionWebContentsCreated(web_contents);
618 613
619 TabContentsContainer* tab_contents_container = new TabContentsContainer; 614 TabContentsContainer* tab_contents_container = new TabContentsContainer;
620 615
621 web_contents->GetController().LoadURL( 616 web_contents->GetController().LoadURL(
622 installed_service.url, 617 url,
623 content::Referrer(), 618 content::Referrer(),
624 content::PAGE_TRANSITION_START_PAGE, 619 content::PAGE_TRANSITION_START_PAGE,
625 std::string()); 620 std::string());
626 621
627 // Replace the picker with the inline disposition. 622 // Replace the picker with the inline disposition.
628 contents_->RemoveAllChildViews(true); 623 contents_->RemoveAllChildViews(true);
629 contents_->AddChildView(tab_contents_container); 624 contents_->AddChildView(tab_contents_container);
630 625
631 // The contents can only be changed after the child is added to view 626 // The contents can only be changed after the child is added to view
632 // hierarchy. 627 // hierarchy.
633 tab_contents_container->ChangeWebContents(web_contents); 628 tab_contents_container->ChangeWebContents(web_contents);
634 629
635 gfx::Size size = GetDefaultInlineDispositionSize(web_contents); 630 gfx::Size size = GetDefaultInlineDispositionSize(web_contents);
636 contents_->SetLayoutManager(new views::FillLayout); 631 contents_->SetLayoutManager(new views::FillLayout);
637 contents_->Layout(); 632 contents_->Layout();
638 SizeToContents(); 633 SizeToContents();
639 } 634 }
640 635
641 void WebIntentPickerViews::OnServiceButtonClicked( 636 void WebIntentPickerViews::OnServiceButtonClicked(
642 size_t index,
643 const WebIntentPickerModel::InstalledService& service) { 637 const WebIntentPickerModel::InstalledService& service) {
644 delegate_->OnServiceChosen(index, service.disposition); 638 delegate_->OnServiceChosen(service.url, service.disposition);
645 } 639 }
646 640
647 void WebIntentPickerViews::OnExtensionInstallClicked( 641 void WebIntentPickerViews::OnExtensionInstallClicked(
648 const string16& extension_id) { 642 const string16& extension_id) {
649 // TODO(binji): install extension. 643 // TODO(binji): install extension.
650 } 644 }
651 645
652 void WebIntentPickerViews::OnExtensionLinkClicked( 646 void WebIntentPickerViews::OnExtensionLinkClicked(
653 const string16& extension_id) { 647 const string16& extension_id) {
654 GURL extension_url(extension_urls::GetWebstoreItemDetailURLPrefix() + 648 GURL extension_url(extension_urls::GetWebstoreItemDetailURLPrefix() +
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } 731 }
738 732
739 void WebIntentPickerViews::SizeToContents() { 733 void WebIntentPickerViews::SizeToContents() {
740 gfx::Size client_size = contents_->GetPreferredSize(); 734 gfx::Size client_size = contents_->GetPreferredSize();
741 gfx::Rect client_bounds(client_size); 735 gfx::Rect client_bounds(client_size);
742 gfx::Rect new_window_bounds = window_->non_client_view()->frame_view()-> 736 gfx::Rect new_window_bounds = window_->non_client_view()->frame_view()->
743 GetWindowBoundsForClientBounds(client_bounds); 737 GetWindowBoundsForClientBounds(client_bounds);
744 // TODO(binji): figure out how to get the constrained dialog centered... 738 // TODO(binji): figure out how to get the constrained dialog centered...
745 window_->SetSize(new_window_bounds.size()); 739 window_->SetSize(new_window_bounds.size());
746 } 740 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/intents/web_intent_picker_model_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698