OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/extensions/extension_chrome_auth_private_api.h" | |
6 | |
7 #include <string> | |
8 #include "base/values.h" | |
9 #include "chrome/browser/extensions/extension_service.h" | |
10 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | |
11 | |
12 namespace { | |
13 | |
14 bool IsCloudPrintEnableURL(Profile* profile, const GURL& url) { | |
15 ExtensionService* service = profile->GetExtensionService(); | |
16 const Extension* cloud_print_app = service->GetExtensionById( | |
17 extension_misc::kCloudPrintAppId, false); | |
18 if (!cloud_print_app) { | |
19 NOTREACHED(); | |
20 return false; | |
21 } | |
22 return (service->GetExtensionByWebExtent(url) == cloud_print_app); | |
23 } | |
24 | |
25 bool test_mode = false; | |
26 | |
27 const char kAccessDeniedError[] = | |
28 "Cannot call this API from a non-cloudprint URL."; | |
29 } // namespace | |
30 | |
31 SetCloudPrintCredentialsFunction::SetCloudPrintCredentialsFunction() { | |
32 } | |
33 | |
34 SetCloudPrintCredentialsFunction::~SetCloudPrintCredentialsFunction() { | |
35 } | |
36 | |
37 bool SetCloudPrintCredentialsFunction::RunImpl() { | |
38 // This has to be called from the specific cloud print app. | |
39 if (!IsCloudPrintEnableURL(profile_, source_url())) { | |
40 error_ = kAccessDeniedError; | |
41 return false; | |
42 } | |
43 | |
44 std::string user_email; | |
45 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &user_email)); | |
46 std::string robot_email; | |
47 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &robot_email)); | |
48 std::string credentials; | |
49 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &credentials)); | |
50 if (test_mode) { | |
51 std::string test_response = user_email; | |
52 test_response.append(robot_email); | |
53 test_response.append(credentials); | |
54 result_.reset(Value::CreateStringValue(test_response)); | |
55 } else { | |
56 profile_->GetCloudPrintProxyService()->EnableForUserWithRobot( | |
57 credentials, robot_email, user_email); | |
58 // Send empty string as success response. | |
59 result_.reset(Value::CreateStringValue("")); | |
Matt Perry
2011/06/24 19:11:09
you can omit this if you make the callback param o
sanjeevr
2011/06/24 22:38:48
The callback param is optional. However I got an A
Matt Perry
2011/06/24 22:44:29
You should still call SendResponse, or some state
sanjeevr
2011/06/24 23:05:26
Done.
| |
60 } | |
61 SendResponse(true); | |
62 return true; | |
63 } | |
64 | |
65 // static | |
66 void SetCloudPrintCredentialsFunction::SetTestMode(bool test_mode_enabled) { | |
67 test_mode = test_mode_enabled; | |
68 } | |
OLD | NEW |