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/uber/uber_ui.h" | 5 #include "chrome/browser/ui/webui/uber/uber_ui.h" |
6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
7 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
8 #include "build/build_config.h" | 9 #include "build/build_config.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 11 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
11 #include "chrome/browser/ui/webui/extensions/extensions_ui.h" | 12 #include "chrome/browser/ui/webui/extensions/extensions_ui.h" |
12 #include "chrome/browser/ui/webui/log_web_ui_url.h" | 13 #include "chrome/browser/ui/webui/log_web_ui_url.h" |
13 #include "chrome/browser/ui/webui/md_history_ui.h" | 14 #include "chrome/browser/ui/webui/md_history_ui.h" |
14 #include "chrome/browser/ui/webui/options/options_ui.h" | 15 #include "chrome/browser/ui/webui/options/options_ui.h" |
15 #include "chrome/common/chrome_features.h" | 16 #include "chrome/common/chrome_features.h" |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 chrome::kChromeUIHelpHost); | 168 chrome::kChromeUIHelpHost); |
168 RegisterSubpage(chrome::kChromeUIHistoryFrameURL, | 169 RegisterSubpage(chrome::kChromeUIHistoryFrameURL, |
169 chrome::kChromeUIHistoryHost); | 170 chrome::kChromeUIHistoryHost); |
170 RegisterSubpage(chrome::kChromeUISettingsFrameURL, | 171 RegisterSubpage(chrome::kChromeUISettingsFrameURL, |
171 chrome::kChromeUISettingsHost); | 172 chrome::kChromeUISettingsHost); |
172 RegisterSubpage(chrome::kChromeUIUberFrameURL, | 173 RegisterSubpage(chrome::kChromeUIUberFrameURL, |
173 chrome::kChromeUIUberHost); | 174 chrome::kChromeUIUberHost); |
174 } | 175 } |
175 | 176 |
176 UberUI::~UberUI() { | 177 UberUI::~UberUI() { |
177 base::STLDeleteValues(&sub_uis_); | |
178 } | 178 } |
179 | 179 |
180 void UberUI::RegisterSubpage(const std::string& page_url, | 180 void UberUI::RegisterSubpage(const std::string& page_url, |
181 const std::string& page_host) { | 181 const std::string& page_host) { |
182 sub_uis_[page_url] = web_ui()->GetWebContents()->CreateSubframeWebUI( | 182 sub_uis_[page_url] = web_ui()->GetWebContents()->CreateSubframeWebUI( |
183 GURL(page_url), page_host); | 183 GURL(page_url), page_host); |
184 } | 184 } |
185 | 185 |
186 content::WebUI* UberUI::GetSubpage(const std::string& page_url) { | 186 content::WebUI* UberUI::GetSubpage(const std::string& page_url) { |
187 if (!base::ContainsKey(sub_uis_, page_url)) | 187 if (!base::ContainsKey(sub_uis_, page_url)) |
188 return NULL; | 188 return nullptr; |
189 return sub_uis_[page_url]; | 189 return sub_uis_[page_url].get(); |
190 } | 190 } |
191 | 191 |
192 void UberUI::RenderViewCreated(RenderViewHost* render_view_host) { | 192 void UberUI::RenderViewCreated(RenderViewHost* render_view_host) { |
193 for (SubpageMap::iterator iter = sub_uis_.begin(); iter != sub_uis_.end(); | 193 for (auto iter = sub_uis_.begin(); iter != sub_uis_.end(); ++iter) { |
194 ++iter) { | |
195 iter->second->GetController()->RenderViewCreated(render_view_host); | 194 iter->second->GetController()->RenderViewCreated(render_view_host); |
196 } | 195 } |
197 } | 196 } |
198 | 197 |
199 bool UberUI::OverrideHandleWebUIMessage(const GURL& source_url, | 198 bool UberUI::OverrideHandleWebUIMessage(const GURL& source_url, |
200 const std::string& message, | 199 const std::string& message, |
201 const base::ListValue& args) { | 200 const base::ListValue& args) { |
202 // Find the appropriate subpage and forward the message. | 201 // Find the appropriate subpage and forward the message. |
203 SubpageMap::iterator subpage = sub_uis_.find(source_url.GetOrigin().spec()); | 202 auto subpage = sub_uis_.find(source_url.GetOrigin().spec()); |
204 if (subpage == sub_uis_.end()) { | 203 if (subpage == sub_uis_.end()) { |
205 // The message was sent from the uber page itself. | 204 // The message was sent from the uber page itself. |
206 DCHECK_EQ(std::string(chrome::kChromeUIUberHost), source_url.host()); | 205 DCHECK_EQ(std::string(chrome::kChromeUIUberHost), source_url.host()); |
207 return false; | 206 return false; |
208 } | 207 } |
209 | 208 |
210 // The message was sent from a subpage. | 209 // The message was sent from a subpage. |
211 // TODO(jam) fix this to use interface | 210 // TODO(jam) fix this to use interface |
212 // return subpage->second->GetController()->OverrideHandleWebUIMessage( | 211 // return subpage->second->GetController()->OverrideHandleWebUIMessage( |
213 // source_url, message, args); | 212 // source_url, message, args); |
(...skipping 29 matching lines...) Expand all Loading... |
243 // opens the default history page if one is uninstalled or disabled. | 242 // opens the default history page if one is uninstalled or disabled. |
244 UpdateHistoryNavigation(web_ui()); | 243 UpdateHistoryNavigation(web_ui()); |
245 } | 244 } |
246 | 245 |
247 void UberFrameUI::OnExtensionUnloaded( | 246 void UberFrameUI::OnExtensionUnloaded( |
248 content::BrowserContext* browser_context, | 247 content::BrowserContext* browser_context, |
249 const extensions::Extension* extension, | 248 const extensions::Extension* extension, |
250 extensions::UnloadedExtensionInfo::Reason reason) { | 249 extensions::UnloadedExtensionInfo::Reason reason) { |
251 UpdateHistoryNavigation(web_ui()); | 250 UpdateHistoryNavigation(web_ui()); |
252 } | 251 } |
OLD | NEW |