summaryrefslogtreecommitdiffstats
path: root/chrome/browser/remoting/remoting_resources_source.cc
blob: a57596a654d1b45fce11e0468593a9071e653aeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/remoting/remoting_resources_source.h"

#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/google_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/jstemplate_builder.h"
#include "googleurl/src/gurl.h"
#include "grit/app_resources.h"
#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"

// Define the values of standard URLs.
const char RemotingResourcesSource::kInvalidPasswordHelpUrl[] =
  "http://www.google.com/support/accounts/bin/answer.py?ctx=ch&answer=27444";
const char RemotingResourcesSource::kCanNotAccessAccountUrl[] =
  "http://www.google.com/support/accounts/bin/answer.py?answer=48598";
const char RemotingResourcesSource::kCreateNewAccountUrl[] =
  "https://www.google.com/accounts/NewAccount?service=chromiumsync";

RemotingResourcesSource::RemotingResourcesSource()
  : DataSource(chrome::kChromeUIRemotingResourcesHost,
               MessageLoop::current()) {
}

void RemotingResourcesSource::StartDataRequest(const std::string& path_raw,
    bool is_off_the_record, int request_id) {
  const char kRemotingGaiaLoginPath[] = "gaialogin";
  const char kRemotingSetupFlowPath[] = "setup";
  const char kRemotingSetupDonePath[] = "setupdone";

  std::string response;
  if (path_raw == kRemotingGaiaLoginPath) {
    DictionaryValue localized_strings;

    // Start by setting the per-locale URLs we show on the setup wizard.
    localized_strings.SetString("invalidpasswordhelpurl",
        GetLocalizedUrl(kInvalidPasswordHelpUrl));
    localized_strings.SetString("cannotaccessaccounturl",
        GetLocalizedUrl(kCanNotAccessAccountUrl));
    localized_strings.SetString("createnewaccounturl",
        GetLocalizedUrl(kCreateNewAccountUrl));

    localized_strings.SetString("settingupsync",
        l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SETTING_UP_SYNC));
    localized_strings.SetString("introduction", "");
    localized_strings.SetString("signinprefix",
        l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SIGNIN_PREFIX));
    localized_strings.SetString("signinsuffix",
        l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SIGNIN_SUFFIX));
    localized_strings.SetString("cannotbeblank",
        l10n_util::GetStringUTF16(IDS_SYNC_CANNOT_BE_BLANK));
    localized_strings.SetString("emaillabel",
        l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_EMAIL));
    localized_strings.SetString("passwordlabel",
        l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_PASSWORD));
    localized_strings.SetString("invalidcredentials",
        l10n_util::GetStringUTF16(IDS_SYNC_INVALID_USER_CREDENTIALS));
    localized_strings.SetString("signin",
        l10n_util::GetStringUTF16(IDS_SYNC_SIGNIN));
    localized_strings.SetString("couldnotconnect",
        l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_COULD_NOT_CONNECT));
    localized_strings.SetString("cannotaccessaccount",
        l10n_util::GetStringUTF16(IDS_SYNC_CANNOT_ACCESS_ACCOUNT));
    localized_strings.SetString("createaccount",
        l10n_util::GetStringUTF16(IDS_SYNC_CREATE_ACCOUNT));
    localized_strings.SetString("cancel",
        l10n_util::GetStringUTF16(IDS_CANCEL));
    localized_strings.SetString("settingup",
        l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SETTING_UP));
    localized_strings.SetString("success",
        l10n_util::GetStringUTF16(IDS_SYNC_SUCCESS));
    localized_strings.SetString("errorsigningin",
        l10n_util::GetStringUTF16(IDS_SYNC_ERROR_SIGNING_IN));
    localized_strings.SetString("captchainstructions",
        l10n_util::GetStringUTF16(IDS_SYNC_GAIA_CAPTCHA_INSTRUCTIONS));
    static const base::StringPiece html(ResourceBundle::GetSharedInstance()
        .GetRawDataResource(IDR_GAIA_LOGIN_HTML));
    SetFontAndTextDirection(&localized_strings);
    response = jstemplate_builder::GetI18nTemplateHtml(
        html, &localized_strings);
  } else if (path_raw == kRemotingSetupDonePath) {
    DictionaryValue localized_strings;
    localized_strings.SetString("success",
        l10n_util::GetStringUTF16(IDS_SYNC_SUCCESS));
    localized_strings.SetString("okay",
        l10n_util::GetStringUTF16(IDS_SYNC_SETUP_OK_BUTTON_LABEL));
    static const base::StringPiece html(ResourceBundle::GetSharedInstance()
        .GetRawDataResource(IDR_REMOTING_SETUP_DONE_HTML));
    SetFontAndTextDirection(&localized_strings);
    response = jstemplate_builder::GetI18nTemplateHtml(
        html, &localized_strings);
  } else if (path_raw == kRemotingSetupFlowPath) {
    static const base::StringPiece html(ResourceBundle::GetSharedInstance()
        .GetRawDataResource(IDR_REMOTING_SETUP_FLOW_HTML));
    response = html.as_string();
  }
  // Send the response.
  scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
  html_bytes->data.resize(response.size());
  std::copy(response.begin(), response.end(), html_bytes->data.begin());
  SendResponse(request_id, html_bytes);
}

std::string RemotingResourcesSource::GetLocalizedUrl(
    const std::string& url) const {
  GURL original_url(url);
  DCHECK(original_url.is_valid());
  GURL localized_url = google_util::AppendGoogleLocaleParam(original_url);
  return localized_url.spec();
}