OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/views/options/advanced_contents_view.h" | 5 #include "chrome/browser/views/options/advanced_contents_view.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <cryptuiapi.h> | 9 #include <cryptuiapi.h> |
10 #pragma comment(lib, "cryptui.lib") | 10 #pragma comment(lib, "cryptui.lib") |
11 #include <shellapi.h> | 11 #include <shellapi.h> |
12 #include <vsstyle.h> | 12 #include <vsstyle.h> |
13 #include <vssym32.h> | 13 #include <vssym32.h> |
14 | 14 |
15 #include "app/l10n_util.h" | 15 #include "app/l10n_util.h" |
16 #include "app/resource_bundle.h" | 16 #include "app/resource_bundle.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
19 #include "base/i18n/rtl.h" | 19 #include "base/i18n/rtl.h" |
20 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 22 #include "base/scoped_callback_factory.h" |
22 #include "base/thread.h" | 23 #include "base/thread.h" |
23 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
24 #include "chrome/browser/browser.h" | 25 #include "chrome/browser/browser.h" |
25 #include "chrome/browser/browser_list.h" | 26 #include "chrome/browser/browser_list.h" |
26 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
27 #include "chrome/browser/download/download_manager.h" | 28 #include "chrome/browser/download/download_manager.h" |
28 #include "chrome/browser/download/download_prefs.h" | 29 #include "chrome/browser/download/download_prefs.h" |
29 #include "chrome/browser/gears_integration.h" | 30 #include "chrome/browser/gears_integration.h" |
30 #include "chrome/browser/net/predictor_api.h" | 31 #include "chrome/browser/net/predictor_api.h" |
31 #include "chrome/browser/options_util.h" | 32 #include "chrome/browser/options_util.h" |
32 #include "chrome/browser/prefs/pref_member.h" | 33 #include "chrome/browser/prefs/pref_member.h" |
33 #include "chrome/browser/prefs/pref_service.h" | 34 #include "chrome/browser/prefs/pref_service.h" |
34 #include "chrome/browser/prefs/pref_set_observer.h" | 35 #include "chrome/browser/prefs/pref_set_observer.h" |
| 36 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
35 #include "chrome/browser/profile.h" | 37 #include "chrome/browser/profile.h" |
36 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 38 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
37 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 39 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
38 #include "chrome/browser/shell_dialogs.h" | 40 #include "chrome/browser/shell_dialogs.h" |
39 #include "chrome/browser/views/browser_dialogs.h" | 41 #include "chrome/browser/views/browser_dialogs.h" |
40 #include "chrome/browser/views/clear_browsing_data.h" | 42 #include "chrome/browser/views/clear_browsing_data.h" |
41 #include "chrome/browser/views/list_background.h" | 43 #include "chrome/browser/views/list_background.h" |
42 #include "chrome/browser/views/options/content_settings_window_view.h" | 44 #include "chrome/browser/views/options/content_settings_window_view.h" |
43 #include "chrome/browser/views/options/fonts_languages_window_view.h" | 45 #include "chrome/browser/views/options/fonts_languages_window_view.h" |
44 #include "chrome/browser/views/restart_message_box.h" | 46 #include "chrome/browser/views/restart_message_box.h" |
(...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 } | 1360 } |
1359 | 1361 |
1360 void ChromeAppsSection::NotifyPrefChanged(const std::string* pref_name) { | 1362 void ChromeAppsSection::NotifyPrefChanged(const std::string* pref_name) { |
1361 if (!pref_name || *pref_name == prefs::kBackgroundModeEnabled) { | 1363 if (!pref_name || *pref_name == prefs::kBackgroundModeEnabled) { |
1362 enable_background_mode_checkbox_->SetChecked( | 1364 enable_background_mode_checkbox_->SetChecked( |
1363 enable_background_mode_.GetValue()); | 1365 enable_background_mode_.GetValue()); |
1364 } | 1366 } |
1365 } | 1367 } |
1366 | 1368 |
1367 //////////////////////////////////////////////////////////////////////////////// | 1369 //////////////////////////////////////////////////////////////////////////////// |
| 1370 // CloudPrintProxySection |
| 1371 |
| 1372 class CloudPrintProxySection : public AdvancedSection, |
| 1373 public views::ButtonListener { |
| 1374 public: |
| 1375 explicit CloudPrintProxySection(Profile* profile); |
| 1376 virtual ~CloudPrintProxySection() {} |
| 1377 |
| 1378 // Overridden from views::ButtonListener: |
| 1379 virtual void ButtonPressed(views::Button* sender, const views::Event& event); |
| 1380 |
| 1381 // Callback that gets the cloud print proxy status. |
| 1382 void StatusCallback(bool enabled, std::string email); |
| 1383 |
| 1384 protected: |
| 1385 // OptionsPageView overrides: |
| 1386 virtual void InitControlLayout(); |
| 1387 virtual void NotifyPrefChanged(const std::string* pref_name); |
| 1388 |
| 1389 private: |
| 1390 bool Enabled() const; |
| 1391 |
| 1392 // Controls for this section: |
| 1393 views::Label* section_description_label_; |
| 1394 views::NativeButton* enable_disable_button_; |
| 1395 views::NativeButton* manage_printer_button_; |
| 1396 |
| 1397 // Preferences we tie things to. |
| 1398 StringPrefMember cloud_print_proxy_email_; |
| 1399 |
| 1400 base::ScopedCallbackFactory<CloudPrintProxySection> factory_; |
| 1401 |
| 1402 DISALLOW_COPY_AND_ASSIGN(CloudPrintProxySection); |
| 1403 }; |
| 1404 |
| 1405 CloudPrintProxySection::CloudPrintProxySection(Profile* profile) |
| 1406 : section_description_label_(NULL), |
| 1407 enable_disable_button_(NULL), |
| 1408 manage_printer_button_(NULL), |
| 1409 factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 1410 AdvancedSection(profile, |
| 1411 l10n_util::GetString( |
| 1412 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CLOUD_PRINT)) { |
| 1413 } |
| 1414 |
| 1415 void CloudPrintProxySection::ButtonPressed(views::Button* sender, |
| 1416 const views::Event& event) { |
| 1417 if (sender == enable_disable_button_) { |
| 1418 if (Enabled()) { |
| 1419 // Enabled, we must be the disable button. |
| 1420 UserMetricsRecordAction( |
| 1421 UserMetricsAction("Options_DisableCloudPrintProxy"), NULL); |
| 1422 CloudPrintSetupFlow::DisableCloudPrintProxy(profile()); |
| 1423 } else { |
| 1424 UserMetricsRecordAction( |
| 1425 UserMetricsAction("Options_EnableCloudPrintProxy"), NULL); |
| 1426 // We open a new browser window so the Options dialog doesn't |
| 1427 // get lost behind other windows. |
| 1428 CloudPrintSetupFlow::OpenDialog(profile()); |
| 1429 } |
| 1430 } else if (sender == manage_printer_button_) { |
| 1431 // Open a new browser window for the management tab. The browser |
| 1432 // will go away when the user closes that tab. |
| 1433 Browser* browser = Browser::Create(profile()); |
| 1434 // FIXME(scottbyer): Refactor Cloud Print URL creation. |
| 1435 // http://code.google.com/p/chromium/issues/detail?id=56850 |
| 1436 browser->OpenURL(GURL("https://www.google.com/cloudprint/manage.html"), |
| 1437 GURL(), NEW_WINDOW, PageTransition::LINK); |
| 1438 } |
| 1439 } |
| 1440 |
| 1441 void CloudPrintProxySection::StatusCallback(bool enabled, std::string email) { |
| 1442 profile()->GetPrefs()->SetString(prefs::kCloudPrintEmail, |
| 1443 enabled ? email : std::string()); |
| 1444 } |
| 1445 |
| 1446 void CloudPrintProxySection::InitControlLayout() { |
| 1447 AdvancedSection::InitControlLayout(); |
| 1448 |
| 1449 section_description_label_ = new views::Label( |
| 1450 l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL)); |
| 1451 enable_disable_button_ = new views::NativeButton(this, |
| 1452 l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_BUTTON)); |
| 1453 manage_printer_button_ = new views::NativeButton(this, |
| 1454 l10n_util::GetString( |
| 1455 IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_MANAGE_BUTTON)); |
| 1456 |
| 1457 GridLayout* layout = new GridLayout(contents_); |
| 1458 contents_->SetLayoutManager(layout); |
| 1459 |
| 1460 const int single_column_view_set_id = 0; |
| 1461 AddWrappingColumnSet(layout, single_column_view_set_id); |
| 1462 const int control_view_set_id = 1; |
| 1463 AddDependentTwoColumnSet(layout, control_view_set_id); |
| 1464 |
| 1465 // The description label at the top and label. |
| 1466 section_description_label_->SetMultiLine(true); |
| 1467 AddWrappingLabelRow(layout, section_description_label_, |
| 1468 single_column_view_set_id, true); |
| 1469 |
| 1470 // The enable / disable button and manage button. |
| 1471 AddTwoColumnRow(layout, enable_disable_button_, manage_printer_button_, false, |
| 1472 control_view_set_id, kRelatedControlVerticalSpacing); |
| 1473 |
| 1474 // Attach the preferences so we can flip things appropriately. |
| 1475 cloud_print_proxy_email_.Init(prefs::kCloudPrintEmail, |
| 1476 profile()->GetPrefs(), this); |
| 1477 |
| 1478 // Start the UI off in the state we think it should be in. |
| 1479 std::string pref_string(prefs::kCloudPrintEmail); |
| 1480 NotifyPrefChanged(&pref_string); |
| 1481 |
| 1482 // Kick off a task to ask the background service what the real |
| 1483 // answer is. |
| 1484 CloudPrintSetupFlow::RefreshPreferencesFromService( |
| 1485 profile(), |
| 1486 factory_.NewCallback(&CloudPrintProxySection::StatusCallback)); |
| 1487 } |
| 1488 |
| 1489 void CloudPrintProxySection::NotifyPrefChanged(const std::string* pref_name) { |
| 1490 if (pref_name == NULL) |
| 1491 return; |
| 1492 |
| 1493 if (*pref_name == prefs::kCloudPrintEmail) { |
| 1494 if (Enabled()) { |
| 1495 std::string email; |
| 1496 if (profile()->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail)) |
| 1497 email = profile()->GetPrefs()->GetString(prefs::kCloudPrintEmail); |
| 1498 |
| 1499 section_description_label_->SetText( |
| 1500 l10n_util::GetStringF(IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_LABEL, |
| 1501 UTF8ToWide(email))); |
| 1502 enable_disable_button_->SetLabel( |
| 1503 l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_BUTTON)); |
| 1504 enable_disable_button_->InvalidateLayout(); |
| 1505 manage_printer_button_->SetVisible(true); |
| 1506 manage_printer_button_->InvalidateLayout(); |
| 1507 } else { |
| 1508 section_description_label_->SetText( |
| 1509 l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL)); |
| 1510 enable_disable_button_->SetLabel( |
| 1511 l10n_util::GetString(IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_BUTTON)); |
| 1512 enable_disable_button_->InvalidateLayout(); |
| 1513 manage_printer_button_->SetVisible(false); |
| 1514 } |
| 1515 Layout(); |
| 1516 } |
| 1517 } |
| 1518 |
| 1519 bool CloudPrintProxySection::Enabled() const { |
| 1520 return profile()->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && |
| 1521 !profile()->GetPrefs()->GetString(prefs::kCloudPrintEmail).empty(); |
| 1522 } |
| 1523 |
| 1524 //////////////////////////////////////////////////////////////////////////////// |
1368 // AdvancedContentsView | 1525 // AdvancedContentsView |
1369 | 1526 |
1370 class AdvancedContentsView : public OptionsPageView { | 1527 class AdvancedContentsView : public OptionsPageView { |
1371 public: | 1528 public: |
1372 explicit AdvancedContentsView(Profile* profile); | 1529 explicit AdvancedContentsView(Profile* profile); |
1373 virtual ~AdvancedContentsView(); | 1530 virtual ~AdvancedContentsView(); |
1374 | 1531 |
1375 // views::View overrides: | 1532 // views::View overrides: |
1376 virtual int GetLineScrollIncrement(views::ScrollView* scroll_view, | 1533 virtual int GetLineScrollIncrement(views::ScrollView* scroll_view, |
1377 bool is_horizontal, bool is_positive); | 1534 bool is_horizontal, bool is_positive); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 layout->AddView(new NetworkSection(profile())); | 1612 layout->AddView(new NetworkSection(profile())); |
1456 layout->StartRow(0, single_column_view_set_id); | 1613 layout->StartRow(0, single_column_view_set_id); |
1457 layout->AddView(new TranslateSection(profile())); | 1614 layout->AddView(new TranslateSection(profile())); |
1458 layout->StartRow(0, single_column_view_set_id); | 1615 layout->StartRow(0, single_column_view_set_id); |
1459 layout->AddView(new DownloadSection(profile())); | 1616 layout->AddView(new DownloadSection(profile())); |
1460 layout->StartRow(0, single_column_view_set_id); | 1617 layout->StartRow(0, single_column_view_set_id); |
1461 layout->AddView(new WebContentSection(profile())); | 1618 layout->AddView(new WebContentSection(profile())); |
1462 layout->StartRow(0, single_column_view_set_id); | 1619 layout->StartRow(0, single_column_view_set_id); |
1463 layout->AddView(new SecuritySection(profile())); | 1620 layout->AddView(new SecuritySection(profile())); |
1464 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1621 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1622 switches::kEnableCloudPrintProxy)) { |
| 1623 layout->StartRow(0, single_column_view_set_id); |
| 1624 layout->AddView(new CloudPrintProxySection(profile())); |
| 1625 } |
| 1626 if (CommandLine::ForCurrentProcess()->HasSwitch( |
1465 switches::kEnableBackgroundMode)) { | 1627 switches::kEnableBackgroundMode)) { |
1466 layout->StartRow(0, single_column_view_set_id); | 1628 layout->StartRow(0, single_column_view_set_id); |
1467 layout->AddView(new ChromeAppsSection(profile())); | 1629 layout->AddView(new ChromeAppsSection(profile())); |
1468 } | 1630 } |
1469 } | 1631 } |
1470 | 1632 |
1471 //////////////////////////////////////////////////////////////////////////////// | 1633 //////////////////////////////////////////////////////////////////////////////// |
1472 // AdvancedContentsView, private: | 1634 // AdvancedContentsView, private: |
1473 | 1635 |
1474 void AdvancedContentsView::InitClass() { | 1636 void AdvancedContentsView::InitClass() { |
(...skipping 23 matching lines...) Expand all Loading... |
1498 // AdvancedScrollViewContainer, views::View overrides: | 1660 // AdvancedScrollViewContainer, views::View overrides: |
1499 | 1661 |
1500 void AdvancedScrollViewContainer::Layout() { | 1662 void AdvancedScrollViewContainer::Layout() { |
1501 gfx::Rect lb = GetLocalBounds(false); | 1663 gfx::Rect lb = GetLocalBounds(false); |
1502 | 1664 |
1503 gfx::Size border = gfx::NativeTheme::instance()->GetThemeBorderSize( | 1665 gfx::Size border = gfx::NativeTheme::instance()->GetThemeBorderSize( |
1504 gfx::NativeTheme::LIST); | 1666 gfx::NativeTheme::LIST); |
1505 lb.Inset(border.width(), border.height()); | 1667 lb.Inset(border.width(), border.height()); |
1506 scroll_view_->SetBounds(lb); | 1668 scroll_view_->SetBounds(lb); |
1507 } | 1669 } |
OLD | NEW |