OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <map> |
| 10 |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/string16.h" |
| 13 #include "chrome/browser/media_gallery/media_galleries_preferences.h" |
| 14 #include "ui/base/dialogs/select_file_dialog.h" |
| 15 #include "ui/gfx/native_widget_types.h" |
| 16 |
| 17 namespace extensions { |
| 18 class Extension; |
| 19 } |
| 20 |
| 21 class TabContents; |
| 22 |
| 23 namespace chrome { |
| 24 |
| 25 class MediaGalleriesDialogController; |
| 26 |
| 27 // The view. |
| 28 class MediaGalleriesDialog { |
| 29 public: |
| 30 // Updates the checkbox state for |gallery|. |gallery| is owned by the |
| 31 // controller and is guaranteed to live longer than the dialog. If the |
| 32 // checkbox doesn't already exist, it should be created. |
| 33 virtual void UpdateGallery(const MediaGalleryPrefInfo* gallery, |
| 34 bool permitted) = 0; |
| 35 |
| 36 // Constructs a platform-specific dialog owned and controlled by |controller|. |
| 37 static MediaGalleriesDialog* Create( |
| 38 MediaGalleriesDialogController* controller); |
| 39 }; |
| 40 |
| 41 // The controller is responsible for handling the logic of the dialog and |
| 42 // interfacing with the model (i.e., MediaGalleriesPreferences). It shows |
| 43 // the dialog and owns itself. |
| 44 class MediaGalleriesDialogController : public ui::SelectFileDialog::Listener { |
| 45 public: |
| 46 // A fancy pair. |
| 47 struct GalleryPermission { |
| 48 GalleryPermission(const MediaGalleryPrefInfo& pref_info, bool allowed) |
| 49 : pref_info(pref_info), allowed(allowed) {} |
| 50 GalleryPermission() {} |
| 51 |
| 52 MediaGalleryPrefInfo pref_info; |
| 53 bool allowed; |
| 54 }; |
| 55 |
| 56 // This type keeps track of media galleries already known to the prefs system. |
| 57 typedef std::map<MediaGalleryPrefId, GalleryPermission> |
| 58 KnownGalleryPermissions; |
| 59 |
| 60 // The constructor creates a dialog controller which owns itself. |
| 61 MediaGalleriesDialogController(TabContents* tab_contents, |
| 62 const extensions::Extension& extension, |
| 63 const base::Callback<void(void)>& on_finish); |
| 64 |
| 65 // Called by the view. |
| 66 string16 GetHeader(); |
| 67 string16 GetSubtext(); |
| 68 void OnAddFolderClicked(); |
| 69 void GalleryToggled(const MediaGalleryPrefInfo* pref_info, bool enabled); |
| 70 void DialogFinished(bool accepted); |
| 71 |
| 72 // SelectFileDialog::Listener implementation: |
| 73 virtual void FileSelected(const FilePath& path, |
| 74 int index, |
| 75 void* params) OVERRIDE; |
| 76 const KnownGalleryPermissions& permissions() const { |
| 77 return known_galleries_; |
| 78 } |
| 79 |
| 80 TabContents* tab_contents() const { |
| 81 return tab_contents_; |
| 82 } |
| 83 |
| 84 private: |
| 85 // This type is for media galleries that have been added via "add gallery" |
| 86 // button, but have not yet been committed to the prefs system and will be |
| 87 // forgotten if the user Cancels. Since they don't have IDs assigned yet, it's |
| 88 // just a list and not a map. |
| 89 typedef std::list<GalleryPermission> NewGalleryPermissions; |
| 90 |
| 91 virtual ~MediaGalleriesDialogController(); |
| 92 |
| 93 // Populates |known_galleries_|. |
| 94 void LookUpPermissions(); |
| 95 |
| 96 // Saves state of |known_galleries_| and |new_galleries_| to model. |
| 97 void SavePermissions(); |
| 98 |
| 99 // The tab contents from which the request originated. |
| 100 TabContents* tab_contents_; |
| 101 |
| 102 // This is just a reference, but it's assumed that it won't become invalid |
| 103 // while the dialog is showing. |
| 104 const extensions::Extension& extension_; |
| 105 |
| 106 // This map excludes those galleries which have been blacklisted; it only |
| 107 // counts active known galleries. |
| 108 KnownGalleryPermissions known_galleries_; |
| 109 NewGalleryPermissions new_galleries_; |
| 110 |
| 111 // We run this callback when done. |
| 112 const base::Callback<void(void)>& on_finish_; |
| 113 |
| 114 // The model that tracks galleries and extensions' permissions. |
| 115 MediaGalleriesPreferences* preferences_; |
| 116 |
| 117 // The view that's showing. |
| 118 scoped_ptr<MediaGalleriesDialog> dialog_; |
| 119 |
| 120 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_; |
| 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogController); |
| 123 }; |
| 124 |
| 125 } // namespace chrome |
| 126 |
| 127 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
OLD | NEW |