Chromium Code Reviews| 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/ui/webui/options/media_galleries_handler.h" | 5 #include "chrome/browser/ui/webui/options/media_galleries_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "chrome/browser/media_gallery/media_file_system_registry.h" | 9 #include "chrome/browser/media_gallery/media_file_system_registry.h" |
| 10 #include "chrome/browser/media_gallery/media_galleries_preferences.h" | 10 #include "chrome/browser/media_gallery/media_galleries_preferences.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 IDS_MEDIA_GALLERY_MANAGE_TITLE); | 45 IDS_MEDIA_GALLERY_MANAGE_TITLE); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void MediaGalleriesHandler::InitializePage() { | 48 void MediaGalleriesHandler::InitializePage() { |
| 49 Profile* profile = Profile::FromWebUI(web_ui()); | 49 Profile* profile = Profile::FromWebUI(web_ui()); |
| 50 if (!chrome::MediaGalleriesPreferences::APIHasBeenUsed(profile)) | 50 if (!chrome::MediaGalleriesPreferences::APIHasBeenUsed(profile)) |
| 51 return; | 51 return; |
| 52 | 52 |
| 53 if (pref_change_registrar_.IsEmpty()) { | 53 if (pref_change_registrar_.IsEmpty()) { |
| 54 pref_change_registrar_.Init(profile->GetPrefs()); | 54 pref_change_registrar_.Init(profile->GetPrefs()); |
| 55 pref_change_registrar_.Add(prefs::kMediaGalleriesRememberedGalleries, this); | 55 pref_change_registrar_.Add( |
| 56 prefs::kMediaGalleriesRememberedGalleries, | |
| 57 base::Bind(&MediaGalleriesHandler::OnGalleriesChanged, | |
| 58 base::Unretained(this))); | |
| 56 } | 59 } |
| 57 | 60 |
| 58 OnGalleriesChanged(); | 61 OnGalleriesChanged(); |
| 59 } | 62 } |
| 60 | 63 |
| 61 void MediaGalleriesHandler::RegisterMessages() { | 64 void MediaGalleriesHandler::RegisterMessages() { |
| 62 web_ui()->RegisterMessageCallback( | 65 web_ui()->RegisterMessageCallback( |
| 63 "addNewGallery", | 66 "addNewGallery", |
| 64 base::Bind(&MediaGalleriesHandler::HandleAddNewGallery, | 67 base::Bind(&MediaGalleriesHandler::HandleAddNewGallery, |
| 65 base::Unretained(this))); | 68 base::Unretained(this))); |
| 66 web_ui()->RegisterMessageCallback( | 69 web_ui()->RegisterMessageCallback( |
| 67 "forgetGallery", | 70 "forgetGallery", |
| 68 base::Bind(&MediaGalleriesHandler::HandleForgetGallery, | 71 base::Bind(&MediaGalleriesHandler::HandleForgetGallery, |
| 69 base::Unretained(this))); | 72 base::Unretained(this))); |
| 70 } | 73 } |
| 71 | 74 |
| 72 void MediaGalleriesHandler::OnGalleriesChanged() { | |
| 73 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 74 chrome::MediaGalleriesPreferences* preferences = | |
| 75 chrome::MediaFileSystemRegistry::GetInstance()->GetPreferences(profile); | |
| 76 | |
| 77 ListValue list; | |
| 78 const MediaGalleriesPrefInfoMap& galleries = preferences->known_galleries(); | |
| 79 for (MediaGalleriesPrefInfoMap::const_iterator iter = galleries.begin(); | |
| 80 iter != galleries.end(); ++iter) { | |
| 81 const MediaGalleryPrefInfo& gallery = iter->second; | |
| 82 if (gallery.type == MediaGalleryPrefInfo::kBlackListed) | |
| 83 continue; | |
| 84 | |
| 85 DictionaryValue* dict = new DictionaryValue(); | |
| 86 dict->SetString("displayName", gallery.display_name); | |
| 87 dict->SetString("path", gallery.AbsolutePath().LossyDisplayName()); | |
| 88 dict->SetString("id", base::Uint64ToString(gallery.pref_id)); | |
| 89 list.Append(dict); | |
| 90 } | |
| 91 | |
| 92 web_ui()->CallJavascriptFunction( | |
| 93 "options.MediaGalleriesManager.setAvailableMediaGalleries", list); | |
| 94 } | |
| 95 | |
| 96 void MediaGalleriesHandler::HandleAddNewGallery(const base::ListValue* args) { | 75 void MediaGalleriesHandler::HandleAddNewGallery(const base::ListValue* args) { |
| 97 ui::SelectFileDialog* dialog = ui::SelectFileDialog::Create( | 76 ui::SelectFileDialog* dialog = ui::SelectFileDialog::Create( |
| 98 this, | 77 this, |
| 99 new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | 78 new ChromeSelectFilePolicy(web_ui()->GetWebContents())); |
| 100 dialog->SelectFile(ui::SelectFileDialog::SELECT_FOLDER, | 79 dialog->SelectFile(ui::SelectFileDialog::SELECT_FOLDER, |
| 101 string16(), // TODO(estade): a name for the dialog? | 80 string16(), // TODO(estade): a name for the dialog? |
| 102 FilePath(), | 81 FilePath(), |
| 103 NULL, 0, | 82 NULL, 0, |
| 104 FilePath::StringType(), | 83 FilePath::StringType(), |
| 105 web_ui()->GetWebContents()->GetView()-> | 84 web_ui()->GetWebContents()->GetView()-> |
| 106 GetTopLevelNativeWindow(), | 85 GetTopLevelNativeWindow(), |
| 107 NULL); | 86 NULL); |
| 108 } | 87 } |
| 109 | 88 |
| 110 void MediaGalleriesHandler::HandleForgetGallery(const base::ListValue* args) { | 89 void MediaGalleriesHandler::HandleForgetGallery(const base::ListValue* args) { |
| 111 std::string string_id; | 90 std::string string_id; |
| 112 uint64 id = 0; | 91 uint64 id = 0; |
| 113 if (!args->GetString(0, &string_id) || | 92 if (!args->GetString(0, &string_id) || |
| 114 !base::StringToUint64(string_id, &id)) { | 93 !base::StringToUint64(string_id, &id)) { |
| 115 NOTREACHED(); | 94 NOTREACHED(); |
| 116 return; | 95 return; |
| 117 } | 96 } |
| 118 | 97 |
| 119 chrome::MediaGalleriesPreferences* prefs = | 98 chrome::MediaGalleriesPreferences* prefs = |
| 120 chrome::MediaFileSystemRegistry::GetInstance()->GetPreferences( | 99 chrome::MediaFileSystemRegistry::GetInstance()->GetPreferences( |
| 121 Profile::FromWebUI(web_ui())); | 100 Profile::FromWebUI(web_ui())); |
| 122 prefs->ForgetGalleryById(id); | 101 prefs->ForgetGalleryById(id); |
| 123 } | 102 } |
| 124 | 103 |
| 125 void MediaGalleriesHandler::FileSelected( | 104 void MediaGalleriesHandler::FileSelected(const FilePath& path, |
| 126 const FilePath& path, int index, void* params) { | 105 int index, |
| 106 void* params) { | |
| 127 chrome::MediaGalleriesPreferences* prefs = | 107 chrome::MediaGalleriesPreferences* prefs = |
| 128 chrome::MediaFileSystemRegistry::GetInstance()->GetPreferences( | 108 chrome::MediaFileSystemRegistry::GetInstance()->GetPreferences( |
| 129 Profile::FromWebUI(web_ui())); | 109 Profile::FromWebUI(web_ui())); |
| 130 prefs->AddGalleryByPath(path); | 110 prefs->AddGalleryByPath(path); |
| 131 } | 111 } |
| 132 | 112 |
| 133 void MediaGalleriesHandler::OnPreferenceChanged(PrefServiceBase* service, | 113 void MediaGalleriesHandler::OnGalleriesChanged() { |
|
Jói
2012/11/21 13:37:45
You've reordered methods here, which is OK, but in
tfarina
2012/11/21 13:48:33
Done.
| |
| 134 const std::string& pref_name) { | 114 Profile* profile = Profile::FromWebUI(web_ui()); |
| 135 DCHECK_EQ(std::string(prefs::kMediaGalleriesRememberedGalleries), pref_name); | 115 chrome::MediaGalleriesPreferences* preferences = |
| 136 OnGalleriesChanged(); | 116 chrome::MediaFileSystemRegistry::GetInstance()->GetPreferences(profile); |
| 117 | |
| 118 ListValue list; | |
| 119 const MediaGalleriesPrefInfoMap& galleries = preferences->known_galleries(); | |
| 120 for (MediaGalleriesPrefInfoMap::const_iterator iter = galleries.begin(); | |
| 121 iter != galleries.end(); ++iter) { | |
| 122 const MediaGalleryPrefInfo& gallery = iter->second; | |
| 123 if (gallery.type == MediaGalleryPrefInfo::kBlackListed) | |
| 124 continue; | |
| 125 | |
| 126 DictionaryValue* dict = new DictionaryValue(); | |
| 127 dict->SetString("displayName", gallery.display_name); | |
| 128 dict->SetString("path", gallery.AbsolutePath().LossyDisplayName()); | |
| 129 dict->SetString("id", base::Uint64ToString(gallery.pref_id)); | |
| 130 list.Append(dict); | |
| 131 } | |
| 132 | |
| 133 web_ui()->CallJavascriptFunction( | |
| 134 "options.MediaGalleriesManager.setAvailableMediaGalleries", list); | |
| 137 } | 135 } |
| 138 | 136 |
| 139 } // namespace options | 137 } // namespace options |
| OLD | NEW |