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/extensions/api/identity/web_auth_flow.h" | 5 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" |
6 | 6 |
7 #include "apps/app_window.h" | |
8 #include "base/base64.h" | 7 #include "base/base64.h" |
9 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
10 #include "base/location.h" | 9 #include "base/location.h" |
11 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/extensions/component_loader.h" | 13 #include "chrome/browser/extensions/component_loader.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/extensions/api/identity_private.h" | 16 #include "chrome/common/extensions/api/identity_private.h" |
18 #include "chrome/common/extensions/extension_constants.h" | 17 #include "chrome/common/extensions/extension_constants.h" |
19 #include "content/public/browser/navigation_details.h" | 18 #include "content/public/browser/navigation_details.h" |
20 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
21 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
22 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
24 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
25 #include "content/public/browser/render_frame_host.h" | 24 #include "content/public/browser/render_frame_host.h" |
26 #include "content/public/browser/resource_request_details.h" | 25 #include "content/public/browser/resource_request_details.h" |
27 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
28 #include "crypto/random.h" | 27 #include "crypto/random.h" |
| 28 #include "extensions/browser/app_window/app_window.h" |
29 #include "extensions/browser/event_router.h" | 29 #include "extensions/browser/event_router.h" |
30 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
31 #include "extensions/browser/guest_view/guest_view_base.h" | 31 #include "extensions/browser/guest_view/guest_view_base.h" |
32 #include "grit/browser_resources.h" | 32 #include "grit/browser_resources.h" |
33 #include "url/gurl.h" | 33 #include "url/gurl.h" |
34 | 34 |
35 using apps::AppWindow; | |
36 using content::RenderViewHost; | 35 using content::RenderViewHost; |
37 using content::ResourceRedirectDetails; | 36 using content::ResourceRedirectDetails; |
38 using content::WebContents; | 37 using content::WebContents; |
39 using content::WebContentsObserver; | 38 using content::WebContentsObserver; |
40 | 39 |
41 namespace extensions { | 40 namespace extensions { |
42 | 41 |
43 namespace identity_private = api::identity_private; | 42 namespace identity_private = api::identity_private; |
44 | 43 |
45 WebAuthFlow::WebAuthFlow( | 44 WebAuthFlow::WebAuthFlow( |
(...skipping 10 matching lines...) Expand all Loading... |
56 | 55 |
57 WebAuthFlow::~WebAuthFlow() { | 56 WebAuthFlow::~WebAuthFlow() { |
58 DCHECK(delegate_ == NULL); | 57 DCHECK(delegate_ == NULL); |
59 | 58 |
60 // Stop listening to notifications first since some of the code | 59 // Stop listening to notifications first since some of the code |
61 // below may generate notifications. | 60 // below may generate notifications. |
62 registrar_.RemoveAll(); | 61 registrar_.RemoveAll(); |
63 WebContentsObserver::Observe(NULL); | 62 WebContentsObserver::Observe(NULL); |
64 | 63 |
65 if (!app_window_key_.empty()) { | 64 if (!app_window_key_.empty()) { |
66 apps::AppWindowRegistry::Get(profile_)->RemoveObserver(this); | 65 AppWindowRegistry::Get(profile_)->RemoveObserver(this); |
67 | 66 |
68 if (app_window_ && app_window_->web_contents()) | 67 if (app_window_ && app_window_->web_contents()) |
69 app_window_->web_contents()->Close(); | 68 app_window_->web_contents()->Close(); |
70 } | 69 } |
71 } | 70 } |
72 | 71 |
73 void WebAuthFlow::Start() { | 72 void WebAuthFlow::Start() { |
74 apps::AppWindowRegistry::Get(profile_)->AddObserver(this); | 73 AppWindowRegistry::Get(profile_)->AddObserver(this); |
75 | 74 |
76 // Attach a random ID string to the window so we can recoginize it | 75 // Attach a random ID string to the window so we can recoginize it |
77 // in OnAppWindowAdded. | 76 // in OnAppWindowAdded. |
78 std::string random_bytes; | 77 std::string random_bytes; |
79 crypto::RandBytes(WriteInto(&random_bytes, 33), 32); | 78 crypto::RandBytes(WriteInto(&random_bytes, 33), 32); |
80 base::Base64Encode(random_bytes, &app_window_key_); | 79 base::Base64Encode(random_bytes, &app_window_key_); |
81 | 80 |
82 // identityPrivate.onWebFlowRequest(app_window_key, provider_url_, mode_) | 81 // identityPrivate.onWebFlowRequest(app_window_key, provider_url_, mode_) |
83 scoped_ptr<base::ListValue> args(new base::ListValue()); | 82 scoped_ptr<base::ListValue> args(new base::ListValue()); |
84 args->AppendString(app_window_key_); | 83 args->AppendString(app_window_key_); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 236 } |
238 | 237 |
239 void WebAuthFlow::DidNavigateMainFrame( | 238 void WebAuthFlow::DidNavigateMainFrame( |
240 const content::LoadCommittedDetails& details, | 239 const content::LoadCommittedDetails& details, |
241 const content::FrameNavigateParams& params) { | 240 const content::FrameNavigateParams& params) { |
242 if (delegate_ && details.http_status_code >= 400) | 241 if (delegate_ && details.http_status_code >= 400) |
243 delegate_->OnAuthFlowFailure(LOAD_FAILED); | 242 delegate_->OnAuthFlowFailure(LOAD_FAILED); |
244 } | 243 } |
245 | 244 |
246 } // namespace extensions | 245 } // namespace extensions |
OLD | NEW |