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

Side by Side Diff: chrome/browser/ui/intents/web_intent_picker_controller.h

Issue 9148032: [Web Intents] Refactor picker to use WebIntentPickerModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: vertical layout for views 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
groby-ooo-7-16 2012/01/25 22:03:13 2011-2012
binji 2012/01/26 00:27:41 I don't see any examples of this in chrome.
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 #ifndef CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/string16.h" 13 #include "base/string16.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 "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
17 #include "webkit/glue/web_intent_data.h" 17 #include "webkit/glue/web_intent_data.h"
18 18
19 class Browser; 19 class Browser;
20 class GURL; 20 class GURL;
21 class SkBitmap; 21 class TabContents;
22 class TabContentsWrapper; 22 class TabContentsWrapper;
23 class WebIntentPicker; 23 class WebIntentPicker;
24 class WebIntentPickerFactory; 24 class WebIntentPickerModel;
25 25
26 namespace content { 26 namespace content {
27 class WebContents; 27 class WebContents;
28 class WebIntentsDispatcher; 28 class WebIntentsDispatcher;
29 } 29 }
30 30
31 namespace gfx {
32 class Image;
33 }
34
31 namespace webkit_glue { 35 namespace webkit_glue {
32 struct WebIntentServiceData; 36 struct WebIntentServiceData;
33 } 37 }
34 38
35 // Controls the creation of the WebIntentPicker UI and forwards the user's 39 // Controls the creation of the WebIntentPicker UI and forwards the user's
36 // intent handler choice back to the TabContents object. 40 // intent handler choice back to the TabContents object.
37 class WebIntentPickerController : public content::NotificationObserver, 41 class WebIntentPickerController : public content::NotificationObserver,
38 public WebIntentPickerDelegate { 42 public WebIntentPickerDelegate {
39 public: 43 public:
40 // Takes ownership of |factory|. 44 // Takes ownership of |factory|.
41 WebIntentPickerController(TabContentsWrapper* wrapper, 45 explicit WebIntentPickerController(TabContentsWrapper* wrapper);
42 WebIntentPickerFactory* factory);
43 virtual ~WebIntentPickerController(); 46 virtual ~WebIntentPickerController();
44 47
45 // Sets the intent data and return pathway handler object for which 48 // Sets the intent data and return pathway handler object for which
46 // this picker was created. The picker takes ownership of 49 // this picker was created. The picker takes ownership of
47 // |intents_dispatcher|. |intents_dispatcher| must not be NULL. 50 // |intents_dispatcher|. |intents_dispatcher| must not be NULL.
48 void SetIntentsDispatcher(content::WebIntentsDispatcher* intents_dispatcher); 51 void SetIntentsDispatcher(content::WebIntentsDispatcher* intents_dispatcher);
49 52
50 // Shows the web intent picker for |browser|, given the intent 53 // Shows the web intent picker for |browser|, given the intent
51 // |action| and MIME-type |type|. 54 // |action| and MIME-type |type|.
52 void ShowDialog(Browser* browser, 55 void ShowDialog(Browser* browser,
53 const string16& action, 56 const string16& action,
54 const string16& type); 57 const string16& type);
55 58
56 protected: 59 protected:
57 // content::NotificationObserver implementation. 60 // content::NotificationObserver implementation.
58 virtual void Observe(int type, 61 virtual void Observe(int type,
59 const content::NotificationSource& source, 62 const content::NotificationSource& source,
60 const content::NotificationDetails& details) OVERRIDE; 63 const content::NotificationDetails& details) OVERRIDE;
61 64
62 // WebIntentPickerDelegate implementation. 65 // WebIntentPickerDelegate implementation.
63 virtual void OnServiceChosen(size_t index) OVERRIDE; 66 virtual void OnServiceChosen(size_t index, Disposition disposition) OVERRIDE;
67 virtual void OnInlineDispositionWebContentsCreated(
68 content::WebContents* web_contents) OVERRIDE;
64 virtual void OnCancelled() OVERRIDE; 69 virtual void OnCancelled() OVERRIDE;
65 virtual void OnClosing() OVERRIDE; 70 virtual void OnClosing() OVERRIDE;
66 71
67 private: 72 private:
68 // Gets a notification when the return message is sent to the source tab,
69 // so we can close the picker dialog or service tab.
70 void OnSendReturnMessage();
71
72 friend class WebIntentPickerControllerTest;
73 friend class WebIntentPickerControllerBrowserTest; 73 friend class WebIntentPickerControllerBrowserTest;
74 friend class InvokingTabObserver; 74 friend class InvokingTabObserver;
75 class WebIntentDataFetcher; 75 class WebIntentDataFetcher;
76 class FaviconFetcher; 76 class FaviconFetcher;
77 77
78 // Gets a notification when the return message is sent to the source tab,
79 // so we can close the picker dialog or service tab.
80 void OnSendReturnMessage();
81
82 // Exposed for tests only.
83 void set_picker(WebIntentPicker* picker) { picker_ = picker; }
groby-ooo-7-16 2012/01/25 22:03:13 Why add methods? Tests are friends of ours, so the
binji 2012/01/26 00:27:41 True, though I thought it was a little clearer her
84
85 // Exposed for tests only.
86 void set_model_observer(WebIntentPickerModelObserver* observer) {
87 picker_model_->set_observer(observer);
88 }
89
90 // Exposed for tests only.
78 int pending_async_count() const { return pending_async_count_; } 91 int pending_async_count() const { return pending_async_count_; }
79 92
80 // Called from the WebIntentDataFetcher when intent data is available. 93 // Called from the WebIntentDataFetcher when intent data is available.
81 void OnWebIntentDataAvailable( 94 void OnWebIntentDataAvailable(
82 const std::vector<webkit_glue::WebIntentServiceData>& services); 95 const std::vector<webkit_glue::WebIntentServiceData>& services);
83 96
84 // Called from the FaviconDataFetcher when a favicon is available. 97 // Called from the FaviconDataFetcher when a favicon is available.
85 void OnFaviconDataAvailable(size_t index, const SkBitmap& icon_bitmap); 98 void OnFaviconDataAvailable(size_t index, const gfx::Image& icon);
86 99
87 // Called from the FaviconDataFetcher when a favicon is not available. 100 // Called from the FaviconDataFetcher when a favicon is not available.
88 void OnFaviconDataUnavailable(size_t index); 101 void OnFaviconDataUnavailable(size_t index);
89 102
90 // Closes the currently active picker. 103 // Closes the currently active picker.
91 void ClosePicker(); 104 void ClosePicker();
92 105
93 // A weak pointer to the tab contents that the picker is displayed on. 106 // A weak pointer to the tab contents that the picker is displayed on.
94 TabContentsWrapper* wrapper_; 107 TabContentsWrapper* wrapper_;
95 108
96 // A notification registrar, listening for notifications when the tab closes 109 // A notification registrar, listening for notifications when the tab closes
97 // to close the picker ui. 110 // to close the picker ui.
98 content::NotificationRegistrar registrar_; 111 content::NotificationRegistrar registrar_;
99 112
100 // A factory to create a new picker.
101 scoped_ptr<WebIntentPickerFactory> picker_factory_;
102
103 // A helper class to fetch web intent data asynchronously. 113 // A helper class to fetch web intent data asynchronously.
104 scoped_ptr<WebIntentDataFetcher> web_intent_data_fetcher_; 114 scoped_ptr<WebIntentDataFetcher> web_intent_data_fetcher_;
105 115
106 // A helper class to fetch favicon data asynchronously. 116 // A helper class to fetch favicon data asynchronously.
107 scoped_ptr<FaviconFetcher> favicon_fetcher_; 117 scoped_ptr<FaviconFetcher> favicon_fetcher_;
108 118
109 // A weak pointer to the picker this controller controls. 119 // A weak pointer to the picker this controller controls.
110 WebIntentPicker* picker_; 120 WebIntentPicker* picker_;
111 121
112 // A list of URLs to display in the UI. 122 // The model for the picker. Owned by this controller. It should not be NULL
113 std::vector<GURL> urls_; 123 // while this controller exists, even if the picker is not shown.
114 124 scoped_ptr<WebIntentPickerModel> picker_model_;
115 // A list of the service data on display in the UI.
116 std::vector<webkit_glue::WebIntentServiceData> service_data_;
117 125
118 // A count of the outstanding asynchronous calls. 126 // A count of the outstanding asynchronous calls.
119 int pending_async_count_; 127 int pending_async_count_;
120 128
129 // Is true if the picker is currently visible.
130 bool picker_shown_;
groby-ooo-7-16 2012/01/25 22:03:13 I might be wrong, but as far as I can tell, this i
binji 2012/01/26 00:27:41 I suppose it is a little tricky. The picker can be
131
121 // The routing object for the renderer which launched the intent. 132 // The routing object for the renderer which launched the intent.
122 // Contains the intent data and a way to signal back to the client page. 133 // Contains the intent data and a way to signal back to the client page.
123 scoped_ptr<content::WebIntentsDispatcher> intents_dispatcher_; 134 scoped_ptr<content::WebIntentsDispatcher> intents_dispatcher_;
124 135
125 // Weak pointer to the tab servicing the intent. Remembered in order to 136 // Weak pointer to the tab servicing the intent. Remembered in order to
126 // close it when a reply is sent. 137 // close it when a reply is sent.
127 content::WebContents* service_tab_; 138 content::WebContents* service_tab_;
128 139
129 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerController); 140 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerController);
130 }; 141 };
131 142
132 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ 143 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698