OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ntp/new_tab_page_sync_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // plug in their own sync engine, we should allow this value to be | 25 // plug in their own sync engine, we should allow this value to be |
26 // configurable. | 26 // configurable. |
27 static const char kSyncDefaultViewOnlineUrl[] = "http://docs.google.com"; | 27 static const char kSyncDefaultViewOnlineUrl[] = "http://docs.google.com"; |
28 | 28 |
29 // TODO(idana): the following code was originally copied from | 29 // TODO(idana): the following code was originally copied from |
30 // toolbar_importer.h/cc and it needs to be moved to a common Google Accounts | 30 // toolbar_importer.h/cc and it needs to be moved to a common Google Accounts |
31 // utility. | 31 // utility. |
32 | 32 |
33 // A simple pair of fields that identify a set of Google cookies, used to | 33 // A simple pair of fields that identify a set of Google cookies, used to |
34 // filter from a larger set. | 34 // filter from a larger set. |
35 struct GoogleCookieFilter { | 35 // struct GoogleCookieFilter { |
36 // The generalized, fully qualified URL of pages where | 36 // // The generalized, fully qualified URL of pages where |
37 // cookies with id |cookie_id| are obtained / accessed. | 37 // // cookies with id |cookie_id| are obtained / accessed. |
38 const char* url; | 38 // const char* url; |
39 // The id of the cookie this filter is selecting, | 39 // // The id of the cookie this filter is selecting, |
40 // with name/value delimiter (i.e '='). | 40 // // with name/value delimiter (i.e '='). |
41 const char* cookie_id; | 41 // const char* cookie_id; |
42 }; | 42 // }; |
43 | 43 |
44 // Filters to select Google GAIA cookies. | 44 // // Filters to select Google GAIA cookies. |
45 static const GoogleCookieFilter kGAIACookieFilters[] = { | 45 // static const GoogleCookieFilter kGAIACookieFilters[] = { |
46 { "http://.google.com/", "SID=" }, // Gmail. | 46 // { "http://.google.com/", "SID=" }, // Gmail. |
47 // Add filters here for other interesting cookies that should result in | 47 // // Add filters here for other interesting cookies that should result in |
48 // showing the promotions (e.g ASIDAS for dasher accounts). | 48 // // showing the promotions (e.g ASIDAS for dasher accounts). |
49 }; | 49 // }; |
50 | |
51 bool IsGoogleGAIACookieInstalled() { | |
52 for (size_t i = 0; i < arraysize(kGAIACookieFilters); ++i) { | |
53 // Since we are running on the UI thread don't call GetURLRequestContext(). | |
54 net::CookieStore* store = | |
55 Profile::Deprecated::GetDefaultRequestContext()-> | |
56 DONTUSEME_GetCookieStore(); | |
57 GURL url(kGAIACookieFilters[i].url); | |
58 net::CookieOptions options; | |
59 options.set_include_httponly(); // The SID cookie might be httponly. | |
60 std::string cookies = store->GetCookiesWithOptions(url, options); | |
61 std::vector<std::string> cookie_list; | |
62 base::SplitString(cookies, ';', &cookie_list); | |
63 for (std::vector<std::string>::iterator current = cookie_list.begin(); | |
64 current != cookie_list.end(); | |
65 ++current) { | |
66 size_t position = | |
67 current->find(kGAIACookieFilters[i].cookie_id); | |
68 if (0 == position) | |
69 return true; | |
70 } | |
71 } | |
72 return false; | |
73 } | |
74 | 50 |
75 NewTabPageSyncHandler::NewTabPageSyncHandler() : sync_service_(NULL), | 51 NewTabPageSyncHandler::NewTabPageSyncHandler() : sync_service_(NULL), |
76 waiting_for_initial_page_load_(true) { | 52 waiting_for_initial_page_load_(true) { |
77 } | 53 } |
78 | 54 |
79 NewTabPageSyncHandler::~NewTabPageSyncHandler() { | 55 NewTabPageSyncHandler::~NewTabPageSyncHandler() { |
80 if (sync_service_) | 56 if (sync_service_) |
81 sync_service_->RemoveObserver(this); | 57 sync_service_->RemoveObserver(this); |
82 } | 58 } |
83 | 59 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 if (linkurl.empty()) { | 188 if (linkurl.empty()) { |
213 value.SetBoolean("linkurlisset", false); | 189 value.SetBoolean("linkurlisset", false); |
214 } else { | 190 } else { |
215 value.SetBoolean("linkurlisset", true); | 191 value.SetBoolean("linkurlisset", true); |
216 value.SetString("linkurl", linkurl); | 192 value.SetString("linkurl", linkurl); |
217 } | 193 } |
218 } | 194 } |
219 } | 195 } |
220 web_ui_->CallJavascriptFunction("syncMessageChanged", value); | 196 web_ui_->CallJavascriptFunction("syncMessageChanged", value); |
221 } | 197 } |
OLD | NEW |