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 "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 7 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/sessions/session_tab_helper.h" | 9 #include "chrome/browser/sessions/session_tab_helper.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
11 #include "content/public/browser/render_frame_host.h" | |
11 #include "content/public/browser/web_ui.h" | 12 #include "content/public/browser/web_ui.h" |
12 #include "content/public/browser/web_ui_data_source.h" | 13 #include "content/public/browser/web_ui_data_source.h" |
13 #include "grit/browser_resources.h" | 14 #include "grit/browser_resources.h" |
14 #include "grit/chromium_strings.h" | 15 #include "grit/chromium_strings.h" |
15 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
16 #include "chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h " | 17 #include "chrome/browser/ui/webui/chromeos/login/inline_login_handler_chromeos.h " |
17 #else | 18 #else |
18 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" | 19 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" |
19 #endif | 20 #endif |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 content::WebUIDataSource* CreateWebUIDataSource() { | 24 content::WebUIDataSource* CreateWebUIDataSource() { |
24 content::WebUIDataSource* source = | 25 content::WebUIDataSource* source = |
25 content::WebUIDataSource::Create(chrome::kChromeUIChromeSigninHost); | 26 content::WebUIDataSource::Create(chrome::kChromeUIChromeSigninHost); |
26 source->OverrideContentSecurityPolicyFrameSrc("frame-src chrome-extension:;"); | 27 source->OverrideContentSecurityPolicyFrameSrc("frame-src chrome-extension:;"); |
27 source->SetUseJsonJSFormatV2(); | 28 source->SetUseJsonJSFormatV2(); |
28 source->SetJsonPath("strings.js"); | 29 source->SetJsonPath("strings.js"); |
29 | 30 |
30 source->SetDefaultResource(IDR_INLINE_LOGIN_HTML); | 31 source->SetDefaultResource(IDR_INLINE_LOGIN_HTML); |
31 source->AddResourcePath("inline_login.css", IDR_INLINE_LOGIN_CSS); | 32 source->AddResourcePath("inline_login.css", IDR_INLINE_LOGIN_CSS); |
32 source->AddResourcePath("inline_login.js", IDR_INLINE_LOGIN_JS); | 33 source->AddResourcePath("inline_login.js", IDR_INLINE_LOGIN_JS); |
33 | 34 |
34 source->AddLocalizedString("title", IDS_CHROME_SIGNIN_TITLE); | 35 source->AddLocalizedString("title", IDS_CHROME_SIGNIN_TITLE); |
35 return source; | 36 return source; |
36 }; | 37 } |
38 | |
39 void AddToSetIfIsAuthIframe(std::set<content::RenderFrameHost*>* frame_set, | |
40 const GURL& parent_origin, | |
41 const std::string& parent_frame_name, | |
42 content::RenderFrameHost* frame) { | |
43 content::RenderFrameHost* parent = frame->GetParent(); | |
44 if (parent && parent->GetFrameName() == parent_frame_name && | |
45 (parent_origin.is_empty() || | |
46 parent->GetLastCommittedURL().GetOrigin() == parent_origin)) { | |
47 frame_set->insert(frame); | |
48 } | |
49 } | |
37 | 50 |
38 } // empty namespace | 51 } // empty namespace |
39 | 52 |
40 InlineLoginUI::InlineLoginUI(content::WebUI* web_ui) | 53 InlineLoginUI::InlineLoginUI(content::WebUI* web_ui) |
41 : WebDialogUI(web_ui), | 54 : WebDialogUI(web_ui), |
42 auth_extension_(Profile::FromWebUI(web_ui)) { | 55 auth_extension_(Profile::FromWebUI(web_ui)) { |
43 Profile* profile = Profile::FromWebUI(web_ui); | 56 Profile* profile = Profile::FromWebUI(web_ui); |
44 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); | 57 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); |
45 | 58 |
46 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
47 web_ui->AddMessageHandler(new chromeos::InlineLoginHandlerChromeOS()); | 60 web_ui->AddMessageHandler(new chromeos::InlineLoginHandlerChromeOS()); |
48 #else | 61 #else |
49 web_ui->AddMessageHandler(new InlineLoginHandlerImpl()); | 62 web_ui->AddMessageHandler(new InlineLoginHandlerImpl()); |
50 #endif | 63 #endif |
51 content::WebContents* contents = web_ui->GetWebContents(); | 64 content::WebContents* contents = web_ui->GetWebContents(); |
52 // Required for intercepting extension function calls when the page is loaded | 65 // Required for intercepting extension function calls when the page is loaded |
53 // in a bubble (not a full tab, thus tab helpers are not registered | 66 // in a bubble (not a full tab, thus tab helpers are not registered |
54 // automatically). | 67 // automatically). |
55 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 68 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
56 contents); | 69 contents); |
57 // Ensure that the login UI has a tab ID, which will allow the GAIA auth | 70 // Ensure that the login UI has a tab ID, which will allow the GAIA auth |
58 // extension's background script to tell it apart from iframes injected by | 71 // extension's background script to tell it apart from iframes injected by |
59 // other extensions. | 72 // other extensions. |
60 SessionTabHelper::CreateForWebContents(contents); | 73 SessionTabHelper::CreateForWebContents(contents); |
61 } | 74 } |
62 | 75 |
63 InlineLoginUI::~InlineLoginUI() {} | 76 InlineLoginUI::~InlineLoginUI() {} |
77 | |
78 // Gets the Gaia iframe within a WebContents. | |
79 content::RenderFrameHost* InlineLoginUI::GetAuthIframe( | |
80 content::WebContents* web_contents, | |
81 const GURL& parent_origin, | |
82 const std::string& parent_frame_name) { | |
83 std::set<content::RenderFrameHost*> frame_set; | |
84 web_contents->ForEachFrame( | |
85 base::Bind(&AddToSetIfIsAuthIframe, &frame_set, | |
86 parent_origin, parent_frame_name)); | |
87 DCHECK_GE(1U, frame_set.size()); | |
88 if (!frame_set.empty()) | |
89 return *frame_set.begin(); | |
90 else | |
Charlie Reis
2014/07/23 21:42:00
nit: No need for an else block, since we return in
guohui
2014/07/23 21:57:51
Done.
| |
91 return NULL; | |
92 } | |
OLD | NEW |