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_galleries/media_galleries_dialog_controller.h" | 5 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| 13 #include "chrome/browser/extensions/extension_prefs.h" |
12 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 14 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
13 #include "chrome/browser/media_galleries/media_galleries_histograms.h" | 15 #include "chrome/browser/media_galleries/media_galleries_histograms.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/storage_monitor/storage_info.h" | 17 #include "chrome/browser/storage_monitor/storage_info.h" |
16 #include "chrome/browser/storage_monitor/storage_monitor.h" | 18 #include "chrome/browser/storage_monitor/storage_monitor.h" |
17 #include "chrome/browser/ui/chrome_select_file_policy.h" | 19 #include "chrome/browser/ui/chrome_select_file_policy.h" |
18 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/extensions/permissions/media_galleries_permission.h" | 21 #include "chrome/common/extensions/permissions/media_galleries_permission.h" |
20 #include "chrome/common/extensions/permissions/permissions_data.h" | 22 #include "chrome/common/extensions/permissions/permissions_data.h" |
21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 83 |
82 MediaGalleriesDialogController::MediaGalleriesDialogController( | 84 MediaGalleriesDialogController::MediaGalleriesDialogController( |
83 content::WebContents* web_contents, | 85 content::WebContents* web_contents, |
84 const Extension& extension, | 86 const Extension& extension, |
85 const base::Closure& on_finish) | 87 const base::Closure& on_finish) |
86 : web_contents_(web_contents), | 88 : web_contents_(web_contents), |
87 extension_(&extension), | 89 extension_(&extension), |
88 on_finish_(on_finish) { | 90 on_finish_(on_finish) { |
89 preferences_ = | 91 preferences_ = |
90 g_browser_process->media_file_system_registry()->GetPreferences( | 92 g_browser_process->media_file_system_registry()->GetPreferences( |
91 Profile::FromBrowserContext(web_contents_->GetBrowserContext())); | 93 GetProfile()); |
92 // Passing unretained pointer is safe, since the dialog controller | 94 // Passing unretained pointer is safe, since the dialog controller |
93 // is self-deleting, and so won't be deleted until it can be shown | 95 // is self-deleting, and so won't be deleted until it can be shown |
94 // and then closed. | 96 // and then closed. |
95 preferences_->EnsureInitialized( | 97 preferences_->EnsureInitialized( |
96 base::Bind(&MediaGalleriesDialogController::OnPreferencesInitialized, | 98 base::Bind(&MediaGalleriesDialogController::OnPreferencesInitialized, |
97 base::Unretained(this))); | 99 base::Unretained(this))); |
98 | 100 |
99 gallery_menu_model_.reset(new GalleryContextMenuModel(this)); | 101 gallery_menu_model_.reset(new GalleryContextMenuModel(this)); |
100 ui::SimpleMenuModel* menu_model = | 102 ui::SimpleMenuModel* menu_model = |
101 new ui::SimpleMenuModel(gallery_menu_model_.get()); | 103 new ui::SimpleMenuModel(gallery_menu_model_.get()); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 204 } |
203 | 205 |
204 MediaGalleriesDialogController::GalleryPermissionsVector | 206 MediaGalleriesDialogController::GalleryPermissionsVector |
205 MediaGalleriesDialogController::UnattachedPermissions() const { | 207 MediaGalleriesDialogController::UnattachedPermissions() const { |
206 GalleryPermissionsVector unattached; | 208 GalleryPermissionsVector unattached; |
207 FillPermissions(false, &unattached); | 209 FillPermissions(false, &unattached); |
208 return unattached; | 210 return unattached; |
209 } | 211 } |
210 | 212 |
211 void MediaGalleriesDialogController::OnAddFolderClicked() { | 213 void MediaGalleriesDialogController::OnAddFolderClicked() { |
212 base::FilePath desktop; | 214 base::FilePath default_path = |
213 PathService::Get(base::DIR_USER_DESKTOP, &desktop); | 215 extensions::file_system_api::GetLastChooseEntryDirectory( |
| 216 extensions::ExtensionPrefs::Get(GetProfile()), extension_->id()); |
| 217 if (default_path.empty()) |
| 218 PathService::Get(base::DIR_USER_DESKTOP, &default_path); |
214 select_folder_dialog_ = | 219 select_folder_dialog_ = |
215 ui::SelectFileDialog::Create(this, new ChromeSelectFilePolicy(NULL)); | 220 ui::SelectFileDialog::Create(this, new ChromeSelectFilePolicy(NULL)); |
216 select_folder_dialog_->SelectFile( | 221 select_folder_dialog_->SelectFile( |
217 ui::SelectFileDialog::SELECT_FOLDER, | 222 ui::SelectFileDialog::SELECT_FOLDER, |
218 l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY_TITLE), | 223 l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY_TITLE), |
219 desktop, | 224 default_path, |
220 NULL, | 225 NULL, |
221 0, | 226 0, |
222 base::FilePath::StringType(), | 227 base::FilePath::StringType(), |
223 web_contents_->GetView()->GetTopLevelNativeWindow(), | 228 web_contents_->GetView()->GetTopLevelNativeWindow(), |
224 NULL); | 229 NULL); |
225 } | 230 } |
226 | 231 |
227 void MediaGalleriesDialogController::DidToggleGalleryId( | 232 void MediaGalleriesDialogController::DidToggleGalleryId( |
228 MediaGalleryPrefId gallery_id, | 233 MediaGalleryPrefId gallery_id, |
229 bool enabled) { | 234 bool enabled) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 delete this; | 285 delete this; |
281 } | 286 } |
282 | 287 |
283 content::WebContents* MediaGalleriesDialogController::web_contents() { | 288 content::WebContents* MediaGalleriesDialogController::web_contents() { |
284 return web_contents_; | 289 return web_contents_; |
285 } | 290 } |
286 | 291 |
287 void MediaGalleriesDialogController::FileSelected(const base::FilePath& path, | 292 void MediaGalleriesDialogController::FileSelected(const base::FilePath& path, |
288 int /*index*/, | 293 int /*index*/, |
289 void* /*params*/) { | 294 void* /*params*/) { |
| 295 extensions::file_system_api::SetLastChooseEntryDirectory( |
| 296 extensions::ExtensionPrefs::Get(GetProfile()), |
| 297 extension_->id(), |
| 298 path); |
| 299 |
290 // Try to find it in the prefs. | 300 // Try to find it in the prefs. |
291 MediaGalleryPrefInfo gallery; | 301 MediaGalleryPrefInfo gallery; |
292 bool gallery_exists = preferences_->LookUpGalleryByPath(path, &gallery); | 302 bool gallery_exists = preferences_->LookUpGalleryByPath(path, &gallery); |
293 if (gallery_exists && gallery.type != MediaGalleryPrefInfo::kBlackListed) { | 303 if (gallery_exists && gallery.type != MediaGalleryPrefInfo::kBlackListed) { |
294 // The prefs are in sync with |known_galleries_|, so it should exist in | 304 // The prefs are in sync with |known_galleries_|, so it should exist in |
295 // |known_galleries_| as well. User selecting a known gallery effectively | 305 // |known_galleries_| as well. User selecting a known gallery effectively |
296 // just sets the gallery to permitted. | 306 // just sets the gallery to permitted. |
297 DCHECK(ContainsKey(known_galleries_, gallery.pref_id)); | 307 DCHECK(ContainsKey(known_galleries_, gallery.pref_id)); |
298 dialog_->UpdateGalleries(); | 308 dialog_->UpdateGalleries(); |
299 return; | 309 return; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 const std::string& device_id) { | 469 const std::string& device_id) { |
460 dialog_->UpdateGalleries(); | 470 dialog_->UpdateGalleries(); |
461 } | 471 } |
462 | 472 |
463 ui::MenuModel* MediaGalleriesDialogController::GetContextMenuModel( | 473 ui::MenuModel* MediaGalleriesDialogController::GetContextMenuModel( |
464 MediaGalleryPrefId id) { | 474 MediaGalleryPrefId id) { |
465 gallery_menu_model_->set_media_gallery_pref_id(id); | 475 gallery_menu_model_->set_media_gallery_pref_id(id); |
466 return context_menu_model_.get(); | 476 return context_menu_model_.get(); |
467 } | 477 } |
468 | 478 |
| 479 Profile* MediaGalleriesDialogController::GetProfile() { |
| 480 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 481 } |
| 482 |
469 // MediaGalleries dialog ------------------------------------------------------- | 483 // MediaGalleries dialog ------------------------------------------------------- |
470 | 484 |
471 MediaGalleriesDialog::~MediaGalleriesDialog() {} | 485 MediaGalleriesDialog::~MediaGalleriesDialog() {} |
OLD | NEW |