Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/extensions/extension_chrome_auth_private_api.cc

Issue 7253001: Added a private chromeAuthPrivate API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unittest failure Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 }
59 SendResponse(true);
60 return true;
61 }
62
63 // static
64 void SetCloudPrintCredentialsFunction::SetTestMode(bool test_mode_enabled) {
65 test_mode = test_mode_enabled;
66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698