| 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/extensions/app_notify_channel_setup.h" | 5 #include "chrome/browser/extensions/app_notify_channel_setup.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 using content::URLFetcher; | 31 using content::URLFetcher; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 static const char kChannelSetupAuthError[] = "unauthorized"; | 34 static const char kChannelSetupAuthError[] = "unauthorized"; |
| 35 static const char kChannelSetupInternalError[] = "internal_error"; | 35 static const char kChannelSetupInternalError[] = "internal_error"; |
| 36 static const char kChannelSetupCanceledByUser[] = "canceled_by_user"; | 36 static const char kChannelSetupCanceledByUser[] = "canceled_by_user"; |
| 37 // TODO(munjal): Change these to use production URLs when we have them. | 37 // TODO(munjal): Change these to use production URLs when we have them. |
| 38 static const char kAuthorizationHeaderFormat[] = | 38 static const char kAuthorizationHeaderFormat[] = |
| 39 "Authorization: GoogleLogin auth=%s"; | 39 "Authorization: GoogleLogin auth=%s"; |
| 40 static const char kOAuth2IssueTokenURL[] = | 40 static const char kOAuth2IssueTokenURL[] = |
| 41 "https://www-googleapis-staging.sandbox.google.com/oauth2/v2/IssueToken"; | 41 "https://www.googleapis.com/oauth2/v2/IssueToken"; |
| 42 static const char kOAuth2IssueTokenBodyFormat[] = | 42 static const char kOAuth2IssueTokenBodyFormat[] = |
| 43 "force=true" | 43 "force=true" |
| 44 "&response_type=token" | 44 "&response_type=token" |
| 45 "&scope=%s" | 45 "&scope=%s" |
| 46 "&client_id=%s" | 46 "&client_id=%s" |
| 47 "&origin=%s"; | 47 "&origin=%s"; |
| 48 static const char kOAuth2IssueTokenScope[] = | 48 static const char kOAuth2IssueTokenScope[] = |
| 49 "https://www.googleapis.com/auth/chromewebstore.notification"; | 49 "https://www.googleapis.com/auth/chromewebstore.notification"; |
| 50 static const char kCWSChannelServiceURL[] = | 50 static const char kCWSChannelServiceURL[] = |
| 51 "https://www-googleapis-staging.sandbox.google.com/chromewebstore/" | 51 "https://www.googleapis.com/chromewebstore/" |
| 52 "v1internal/channels/app_id/oauth_client_id"; | 52 "v1.1/channels/id"; |
| 53 static const char* kRelevantGaiaServices[] = { | 53 static const char* kRelevantGaiaServices[] = { |
| 54 GaiaConstants::kCWSService, | 54 GaiaConstants::kCWSService, |
| 55 GaiaConstants::kLSOService, | 55 GaiaConstants::kLSOService, |
| 56 }; | 56 }; |
| 57 static const int kRelevantGaiaServicesCount = arraysize(kRelevantGaiaServices); | 57 static const int kRelevantGaiaServicesCount = arraysize(kRelevantGaiaServices); |
| 58 } // namespace. | 58 } // namespace. |
| 59 | 59 |
| 60 AppNotifyChannelSetup::AppNotifyChannelSetup( | 60 AppNotifyChannelSetup::AppNotifyChannelSetup( |
| 61 Profile* profile, | 61 Profile* profile, |
| 62 const std::string& extension_id, | 62 const std::string& extension_id, |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 318 |
| 319 if (delegate_.get()) { | 319 if (delegate_.get()) { |
| 320 delegate_->AppNotifyChannelSetupComplete( | 320 delegate_->AppNotifyChannelSetupComplete( |
| 321 channel_id, error, return_route_id_, callback_id_); | 321 channel_id, error, return_route_id_, callback_id_); |
| 322 } | 322 } |
| 323 Release(); // Matches AddRef in Start. | 323 Release(); // Matches AddRef in Start. |
| 324 } | 324 } |
| 325 | 325 |
| 326 // static | 326 // static |
| 327 GURL AppNotifyChannelSetup::GetCWSChannelServiceURL() { | 327 GURL AppNotifyChannelSetup::GetCWSChannelServiceURL() { |
| 328 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 329 if (command_line->HasSwitch(switches::kAppNotifyChannelServerURL)) { |
| 330 std::string switch_value = command_line->GetSwitchValueASCII( |
| 331 switches::kAppNotifyChannelServerURL); |
| 332 GURL result(switch_value); |
| 333 if (result.is_valid()) { |
| 334 return result; |
| 335 } else { |
| 336 LOG(ERROR) << "Invalid value for " << |
| 337 switches::kAppNotifyChannelServerURL; |
| 338 } |
| 339 } |
| 328 return GURL(kCWSChannelServiceURL); | 340 return GURL(kCWSChannelServiceURL); |
| 329 } | 341 } |
| 330 | 342 |
| 331 // static | 343 // static |
| 332 GURL AppNotifyChannelSetup::GetOAuth2IssueTokenURL() { | 344 GURL AppNotifyChannelSetup::GetOAuth2IssueTokenURL() { |
| 333 return GURL(kOAuth2IssueTokenURL); | 345 return GURL(kOAuth2IssueTokenURL); |
| 334 } | 346 } |
| 335 | 347 |
| 336 // static | 348 // static |
| 337 std::string AppNotifyChannelSetup::MakeOAuth2IssueTokenBody( | 349 std::string AppNotifyChannelSetup::MakeOAuth2IssueTokenBody( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 383 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
| 372 if (!dict->Get("id", &channel_id_value)) | 384 if (!dict->Get("id", &channel_id_value)) |
| 373 return false; | 385 return false; |
| 374 if (channel_id_value->GetType() != base::Value::TYPE_STRING) | 386 if (channel_id_value->GetType() != base::Value::TYPE_STRING) |
| 375 return false; | 387 return false; |
| 376 | 388 |
| 377 StringValue* channel_id = static_cast<StringValue*>(channel_id_value); | 389 StringValue* channel_id = static_cast<StringValue*>(channel_id_value); |
| 378 channel_id->GetAsString(result); | 390 channel_id->GetAsString(result); |
| 379 return true; | 391 return true; |
| 380 } | 392 } |
| OLD | NEW |