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

Side by Side Diff: chrome/browser/chromeos/login/helper.cc

Issue 1021383002: cros: Transfer auth cookies for SAML webview sign-in. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, break UserCloudPolicyManagerChromeOS dependency on UserSessionManager to fix tests Created 5 years, 9 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
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/chromeos/login/helper.h" 5 #include "chrome/browser/chromeos/login/helper.h"
6 6
7 #include "base/bind.h"
7 #include "base/command_line.h" 8 #include "base/command_line.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chromeos/login/startup_utils.h"
11 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
12 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
13 #include "chrome/browser/chromeos/profiles/profile_helper.h"
9 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
10 #include "chromeos/chromeos_switches.h" 15 #include "chromeos/chromeos_switches.h"
11 #include "chromeos/network/network_handler.h" 16 #include "chromeos/network/network_handler.h"
12 #include "chromeos/network/network_state.h" 17 #include "chromeos/network/network_state.h"
13 #include "chromeos/network/network_state_handler.h" 18 #include "chromeos/network/network_state_handler.h"
19 #include "content/public/browser/storage_partition.h"
20 #include "content/public/browser/web_contents.h"
21 #include "extensions/browser/guest_view/guest_view_manager.h"
22 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h" 23 #include "third_party/cros_system_api/dbus/service_constants.h"
15 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/gfx/image/image_skia.h" 25 #include "ui/gfx/image/image_skia.h"
17 #include "ui/gfx/screen.h" 26 #include "ui/gfx/screen.h"
18 27
19 namespace chromeos { 28 namespace chromeos {
20 29
30 namespace {
31
32 // Gets the WebContents instance of current login display. If there is none,
33 // returns nullptr.
34 content::WebContents* GetLoginWebContents() {
35 LoginDisplayHost* host = LoginDisplayHostImpl::default_host();
36 if (!host || !host->GetWebUILoginView())
37 return nullptr;
38
39 return host->GetWebUILoginView()->GetWebContents();
40 }
41
42 // Callback used by GetPartition below to return the first guest contents with a
43 // matching partition name.
44 bool FindGuestByPartitionName(const std::string& partition_name,
45 content::WebContents** out_guest_contents,
46 content::WebContents* guest_contents) {
47 std::string domain;
48 std::string name;
49 bool in_memory;
50 extensions::WebViewGuest::GetGuestPartitionConfigForSite(
51 guest_contents->GetSiteInstance()->GetSiteURL(), &domain, &name,
52 &in_memory);
53 if (partition_name != name)
54 return false;
55
56 *out_guest_contents = guest_contents;
57 return true;
58 }
59
60 // Gets the storage partition of guest contents of a given embedder.
61 // If a name is given, returns the partition associated with the name.
62 // Otherwise, returns the default shared in-memory partition. Returns nullptr if
63 // a matching partition could not be found.
64 content::StoragePartition* GetPartition(content::WebContents* embedder,
65 const std::string& partition_name) {
66 extensions::GuestViewManager* manager =
67 extensions::GuestViewManager::FromBrowserContext(
68 embedder->GetBrowserContext());
69 content::WebContents* guest_contents = nullptr;
70 manager->ForEachGuest(embedder, base::Bind(&FindGuestByPartitionName,
71 partition_name, &guest_contents));
72
73 return guest_contents ? content::BrowserContext::GetStoragePartition(
74 guest_contents->GetBrowserContext(),
75 guest_contents->GetSiteInstance())
76 : nullptr;
77 }
78
79 } // namespace
80
21 gfx::Rect CalculateScreenBounds(const gfx::Size& size) { 81 gfx::Rect CalculateScreenBounds(const gfx::Size& size) {
22 gfx::Rect bounds = 82 gfx::Rect bounds =
23 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().bounds(); 83 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().bounds();
24 if (!size.IsEmpty()) { 84 if (!size.IsEmpty()) {
25 int horizontal_diff = bounds.width() - size.width(); 85 int horizontal_diff = bounds.width() - size.width();
26 int vertical_diff = bounds.height() - size.height(); 86 int vertical_diff = bounds.height() - size.height();
27 bounds.Inset(horizontal_diff / 2, vertical_diff / 2); 87 bounds.Inset(horizontal_diff / 2, vertical_diff / 2);
28 } 88 }
29 return bounds; 89 return bounds;
30 } 90 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 NULL; 135 NULL;
76 } 136 }
77 137
78 bool NetworkStateHelper::IsConnecting() const { 138 bool NetworkStateHelper::IsConnecting() const {
79 chromeos::NetworkStateHandler* nsh = 139 chromeos::NetworkStateHandler* nsh =
80 chromeos::NetworkHandler::Get()->network_state_handler(); 140 chromeos::NetworkHandler::Get()->network_state_handler();
81 return nsh->ConnectingNetworkByType( 141 return nsh->ConnectingNetworkByType(
82 chromeos::NetworkTypePattern::Default()) != NULL; 142 chromeos::NetworkTypePattern::Default()) != NULL;
83 } 143 }
84 144
145 content::StoragePartition* GetSigninPartition() {
146 // Note the partition name must match the sign-in webview used. For now,
147 // this is the default unnamed, shared, in-memory partition.
148 return GetPartition(GetLoginWebContents(), std::string());
149 }
150
151 net::URLRequestContextGetter* GetSigninContext() {
152 if (StartupUtils::IsWebviewSigninEnabled())
153 return GetSigninPartition()->GetURLRequestContext();
154
155 return ProfileHelper::GetSigninProfile()->GetRequestContext();
156 }
157
85 } // namespace login 158 } // namespace login
86 159
87 } // namespace chromeos 160 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698