OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/handler_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/handler_options_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "content/browser/tab_contents/tab_contents.h" |
14 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 | 17 |
17 | 18 |
18 HandlerOptionsHandler::HandlerOptionsHandler() { | 19 HandlerOptionsHandler::HandlerOptionsHandler() { |
19 } | 20 } |
20 | 21 |
21 HandlerOptionsHandler::~HandlerOptionsHandler() { | 22 HandlerOptionsHandler::~HandlerOptionsHandler() { |
22 } | 23 } |
23 | 24 |
(...skipping 12 matching lines...) Expand all Loading... |
36 { "handlers_active_heading", IDS_HANDLERS_ACTIVE_HEADING }, | 37 { "handlers_active_heading", IDS_HANDLERS_ACTIVE_HEADING }, |
37 { "handlers_ignored_heading", IDS_HANDLERS_IGNORED_HEADING }, | 38 { "handlers_ignored_heading", IDS_HANDLERS_IGNORED_HEADING }, |
38 }; | 39 }; |
39 RegisterTitle(localized_strings, "handlersPage", | 40 RegisterTitle(localized_strings, "handlersPage", |
40 IDS_HANDLER_OPTIONS_WINDOW_TITLE); | 41 IDS_HANDLER_OPTIONS_WINDOW_TITLE); |
41 RegisterStrings(localized_strings, resources, arraysize(resources)); | 42 RegisterStrings(localized_strings, resources, arraysize(resources)); |
42 } | 43 } |
43 | 44 |
44 void HandlerOptionsHandler::Initialize() { | 45 void HandlerOptionsHandler::Initialize() { |
45 UpdateHandlerList(); | 46 UpdateHandlerList(); |
| 47 Profile* profile = |
| 48 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
46 notification_registrar_.Add( | 49 notification_registrar_.Add( |
47 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, | 50 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, |
48 Source<Profile>(web_ui_->GetProfile())); | 51 Source<Profile>(profile)); |
49 } | 52 } |
50 | 53 |
51 void HandlerOptionsHandler::RegisterMessages() { | 54 void HandlerOptionsHandler::RegisterMessages() { |
52 DCHECK(web_ui_); | 55 DCHECK(web_ui_); |
53 web_ui_->RegisterMessageCallback("clearDefault", | 56 web_ui_->RegisterMessageCallback("clearDefault", |
54 NewCallback(this, &HandlerOptionsHandler::ClearDefault)); | 57 NewCallback(this, &HandlerOptionsHandler::ClearDefault)); |
55 web_ui_->RegisterMessageCallback("removeHandler", | 58 web_ui_->RegisterMessageCallback("removeHandler", |
56 NewCallback(this, &HandlerOptionsHandler::RemoveHandler)); | 59 NewCallback(this, &HandlerOptionsHandler::RemoveHandler)); |
57 web_ui_->RegisterMessageCallback("setHandlersEnabled", | 60 web_ui_->RegisterMessageCallback("setHandlersEnabled", |
58 NewCallback(this, &HandlerOptionsHandler::SetHandlersEnabled)); | 61 NewCallback(this, &HandlerOptionsHandler::SetHandlersEnabled)); |
59 web_ui_->RegisterMessageCallback("setDefault", | 62 web_ui_->RegisterMessageCallback("setDefault", |
60 NewCallback(this, &HandlerOptionsHandler::SetDefault)); | 63 NewCallback(this, &HandlerOptionsHandler::SetDefault)); |
61 web_ui_->RegisterMessageCallback("removeIgnoredHandler", | 64 web_ui_->RegisterMessageCallback("removeIgnoredHandler", |
62 NewCallback(this, &HandlerOptionsHandler::RemoveIgnoredHandler)); | 65 NewCallback(this, &HandlerOptionsHandler::RemoveIgnoredHandler)); |
63 } | 66 } |
64 | 67 |
65 ProtocolHandlerRegistry* HandlerOptionsHandler::GetProtocolHandlerRegistry() { | 68 ProtocolHandlerRegistry* HandlerOptionsHandler::GetProtocolHandlerRegistry() { |
66 DCHECK(web_ui_); | 69 DCHECK(web_ui_); |
67 return web_ui_->GetProfile()->GetProtocolHandlerRegistry(); | 70 Profile* profile = |
| 71 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 72 return profile->GetProtocolHandlerRegistry(); |
68 } | 73 } |
69 | 74 |
70 static void GetHandlersAsListValue( | 75 static void GetHandlersAsListValue( |
71 const ProtocolHandlerRegistry::ProtocolHandlerList& handlers, | 76 const ProtocolHandlerRegistry::ProtocolHandlerList& handlers, |
72 ListValue* handler_list) { | 77 ListValue* handler_list) { |
73 ProtocolHandlerRegistry::ProtocolHandlerList::const_iterator handler; | 78 ProtocolHandlerRegistry::ProtocolHandlerList::const_iterator handler; |
74 for (handler = handlers.begin(); handler != handlers.end(); ++handler) { | 79 for (handler = handlers.begin(); handler != handlers.end(); ++handler) { |
75 ListValue* handlerValue = new ListValue(); | 80 ListValue* handlerValue = new ListValue(); |
76 handlerValue->Append(Value::CreateStringValue(handler->protocol())); | 81 handlerValue->Append(Value::CreateStringValue(handler->protocol())); |
77 handlerValue->Append(Value::CreateStringValue(handler->url().spec())); | 82 handlerValue->Append(Value::CreateStringValue(handler->url().spec())); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 195 } |
191 | 196 |
192 void HandlerOptionsHandler::Observe(int type, | 197 void HandlerOptionsHandler::Observe(int type, |
193 const NotificationSource& source, | 198 const NotificationSource& source, |
194 const NotificationDetails& details) { | 199 const NotificationDetails& details) { |
195 if (type == chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED) | 200 if (type == chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED) |
196 UpdateHandlerList(); | 201 UpdateHandlerList(); |
197 else | 202 else |
198 NOTREACHED(); | 203 NOTREACHED(); |
199 } | 204 } |
OLD | NEW |