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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
// 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_MEDIA_GALLERIES_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_
#define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_
#include <list>
#include <map>
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "chrome/browser/media_galleries/media_galleries_preferences.h"
#include "chrome/browser/storage_monitor/removable_storage_observer.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/shell_dialogs/select_file_dialog.h"
namespace content {
class WebContents;
}
namespace extensions {
class Extension;
}
namespace ui {
class MenuModel;
}
class GalleryContextMenuModel;
class MediaGalleriesDialogController;
class Profile;
// The view.
class MediaGalleriesDialog {
public:
virtual ~MediaGalleriesDialog();
// Tell the dialog to update its display list of galleries.
virtual void UpdateGalleries() = 0;
// Constructs a platform-specific dialog owned and controlled by |controller|.
static MediaGalleriesDialog* Create(
MediaGalleriesDialogController* controller);
};
// The controller is responsible for handling the logic of the dialog and
// interfacing with the model (i.e., MediaGalleriesPreferences). It shows
// the dialog and owns itself.
class MediaGalleriesDialogController
: public ui::SelectFileDialog::Listener,
public RemovableStorageObserver,
public MediaGalleriesPreferences::GalleryChangeObserver {
public:
struct GalleryPermission {
GalleryPermission(const MediaGalleryPrefInfo& pref_info, bool allowed)
: pref_info(pref_info), allowed(allowed) {}
GalleryPermission() {}
MediaGalleryPrefInfo pref_info;
bool allowed;
};
typedef std::vector<GalleryPermission> GalleryPermissionsVector;
// The constructor creates a dialog controller which owns itself.
MediaGalleriesDialogController(content::WebContents* web_contents,
const extensions::Extension& extension,
const base::Closure& on_finish);
// The title of the dialog view.
string16 GetHeader() const;
// Explanatory text directly below the title.
string16 GetSubtext() const;
// Header for unattached devices part of the dialog.
string16 GetUnattachedLocationsHeader() const;
// Initial state of whether the dialog's confirmation button will be enabled.
bool HasPermittedGalleries() const;
// Get the set of permissions to attached galleries.
virtual GalleryPermissionsVector AttachedPermissions() const;
// Get the set of permissions to unattached galleries.
virtual GalleryPermissionsVector UnattachedPermissions() const;
// Called when the add-folder button in the dialog is clicked.
virtual void OnAddFolderClicked();
// A checkbox beside a gallery permission was checked. The full set
// of gallery permissions checkbox settings is sent on every checkbox toggle.
virtual void DidToggleGalleryId(MediaGalleryPrefId pref_id,
bool enabled);
virtual void DidToggleNewGallery(const MediaGalleryPrefInfo& gallery,
bool enabled);
// The forget command in the context menu was selected.
virtual void DidForgetGallery(MediaGalleryPrefId pref_id);
// The dialog is being deleted.
virtual void DialogFinished(bool accepted);
virtual content::WebContents* web_contents();
ui::MenuModel* GetContextMenuModel(MediaGalleryPrefId id);
protected:
// For use with tests.
explicit MediaGalleriesDialogController(
const extensions::Extension& extension);
virtual ~MediaGalleriesDialogController();
private:
// This type keeps track of media galleries already known to the prefs system.
typedef std::map<MediaGalleryPrefId, GalleryPermission>
KnownGalleryPermissions;
// Bottom half of constructor -- called when |preferences_| is initialized.
void OnPreferencesInitialized();
// SelectFileDialog::Listener implementation:
virtual void FileSelected(const base::FilePath& path,
int index,
void* params) OVERRIDE;
// RemovableStorageObserver implementation.
// Used to keep dialog in sync with removable device status.
virtual void OnRemovableStorageAttached(const StorageInfo& info) OVERRIDE;
virtual void OnRemovableStorageDetached(const StorageInfo& info) OVERRIDE;
// MediaGalleriesPreferences::GalleryChangeObserver implementations.
// Used to keep the dialog in sync when the preferences change.
virtual void OnPermissionAdded(MediaGalleriesPreferences* pref,
const std::string& extension_id,
MediaGalleryPrefId pref_id) OVERRIDE;
virtual void OnPermissionRemoved(MediaGalleriesPreferences* pref,
const std::string& extension_id,
MediaGalleryPrefId pref_id) OVERRIDE;
virtual void OnGalleryAdded(MediaGalleriesPreferences* pref,
MediaGalleryPrefId pref_id) OVERRIDE;
virtual void OnGalleryRemoved(MediaGalleriesPreferences* pref,
MediaGalleryPrefId pref_id) OVERRIDE;
virtual void OnGalleryInfoUpdated(MediaGalleriesPreferences* pref,
MediaGalleryPrefId pref_id) OVERRIDE;
// Populates |known_galleries_| from |preferences_|. Subsequent calls merge
// into |known_galleries_| and do not change permissions for user toggled
// galleries.
void InitializePermissions();
// Saves state of |known_galleries_| and |new_galleries_| to model.
void SavePermissions();
// Updates the model and view when |preferences_| changes. Some of the
// possible changes includes a gallery getting blacklisted, or a new
// auto detected gallery becoming available.
void UpdateGalleriesOnPreferencesEvent();
// Updates the model and view when a device is attached or detached.
void UpdateGalleriesOnDeviceEvent(const std::string& device_id);
// Fill |permissions| with a sorted list of either attached or unattached
// gallery permissions.
void FillPermissions(bool attached,
GalleryPermissionsVector* permissions) const;
Profile* GetProfile();
// The web contents from which the request originated.
content::WebContents* web_contents_;
// This is just a reference, but it's assumed that it won't become invalid
// while the dialog is showing.
const extensions::Extension* extension_;
// This map excludes those galleries which have been blacklisted; it only
// counts active known galleries.
KnownGalleryPermissions known_galleries_;
// Galleries in |known_galleries_| that the user have toggled.
MediaGalleryPrefIdSet toggled_galleries_;
// Map of new galleries the user added, but have not saved. This list should
// never overlap with |known_galleries_|.
GalleryPermissionsVector new_galleries_;
// Callback to run when the dialog closes.
base::Closure on_finish_;
// The model that tracks galleries and extensions' permissions.
// This is the authoritative source for gallery information.
MediaGalleriesPreferences* preferences_;
// The view that's showing.
scoped_ptr<MediaGalleriesDialog> dialog_;
scoped_refptr<ui::SelectFileDialog> select_folder_dialog_;
scoped_ptr<ui::MenuModel> context_menu_model_;
scoped_ptr<GalleryContextMenuModel> gallery_menu_model_;
DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogController);
};
#endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_
|