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/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/ui/login_display_host_impl.h" | |
11 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" | |
9 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
10 #include "chromeos/chromeos_switches.h" | 13 #include "chromeos/chromeos_switches.h" |
11 #include "chromeos/network/network_handler.h" | 14 #include "chromeos/network/network_handler.h" |
12 #include "chromeos/network/network_state.h" | 15 #include "chromeos/network/network_state.h" |
13 #include "chromeos/network/network_state_handler.h" | 16 #include "chromeos/network/network_state_handler.h" |
17 #include "content/public/browser/web_contents.h" | |
18 #include "extensions/browser/guest_view/guest_view_manager.h" | |
19 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/gfx/image/image_skia.h" | 22 #include "ui/gfx/image/image_skia.h" |
17 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
18 | 24 |
19 namespace chromeos { | 25 namespace chromeos { |
20 | 26 |
27 namespace { | |
28 | |
29 // Gets the WebContents instance of current login display. If there is none, | |
30 // returns NULL. | |
31 content::WebContents* GetLoginWebContents() { | |
32 LoginDisplayHost* host = LoginDisplayHostImpl::default_host(); | |
33 if (!host || !host->GetWebUILoginView()) | |
34 return NULL; | |
35 | |
36 return host->GetWebUILoginView()->GetWebContents(); | |
37 } | |
38 | |
39 // Callback used by GetPartition below to return the first guest contents with a | |
40 // matching partition name. | |
41 bool FindGuestByPartitionName(const std::string& partition_name, | |
42 content::WebContents** out_guest_contents, | |
43 content::WebContents* guest_contents) { | |
44 std::string domain; | |
45 std::string name; | |
46 bool in_memory; | |
47 extensions::WebViewGuest::GetGuestPartitionConfigForSite( | |
48 guest_contents->GetSiteInstance()->GetSiteURL(), &domain, &name, | |
49 &in_memory); | |
50 if (partition_name != name) | |
51 return false; | |
52 | |
53 *out_guest_contents = guest_contents; | |
54 return true; | |
55 } | |
56 | |
57 // Gets the storage partition of guest contents of a given embedder. | |
58 // If a name is given, returns the partition associated with the name. | |
59 // Otherwise, returns the default shared in-memory partition. Returns NULL if a | |
60 // matching parition could not be found. | |
61 content::StoragePartition* GetPartition(content::WebContents* embedder, | |
62 const std::string& partition_name) { | |
63 extensions::GuestViewManager* manager = | |
64 extensions::GuestViewManager::FromBrowserContext( | |
65 embedder->GetBrowserContext()); | |
66 content::WebContents* guest_contents = nullptr; | |
67 manager->ForEachGuest(embedder, base::Bind(&FindGuestByPartitionName, | |
68 partition_name, &guest_contents)); | |
69 | |
70 return guest_contents ? content::BrowserContext::GetStoragePartition( | |
71 guest_contents->GetBrowserContext(), | |
72 guest_contents->GetSiteInstance()) | |
73 : nullptr; | |
74 } | |
75 | |
76 } // namespace | |
77 | |
21 gfx::Rect CalculateScreenBounds(const gfx::Size& size) { | 78 gfx::Rect CalculateScreenBounds(const gfx::Size& size) { |
22 gfx::Rect bounds = | 79 gfx::Rect bounds = |
23 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().bounds(); | 80 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().bounds(); |
24 if (!size.IsEmpty()) { | 81 if (!size.IsEmpty()) { |
25 int horizontal_diff = bounds.width() - size.width(); | 82 int horizontal_diff = bounds.width() - size.width(); |
26 int vertical_diff = bounds.height() - size.height(); | 83 int vertical_diff = bounds.height() - size.height(); |
27 bounds.Inset(horizontal_diff / 2, vertical_diff / 2); | 84 bounds.Inset(horizontal_diff / 2, vertical_diff / 2); |
28 } | 85 } |
29 return bounds; | 86 return bounds; |
30 } | 87 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 NULL; | 132 NULL; |
76 } | 133 } |
77 | 134 |
78 bool NetworkStateHelper::IsConnecting() const { | 135 bool NetworkStateHelper::IsConnecting() const { |
79 chromeos::NetworkStateHandler* nsh = | 136 chromeos::NetworkStateHandler* nsh = |
80 chromeos::NetworkHandler::Get()->network_state_handler(); | 137 chromeos::NetworkHandler::Get()->network_state_handler(); |
81 return nsh->ConnectingNetworkByType( | 138 return nsh->ConnectingNetworkByType( |
82 chromeos::NetworkTypePattern::Default()) != NULL; | 139 chromeos::NetworkTypePattern::Default()) != NULL; |
83 } | 140 } |
84 | 141 |
142 content::StoragePartition* GetSigninPartition() { | |
143 // Note the partition name must match the sign-in webview used. For now, | |
144 // this is the default unnamed, shared, in-memory partition. | |
145 return GetPartition(GetLoginWebContents(), std::string()); | |
dzhioev_at_google
2015/03/23 23:01:17
I'm adding another <webview> to OOBE page now, use
xiyuan
2015/03/23 23:10:48
I had a long discussion with Ivan in his https://c
| |
146 } | |
147 | |
85 } // namespace login | 148 } // namespace login |
86 | 149 |
87 } // namespace chromeos | 150 } // namespace chromeos |
OLD | NEW |