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

Unified Diff: chrome/browser/ui/cocoa/web_intent_picker_cocoa.mm

Issue 9148032: [Web Intents] Refactor picker to use WebIntentPickerModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: groby's fix Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/web_intent_picker_cocoa.h ('k') | chrome/browser/ui/gtk/web_intent_picker_gtk.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/web_intent_picker_cocoa.mm
diff --git a/chrome/browser/ui/cocoa/web_intent_picker_cocoa.mm b/chrome/browser/ui/cocoa/web_intent_picker_cocoa.mm
index 03b5cdff89ec031ce5c7881c1d147f2a75a0bf74..dc0c944553aff9f5ae512a7637e3928446d123d0 100644
--- a/chrome/browser/ui/cocoa/web_intent_picker_cocoa.mm
+++ b/chrome/browser/ui/cocoa/web_intent_picker_cocoa.mm
@@ -17,6 +17,7 @@
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "content/public/browser/web_contents.h"
#include "skia/ext/skia_utils_mac.h"
+#include "ui/gfx/image/image.h"
using content::WebContents;
@@ -42,21 +43,29 @@ class InlineHtmlContentDelegate: public content::WebContentsDelegate {
// static
WebIntentPicker* WebIntentPicker::Create(Browser* browser,
TabContentsWrapper* wrapper,
- WebIntentPickerDelegate* delegate) {
- return new WebIntentPickerCocoa(browser, wrapper, delegate);
+ WebIntentPickerDelegate* delegate,
+ WebIntentPickerModel* model) {
+ return new WebIntentPickerCocoa(browser, wrapper, delegate, model);
}
WebIntentPickerCocoa::WebIntentPickerCocoa()
- : delegate_(NULL), browser_(NULL), controller_(NULL) {
+ : delegate_(NULL),
+ model_(NULL),
+ browser_(NULL),
+ controller_(NULL) {
}
WebIntentPickerCocoa::WebIntentPickerCocoa(Browser* browser,
TabContentsWrapper* wrapper,
- WebIntentPickerDelegate* delegate)
- : delegate_(delegate),
- browser_(browser),
- controller_(NULL) {
+ WebIntentPickerDelegate* delegate,
+ WebIntentPickerModel* model)
+ : delegate_(delegate),
+ model_(model),
+ browser_(browser),
+ controller_(NULL) {
+ model_->set_observer(this);
+
DCHECK(browser);
DCHECK(delegate);
NSWindow* parentWindow = browser->window()->GetNativeHandle();
@@ -74,54 +83,58 @@ WebIntentPickerCocoa::WebIntentPickerCocoa(Browser* browser,
anchoredAt:anchor];
}
-void WebIntentPickerCocoa::SetServiceURLs(const std::vector<GURL>& urls) {
+WebIntentPickerCocoa::~WebIntentPickerCocoa() {
+ if (model_ != NULL)
+ model_->set_observer(NULL);
+}
+
+void WebIntentPickerCocoa::Close() {
+}
+
+void WebIntentPickerCocoa::OnModelChanged(WebIntentPickerModel* model) {
DCHECK(controller_);
scoped_nsobject<NSMutableArray> urlArray(
- [[NSMutableArray alloc] initWithCapacity:urls.size()]);
+ [[NSMutableArray alloc] initWithCapacity:model->GetItemCount()]);
+
+ for (size_t i = 0; i < model->GetItemCount(); ++i) {
+ const WebIntentPickerModel::Item& item = model->GetItemAt(i);
- for (std::vector<GURL>::const_iterator iter(urls.begin());
- iter != urls.end(); ++iter) {
[urlArray addObject:
- [NSString stringWithUTF8String:iter->spec().c_str()]];
+ [NSString stringWithUTF8String:item.url.spec().c_str()]];
+ [controller_ replaceImageAtIndex:i withImage:item.favicon.ToNSImage()];
}
[controller_ setServiceURLs:urlArray];
}
-void WebIntentPickerCocoa::SetServiceIcon(size_t index, const SkBitmap& icon) {
+void WebIntentPickerCocoa::OnFaviconChanged(WebIntentPickerModel* model,
+ size_t index) {
DCHECK(controller_);
- if (icon.empty())
- return;
-
- NSImage* image = gfx::SkBitmapToNSImage(icon);
- [controller_ replaceImageAtIndex:index withImage:image];
-}
-void WebIntentPickerCocoa::SetDefaultServiceIcon(size_t index) {
+ const WebIntentPickerModel::Item& item = model->GetItemAt(index);
+ [controller_ replaceImageAtIndex:index withImage:item.favicon.ToNSImage()];
}
-void WebIntentPickerCocoa::Close() {
-}
+void WebIntentPickerCocoa::OnInlineDisposition(WebIntentPickerModel* model) {
+ const WebIntentPickerModel::Item& item = model->GetItemAt(
+ model->inline_disposition_index());
-WebContents* WebIntentPickerCocoa::SetInlineDisposition(const GURL& url) {
- WebContents* web_contents = WebContents::Create(
+ content::WebContents* web_contents = content::WebContents::Create(
browser_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
inline_disposition_tab_contents_.reset(new TabContentsWrapper(web_contents));
inline_disposition_delegate_.reset(new InlineHtmlContentDelegate);
web_contents->SetDelegate(inline_disposition_delegate_.get());
inline_disposition_tab_contents_->web_contents()->GetController().LoadURL(
- url,
+ item.url,
content::Referrer(),
content::PAGE_TRANSITION_START_PAGE,
std::string());
[controller_ setInlineDispositionTabContents:
inline_disposition_tab_contents_.get()];
- return inline_disposition_tab_contents_->web_contents();
-}
-WebIntentPickerCocoa::~WebIntentPickerCocoa() {
+ delegate_->OnInlineDispositionWebContentsCreated(web_contents);
}
void WebIntentPickerCocoa::OnCancelled() {
@@ -132,7 +145,8 @@ void WebIntentPickerCocoa::OnCancelled() {
void WebIntentPickerCocoa::OnServiceChosen(size_t index) {
DCHECK(delegate_);
- delegate_->OnServiceChosen(index);
+ const WebIntentPickerModel::Item& item = model_->GetItemAt(index);
+ delegate_->OnServiceChosen(index, item.disposition);
}
void WebIntentPickerCocoa::set_controller(
« no previous file with comments | « chrome/browser/ui/cocoa/web_intent_picker_cocoa.h ('k') | chrome/browser/ui/gtk/web_intent_picker_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698