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

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

Issue 9763001: [Web Intents] Inline installation of extensions in web intents picker. (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
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 #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/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
14 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "chrome/browser/extensions/webstore_installer.h"
15 #include "chrome/browser/favicon/favicon_service.h" 17 #include "chrome/browser/favicon/favicon_service.h"
16 #include "chrome/browser/intents/web_intents_registry.h" 18 #include "chrome/browser/intents/web_intents_registry.h"
17 #include "chrome/browser/intents/cws_intents_registry.h" 19 #include "chrome/browser/intents/cws_intents_registry.h"
18 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" 20 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h"
19 #include "content/public/browser/notification_observer.h" 21 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
21 #include "webkit/glue/web_intent_data.h" 23 #include "webkit/glue/web_intent_data.h"
22 #include "webkit/glue/web_intent_reply_data.h" 24 #include "webkit/glue/web_intent_reply_data.h"
23 25
24 class Browser; 26 class Browser;
25 struct DefaultWebIntentService; 27 struct DefaultWebIntentService;
26 class GURL; 28 class GURL;
27 class TabContentsWrapper; 29 class TabContentsWrapper;
28 class WebIntentPicker; 30 class WebIntentPicker;
29 class WebIntentPickerModel; 31 class WebIntentPickerModel;
32 class WebstoreInstaller;
30 33
31 namespace content { 34 namespace content {
32 class WebContents; 35 class WebContents;
33 class WebIntentsDispatcher; 36 class WebIntentsDispatcher;
34 } 37 }
35 38
36 namespace webkit_glue { 39 namespace webkit_glue {
37 struct WebIntentServiceData; 40 struct WebIntentServiceData;
38 } 41 }
39 42
40 // Controls the creation of the WebIntentPicker UI and forwards the user's 43 // Controls the creation of the WebIntentPicker UI and forwards the user's
41 // intent handler choice back to the TabContents object. 44 // intent handler choice back to the TabContents object.
42 class WebIntentPickerController : public content::NotificationObserver, 45 class WebIntentPickerController : public content::NotificationObserver,
43 public WebIntentPickerDelegate, 46 public WebIntentPickerDelegate,
44 public WebIntentsRegistry::Consumer { 47 public WebstoreInstaller::Delegate {
45 public: 48 public:
46 // Takes ownership of |factory|. 49 // Takes ownership of |factory|.
47 explicit WebIntentPickerController(TabContentsWrapper* wrapper); 50 explicit WebIntentPickerController(TabContentsWrapper* wrapper);
48 virtual ~WebIntentPickerController(); 51 virtual ~WebIntentPickerController();
49 52
50 // Sets the intent data and return pathway handler object for which 53 // Sets the intent data and return pathway handler object for which
51 // this picker was created. The picker takes ownership of 54 // this picker was created. The picker takes ownership of
52 // |intents_dispatcher|. |intents_dispatcher| must not be NULL. 55 // |intents_dispatcher|. |intents_dispatcher| must not be NULL.
53 void SetIntentsDispatcher(content::WebIntentsDispatcher* intents_dispatcher); 56 void SetIntentsDispatcher(content::WebIntentsDispatcher* intents_dispatcher);
54 57
55 // Shows the web intent picker for |browser|, given the intent 58 // Shows the web intent picker for |browser|, given the intent
56 // |action| and MIME-type |type|. 59 // |action| and MIME-type |type|.
57 void ShowDialog(Browser* browser, 60 void ShowDialog(Browser* browser,
58 const string16& action, 61 const string16& action,
59 const string16& type); 62 const string16& type);
60 63
61 protected: 64 protected:
62 // content::NotificationObserver implementation. 65 // content::NotificationObserver implementation.
63 virtual void Observe(int type, 66 virtual void Observe(int type,
64 const content::NotificationSource& source, 67 const content::NotificationSource& source,
65 const content::NotificationDetails& details) OVERRIDE; 68 const content::NotificationDetails& details) OVERRIDE;
66 69
67 // WebIntentPickerDelegate implementation. 70 // WebIntentPickerDelegate implementation.
68 virtual void OnServiceChosen(const GURL& url, 71 virtual void OnServiceChosen(const GURL& url,
69 Disposition disposition) OVERRIDE; 72 Disposition disposition) OVERRIDE;
70 virtual void OnInlineDispositionWebContentsCreated( 73 virtual void OnInlineDispositionWebContentsCreated(
71 content::WebContents* web_contents) OVERRIDE; 74 content::WebContents* web_contents) OVERRIDE;
75 virtual void OnExtensionInstallRequested(const std::string& id) OVERRIDE;
72 virtual void OnCancelled() OVERRIDE; 76 virtual void OnCancelled() OVERRIDE;
73 virtual void OnClosing() OVERRIDE; 77 virtual void OnClosing() OVERRIDE;
74 78
79 // WebstoreInstaller::Delegate implementation.
80 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
81 virtual void OnExtensionInstallFailure(const std::string& id,
82 const std::string& error) OVERRIDE;
83
75 private: 84 private:
76 friend class WebIntentPickerControllerTest; 85 friend class WebIntentPickerControllerTest;
77 friend class WebIntentPickerControllerBrowserTest; 86 friend class WebIntentPickerControllerBrowserTest;
78 friend class InvokingTabObserver; 87 friend class InvokingTabObserver;
79 88
80 // Gets a notification when the return message is sent to the source tab, 89 // Gets a notification when the return message is sent to the source tab,
81 // so we can close the picker dialog or service tab. 90 // so we can close the picker dialog or service tab.
82 void OnSendReturnMessage(webkit_glue::WebIntentReplyType reply_type); 91 void OnSendReturnMessage(webkit_glue::WebIntentReplyType reply_type);
83 92
84 // Exposed for tests only. 93 // Exposed for tests only.
85 void set_picker(WebIntentPicker* picker) { picker_ = picker; } 94 void set_picker(WebIntentPicker* picker) { picker_ = picker; }
86 95
87 // Exposed for tests only. 96 // Exposed for tests only.
88 void set_model_observer(WebIntentPickerModelObserver* observer) { 97 void set_model_observer(WebIntentPickerModelObserver* observer) {
89 picker_model_->set_observer(observer); 98 picker_model_->set_observer(observer);
90 } 99 }
91 100
92 // Called when WebIntentServiceData is returned from the WebIntentsRegistry. 101 // Called when WebIntentServiceData is returned from the WebIntentsRegistry.
93 virtual void OnIntentsQueryDone( 102 void OnWebIntentServicesAvailable(
94 WebIntentsRegistry::QueryID, 103 const std::vector<webkit_glue::WebIntentServiceData>& services);
95 const std::vector<webkit_glue::WebIntentServiceData>& services) OVERRIDE;
96
97 // Called when the WebIntentsRegistry returns responses to a defaults request.
98 virtual void OnIntentsDefaultsQueryDone(
99 WebIntentsRegistry::QueryID,
100 const DefaultWebIntentService& default_service) OVERRIDE;
101 104
102 // Called when FaviconData is returned from the FaviconService. 105 // Called when FaviconData is returned from the FaviconService.
103 void OnFaviconDataAvailable(FaviconService::Handle handle, 106 void OnFaviconDataAvailable(FaviconService::Handle handle,
104 history::FaviconData favicon_data); 107 history::FaviconData favicon_data);
105 108
106 // Called when IntentExtensionInfo is returned from the CWSIntentsRegistry. 109 // Called when IntentExtensionInfo is returned from the CWSIntentsRegistry.
107 void OnCWSIntentServicesAvailable( 110 void OnCWSIntentServicesAvailable(
108 const CWSIntentsRegistry::IntentExtensionList& extensions); 111 const CWSIntentsRegistry::IntentExtensionList& extensions);
109 112
110 // Called when a suggested extension's icon is fetched. 113 // Called when a suggested extension's icon is fetched.
111 void OnExtensionIconURLFetchComplete(const string16& extension_id, 114 void OnExtensionIconURLFetchComplete(const string16& extension_id,
112 const content::URLFetcher* source); 115 const content::URLFetcher* source);
113 116
114 typedef base::Callback<void(const gfx::Image&)> 117 typedef base::Callback<void(const gfx::Image&)>
115 ExtensionIconAvailableCallback; 118 ExtensionIconAvailableCallback;
116 // Called on a worker thread to decode and resize the extension's icon. 119 // Called on a worker thread to decode and resize the extension's icon.
117 static void DecodeExtensionIconAndResize( 120 static void DecodeExtensionIconAndResize(
118 scoped_ptr<std::string> icon_response, 121 scoped_ptr<std::string> icon_response,
119 const ExtensionIconAvailableCallback& callback, 122 const ExtensionIconAvailableCallback& callback,
120 const base::Closure& unavailable_callback); 123 const base::Closure& unavailable_callback);
121 124
122 // Called when an extension's icon is successfully decoded and resized. 125 // Called when an extension's icon is successfully decoded and resized.
123 void OnExtensionIconAvailable(const string16& extension_id, 126 void OnExtensionIconAvailable(const string16& extension_id,
124 const gfx::Image& icon_image); 127 const gfx::Image& icon_image);
125 128
126 // Called when an extension's icon failed to be decoded or resized. 129 // Called when an extension's icon failed to be decoded or resized.
127 void OnExtensionIconUnavailable(const string16& extension_id); 130 void OnExtensionIconUnavailable(const string16& extension_id);
128 131
132 // When an extension is installed, all that is known is the extension id.
133 // This callback receives the intent service data for that extension.
134 // |services| must be a non-empty list.
135 void OnExtensionInstallServiceAvailable(
136 const std::vector<webkit_glue::WebIntentServiceData>& services);
137
129 // Decrements the |pending_async_count_| and notifies the picker if it 138 // Decrements the |pending_async_count_| and notifies the picker if it
130 // reaches zero. 139 // reaches zero.
131 void AsyncOperationFinished(); 140 void AsyncOperationFinished();
132 141
133 // Closes the currently active picker. 142 // Closes the currently active picker.
134 void ClosePicker(); 143 void ClosePicker();
135 144
136 // A weak pointer to the tab contents that the picker is displayed on. 145 // A weak pointer to the tab contents that the picker is displayed on.
137 TabContentsWrapper* wrapper_; 146 TabContentsWrapper* wrapper_;
138 147
(...skipping 21 matching lines...) Expand all
160 // client page. 169 // client page.
161 content::WebIntentsDispatcher* intents_dispatcher_; 170 content::WebIntentsDispatcher* intents_dispatcher_;
162 171
163 // Weak pointer to the tab servicing the intent. Remembered in order to 172 // Weak pointer to the tab servicing the intent. Remembered in order to
164 // close it when a reply is sent. 173 // close it when a reply is sent.
165 content::WebContents* service_tab_; 174 content::WebContents* service_tab_;
166 175
167 // Request consumer used when asynchronously loading favicons. 176 // Request consumer used when asynchronously loading favicons.
168 CancelableRequestConsumerTSimple<size_t> favicon_consumer_; 177 CancelableRequestConsumerTSimple<size_t> favicon_consumer_;
169 178
179 // Used to install extensions from the Chrome Web Store.
180 scoped_refptr<WebstoreInstaller> webstore_installer_;
181
170 base::WeakPtrFactory<WebIntentPickerController> weak_ptr_factory_; 182 base::WeakPtrFactory<WebIntentPickerController> weak_ptr_factory_;
171 183
172 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerController); 184 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerController);
173 }; 185 };
174 186
175 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_ 187 #endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/intents/web_intent_picker.h ('k') | chrome/browser/ui/intents/web_intent_picker_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698