OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/signin/inline_login_ui.h" | 5 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" |
6 | 6 |
7 #include "base/files/file_util.h" | |
8 #include "base/path_service.h" | |
9 #include "base/strings/string_split.h" | |
7 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 10 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
8 #include "chrome/browser/extensions/tab_helper.h" | 11 #include "chrome/browser/extensions/tab_helper.h" |
9 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sessions/session_tab_helper.h" | 13 #include "chrome/browser/sessions/session_tab_helper.h" |
14 #include "chrome/common/chrome_paths.h" | |
11 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
12 #include "chrome/grit/chromium_strings.h" | 16 #include "chrome/grit/chromium_strings.h" |
13 #include "components/signin/core/common/profile_management_switches.h" | 17 #include "components/signin/core/common/profile_management_switches.h" |
14 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
15 #include "content/public/browser/web_ui.h" | 19 #include "content/public/browser/web_ui.h" |
16 #include "content/public/browser/web_ui_data_source.h" | 20 #include "content/public/browser/web_ui_data_source.h" |
17 #include "extensions/browser/guest_view/guest_view_manager.h" | 21 #include "extensions/browser/guest_view/guest_view_manager.h" |
18 #include "grit/browser_resources.h" | 22 #include "grit/browser_resources.h" |
19 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
20 #include "chrome/browser/chromeos/login/startup_utils.h" | 24 #include "chrome/browser/chromeos/login/startup_utils.h" |
21 #include "chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h " | 25 #include "chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h " |
22 #else | 26 #else |
23 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" | 27 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" |
24 #endif | 28 #endif |
25 | 29 |
26 namespace { | 30 namespace { |
27 | 31 |
32 bool HandleTestFileRequestCallback( | |
33 const std::string& path, | |
34 const content::WebUIDataSource::GotDataCallback& callback) { | |
35 std::vector<std::string> url_substr; | |
36 base::SplitString(path, '/', &url_substr); | |
37 if (url_substr.size() != 2 || url_substr[0] != "test") | |
38 return false; | |
39 | |
40 std::string contents; | |
41 base::FilePath test_data_dir; | |
42 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | |
43 if (!base::ReadFileToString( | |
44 test_data_dir.AppendASCII("webui").AppendASCII(url_substr[1]), | |
45 &contents, | |
46 std::string::npos)) | |
47 return false; | |
48 | |
49 base::RefCountedString* ref_contents = new base::RefCountedString(); | |
50 ref_contents->data() = contents; | |
51 callback.Run(ref_contents); | |
52 return true; | |
53 } | |
54 | |
28 content::WebUIDataSource* CreateWebUIDataSource() { | 55 content::WebUIDataSource* CreateWebUIDataSource() { |
29 content::WebUIDataSource* source = | 56 content::WebUIDataSource* source = |
30 content::WebUIDataSource::Create(chrome::kChromeUIChromeSigninHost); | 57 content::WebUIDataSource::Create(chrome::kChromeUIChromeSigninHost); |
31 source->OverrideContentSecurityPolicyFrameSrc("frame-src chrome-extension:;"); | 58 source->OverrideContentSecurityPolicyFrameSrc("frame-src chrome-extension:;"); |
32 source->OverrideContentSecurityPolicyObjectSrc("object-src *;"); | 59 source->OverrideContentSecurityPolicyObjectSrc("object-src *;"); |
33 source->SetJsonPath("strings.js"); | 60 source->SetJsonPath("strings.js"); |
34 | 61 |
35 bool is_webview_signin_enabled = switches::IsEnableWebviewBasedSignin(); | 62 bool is_webview_signin_enabled = switches::IsEnableWebviewBasedSignin(); |
36 source->SetDefaultResource(is_webview_signin_enabled ? | 63 source->SetDefaultResource(is_webview_signin_enabled ? |
37 IDR_NEW_INLINE_LOGIN_HTML : IDR_INLINE_LOGIN_HTML); | 64 IDR_NEW_INLINE_LOGIN_HTML : IDR_INLINE_LOGIN_HTML); |
65 source->SetRequestFilter(base::Bind(&HandleTestFileRequestCallback)); | |
xiyuan
2015/03/18 16:11:04
We should only add this when the code runs as test
Xi Han
2015/03/18 20:36:26
That is also what my concern is. Thanks!
| |
38 source->AddResourcePath("inline_login.css", IDR_INLINE_LOGIN_CSS); | 66 source->AddResourcePath("inline_login.css", IDR_INLINE_LOGIN_CSS); |
39 source->AddResourcePath("inline_login.js", IDR_INLINE_LOGIN_JS); | 67 source->AddResourcePath("inline_login.js", IDR_INLINE_LOGIN_JS); |
40 source->AddResourcePath("gaia_auth_host.js", is_webview_signin_enabled ? | 68 source->AddResourcePath("gaia_auth_host.js", is_webview_signin_enabled ? |
41 IDR_GAIA_AUTH_AUTHENTICATOR_JS : IDR_GAIA_AUTH_HOST_JS); | 69 IDR_GAIA_AUTH_AUTHENTICATOR_JS : IDR_GAIA_AUTH_HOST_JS); |
42 | 70 |
43 source->AddLocalizedString("title", IDS_CHROME_SIGNIN_TITLE); | 71 source->AddLocalizedString("title", IDS_CHROME_SIGNIN_TITLE); |
44 return source; | 72 return source; |
45 } | 73 } |
46 | 74 |
47 void AddToSetIfIsAuthIframe(std::set<content::RenderFrameHost*>* frame_set, | 75 void AddToSetIfIsAuthIframe(std::set<content::RenderFrameHost*>* frame_set, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 web_contents->ForEachFrame( | 138 web_contents->ForEachFrame( |
111 base::Bind(&AddToSetIfIsAuthIframe, &frame_set, | 139 base::Bind(&AddToSetIfIsAuthIframe, &frame_set, |
112 parent_origin, parent_frame_name)); | 140 parent_origin, parent_frame_name)); |
113 } | 141 } |
114 DCHECK_GE(1U, frame_set.size()); | 142 DCHECK_GE(1U, frame_set.size()); |
115 if (!frame_set.empty()) | 143 if (!frame_set.empty()) |
116 return *frame_set.begin(); | 144 return *frame_set.begin(); |
117 | 145 |
118 return NULL; | 146 return NULL; |
119 } | 147 } |
OLD | NEW |