Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: chrome/browser/ui/webui/options2/media_galleries_handler.cc

Issue 10835016: Rename media gallery -> media galleries in pref/UI components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/options2/media_gallery_handler.h" 5 #include "chrome/browser/ui/webui/options2/media_galleries_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/media_gallery/media_gallery_registry.h" 8 #include "chrome/browser/media_gallery/media_galleries_preferences.h"
9 #include "chrome/browser/media_gallery/media_gallery_registry_factory.h" 9 #include "chrome/browser/media_gallery/media_galleries_preferences_factory.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/chrome_select_file_policy.h" 12 #include "chrome/browser/ui/chrome_select_file_policy.h"
13 #include "chrome/common/chrome_notification_types.h" 13 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "content/public/browser/notification_details.h" 15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_view.h" 17 #include "content/public/browser/web_contents_view.h"
18 #include "content/public/browser/web_ui.h" 18 #include "content/public/browser/web_ui.h"
19 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
20 20
21 namespace options2 { 21 namespace options2 {
22 22
23 MediaGalleryHandler::MediaGalleryHandler() { 23 MediaGalleriesHandler::MediaGalleriesHandler() {
24 } 24 }
25 25
26 MediaGalleryHandler::~MediaGalleryHandler() { 26 MediaGalleriesHandler::~MediaGalleriesHandler() {
27 } 27 }
28 28
29 void MediaGalleryHandler::GetLocalizedValues(DictionaryValue* values) { 29 void MediaGalleriesHandler::GetLocalizedValues(DictionaryValue* values) {
30 DCHECK(values); 30 DCHECK(values);
31 31
32 static OptionsStringResource resources[] = { 32 static OptionsStringResource resources[] = {
33 { "mediaGalleriesSectionLabel", IDS_MEDIA_GALLERY_SECTION_LABEL }, 33 { "mediaGalleriesSectionLabel", IDS_MEDIA_GALLERY_SECTION_LABEL },
34 { "manageGalleriesButton", IDS_MEDIA_GALLERY_MANAGE_BUTTON }, 34 { "manageGalleriesButton", IDS_MEDIA_GALLERY_MANAGE_BUTTON },
35 { "addNewGalleryButton", IDS_MEDIA_GALLERY_ADD_NEW_BUTTON }, 35 { "addNewGalleryButton", IDS_MEDIA_GALLERY_ADD_NEW_BUTTON },
36 }; 36 };
37 37
38 RegisterStrings(values, resources, arraysize(resources)); 38 RegisterStrings(values, resources, arraysize(resources));
39 RegisterTitle(values, "manageMediaGalleries", 39 RegisterTitle(values, "manageMediaGalleries",
40 IDS_MEDIA_GALLERY_MANAGE_TITLE); 40 IDS_MEDIA_GALLERY_MANAGE_TITLE);
41 } 41 }
42 42
43 void MediaGalleryHandler::InitializeHandler() { 43 void MediaGalleriesHandler::InitializeHandler() {
44 if (!MediaGalleryRegistry::UserInteractionIsEnabled()) 44 if (!MediaGalleriesPreferences::UserInteractionIsEnabled())
45 return; 45 return;
46 46
47 Profile* profile = Profile::FromWebUI(web_ui()); 47 Profile* profile = Profile::FromWebUI(web_ui());
48 pref_change_registrar_.Init(profile->GetPrefs()); 48 pref_change_registrar_.Init(profile->GetPrefs());
49 pref_change_registrar_.Add(prefs::kMediaGalleryRememberedGalleries, this); 49 pref_change_registrar_.Add(prefs::kMediaGalleriesRememberedGalleries, this);
50 } 50 }
51 51
52 void MediaGalleryHandler::InitializePage() { 52 void MediaGalleriesHandler::InitializePage() {
53 if (!MediaGalleryRegistry::UserInteractionIsEnabled()) 53 if (!MediaGalleriesPreferences::UserInteractionIsEnabled())
54 return; 54 return;
55 55
56 OnGalleriesChanged(); 56 OnGalleriesChanged();
57 } 57 }
58 58
59 void MediaGalleryHandler::RegisterMessages() { 59 void MediaGalleriesHandler::RegisterMessages() {
60 web_ui()->RegisterMessageCallback( 60 web_ui()->RegisterMessageCallback(
61 "addNewGallery", 61 "addNewGallery",
62 base::Bind(&MediaGalleryHandler::HandleAddNewGallery, 62 base::Bind(&MediaGalleriesHandler::HandleAddNewGallery,
63 base::Unretained(this))); 63 base::Unretained(this)));
64 web_ui()->RegisterMessageCallback( 64 web_ui()->RegisterMessageCallback(
65 "forgetGallery", 65 "forgetGallery",
66 base::Bind(&MediaGalleryHandler::HandleForgetGallery, 66 base::Bind(&MediaGalleriesHandler::HandleForgetGallery,
67 base::Unretained(this))); 67 base::Unretained(this)));
68 } 68 }
69 69
70 void MediaGalleryHandler::OnGalleriesChanged() { 70 void MediaGalleriesHandler::OnGalleriesChanged() {
71 Profile* profile = Profile::FromWebUI(web_ui()); 71 Profile* profile = Profile::FromWebUI(web_ui());
72 const ListValue* list = profile->GetPrefs()->GetList( 72 const ListValue* list = profile->GetPrefs()->GetList(
73 prefs::kMediaGalleryRememberedGalleries); 73 prefs::kMediaGalleriesRememberedGalleries);
74 web_ui()->CallJavascriptFunction( 74 web_ui()->CallJavascriptFunction(
75 "options.MediaGalleryManager.setAvailableMediaGalleries", *list); 75 "options.MediaGalleriesManager.setAvailableMediaGalleries", *list);
76 } 76 }
77 77
78 void MediaGalleryHandler::HandleAddNewGallery(const base::ListValue* args) { 78 void MediaGalleriesHandler::HandleAddNewGallery(const base::ListValue* args) {
79 SelectFileDialog* dialog = SelectFileDialog::Create( 79 SelectFileDialog* dialog = SelectFileDialog::Create(
80 this, 80 this,
81 new ChromeSelectFilePolicy(web_ui()->GetWebContents())); 81 new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
82 dialog->SelectFile(SelectFileDialog::SELECT_FOLDER, 82 dialog->SelectFile(SelectFileDialog::SELECT_FOLDER,
83 string16(), // TODO(estade): a name for the dialog? 83 string16(), // TODO(estade): a name for the dialog?
84 FilePath(), 84 FilePath(),
85 NULL, 0, 85 NULL, 0,
86 FilePath::StringType(), 86 FilePath::StringType(),
87 web_ui()->GetWebContents()->GetView()-> 87 web_ui()->GetWebContents()->GetView()->
88 GetTopLevelNativeWindow(), 88 GetTopLevelNativeWindow(),
89 NULL); 89 NULL);
90 } 90 }
91 91
92 void MediaGalleryHandler::HandleForgetGallery(const base::ListValue* args) { 92 void MediaGalleriesHandler::HandleForgetGallery(const base::ListValue* args) {
93 // TODO(estade): use uint64. 93 // TODO(estade): use uint64.
94 int id; 94 int id;
95 CHECK(ExtractIntegerValue(args, &id)); 95 CHECK(ExtractIntegerValue(args, &id));
96 MediaGalleryRegistry* registry = 96 MediaGalleriesPreferences* prefs =
97 MediaGalleryRegistryFactory::GetForProfile(Profile::FromWebUI(web_ui())); 97 MediaGalleriesPreferencesFactory::GetForProfile(
98 registry->ForgetGalleryById(id); 98 Profile::FromWebUI(web_ui()));
99 prefs->ForgetGalleryById(id);
99 } 100 }
100 101
101 void MediaGalleryHandler::FileSelected( 102 void MediaGalleriesHandler::FileSelected(
102 const FilePath& path, int index, void* params) { 103 const FilePath& path, int index, void* params) {
103 MediaGalleryRegistry* registry = 104 MediaGalleriesPreferences* prefs =
104 MediaGalleryRegistryFactory::GetForProfile(Profile::FromWebUI(web_ui())); 105 MediaGalleriesPreferencesFactory::GetForProfile(
105 registry->AddGalleryByPath(path); 106 Profile::FromWebUI(web_ui()));
107 prefs->AddGalleryByPath(path);
106 } 108 }
107 109
108 void MediaGalleryHandler::Observe( 110 void MediaGalleriesHandler::Observe(
109 int type, 111 int type,
110 const content::NotificationSource& source, 112 const content::NotificationSource& source,
111 const content::NotificationDetails& details) { 113 const content::NotificationDetails& details) {
112 if (type == chrome::NOTIFICATION_PREF_CHANGED && 114 if (type == chrome::NOTIFICATION_PREF_CHANGED &&
113 *content::Details<std::string>(details).ptr() == 115 *content::Details<std::string>(details).ptr() ==
114 prefs::kMediaGalleryRememberedGalleries) { 116 prefs::kMediaGalleriesRememberedGalleries) {
115 OnGalleriesChanged(); 117 OnGalleriesChanged();
116 } else { 118 } else {
117 NOTREACHED(); 119 NOTREACHED();
118 } 120 }
119 } 121 }
120 122
121 } // namespace options2 123 } // namespace options2
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options2/media_galleries_handler.h ('k') | chrome/browser/ui/webui/options2/media_gallery_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698