| 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" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/net/chrome_url_request_context.h" | 14 #include "chrome/browser/net/chrome_url_request_context.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "content/browser/renderer_host/render_view_host.h" | 16 #include "content/browser/renderer_host/render_view_host.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "net/base/cookie_monster.h" | 18 #include "net/base/cookie_monster.h" |
| 19 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 | 21 |
| 22 // Default URL for the sync web interface. | 22 // Default URL for the sync web interface. |
| 23 // | 23 // |
| 24 // TODO(idana): when we figure out how we are going to allow third parties to | 24 // TODO(idana): when we figure out how we are going to allow third parties to |
| 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 | |
| 30 // toolbar_importer.h/cc and it needs to be moved to a common Google Accounts | |
| 31 // utility. | |
| 32 | |
| 33 // A simple pair of fields that identify a set of Google cookies, used to | |
| 34 // filter from a larger set. | |
| 35 struct GoogleCookieFilter { | |
| 36 // The generalized, fully qualified URL of pages where | |
| 37 // cookies with id |cookie_id| are obtained / accessed. | |
| 38 const char* url; | |
| 39 // The id of the cookie this filter is selecting, | |
| 40 // with name/value delimiter (i.e '='). | |
| 41 const char* cookie_id; | |
| 42 }; | |
| 43 | |
| 44 // Filters to select Google GAIA cookies. | |
| 45 static const GoogleCookieFilter kGAIACookieFilters[] = { | |
| 46 { "http://.google.com/", "SID=" }, // Gmail. | |
| 47 // Add filters here for other interesting cookies that should result in | |
| 48 // showing the promotions (e.g ASIDAS for dasher accounts). | |
| 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 | |
| 75 NewTabPageSyncHandler::NewTabPageSyncHandler() : sync_service_(NULL), | 29 NewTabPageSyncHandler::NewTabPageSyncHandler() : sync_service_(NULL), |
| 76 waiting_for_initial_page_load_(true) { | 30 waiting_for_initial_page_load_(true) { |
| 77 } | 31 } |
| 78 | 32 |
| 79 NewTabPageSyncHandler::~NewTabPageSyncHandler() { | 33 NewTabPageSyncHandler::~NewTabPageSyncHandler() { |
| 80 if (sync_service_) | 34 if (sync_service_) |
| 81 sync_service_->RemoveObserver(this); | 35 sync_service_->RemoveObserver(this); |
| 82 } | 36 } |
| 83 | 37 |
| 84 // static | 38 // static |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 if (linkurl.empty()) { | 166 if (linkurl.empty()) { |
| 213 value.SetBoolean("linkurlisset", false); | 167 value.SetBoolean("linkurlisset", false); |
| 214 } else { | 168 } else { |
| 215 value.SetBoolean("linkurlisset", true); | 169 value.SetBoolean("linkurlisset", true); |
| 216 value.SetString("linkurl", linkurl); | 170 value.SetString("linkurl", linkurl); |
| 217 } | 171 } |
| 218 } | 172 } |
| 219 } | 173 } |
| 220 web_ui_->CallJavascriptFunction("syncMessageChanged", value); | 174 web_ui_->CallJavascriptFunction("syncMessageChanged", value); |
| 221 } | 175 } |
| OLD | NEW |