| 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" | 12 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| 13 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 13 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 14 #include "chrome/browser/media_galleries/media_galleries_histograms.h" | 14 #include "chrome/browser/media_galleries/media_galleries_histograms.h" |
| 15 #include "chrome/browser/media_galleries/media_gallery_context_menu.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/storage_monitor/storage_info.h" | 17 #include "chrome/browser/storage_monitor/storage_info.h" |
| 17 #include "chrome/browser/storage_monitor/storage_monitor.h" | 18 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 18 #include "chrome/browser/ui/chrome_select_file_policy.h" | 19 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 19 #include "chrome/common/extensions/permissions/media_galleries_permission.h" | 20 #include "chrome/common/extensions/permissions/media_galleries_permission.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/browser/web_contents_view.h" | 22 #include "content/public/browser/web_contents_view.h" |
| 22 #include "extensions/browser/extension_prefs.h" | 23 #include "extensions/browser/extension_prefs.h" |
| 23 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 24 #include "extensions/common/permissions/permissions_data.h" | 25 #include "extensions/common/permissions/permissions_data.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 40 if (a.allowed && !b.allowed) | 41 if (a.allowed && !b.allowed) |
| 41 return true; | 42 return true; |
| 42 if (!a.allowed && b.allowed) | 43 if (!a.allowed && b.allowed) |
| 43 return false; | 44 return false; |
| 44 | 45 |
| 45 return a.pref_info.AbsolutePath() < b.pref_info.AbsolutePath(); | 46 return a.pref_info.AbsolutePath() < b.pref_info.AbsolutePath(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 } // namespace | 49 } // namespace |
| 49 | 50 |
| 50 class GalleryContextMenuModel : public ui::SimpleMenuModel::Delegate { | |
| 51 public: | |
| 52 explicit GalleryContextMenuModel(MediaGalleriesDialogController* controller) | |
| 53 : controller_(controller), id_(kInvalidMediaGalleryPrefId) {} | |
| 54 virtual ~GalleryContextMenuModel() {} | |
| 55 | |
| 56 void set_media_gallery_pref_id(MediaGalleryPrefId id) { | |
| 57 id_ = id; | |
| 58 } | |
| 59 | |
| 60 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { | |
| 61 return false; | |
| 62 } | |
| 63 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE { | |
| 64 return true; | |
| 65 } | |
| 66 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE { | |
| 67 return true; | |
| 68 } | |
| 69 | |
| 70 virtual bool GetAcceleratorForCommandId( | |
| 71 int command_id, ui::Accelerator* accelerator) OVERRIDE { | |
| 72 return false; | |
| 73 } | |
| 74 | |
| 75 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE { | |
| 76 controller_->DidForgetGallery(id_); | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 MediaGalleriesDialogController* controller_; | |
| 81 MediaGalleryPrefId id_; | |
| 82 }; | |
| 83 | |
| 84 MediaGalleriesDialogController::MediaGalleriesDialogController( | 51 MediaGalleriesDialogController::MediaGalleriesDialogController( |
| 85 content::WebContents* web_contents, | 52 content::WebContents* web_contents, |
| 86 const Extension& extension, | 53 const Extension& extension, |
| 87 const base::Closure& on_finish) | 54 const base::Closure& on_finish) |
| 88 : web_contents_(web_contents), | 55 : web_contents_(web_contents), |
| 89 extension_(&extension), | 56 extension_(&extension), |
| 90 on_finish_(on_finish) { | 57 on_finish_(on_finish) { |
| 91 preferences_ = | 58 preferences_ = |
| 92 g_browser_process->media_file_system_registry()->GetPreferences( | 59 g_browser_process->media_file_system_registry()->GetPreferences( |
| 93 GetProfile()); | 60 GetProfile()); |
| 94 // Passing unretained pointer is safe, since the dialog controller | 61 // Passing unretained pointer is safe, since the dialog controller |
| 95 // is self-deleting, and so won't be deleted until it can be shown | 62 // is self-deleting, and so won't be deleted until it can be shown |
| 96 // and then closed. | 63 // and then closed. |
| 97 preferences_->EnsureInitialized( | 64 preferences_->EnsureInitialized( |
| 98 base::Bind(&MediaGalleriesDialogController::OnPreferencesInitialized, | 65 base::Bind(&MediaGalleriesDialogController::OnPreferencesInitialized, |
| 99 base::Unretained(this))); | 66 base::Unretained(this))); |
| 100 | 67 |
| 101 gallery_menu_model_.reset(new GalleryContextMenuModel(this)); | 68 // Unretained is safe because |this| owns |context_menu_|. |
| 102 ui::SimpleMenuModel* menu_model = | 69 context_menu_.reset( |
| 103 new ui::SimpleMenuModel(gallery_menu_model_.get()); | 70 new MediaGalleryContextMenu( |
| 104 menu_model->AddItem( | 71 base::Bind(&MediaGalleriesDialogController::DidForgetGallery, |
| 105 1, l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_DELETE)); | 72 base::Unretained(this)))); |
| 106 context_menu_model_.reset(menu_model); | |
| 107 } | 73 } |
| 108 | 74 |
| 109 void MediaGalleriesDialogController::OnPreferencesInitialized() { | 75 void MediaGalleriesDialogController::OnPreferencesInitialized() { |
| 110 InitializePermissions(); | 76 InitializePermissions(); |
| 111 | 77 |
| 112 dialog_.reset(MediaGalleriesDialog::Create(this)); | 78 dialog_.reset(MediaGalleriesDialog::Create(this)); |
| 113 | 79 |
| 114 StorageMonitor::GetInstance()->AddObserver(this); | 80 StorageMonitor::GetInstance()->AddObserver(this); |
| 115 | 81 |
| 116 preferences_->AddGalleryChangeObserver(this); | 82 preferences_->AddGalleryChangeObserver(this); |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 } | 431 } |
| 466 | 432 |
| 467 dialog_->UpdateGalleries(); | 433 dialog_->UpdateGalleries(); |
| 468 } | 434 } |
| 469 | 435 |
| 470 void MediaGalleriesDialogController::UpdateGalleriesOnDeviceEvent( | 436 void MediaGalleriesDialogController::UpdateGalleriesOnDeviceEvent( |
| 471 const std::string& device_id) { | 437 const std::string& device_id) { |
| 472 dialog_->UpdateGalleries(); | 438 dialog_->UpdateGalleries(); |
| 473 } | 439 } |
| 474 | 440 |
| 475 ui::MenuModel* MediaGalleriesDialogController::GetContextMenuModel( | 441 ui::MenuModel* MediaGalleriesDialogController::GetContextMenu( |
| 476 MediaGalleryPrefId id) { | 442 MediaGalleryPrefId id) { |
| 477 gallery_menu_model_->set_media_gallery_pref_id(id); | 443 context_menu_->set_pref_id(id); |
| 478 return context_menu_model_.get(); | 444 return context_menu_.get(); |
| 479 } | 445 } |
| 480 | 446 |
| 481 Profile* MediaGalleriesDialogController::GetProfile() { | 447 Profile* MediaGalleriesDialogController::GetProfile() { |
| 482 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 448 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 483 } | 449 } |
| 484 | 450 |
| 485 // MediaGalleries dialog ------------------------------------------------------- | 451 // MediaGalleries dialog ------------------------------------------------------- |
| 486 | 452 |
| 487 MediaGalleriesDialog::~MediaGalleriesDialog() {} | 453 MediaGalleriesDialog::~MediaGalleriesDialog() {} |
| OLD | NEW |