summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-17 00:25:47 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-17 00:25:47 +0000
commit6eae9cf004fba00e78533a12c69f9987cdb0b7c7 (patch)
treecf6ff07e905adc3f4fed6be43e763876e268e64c /chrome/browser
parent0cfe5dae9265f8d3be8648e33421c7c76cb31b4e (diff)
downloadchromium_src-6eae9cf004fba00e78533a12c69f9987cdb0b7c7.zip
chromium_src-6eae9cf004fba00e78533a12c69f9987cdb0b7c7.tar.gz
chromium_src-6eae9cf004fba00e78533a12c69f9987cdb0b7c7.tar.bz2
Setup dialog for remoting
Adding more setup content to remoting. Including the gaia authenication and done message. This provides the basic flow for the setup. There's a lot still needs to be worked on: 1. Merge RemotingSetupFlow and RemotingSetupMessageHandler because we shouldn't splitting the logic into two separate classes. 2. Cleanup the memory ownership. 3. Perform the actual gaia login. 4. Perform host registration. Review URL: http://codereview.chromium.org/3160016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56273 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser.cc4
-rw-r--r--chrome/browser/browser_resources.grd2
-rw-r--r--chrome/browser/dom_ui/dom_ui_factory.cc3
-rw-r--r--chrome/browser/remoting/remoting_resources_source.cc121
-rw-r--r--chrome/browser/remoting/remoting_resources_source.h33
-rw-r--r--chrome/browser/remoting/remoting_setup_flow.cc125
-rw-r--r--chrome/browser/remoting/remoting_setup_flow.h (renamed from chrome/browser/remoting/setup_flow.h)51
-rw-r--r--chrome/browser/remoting/remoting_setup_message_handler.cc74
-rw-r--r--chrome/browser/remoting/remoting_setup_message_handler.h44
-rw-r--r--chrome/browser/remoting/resources/setup_done.html67
-rw-r--r--chrome/browser/remoting/resources/setup_flow.html35
-rw-r--r--chrome/browser/remoting/setup.cc21
-rw-r--r--chrome/browser/remoting/setup.h19
-rw-r--r--chrome/browser/remoting/setup_flow.cc97
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc12
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.h2
16 files changed, 529 insertions, 181 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index c7f77b1..c6cd15b 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -62,7 +62,7 @@
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
#if defined(ENABLE_REMOTING)
-#include "chrome/browser/remoting/setup.h"
+#include "chrome/browser/remoting/remoting_setup_flow.h"
#endif
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/site_instance.h"
@@ -1846,7 +1846,7 @@ void Browser::OpenSyncMyBookmarksDialog() {
#if defined(ENABLE_REMOTING)
void Browser::OpenRemotingSetupDialog() {
- remoting_setup::OpenRemotingSetupDialog(profile_);
+ ::OpenRemotingSetupDialog(profile_);
}
#endif
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd
index 63137c2..3c277f7 100644
--- a/chrome/browser/browser_resources.grd
+++ b/chrome/browser/browser_resources.grd
@@ -57,6 +57,8 @@ without changes to the corresponding grd file. eadee -->
<include name="IDR_SYNC_CHOOSE_DATATYPES_HTML" file="sync\resources\choose_datatypes.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_SYNC_SETUP_DONE_HTML" file="sync\resources\setup_done.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_SYNC_SETUP_FLOW_HTML" file="sync\resources\setup_flow.html" flattenhtml="true" type="BINDATA" />
+ <include name="IDR_REMOTING_SETUP_FLOW_HTML" file="remoting\resources\setup_flow.html" flattenhtml="true" type="BINDATA" />
+ <include name="IDR_REMOTING_SETUP_DONE_HTML" file="remoting\resources\setup_done.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_TRANSLATE_JS" file="resources\translate.js" type="BINDATA" />
<if expr="pp_ifdef('chromeos')">
diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc
index 3d4b9af..5c50067 100644
--- a/chrome/browser/dom_ui/dom_ui_factory.cc
+++ b/chrome/browser/dom_ui/dom_ui_factory.cc
@@ -86,7 +86,8 @@ static DOMUIFactoryFunction GetDOMUIFactoryFunction(const GURL& url) {
!url.SchemeIs(chrome::kChromeUIScheme))
return NULL;
- if (url.host() == chrome::kChromeUISyncResourcesHost)
+ if (url.host() == chrome::kChromeUISyncResourcesHost ||
+ url.host() == chrome::kChromeUIRemotingResourcesHost)
return &NewDOMUI<HtmlDialogUI>;
// Special case the new tab page. In older versions of Chrome, the new tab
diff --git a/chrome/browser/remoting/remoting_resources_source.cc b/chrome/browser/remoting/remoting_resources_source.cc
new file mode 100644
index 0000000..b7e68dc
--- /dev/null
+++ b/chrome/browser/remoting/remoting_resources_source.cc
@@ -0,0 +1,121 @@
+// 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/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(L"invalidpasswordhelpurl",
+ GetLocalizedUrl(kInvalidPasswordHelpUrl));
+ localized_strings.SetString(L"cannotaccessaccounturl",
+ GetLocalizedUrl(kCanNotAccessAccountUrl));
+ localized_strings.SetString(L"createnewaccounturl",
+ GetLocalizedUrl(kCreateNewAccountUrl));
+
+ localized_strings.SetString(L"settingupsync",
+ l10n_util::GetString(IDS_SYNC_LOGIN_SETTING_UP_SYNC));
+ localized_strings.SetString(L"introduction",
+ std::wstring(L"Remoting ") +
+ l10n_util::GetString(IDS_PRODUCT_NAME));
+ localized_strings.SetString(L"signinprefix",
+ l10n_util::GetString(IDS_SYNC_LOGIN_SIGNIN_PREFIX));
+ localized_strings.SetString(L"signinsuffix",
+ l10n_util::GetString(IDS_SYNC_LOGIN_SIGNIN_SUFFIX));
+ localized_strings.SetString(L"cannotbeblank",
+ l10n_util::GetString(IDS_SYNC_CANNOT_BE_BLANK));
+ localized_strings.SetString(L"emaillabel",
+ l10n_util::GetString(IDS_SYNC_LOGIN_EMAIL));
+ localized_strings.SetString(L"passwordlabel",
+ l10n_util::GetString(IDS_SYNC_LOGIN_PASSWORD));
+ localized_strings.SetString(L"invalidcredentials",
+ l10n_util::GetString(IDS_SYNC_INVALID_USER_CREDENTIALS));
+ localized_strings.SetString(L"signin",
+ l10n_util::GetString(IDS_SYNC_SIGNIN));
+ localized_strings.SetString(L"couldnotconnect",
+ l10n_util::GetString(IDS_SYNC_LOGIN_COULD_NOT_CONNECT));
+ localized_strings.SetString(L"cannotaccessaccount",
+ l10n_util::GetString(IDS_SYNC_CANNOT_ACCESS_ACCOUNT));
+ localized_strings.SetString(L"createaccount",
+ l10n_util::GetString(IDS_SYNC_CREATE_ACCOUNT));
+ localized_strings.SetString(L"cancel",
+ l10n_util::GetString(IDS_CANCEL));
+ localized_strings.SetString(L"settingup",
+ l10n_util::GetString(IDS_SYNC_LOGIN_SETTING_UP));
+ localized_strings.SetString(L"success",
+ l10n_util::GetString(IDS_SYNC_SUCCESS));
+ localized_strings.SetString(L"errorsigningin",
+ l10n_util::GetString(IDS_SYNC_ERROR_SIGNING_IN));
+ localized_strings.SetString(L"captchainstructions",
+ l10n_util::GetString(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(L"success",
+ l10n_util::GetString(IDS_SYNC_SUCCESS));
+ localized_strings.SetString(L"okay",
+ l10n_util::GetString(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();
+}
diff --git a/chrome/browser/remoting/remoting_resources_source.h b/chrome/browser/remoting/remoting_resources_source.h
new file mode 100644
index 0000000..96d1b4d
--- /dev/null
+++ b/chrome/browser/remoting/remoting_resources_source.h
@@ -0,0 +1,33 @@
+// 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 "base/message_loop.h"
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
+#include "chrome/common/url_constants.h"
+
+class RemotingResourcesSource : public ChromeURLDataManager::DataSource {
+ public:
+ RemotingResourcesSource();
+ virtual void StartDataRequest(const std::string& path,
+ bool is_off_the_record,
+ int request_id);
+
+ virtual std::string GetMimeType(const std::string& path) const {
+ return "text/html";
+ }
+
+ static const char kInvalidPasswordHelpUrl[];
+ static const char kCanNotAccessAccountUrl[];
+ static const char kCreateNewAccountUrl[];
+
+ private:
+ virtual ~RemotingResourcesSource() {}
+
+ // Takes a string containing an URL and returns an URL containing a CGI
+ // parameter of the form "&hl=xy" where 'xy' is the language code of the
+ // current locale.
+ std::string GetLocalizedUrl(const std::string& url) const;
+
+ DISALLOW_COPY_AND_ASSIGN(RemotingResourcesSource);
+};
diff --git a/chrome/browser/remoting/remoting_setup_flow.cc b/chrome/browser/remoting/remoting_setup_flow.cc
new file mode 100644
index 0000000..c9aa2b3
--- /dev/null
+++ b/chrome/browser/remoting/remoting_setup_flow.cc
@@ -0,0 +1,125 @@
+// 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_setup_flow.h"
+
+#include "app/gfx/font_util.h"
+#include "base/json/json_writer.h"
+#include "base/singleton.h"
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
+#include "chrome/browser/dom_ui/dom_ui_util.h"
+#include "chrome/browser/google_service_auth_error.h"
+#include "chrome/browser/platform_util.h"
+#include "chrome/browser/pref_service.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/remoting/remoting_resources_source.h"
+#include "chrome/browser/remoting/remoting_setup_message_handler.h"
+#include "chrome/common/pref_names.h"
+#include "gfx/font.h"
+#include "grit/locale_settings.h"
+
+// Use static Run method to get an instance.
+RemotingSetupFlow::RemotingSetupFlow(const std::string& args, Profile* profile)
+ : message_handler_(NULL),
+ dialog_start_args_(args),
+ profile_(profile) {
+ // TODO(hclam): We are currently leaking this objcet. Need to fix this!
+ message_handler_ = new RemotingSetupMessageHandler(this);
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(Singleton<ChromeURLDataManager>::get(),
+ &ChromeURLDataManager::AddDataSource,
+ make_scoped_refptr(new RemotingResourcesSource())));
+}
+
+RemotingSetupFlow::~RemotingSetupFlow() {
+}
+
+void RemotingSetupFlow::GetDialogSize(gfx::Size* size) const {
+ PrefService* prefs = profile_->GetPrefs();
+ gfx::Font approximate_web_font(
+ UTF8ToWide(prefs->GetString(prefs::kWebKitSansSerifFontFamily)),
+ prefs->GetInteger(prefs::kWebKitDefaultFontSize));
+
+ // TODO(pranavk) Replace the following SYNC resources with REMOTING Resources.
+ *size = gfx::GetLocalizedContentsSizeForFont(
+ IDS_SYNC_SETUP_WIZARD_WIDTH_CHARS,
+ IDS_SYNC_SETUP_WIZARD_HEIGHT_LINES,
+ approximate_web_font);
+}
+
+// A callback to notify the delegate that the dialog closed.
+void RemotingSetupFlow::OnDialogClosed(const std::string& json_retval) {
+ delete this;
+}
+
+// static
+void RemotingSetupFlow::GetArgsForGaiaLogin(DictionaryValue* args) {
+ args->SetString(L"iframeToShow", "login");
+ args->SetString(L"user", std::wstring());
+ args->SetInteger(L"error", 0);
+ args->SetBoolean(L"editable_user", true);
+}
+
+void RemotingSetupFlow::GetDOMMessageHandlers(
+ std::vector<DOMMessageHandler*>* handlers) const {
+ // Create the message handler only after we are asked.
+ handlers->push_back(message_handler_);
+}
+
+void RemotingSetupFlow::Focus() {
+ // TODO(pranavk): implement this method.
+ NOTIMPLEMENTED();
+}
+
+void RemotingSetupFlow::OnUserSubmittedAuth(const std::string& user,
+ const std::string& password,
+ const std::string& captcha) {
+ // TODO(hclam): Should do the following two things.
+ // 1. Authenicate using the info.
+ // 2. Register the host service.
+ message_handler_->ShowGaiaSuccessAndSettingUp();
+
+ // TODO(hclam): This is very unsafe because |message_handler_| is not
+ // refcounted. Destruction of the handler before the timeout will cause
+ // memory error.
+ // This services as a demo to show that we can do authenication asynchronously
+ // and setting up stuff and then present the done page later.
+ ChromeThread::PostDelayedTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(message_handler_,
+ &RemotingSetupMessageHandler::ShowSetupDone),
+ 2000);
+}
+
+// static
+RemotingSetupFlow* RemotingSetupFlow::Run(Profile* profile) {
+ // Set the arguments for showing the gaia login page.
+ DictionaryValue args;
+ GetArgsForGaiaLogin(&args);
+ std::string json_args;
+ base::JSONWriter::Write(&args, false, &json_args);
+
+ RemotingSetupFlow* flow = new RemotingSetupFlow(json_args, profile);
+ Browser* b = BrowserList::GetLastActive();
+ if (b) {
+ b->BrowserShowHtmlDialog(flow, NULL);
+ } else {
+ delete flow;
+ return NULL;
+ }
+ return flow;
+}
+
+// Global function to start the remoting setup dialog.
+void OpenRemotingSetupDialog(Profile* profile) {
+ RemotingSetupFlow::Run(profile->GetOriginalProfile());
+}
+
+DISABLE_RUNNABLE_METHOD_REFCOUNT(RemotingSetupMessageHandler);
diff --git a/chrome/browser/remoting/setup_flow.h b/chrome/browser/remoting/remoting_setup_flow.h
index dd33c55..5d7ec15 100644
--- a/chrome/browser/remoting/setup_flow.h
+++ b/chrome/browser/remoting/remoting_setup_flow.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_REMOTING_SETUP_FLOW_H_
-#define CHROME_BROWSER_REMOTING_SETUP_FLOW_H_
+#ifndef CHROME_BROWSER_REMOTING_REMOTING_SETUP_FLOW_H_
+#define CHROME_BROWSER_REMOTING_REMOTING_SETUP_FLOW_H_
#include <string>
#include <vector>
@@ -14,24 +14,21 @@
#include "gfx/native_widget_types.h"
#include "grit/generated_resources.h"
-namespace remoting_setup {
+class RemotingSetupMessageHandler;
// The state machine used by Remoting for setup wizard.
-class SetupFlow : public HtmlDialogUIDelegate {
+class RemotingSetupFlow : public HtmlDialogUIDelegate {
public:
- virtual ~SetupFlow();
+ virtual ~RemotingSetupFlow();
// Runs a flow from |start| to |end|, and does the work of actually showing
// the HTML dialog. |container| is kept up-to-date with the lifetime of the
// flow (e.g it is emptied on dialog close).
- static SetupFlow* Run(Profile* service);
+ static RemotingSetupFlow* Run(Profile* service);
// Fills |args| with "user" and "error" arguments by querying |service|.
static void GetArgsForGaiaLogin(DictionaryValue* args);
- // Triggers a state machine transition to advance_state.
- void Advance();
-
// Focuses the dialog. This is useful in cases where the dialog has been
// obscured by a browser window.
void Focus();
@@ -57,47 +54,31 @@ class SetupFlow : public HtmlDialogUIDelegate {
}
// HtmlDialogUIDelegate implementation.
- // A callback to notify the delegate that the dialog closed.
virtual void OnDialogClosed(const std::string& json_retval);
-
- // HtmlDialogUIDelegate implementation.
virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) { }
-
- // HtmlDialogUIDelegate implementation.
virtual std::wstring GetDialogTitle() const {
return l10n_util::GetString(IDS_REMOTING_SETUP_DIALOG_TITLE);
}
-
- // HtmlDialogUIDelegate implementation.
virtual bool IsDialogModal() const {
- return false;
- }
-
- void OnUserClickedCustomize() {
- // TODO(pranavk): Implement this method.
- }
-
- bool ClickCustomizeOk() {
- // TODO(pranavk): Implement this method.
return true;
}
- void ClickCustomizeCancel() {
- // TODO(pranavk): Implement this method.
- }
+ void OnUserSubmittedAuth(const std::string& user, const std::string& password,
+ const std::string& captcha);
private:
-
// Use static Run method to get an instance.
- SetupFlow(const std::string& args, Profile* profile);
-
- DISALLOW_COPY_AND_ASSIGN(SetupFlow);
+ RemotingSetupFlow(const std::string& args, Profile* profile);
+ RemotingSetupMessageHandler* message_handler_;
std::string dialog_start_args_; // The args to pass to the initial page.
-
Profile* profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(RemotingSetupFlow);
};
-} // namespace remoting_setup
+// Open the appropriate setup dialog for the given profile (which can be
+// incognito).
+void OpenRemotingSetupDialog(Profile* profile);
-#endif // CHROME_BROWSER_REMOTING_SETUP_FLOW_H_
+#endif // CHROME_BROWSER_REMOTING_REMOTING_SETUP_FLOW_H_
diff --git a/chrome/browser/remoting/remoting_setup_message_handler.cc b/chrome/browser/remoting/remoting_setup_message_handler.cc
new file mode 100644
index 0000000..d9d8dea
--- /dev/null
+++ b/chrome/browser/remoting/remoting_setup_message_handler.cc
@@ -0,0 +1,74 @@
+// 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_setup_message_handler.h"
+
+#include "base/scoped_ptr.h"
+#include "base/json/json_reader.h"
+#include "base/json/json_writer.h"
+#include "chrome/browser/dom_ui/dom_ui_util.h"
+#include "chrome/browser/remoting/remoting_setup_flow.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+
+static const wchar_t kLoginIFrameXPath[] = L"//iframe[@id='login']";
+static const wchar_t kDoneIframeXPath[] = L"//iframe[@id='done']";
+
+void RemotingSetupMessageHandler::RegisterMessages() {
+ dom_ui_->RegisterMessageCallback("SubmitAuth",
+ NewCallback(this, &RemotingSetupMessageHandler::HandleSubmitAuth));
+}
+
+void RemotingSetupMessageHandler::HandleSubmitAuth(const Value* value) {
+ std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(value));
+ std::string username, password, captcha;
+ if (json.empty())
+ return;
+
+ scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false));
+ if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) {
+ NOTREACHED() << "Unable to parse auth data";
+ return;
+ }
+
+ DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get());
+ if (!result->GetString("user", &username) ||
+ !result->GetString("pass", &password) ||
+ !result->GetString("captcha", &captcha)) {
+ NOTREACHED() << "Unable to parse auth data";
+ return;
+ }
+
+ // Pass the information to the flow.
+ if (flow_)
+ flow_->OnUserSubmittedAuth(username, password, captcha);
+}
+
+void RemotingSetupMessageHandler::ShowGaiaSuccessAndSettingUp() {
+ ExecuteJavascriptInIFrame(kLoginIFrameXPath,
+ L"showGaiaSuccessAndSettingUp();");
+}
+
+void RemotingSetupMessageHandler::ShowGaiaFailed() {
+ // TODO(hclam): Implement this.
+}
+
+void RemotingSetupMessageHandler::ShowSetupDone() {
+ std::wstring javascript = L"setMessage('You are all set!');";
+ ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript);
+
+ if (dom_ui_)
+ dom_ui_->CallJavascriptFunction(L"showSetupDone");
+
+ ExecuteJavascriptInIFrame(kDoneIframeXPath, L"onPageShown();");
+}
+
+void RemotingSetupMessageHandler::ExecuteJavascriptInIFrame(
+ const std::wstring& iframe_xpath,
+ const std::wstring& js) {
+ if (dom_ui_) {
+ RenderViewHost* rvh = dom_ui_->tab_contents()->render_view_host();
+ rvh->ExecuteJavascriptInWebFrame(iframe_xpath, js);
+ }
+}
diff --git a/chrome/browser/remoting/remoting_setup_message_handler.h b/chrome/browser/remoting/remoting_setup_message_handler.h
new file mode 100644
index 0000000..b4dcfcb
--- /dev/null
+++ b/chrome/browser/remoting/remoting_setup_message_handler.h
@@ -0,0 +1,44 @@
+// 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.
+
+#ifndef CHROME_BROWSER_REMOTING_REMOTING_SETUP_MESSAGE_HANDLER_H_
+#define CHROME_BROWSER_REMOTING_REMOTING_SETUP_MESSAGE_HANDLER_H_
+
+#include <string>
+
+#include "base/values.h"
+#include "chrome/browser/dom_ui/html_dialog_ui.h"
+
+class RemotingSetupFlow;
+
+// This class is used to handle DOM messages from the setup dialog.
+class RemotingSetupMessageHandler : public DOMMessageHandler {
+ public:
+ RemotingSetupMessageHandler(RemotingSetupFlow* flow) : flow_(flow) {}
+ virtual ~RemotingSetupMessageHandler() {}
+
+ // DOMMessageHandler implementation.
+ virtual void RegisterMessages();
+
+ // Callbacks from the page.
+ void HandleSubmitAuth(const Value* value);
+
+ // These functions control which part of the HTML is visible.
+ // TODO(hclam): I really don't feel right about exposing these as public
+ // methods. It will be better that we notify RemotingSetupFlow and then get
+ // a return value for state transition inside this class, or better we merge
+ // this class into RemotingSetupFlow.
+ void ShowGaiaSuccessAndSettingUp();
+ void ShowGaiaFailed();
+ void ShowSetupDone();
+
+ private:
+ void ExecuteJavascriptInIFrame(const std::wstring& iframe_xpath,
+ const std::wstring& js);
+ RemotingSetupFlow* flow_;
+
+ DISALLOW_COPY_AND_ASSIGN(RemotingSetupMessageHandler);
+};
+
+#endif // CHROME_BROWSER_REMOTING_REMOTING_SETUP_MESSAGE_HANDLER_H_
diff --git a/chrome/browser/remoting/resources/setup_done.html b/chrome/browser/remoting/resources/setup_done.html
new file mode 100644
index 0000000..88a365c
--- /dev/null
+++ b/chrome/browser/remoting/resources/setup_done.html
@@ -0,0 +1,67 @@
+<html i18n-values="dir:textdirection;">
+<head>
+<title></title>
+<style type="text/css">
+body {
+ background: #FFFFFF;
+ font-size: 11pt;
+ line-height: 1.5em;
+ margin: 10px 15px;
+ -webkit-user-select: none;
+}
+.remoting-header {
+ font-size: 1.2em;
+ font-weight: bold;
+}
+.remoting-success-image {
+ text-align: center;
+ margin: 20px;
+}
+#message {
+ font-weight: bold;
+}
+.remoting-footer {
+ position: fixed;
+ right: 0px;
+ bottom: 0px;
+ margin-right: 10px;
+ margin-bottom: 10px;
+}
+html[dir='rtl'] .remoting-footer {
+ text-align: left;
+ left: 0px;
+ bottom: 0px;
+ margin-left: 20px;
+}
+input[type='submit'] {
+ min-width: 87px;
+ min-height: 26px;
+}
+html[os='mac'] input[type='submit'] {
+ font-size: 12pt;
+}
+
+</style>
+<script>
+ function setShowFirstTimeSetupSummary() {
+ document.getElementById("summary").innerHTML =
+ templateData['firsttimesetupsummary'];
+ }
+ function setMessage(msg) {
+ document.getElementById('msgContent').innerHTML = msg;
+ }
+ function onPageShown() {
+ document.getElementById("close").focus();
+ }
+</script>
+</head>
+<body i18n-values=".style.fontFamily:fontfamily">
+ <div class="remoting-header" i18n-content="success"></div>
+ <div id="msgContent"></div>
+ <div id="summary" i18n-content="setupsummary"></div>
+ <div class="remoting-footer">
+ <input id="close" type="submit" i18n-values="value:okay"
+ onclick='chrome.send("DialogClose", [""])' />
+ </div>
+</body>
+</html>
diff --git a/chrome/browser/remoting/resources/setup_flow.html b/chrome/browser/remoting/resources/setup_flow.html
new file mode 100644
index 0000000..aafe008
--- /dev/null
+++ b/chrome/browser/remoting/resources/setup_flow.html
@@ -0,0 +1,35 @@
+<html id='t'>
+<head>
+<title></title>
+<script type="text/javascript">
+ // Called once, when this html/js is loaded.
+ function showTheRightIframe() {
+ hideAllPages();
+ var args = JSON.parse(chrome.dialogArguments);
+ document.getElementById(args.iframeToShow).style.display = 'block';
+ document.getElementById(args.iframeToShow).tabIndex = 0;
+ }
+
+ function hideAllPages() {
+ document.getElementById('login').style.display = 'none';
+ document.getElementById('login').tabIndex = -1;
+ document.getElementById('done').style.display = 'none';
+ document.getElementById('done').tabIndex = -1;
+ }
+
+ function showSetupDone() {
+ hideAllPages();
+ document.getElementById('done').style.display = 'block';
+ document.getElementById('done').tabIndex = 0;
+ }
+</script>
+</head>
+<body style="margin:0; border:0;" onload="showTheRightIframe();">
+ <iframe id="login" frameborder="0" width="100%" scrolling="no" height="100%"
+ src="chrome://remotingresources/gaialogin" style="display:none"
+ tabindex="-1"></iframe>
+ <iframe id="done" frameborder="0" width="100%" scrolling="no" height="100%"
+ src="chrome://remotingresources/setupdone" style="display:none"
+ tabindex="-1"></iframe>
+</body>
+</html>
diff --git a/chrome/browser/remoting/setup.cc b/chrome/browser/remoting/setup.cc
deleted file mode 100644
index 0054efb..0000000
--- a/chrome/browser/remoting/setup.cc
+++ /dev/null
@@ -1,21 +0,0 @@
-// 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/setup.h"
-#include "chrome/browser/remoting/setup_flow.h"
-
-//#include "app/l10n_util.h"
-//#include "base/utf_string_conversions.h"
-#include "chrome/browser/google_service_auth_error.h"
-#include "chrome/browser/profile.h"
-
-typedef GoogleServiceAuthError AuthError;
-
-namespace remoting_setup {
-
-void OpenRemotingSetupDialog(Profile* profile) {
- remoting_setup::SetupFlow::Run(profile->GetOriginalProfile());
-}
-
-} // namespace remoting_setup
diff --git a/chrome/browser/remoting/setup.h b/chrome/browser/remoting/setup.h
deleted file mode 100644
index 1b7a8bf..0000000
--- a/chrome/browser/remoting/setup.h
+++ /dev/null
@@ -1,19 +0,0 @@
-// 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.
-
-#ifndef CHROME_BROWSER_REMOTING_SETUP_H_
-#define CHROME_BROWSER_REMOTING_SETUP_H_
-
-#include "base/string16.h"
-
-class Profile;
-
-namespace remoting_setup {
-
-// Open the appropriate setup dialog for the given profile (which can be
-// incognito).
-void OpenRemotingSetupDialog(Profile* profile);
-} // namespace remoting_setup
-
-#endif // CHROME_BROWSER_REMOTING_SETUP_H_
diff --git a/chrome/browser/remoting/setup_flow.cc b/chrome/browser/remoting/setup_flow.cc
deleted file mode 100644
index 5e71c99..0000000
--- a/chrome/browser/remoting/setup_flow.cc
+++ /dev/null
@@ -1,97 +0,0 @@
-// 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/setup_flow.h"
-
-#include "app/gfx/font_util.h"
-#include "base/callback.h"
-#include "base/histogram.h"
-#include "base/json/json_reader.h"
-#include "base/json/json_writer.h"
-#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
-#include "base/values.h"
-#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_list.h"
-#if defined(OS_MACOSX)
-#include "chrome/browser/cocoa/html_dialog_window_controller_cppsafe.h"
-#endif
-#include "chrome/browser/dom_ui/dom_ui_util.h"
-#include "chrome/browser/google_service_auth_error.h"
-#include "chrome/browser/platform_util.h"
-#include "chrome/browser/pref_service.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/renderer_host/render_view_host.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/common/pref_names.h"
-#include "gfx/font.h"
-#include "grit/locale_settings.h"
-
-namespace remoting_setup {
-
-// Use static Run method to get an instance.
-SetupFlow::SetupFlow(const std::string& args, Profile* profile)
- : dialog_start_args_(args),
- profile_(profile) {
-}
-
-SetupFlow::~SetupFlow() {
-}
-
-void SetupFlow::GetDialogSize(gfx::Size* size) const {
- PrefService* prefs = profile_->GetPrefs();
- gfx::Font approximate_web_font(
- UTF8ToWide(prefs->GetString(prefs::kWebKitSansSerifFontFamily)),
- prefs->GetInteger(prefs::kWebKitDefaultFontSize));
-
- // TODO(pranavk) Replace the following SYNC resources with REMOTING Resources.
- *size = gfx::GetLocalizedContentsSizeForFont(
- IDS_SYNC_SETUP_WIZARD_WIDTH_CHARS,
- IDS_SYNC_SETUP_WIZARD_HEIGHT_LINES,
- approximate_web_font);
-}
-
-// A callback to notify the delegate that the dialog closed.
-void SetupFlow::OnDialogClosed(const std::string& json_retval) {
- delete this;
-}
-
-// static
-void SetupFlow::GetArgsForGaiaLogin(DictionaryValue* args) {
- // TODO(pranavk): implement this method.
-}
-
-void SetupFlow::GetDOMMessageHandlers(
- std::vector<DOMMessageHandler*>* handlers) const {
- // TODO(pranavk): implement this method.
-}
-
-
-void SetupFlow::Advance() {
- // TODO(pranavk): implement this method.
-}
-
-void SetupFlow::Focus() {
- // TODO(pranavk): implement this method.
- NOTIMPLEMENTED();
-}
-
-// static
-SetupFlow* SetupFlow::Run(Profile* service) {
- DictionaryValue args;
- std::string json_args;
- base::JSONWriter::Write(&args, false, &json_args);
-
- SetupFlow* flow = new SetupFlow(json_args, service);
- Browser* b = BrowserList::GetLastActive();
- if (b) {
- b->BrowserShowHtmlDialog(flow, NULL);
- } else {
- delete flow;
- return NULL;
- }
- return flow;
-}
-
-} // namespace remoting_setup
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 772360b..c7b3289 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -65,9 +65,11 @@ bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) {
}
// static
-bool RenderViewContextMenu::IsSyncResourcesURL(const GURL& url) {
- return url.SchemeIs(chrome::kChromeUIScheme) &&
- url.host() == chrome::kChromeUISyncResourcesHost;
+bool RenderViewContextMenu::IsInternalResourcesURL(const GURL& url) {
+ if (!url.SchemeIs(chrome::kChromeUIScheme))
+ return false;
+ return url.host() == chrome::kChromeUISyncResourcesHost ||
+ url.host() == chrome::kChromeUIRemotingResourcesHost;
}
static const int kSpellcheckRadioGroup = 1;
@@ -354,11 +356,11 @@ void RenderViewContextMenu::InitMenu() {
// If context is in subframe, show subframe options instead.
if (!params_.frame_url.is_empty()) {
is_devtools = IsDevToolsURL(params_.frame_url);
- if (!is_devtools && !IsSyncResourcesURL(params_.frame_url))
+ if (!is_devtools && !IsInternalResourcesURL(params_.frame_url))
AppendFrameItems();
} else if (!params_.page_url.is_empty()) {
is_devtools = IsDevToolsURL(params_.page_url);
- if (!is_devtools && !IsSyncResourcesURL(params_.page_url))
+ if (!is_devtools && !IsInternalResourcesURL(params_.page_url))
AppendPageItems();
}
}
diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h
index 21abb1d..73cdba8 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.h
+++ b/chrome/browser/tab_contents/render_view_context_menu.h
@@ -76,7 +76,7 @@ class RenderViewContextMenu : public menus::SimpleMenuModel::Delegate {
private:
static bool IsDevToolsURL(const GURL& url);
- static bool IsSyncResourcesURL(const GURL& url);
+ static bool IsInternalResourcesURL(const GURL& url);
bool AppendCustomItems();
void AppendDeveloperItems();
void AppendLinkItems();