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/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 "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 9 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
10 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 10 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
11 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" | 11 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
12 #include "chrome/browser/ui/webui/extensions/extensions_ui.h" | 12 #include "chrome/browser/ui/webui/extensions/extensions_ui.h" |
13 #include "chrome/browser/ui/webui/options/options_ui.h" | 13 #include "chrome/browser/ui/webui/options2/options_ui2.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
16 #include "grit/browser_resources.h" | 16 #include "grit/browser_resources.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 ChromeWebUIDataSource* CreateUberHTMLSource() { | 20 ChromeWebUIDataSource* CreateUberHTMLSource() { |
21 ChromeWebUIDataSource* source = | 21 ChromeWebUIDataSource* source = |
22 new ChromeWebUIDataSource(chrome::kChromeUIUberHost); | 22 new ChromeWebUIDataSource(chrome::kChromeUIUberHost); |
23 | 23 |
24 source->set_json_path("strings.js"); | 24 source->set_json_path("strings.js"); |
25 source->add_resource_path("uber.js", IDR_UBER_JS); | 25 source->add_resource_path("uber.js", IDR_UBER_JS); |
26 source->set_default_resource(IDR_UBER_HTML); | 26 source->set_default_resource(IDR_UBER_HTML); |
27 return source; | 27 return source; |
28 } | 28 } |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 UberUI::UberUI(TabContents* contents) : ChromeWebUI(contents) { | 32 UberUI::UberUI(TabContents* contents) : ChromeWebUI(contents) { |
33 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 33 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
34 profile->GetChromeURLDataManager()->AddDataSource(CreateUberHTMLSource()); | 34 profile->GetChromeURLDataManager()->AddDataSource(CreateUberHTMLSource()); |
35 | 35 |
36 RegisterSubpage(chrome::kChromeUISettingsURL); | 36 RegisterSubpage(chrome::kChromeUISettingsFrameURL); |
37 RegisterSubpage(chrome::kChromeUIExtensionsFrameURL); | 37 RegisterSubpage(chrome::kChromeUIExtensionsFrameURL); |
38 } | 38 } |
39 | 39 |
40 UberUI::~UberUI() { | 40 UberUI::~UberUI() { |
41 STLDeleteValues(&sub_uis_); | 41 STLDeleteValues(&sub_uis_); |
42 } | 42 } |
43 | 43 |
44 void UberUI::RegisterSubpage(const std::string& page_url) { | 44 void UberUI::RegisterSubpage(const std::string& page_url) { |
45 ChromeWebUI* web_ui = static_cast<ChromeWebUI*>( | 45 ChromeWebUI* web_ui = static_cast<ChromeWebUI*>( |
46 ChromeWebUIFactory::GetInstance()->CreateWebUIForURL(tab_contents_, | 46 ChromeWebUIFactory::GetInstance()->CreateWebUIForURL(tab_contents_, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 SubpageMap::iterator subpage = sub_uis_.find(source_url.GetOrigin().spec()); | 84 SubpageMap::iterator subpage = sub_uis_.find(source_url.GetOrigin().spec()); |
85 if (subpage == sub_uis_.end()) { | 85 if (subpage == sub_uis_.end()) { |
86 // The message was sent from the uber page itself. | 86 // The message was sent from the uber page itself. |
87 DCHECK_EQ(std::string(chrome::kChromeUIUberHost), source_url.host()); | 87 DCHECK_EQ(std::string(chrome::kChromeUIUberHost), source_url.host()); |
88 ChromeWebUI::OnWebUISend(source_url, message, args); | 88 ChromeWebUI::OnWebUISend(source_url, message, args); |
89 } else { | 89 } else { |
90 // The message was sent from a subpage. | 90 // The message was sent from a subpage. |
91 subpage->second->OnWebUISend(source_url, message, args); | 91 subpage->second->OnWebUISend(source_url, message, args); |
92 } | 92 } |
93 } | 93 } |
OLD | NEW |