| Index: chrome/browser/views/options/advanced_contents_view.cc
|
| diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc
|
| index 6270e4fc4af44dbf6674a199277311d9454b9ff7..32004945425011cf41c1218b416490e5d16c92ab 100644
|
| --- a/chrome/browser/views/options/advanced_contents_view.cc
|
| +++ b/chrome/browser/views/options/advanced_contents_view.cc
|
| @@ -19,6 +19,7 @@
|
| #include "base/i18n/rtl.h"
|
| #include "base/message_loop.h"
|
| #include "base/path_service.h"
|
| +#include "base/scoped_callback_factory.h"
|
| #include "base/thread.h"
|
| #include "base/utf_string_conversions.h"
|
| #include "chrome/browser/browser.h"
|
| @@ -32,6 +33,7 @@
|
| #include "chrome/browser/prefs/pref_member.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| #include "chrome/browser/prefs/pref_set_observer.h"
|
| +#include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h"
|
| #include "chrome/browser/profile.h"
|
| #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
|
| #include "chrome/browser/safe_browsing/safe_browsing_service.h"
|
| @@ -1365,6 +1367,161 @@ void ChromeAppsSection::NotifyPrefChanged(const std::string* pref_name) {
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| +// CloudPrintProxySection
|
| +
|
| +class CloudPrintProxySection : public AdvancedSection,
|
| + public views::ButtonListener {
|
| + public:
|
| + explicit CloudPrintProxySection(Profile* profile);
|
| + virtual ~CloudPrintProxySection() {}
|
| +
|
| + // Overridden from views::ButtonListener:
|
| + virtual void ButtonPressed(views::Button* sender, const views::Event& event);
|
| +
|
| + // Callback that gets the cloud print proxy status.
|
| + void StatusCallback(bool enabled, std::string email);
|
| +
|
| + protected:
|
| + // OptionsPageView overrides:
|
| + virtual void InitControlLayout();
|
| + virtual void NotifyPrefChanged(const std::string* pref_name);
|
| +
|
| + private:
|
| + bool Enabled() const;
|
| +
|
| + // Controls for this section:
|
| + views::Label* section_description_label_;
|
| + views::NativeButton* enable_disable_button_;
|
| + views::NativeButton* manage_printer_button_;
|
| +
|
| + // Preferences we tie things to.
|
| + StringPrefMember cloud_print_proxy_email_;
|
| +
|
| + base::ScopedCallbackFactory<CloudPrintProxySection> factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CloudPrintProxySection);
|
| +};
|
| +
|
| +CloudPrintProxySection::CloudPrintProxySection(Profile* profile)
|
| + : section_description_label_(NULL),
|
| + enable_disable_button_(NULL),
|
| + manage_printer_button_(NULL),
|
| + factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| + AdvancedSection(profile,
|
| + l10n_util::GetString(
|
| + IDS_OPTIONS_ADVANCED_SECTION_TITLE_CLOUD_PRINT)) {
|
| +}
|
| +
|
| +void CloudPrintProxySection::ButtonPressed(views::Button* sender,
|
| + const views::Event& event) {
|
| + if (sender == enable_disable_button_) {
|
| + if (Enabled()) {
|
| + // Enabled, we must be the disable button.
|
| + UserMetricsRecordAction(
|
| + UserMetricsAction("Options_DisableCloudPrintProxy"), NULL);
|
| + CloudPrintSetupFlow::DisableCloudPrintProxy(profile());
|
| + } else {
|
| + UserMetricsRecordAction(
|
| + UserMetricsAction("Options_EnableCloudPrintProxy"), NULL);
|
| + // We open a new browser window so the Options dialog doesn't
|
| + // get lost behind other windows.
|
| + CloudPrintSetupFlow::OpenDialog(profile());
|
| + }
|
| + } else if (sender == manage_printer_button_) {
|
| + // Open a new browser window for the management tab. The browser
|
| + // will go away when the user closes that tab.
|
| + Browser* browser = Browser::Create(profile());
|
| + // FIXME(scottbyer): Refactor Cloud Print URL creation.
|
| + // http://code.google.com/p/chromium/issues/detail?id=56850
|
| + browser->OpenURL(GURL("https://www.google.com/cloudprint/manage.html"),
|
| + GURL(), NEW_WINDOW, PageTransition::LINK);
|
| + }
|
| +}
|
| +
|
| +void CloudPrintProxySection::StatusCallback(bool enabled, std::string email) {
|
| + profile()->GetPrefs()->SetString(prefs::kCloudPrintEmail,
|
| + enabled ? email : std::string());
|
| +}
|
| +
|
| +void CloudPrintProxySection::InitControlLayout() {
|
| + AdvancedSection::InitControlLayout();
|
| +
|
| + section_description_label_ = new views::Label(
|
| + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL));
|
| + enable_disable_button_ = new views::NativeButton(this,
|
| + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_BUTTON));
|
| + manage_printer_button_ = new views::NativeButton(this,
|
| + l10n_util::GetString(
|
| + IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_MANAGE_BUTTON));
|
| +
|
| + GridLayout* layout = new GridLayout(contents_);
|
| + contents_->SetLayoutManager(layout);
|
| +
|
| + const int single_column_view_set_id = 0;
|
| + AddWrappingColumnSet(layout, single_column_view_set_id);
|
| + const int control_view_set_id = 1;
|
| + AddDependentTwoColumnSet(layout, control_view_set_id);
|
| +
|
| + // The description label at the top and label.
|
| + section_description_label_->SetMultiLine(true);
|
| + AddWrappingLabelRow(layout, section_description_label_,
|
| + single_column_view_set_id, true);
|
| +
|
| + // The enable / disable button and manage button.
|
| + AddTwoColumnRow(layout, enable_disable_button_, manage_printer_button_, false,
|
| + control_view_set_id, kRelatedControlVerticalSpacing);
|
| +
|
| + // Attach the preferences so we can flip things appropriately.
|
| + cloud_print_proxy_email_.Init(prefs::kCloudPrintEmail,
|
| + profile()->GetPrefs(), this);
|
| +
|
| + // Start the UI off in the state we think it should be in.
|
| + std::string pref_string(prefs::kCloudPrintEmail);
|
| + NotifyPrefChanged(&pref_string);
|
| +
|
| + // Kick off a task to ask the background service what the real
|
| + // answer is.
|
| + CloudPrintSetupFlow::RefreshPreferencesFromService(
|
| + profile(),
|
| + factory_.NewCallback(&CloudPrintProxySection::StatusCallback));
|
| +}
|
| +
|
| +void CloudPrintProxySection::NotifyPrefChanged(const std::string* pref_name) {
|
| + if (pref_name == NULL)
|
| + return;
|
| +
|
| + if (*pref_name == prefs::kCloudPrintEmail) {
|
| + if (Enabled()) {
|
| + std::string email;
|
| + if (profile()->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail))
|
| + email = profile()->GetPrefs()->GetString(prefs::kCloudPrintEmail);
|
| +
|
| + section_description_label_->SetText(
|
| + l10n_util::GetStringF(IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_LABEL,
|
| + UTF8ToWide(email)));
|
| + enable_disable_button_->SetLabel(
|
| + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_BUTTON));
|
| + enable_disable_button_->InvalidateLayout();
|
| + manage_printer_button_->SetVisible(true);
|
| + manage_printer_button_->InvalidateLayout();
|
| + } else {
|
| + section_description_label_->SetText(
|
| + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL));
|
| + enable_disable_button_->SetLabel(
|
| + l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_BUTTON));
|
| + enable_disable_button_->InvalidateLayout();
|
| + manage_printer_button_->SetVisible(false);
|
| + }
|
| + Layout();
|
| + }
|
| +}
|
| +
|
| +bool CloudPrintProxySection::Enabled() const {
|
| + return profile()->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) &&
|
| + !profile()->GetPrefs()->GetString(prefs::kCloudPrintEmail).empty();
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| // AdvancedContentsView
|
|
|
| class AdvancedContentsView : public OptionsPageView {
|
| @@ -1462,6 +1619,11 @@ void AdvancedContentsView::InitControlLayout() {
|
| layout->StartRow(0, single_column_view_set_id);
|
| layout->AddView(new SecuritySection(profile()));
|
| if (CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kEnableCloudPrintProxy)) {
|
| + layout->StartRow(0, single_column_view_set_id);
|
| + layout->AddView(new CloudPrintProxySection(profile()));
|
| + }
|
| + if (CommandLine::ForCurrentProcess()->HasSwitch(
|
| switches::kEnableBackgroundMode)) {
|
| layout->StartRow(0, single_column_view_set_id);
|
| layout->AddView(new ChromeAppsSection(profile()));
|
|
|