1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_
#define CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_
#pragma once
#include <vector>
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/string16.h"
#include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/intents/web_intents_registry.h"
#include "chrome/browser/intents/cws_intents_registry.h"
#include "chrome/browser/ui/intents/web_intent_picker_delegate.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "webkit/glue/web_intent_data.h"
#include "webkit/glue/web_intent_reply_data.h"
class Browser;
struct DefaultWebIntentService;
class GURL;
class TabContentsWrapper;
class WebIntentPicker;
class WebIntentPickerModel;
namespace content {
class WebContents;
class WebIntentsDispatcher;
}
namespace webkit_glue {
struct WebIntentServiceData;
}
// Controls the creation of the WebIntentPicker UI and forwards the user's
// intent handler choice back to the TabContents object.
class WebIntentPickerController : public content::NotificationObserver,
public WebIntentPickerDelegate,
public WebIntentsRegistry::Consumer {
public:
// Takes ownership of |factory|.
explicit WebIntentPickerController(TabContentsWrapper* wrapper);
virtual ~WebIntentPickerController();
// Sets the intent data and return pathway handler object for which
// this picker was created. The picker takes ownership of
// |intents_dispatcher|. |intents_dispatcher| must not be NULL.
void SetIntentsDispatcher(content::WebIntentsDispatcher* intents_dispatcher);
// Shows the web intent picker for |browser|, given the intent
// |action| and MIME-type |type|.
void ShowDialog(Browser* browser,
const string16& action,
const string16& type);
protected:
// content::NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// WebIntentPickerDelegate implementation.
virtual void OnServiceChosen(size_t index, Disposition disposition) OVERRIDE;
virtual void OnInlineDispositionWebContentsCreated(
content::WebContents* web_contents) OVERRIDE;
virtual void OnCancelled() OVERRIDE;
virtual void OnClosing() OVERRIDE;
private:
friend class WebIntentPickerControllerTest;
friend class WebIntentPickerControllerBrowserTest;
friend class InvokingTabObserver;
// Gets a notification when the return message is sent to the source tab,
// so we can close the picker dialog or service tab.
void OnSendReturnMessage(webkit_glue::WebIntentReplyType reply_type);
// Exposed for tests only.
void set_picker(WebIntentPicker* picker) { picker_ = picker; }
// Exposed for tests only.
void set_model_observer(WebIntentPickerModelObserver* observer) {
picker_model_->set_observer(observer);
}
// Called when WebIntentServiceData is returned from the WebIntentsRegistry.
virtual void OnIntentsQueryDone(
WebIntentsRegistry::QueryID,
const std::vector<webkit_glue::WebIntentServiceData>& services) OVERRIDE;
// Called when the WebIntentsRegistry returns responses to a defaults request.
virtual void OnIntentsDefaultsQueryDone(
WebIntentsRegistry::QueryID,
const DefaultWebIntentService& default_service) OVERRIDE;
// Called when FaviconData is returned from the FaviconService.
void OnFaviconDataAvailable(FaviconService::Handle handle,
history::FaviconData favicon_data);
// Called when IntentExtensionInfo is returned from the CWSIntentsRegistry.
void OnCWSIntentServicesAvailable(
const CWSIntentsRegistry::IntentExtensionList& extensions);
// Called when a suggested extension's icon is fetched.
void OnExtensionIconURLFetchComplete(const string16& extension_id,
const content::URLFetcher* source);
typedef base::Callback<void(const gfx::Image&)>
ExtensionIconAvailableCallback;
// Called on a worker thread to decode and resize the extension's icon.
static void DecodeExtensionIconAndResize(
scoped_ptr<std::string> icon_response,
const ExtensionIconAvailableCallback& callback,
const base::Closure& unavailable_callback);
// Called when an extension's icon is successfully decoded and resized.
void OnExtensionIconAvailable(const string16& extension_id,
const gfx::Image& icon_image);
// Called when an extension's icon failed to be decoded or resized.
void OnExtensionIconUnavailable(const string16& extension_id);
// Decrements the |pending_async_count_| and notifies the picker if it
// reaches zero.
void AsyncOperationFinished();
// Closes the currently active picker.
void ClosePicker();
// A weak pointer to the tab contents that the picker is displayed on.
TabContentsWrapper* wrapper_;
// A notification registrar, listening for notifications when the tab closes
// to close the picker ui.
content::NotificationRegistrar registrar_;
// A weak pointer to the picker this controller controls.
WebIntentPicker* picker_;
// The model for the picker. Owned by this controller. It should not be NULL
// while this controller exists, even if the picker is not shown.
scoped_ptr<WebIntentPickerModel> picker_model_;
// A count of the outstanding asynchronous calls.
int pending_async_count_;
// Is true if the picker is currently visible.
// This bool is not equivalent to picker != NULL in a unit test. In that
// case, a picker may be non-NULL before it is shown.
bool picker_shown_;
// Weak pointer to the routing object for the renderer which launched the
// intent. Contains the intent data and a way to signal back to the
// client page.
content::WebIntentsDispatcher* intents_dispatcher_;
// Weak pointer to the tab servicing the intent. Remembered in order to
// close it when a reply is sent.
content::WebContents* service_tab_;
// Request consumer used when asynchronously loading favicons.
CancelableRequestConsumerTSimple<size_t> favicon_consumer_;
base::WeakPtrFactory<WebIntentPickerController> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(WebIntentPickerController);
};
#endif // CHROME_BROWSER_UI_INTENTS_WEB_INTENT_PICKER_CONTROLLER_H_
|