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

Side by Side Diff: chrome/browser/ui/webui/uber/uber_ui.cc

Issue 9967017: Upstream Android native crash handling changes. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: sync again Created 8 years, 8 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/uber/uber_ui.h" 5 #include "chrome/browser/ui/webui/uber/uber_ui.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/extensions/extension_service.h"
Mark Mentovai 2012/04/09 22:55:58 This too.
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 11 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
11 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 12 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
12 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 13 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
13 #include "chrome/browser/ui/webui/extensions/extensions_ui.h" 14 #include "chrome/browser/ui/webui/extensions/extensions_ui.h"
14 #include "chrome/browser/ui/webui/options2/options_ui2.h" 15 #include "chrome/browser/ui/webui/options2/options_ui2.h"
16 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_set.h"
15 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
16 #include "content/public/browser/navigation_controller.h" 20 #include "content/public/browser/navigation_controller.h"
17 #include "content/public/browser/navigation_entry.h" 21 #include "content/public/browser/navigation_entry.h"
22 #include "content/public/browser/notification_source.h"
18 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_ui.h" 24 #include "content/public/browser/web_ui.h"
20 #include "grit/browser_resources.h" 25 #include "grit/browser_resources.h"
21 #include "grit/chromium_strings.h" 26 #include "grit/chromium_strings.h"
22 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
23 28
24 using content::NavigationController; 29 using content::NavigationController;
25 using content::NavigationEntry; 30 using content::NavigationEntry;
26 using content::RenderViewHost; 31 using content::RenderViewHost;
27 using content::WebContents; 32 using content::WebContents;
(...skipping 25 matching lines...) Expand all
53 source->AddString("historyHost", 58 source->AddString("historyHost",
54 ASCIIToUTF16(chrome::kChromeUIHistoryHost)); 59 ASCIIToUTF16(chrome::kChromeUIHistoryHost));
55 source->AddString("settingsFrameURL", 60 source->AddString("settingsFrameURL",
56 ASCIIToUTF16(chrome::kChromeUISettingsFrameURL)); 61 ASCIIToUTF16(chrome::kChromeUISettingsFrameURL));
57 source->AddString("settingsHost", 62 source->AddString("settingsHost",
58 ASCIIToUTF16(chrome::kChromeUISettingsHost)); 63 ASCIIToUTF16(chrome::kChromeUISettingsHost));
59 64
60 return source; 65 return source;
61 } 66 }
62 67
63 ChromeWebUIDataSource* CreateUberFrameHTMLSource() { 68 // Determines whether the user has an active extension of the given type.
69 bool HasExtensionType(Profile* profile, const char* extensionType) {
70 const ExtensionSet* extensionSet =
71 profile->GetExtensionService()->extensions();
72
73 for (ExtensionSet::const_iterator iter = extensionSet->begin();
74 iter != extensionSet->end(); ++iter) {
75 Extension::URLOverrideMap map = (*iter)->GetChromeURLOverrides();
76 Extension::URLOverrideMap::const_iterator result =
77 map.find(std::string(extensionType));
78
79 if (result != map.end())
80 return true;
81 }
82
83 return false;
84 }
85
86 ChromeWebUIDataSource* CreateUberFrameHTMLSource(Profile* profile) {
64 ChromeWebUIDataSource* source = 87 ChromeWebUIDataSource* source =
65 new ChromeWebUIDataSource(chrome::kChromeUIUberFrameHost); 88 new ChromeWebUIDataSource(chrome::kChromeUIUberFrameHost);
66 89
67 source->set_json_path("strings.js"); 90 source->set_json_path("strings.js");
68 source->add_resource_path("uber_frame.js", IDR_UBER_FRAME_JS); 91 source->add_resource_path("uber_frame.js", IDR_UBER_FRAME_JS);
69 source->set_default_resource(IDR_UBER_FRAME_HTML); 92 source->set_default_resource(IDR_UBER_FRAME_HTML);
70 93
71 // TODO(jhawkins): Attempt to get rid of IDS_PRODUCT_OS_NAME. 94 // TODO(jhawkins): Attempt to get rid of IDS_PRODUCT_OS_NAME.
72 #if defined(OS_CHROMEOS) 95 #if defined(OS_CHROMEOS)
73 source->AddLocalizedString("shortProductName", IDS_PRODUCT_OS_NAME); 96 source->AddLocalizedString("shortProductName", IDS_PRODUCT_OS_NAME);
74 #else 97 #else
75 source->AddLocalizedString("shortProductName", IDS_SHORT_PRODUCT_NAME); 98 source->AddLocalizedString("shortProductName", IDS_SHORT_PRODUCT_NAME);
76 #endif // defined(OS_CHROMEOS) 99 #endif // defined(OS_CHROMEOS)
77 100
78 source->AddString("extensionsHost", 101 source->AddString("extensionsHost",
79 ASCIIToUTF16(chrome::kChromeUIExtensionsHost)); 102 ASCIIToUTF16(chrome::kChromeUIExtensionsHost));
80 source->AddLocalizedString("extensionsDisplayName", 103 source->AddLocalizedString("extensionsDisplayName",
81 IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); 104 IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE);
82 source->AddString("helpHost", 105 source->AddString("helpHost",
83 ASCIIToUTF16(chrome::kChromeUIHelpHost)); 106 ASCIIToUTF16(chrome::kChromeUIHelpHost));
84 source->AddLocalizedString("helpDisplayName", IDS_HELP_TITLE); 107 source->AddLocalizedString("helpDisplayName", IDS_HELP_TITLE);
85 source->AddString("historyHost", 108 source->AddString("historyHost",
86 ASCIIToUTF16(chrome::kChromeUIHistoryHost)); 109 ASCIIToUTF16(chrome::kChromeUIHistoryHost));
87 source->AddLocalizedString("historyDisplayName", IDS_HISTORY_TITLE); 110 source->AddLocalizedString("historyDisplayName", IDS_HISTORY_TITLE);
88 source->AddString("settingsHost", 111 source->AddString("settingsHost",
89 ASCIIToUTF16(chrome::kChromeUISettingsHost)); 112 ASCIIToUTF16(chrome::kChromeUISettingsHost));
90 source->AddLocalizedString("settingsDisplayName", IDS_SETTINGS_TITLE); 113 source->AddLocalizedString("settingsDisplayName", IDS_SETTINGS_TITLE);
114 bool overridesHistory = HasExtensionType(profile,
115 chrome::kChromeUIHistoryHost);
116 source->AddString("overridesHistory",
117 ASCIIToUTF16(overridesHistory ? "yes" : "no"));
91 118
92 return source; 119 return source;
93 } 120 }
94 121
95 } // namespace 122 } // namespace
96 123
97 UberUI::UberUI(content::WebUI* web_ui) : WebUIController(web_ui) { 124 UberUI::UberUI(content::WebUI* web_ui) : WebUIController(web_ui) {
98 Profile* profile = Profile::FromWebUI(web_ui); 125 Profile* profile = Profile::FromWebUI(web_ui);
99 profile->GetChromeURLDataManager()->AddDataSource(CreateUberHTMLSource()); 126 profile->GetChromeURLDataManager()->AddDataSource(CreateUberHTMLSource());
100 127
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // source_url, message, args); 190 // source_url, message, args);
164 subpage->second->ProcessWebUIMessage(source_url, message, args); 191 subpage->second->ProcessWebUIMessage(source_url, message, args);
165 return true; 192 return true;
166 } 193 }
167 194
168 // UberFrameUI 195 // UberFrameUI
169 196
170 UberFrameUI::UberFrameUI(content::WebUI* web_ui) : WebUIController(web_ui) { 197 UberFrameUI::UberFrameUI(content::WebUI* web_ui) : WebUIController(web_ui) {
171 Profile* profile = Profile::FromWebUI(web_ui); 198 Profile* profile = Profile::FromWebUI(web_ui);
172 profile->GetChromeURLDataManager()->AddDataSource( 199 profile->GetChromeURLDataManager()->AddDataSource(
173 CreateUberFrameHTMLSource()); 200 CreateUberFrameHTMLSource(profile));
201
202 // Register as an observer for when extensions are loaded and unloaded.
203 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
204 content::Source<Profile>(profile));
205 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
206 content::Source<Profile>(profile));
174 } 207 }
175 208
176 UberFrameUI::~UberFrameUI() { 209 UberFrameUI::~UberFrameUI() {
177 } 210 }
211
212 void UberFrameUI::Observe(int type, const content::NotificationSource& source,
213 const content::NotificationDetails& details) {
214 switch (type) {
215 // We listen for notifications that indicate an extension has been loaded
216 // (i.e., has been installed and/or enabled) or unloaded (i.e., has been
217 // uninstalled and/or disabled). If one of these events has occurred, then
218 // we must update the behavior of the History navigation element so that
219 // it opens the history extension if one is installed and enabled or
220 // opens the default history page if one is uninstalled or disabled.
221 case chrome::NOTIFICATION_EXTENSION_LOADED:
222 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
223 Profile* profile = Profile::FromWebUI(web_ui());
224 bool overridesHistory = HasExtensionType(profile,
225 chrome::kChromeUIHistoryHost);
226 scoped_ptr<Value> controlsValue(
227 Value::CreateStringValue(chrome::kChromeUIHistoryHost));
228 scoped_ptr<Value> overrideValue(
229 Value::CreateStringValue(overridesHistory ? "yes" : "no"));
230 web_ui()->CallJavascriptFunction(
231 "uber_frame.setNavigationOverride", *controlsValue, *overrideValue);
232 break;
233 }
234 default:
235 NOTREACHED();
236 }
237 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698