| 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 #include "chrome/browser/media_gallery/media_galleries_dialog_controller.h" | 5 #include "chrome/browser/media_gallery/media_galleries_dialog_controller.h" |
| 6 | 6 |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/media_gallery/media_galleries_preferences_factory.h" | 9 #include "chrome/browser/media_gallery/media_galleries_preferences_factory.h" |
| 10 #include "chrome/browser/ui/chrome_select_file_policy.h" | 10 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 LookUpPermissions(); | 32 LookUpPermissions(); |
| 33 | 33 |
| 34 dialog_.reset(MediaGalleriesDialog::Create(this)); | 34 dialog_.reset(MediaGalleriesDialog::Create(this)); |
| 35 } | 35 } |
| 36 | 36 |
| 37 MediaGalleriesDialogController::~MediaGalleriesDialogController() { | 37 MediaGalleriesDialogController::~MediaGalleriesDialogController() { |
| 38 if (select_folder_dialog_.get()) | 38 if (select_folder_dialog_.get()) |
| 39 select_folder_dialog_->ListenerDestroyed(); | 39 select_folder_dialog_->ListenerDestroyed(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 string16 MediaGalleriesDialogController::GetHeader() { | 42 string16 MediaGalleriesDialogController::GetHeader() const { |
| 43 return l10n_util::GetStringFUTF16(IDS_MEDIA_GALLERIES_DIALOG_HEADER, | 43 return l10n_util::GetStringFUTF16(IDS_MEDIA_GALLERIES_DIALOG_HEADER, |
| 44 UTF8ToUTF16(extension_.name())); | 44 UTF8ToUTF16(extension_.name())); |
| 45 } | 45 } |
| 46 | 46 |
| 47 string16 MediaGalleriesDialogController::GetSubtext() { | 47 string16 MediaGalleriesDialogController::GetSubtext() const { |
| 48 if (extension_.HasAPIPermission( | 48 if (extension_.HasAPIPermission( |
| 49 extensions::APIPermission::kMediaGalleriesRead)) { | 49 extensions::APIPermission::kMediaGalleriesRead)) { |
| 50 return l10n_util::GetStringFUTF16(IDS_MEDIA_GALLERIES_DIALOG_READ_SUBTEXT, | 50 return l10n_util::GetStringFUTF16(IDS_MEDIA_GALLERIES_DIALOG_READ_SUBTEXT, |
| 51 UTF8ToUTF16(extension_.name())); | 51 UTF8ToUTF16(extension_.name())); |
| 52 } | 52 } |
| 53 // TODO(estade): handle write et al. | 53 // TODO(estade): handle write et al. |
| 54 return string16(); | 54 return string16(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool MediaGalleriesDialogController::HasPermittedGalleries() const { |
| 58 for (KnownGalleryPermissions::const_iterator iter = permissions().begin(); |
| 59 iter != permissions().end(); iter++) { |
| 60 if (iter->second.allowed) |
| 61 return true; |
| 62 } |
| 63 return false; |
| 64 } |
| 65 |
| 57 void MediaGalleriesDialogController::OnAddFolderClicked() { | 66 void MediaGalleriesDialogController::OnAddFolderClicked() { |
| 58 FilePath user_data_dir; | 67 FilePath user_data_dir; |
| 59 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 68 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 60 // TODO(estade): if file dialogs are disabled we need to handle it somehow. | 69 // TODO(estade): if file dialogs are disabled we need to handle it somehow. |
| 61 select_folder_dialog_ = | 70 select_folder_dialog_ = |
| 62 ui::SelectFileDialog::Create(this, new ChromeSelectFilePolicy(NULL)); | 71 ui::SelectFileDialog::Create(this, new ChromeSelectFilePolicy(NULL)); |
| 63 select_folder_dialog_->SelectFile( | 72 select_folder_dialog_->SelectFile( |
| 64 ui::SelectFileDialog::SELECT_FOLDER, | 73 ui::SelectFileDialog::SELECT_FOLDER, |
| 65 l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY_TITLE), | 74 l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY_TITLE), |
| 66 user_data_dir, | 75 user_data_dir, |
| 67 NULL, 0, FILE_PATH_LITERAL(""), | 76 NULL, 0, FILE_PATH_LITERAL(""), |
| 68 tab_contents_->web_contents()->GetView()->GetTopLevelNativeWindow(), | 77 tab_contents_->web_contents()->GetView()->GetTopLevelNativeWindow(), |
| 69 NULL); | 78 NULL); |
| 70 } | 79 } |
| 71 | 80 |
| 72 void MediaGalleriesDialogController::GalleryToggled( | 81 void MediaGalleriesDialogController::DidToggleGallery( |
| 73 const MediaGalleryPrefInfo* gallery, | 82 const MediaGalleryPrefInfo* gallery, |
| 74 bool enabled) { | 83 bool enabled) { |
| 75 // Check known galleries. | 84 // Check known galleries. |
| 76 KnownGalleryPermissions::iterator iter = | 85 KnownGalleryPermissions::iterator iter = |
| 77 known_galleries_.find(gallery->pref_id); | 86 known_galleries_.find(gallery->pref_id); |
| 78 if (iter != known_galleries_.end()) { | 87 if (iter != known_galleries_.end()) { |
| 79 iter->second.allowed = enabled; | 88 iter->second.allowed = enabled; |
| 80 return; | 89 return; |
| 81 } | 90 } |
| 82 | 91 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 preferences_->SetGalleryPermissionForExtension( | 185 preferences_->SetGalleryPermissionForExtension( |
| 177 extension_, id, true); | 186 extension_, id, true); |
| 178 } | 187 } |
| 179 } | 188 } |
| 180 | 189 |
| 181 // MediaGalleries dialog ------------------------------------------------------- | 190 // MediaGalleries dialog ------------------------------------------------------- |
| 182 | 191 |
| 183 MediaGalleriesDialog::~MediaGalleriesDialog() {} | 192 MediaGalleriesDialog::~MediaGalleriesDialog() {} |
| 184 | 193 |
| 185 } // namespace chrome | 194 } // namespace chrome |
| OLD | NEW |