| OLD | NEW |
| 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_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.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/media_gallery/media_galleries_preferences.h" | 14 #include "chrome/browser/media_gallery/media_galleries_preferences.h" |
| 15 #include "ui/base/dialogs/select_file_dialog.h" | 15 #include "ui/base/dialogs/select_file_dialog.h" |
| 16 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
| 17 | 17 |
| 18 namespace content { |
| 19 class WebContents; |
| 20 } |
| 21 |
| 18 namespace extensions { | 22 namespace extensions { |
| 19 class Extension; | 23 class Extension; |
| 20 } | 24 } |
| 21 | 25 |
| 22 class TabContents; | |
| 23 | |
| 24 namespace chrome { | 26 namespace chrome { |
| 25 | 27 |
| 26 class MediaGalleriesDialogController; | 28 class MediaGalleriesDialogController; |
| 27 | 29 |
| 28 // The view. | 30 // The view. |
| 29 class MediaGalleriesDialog { | 31 class MediaGalleriesDialog { |
| 30 public: | 32 public: |
| 31 virtual ~MediaGalleriesDialog(); | 33 virtual ~MediaGalleriesDialog(); |
| 32 | 34 |
| 33 // Updates the checkbox state for |gallery|. |gallery| is owned by the | 35 // Updates the checkbox state for |gallery|. |gallery| is owned by the |
| (...skipping 20 matching lines...) Expand all Loading... |
| 54 | 56 |
| 55 MediaGalleryPrefInfo pref_info; | 57 MediaGalleryPrefInfo pref_info; |
| 56 bool allowed; | 58 bool allowed; |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 // This type keeps track of media galleries already known to the prefs system. | 61 // This type keeps track of media galleries already known to the prefs system. |
| 60 typedef std::map<MediaGalleryPrefId, GalleryPermission> | 62 typedef std::map<MediaGalleryPrefId, GalleryPermission> |
| 61 KnownGalleryPermissions; | 63 KnownGalleryPermissions; |
| 62 | 64 |
| 63 // The constructor creates a dialog controller which owns itself. | 65 // The constructor creates a dialog controller which owns itself. |
| 64 MediaGalleriesDialogController(TabContents* tab_contents, | 66 MediaGalleriesDialogController(content::WebContents* web_contents, |
| 65 const extensions::Extension& extension, | 67 const extensions::Extension& extension, |
| 66 const base::Closure& on_finish); | 68 const base::Closure& on_finish); |
| 67 | 69 |
| 68 // Called by the view. | 70 // Called by the view. |
| 69 virtual string16 GetHeader() const; | 71 virtual string16 GetHeader() const; |
| 70 virtual string16 GetSubtext() const; | 72 virtual string16 GetSubtext() const; |
| 71 virtual bool HasPermittedGalleries() const; | 73 virtual bool HasPermittedGalleries() const; |
| 72 virtual void OnAddFolderClicked(); | 74 virtual void OnAddFolderClicked(); |
| 73 virtual void DidToggleGallery(const MediaGalleryPrefInfo* pref_info, | 75 virtual void DidToggleGallery(const MediaGalleryPrefInfo* pref_info, |
| 74 bool enabled); | 76 bool enabled); |
| 75 virtual void DialogFinished(bool accepted); | 77 virtual void DialogFinished(bool accepted); |
| 76 virtual const KnownGalleryPermissions& permissions() const; | 78 virtual const KnownGalleryPermissions& permissions() const; |
| 77 | 79 |
| 78 // SelectFileDialog::Listener implementation: | 80 // SelectFileDialog::Listener implementation: |
| 79 virtual void FileSelected(const FilePath& path, | 81 virtual void FileSelected(const FilePath& path, |
| 80 int index, | 82 int index, |
| 81 void* params) OVERRIDE; | 83 void* params) OVERRIDE; |
| 82 TabContents* tab_contents() const { | 84 content::WebContents* web_contents() const { |
| 83 return tab_contents_; | 85 return web_contents_; |
| 84 } | 86 } |
| 85 | 87 |
| 86 protected: | 88 protected: |
| 87 // For use with tests. | 89 // For use with tests. |
| 88 MediaGalleriesDialogController(); | 90 MediaGalleriesDialogController(); |
| 89 | 91 |
| 90 virtual ~MediaGalleriesDialogController(); | 92 virtual ~MediaGalleriesDialogController(); |
| 91 | 93 |
| 92 private: | 94 private: |
| 93 // This type is for media galleries that have been added via "add gallery" | 95 // This type is for media galleries that have been added via "add gallery" |
| 94 // button, but have not yet been committed to the prefs system and will be | 96 // button, but have not yet been committed to the prefs system and will be |
| 95 // forgotten if the user Cancels. Since they don't have IDs assigned yet, it's | 97 // forgotten if the user Cancels. Since they don't have IDs assigned yet, it's |
| 96 // just a list and not a map. | 98 // just a list and not a map. |
| 97 typedef std::list<GalleryPermission> NewGalleryPermissions; | 99 typedef std::list<GalleryPermission> NewGalleryPermissions; |
| 98 | 100 |
| 99 // Populates |known_galleries_|. | 101 // Populates |known_galleries_|. |
| 100 void LookUpPermissions(); | 102 void LookUpPermissions(); |
| 101 | 103 |
| 102 // Saves state of |known_galleries_| and |new_galleries_| to model. | 104 // Saves state of |known_galleries_| and |new_galleries_| to model. |
| 103 void SavePermissions(); | 105 void SavePermissions(); |
| 104 | 106 |
| 105 // The tab contents from which the request originated. | 107 // The web contents from which the request originated. |
| 106 TabContents* tab_contents_; | 108 content::WebContents* web_contents_; |
| 107 | 109 |
| 108 // This is just a reference, but it's assumed that it won't become invalid | 110 // This is just a reference, but it's assumed that it won't become invalid |
| 109 // while the dialog is showing. Will be NULL only during tests. | 111 // while the dialog is showing. Will be NULL only during tests. |
| 110 const extensions::Extension* extension_; | 112 const extensions::Extension* extension_; |
| 111 | 113 |
| 112 // This map excludes those galleries which have been blacklisted; it only | 114 // This map excludes those galleries which have been blacklisted; it only |
| 113 // counts active known galleries. | 115 // counts active known galleries. |
| 114 KnownGalleryPermissions known_galleries_; | 116 KnownGalleryPermissions known_galleries_; |
| 115 NewGalleryPermissions new_galleries_; | 117 NewGalleryPermissions new_galleries_; |
| 116 | 118 |
| 117 // We run this callback when done. | 119 // We run this callback when done. |
| 118 base::Closure on_finish_; | 120 base::Closure on_finish_; |
| 119 | 121 |
| 120 // The model that tracks galleries and extensions' permissions. | 122 // The model that tracks galleries and extensions' permissions. |
| 121 MediaGalleriesPreferences* preferences_; | 123 MediaGalleriesPreferences* preferences_; |
| 122 | 124 |
| 123 // The view that's showing. | 125 // The view that's showing. |
| 124 scoped_ptr<MediaGalleriesDialog> dialog_; | 126 scoped_ptr<MediaGalleriesDialog> dialog_; |
| 125 | 127 |
| 126 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_; | 128 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_; |
| 127 | 129 |
| 128 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogController); | 130 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogController); |
| 129 }; | 131 }; |
| 130 | 132 |
| 131 } // namespace chrome | 133 } // namespace chrome |
| 132 | 134 |
| 133 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ | 135 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
| OLD | NEW |