OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #endif // OS_WIN | 10 #endif // OS_WIN |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/base_paths.h" | 15 #include "base/base_paths.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" |
20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
22 #include "base/string_number_conversions.h" | 22 #include "base/string_number_conversions.h" |
23 #include "base/string_util.h" | 23 #include "base/string_util.h" |
24 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
25 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
26 #include "base/threading/thread_restrictions.h" | 26 #include "base/threading/thread_restrictions.h" |
27 #include "base/time.h" | 27 #include "base/time.h" |
28 #include "base/utf_string_conversions.h" | 28 #include "base/utf_string_conversions.h" |
29 #include "base/win/metro.h" | |
Albert Bodenhamer
2012/06/15 18:41:24
Safe to include this here?
MAD
2012/06/19 14:24:10
Right, I need to wrap it within #if defined (OS_WI
MAD
2012/06/28 15:48:14
Done.
| |
29 #include "chrome/app/chrome_command_ids.h" | 30 #include "chrome/app/chrome_command_ids.h" |
30 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 31 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
31 #include "chrome/browser/background/background_contents_service.h" | 32 #include "chrome/browser/background/background_contents_service.h" |
32 #include "chrome/browser/background/background_contents_service_factory.h" | 33 #include "chrome/browser/background/background_contents_service_factory.h" |
33 #include "chrome/browser/bookmarks/bookmark_model.h" | 34 #include "chrome/browser/bookmarks/bookmark_model.h" |
34 #include "chrome/browser/bookmarks/bookmark_utils.h" | 35 #include "chrome/browser/bookmarks/bookmark_utils.h" |
35 #include "chrome/browser/browser_process.h" | 36 #include "chrome/browser/browser_process.h" |
36 #include "chrome/browser/browser_shutdown.h" | 37 #include "chrome/browser/browser_shutdown.h" |
37 #include "chrome/browser/character_encoding.h" | 38 #include "chrome/browser/character_encoding.h" |
38 #include "chrome/browser/chrome_page_zoom.h" | 39 #include "chrome/browser/chrome_page_zoom.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 #include "content/public/common/page_zoom.h" | 173 #include "content/public/common/page_zoom.h" |
173 #include "content/public/common/renderer_preferences.h" | 174 #include "content/public/common/renderer_preferences.h" |
174 #include "grit/chromium_strings.h" | 175 #include "grit/chromium_strings.h" |
175 #include "grit/generated_resources.h" | 176 #include "grit/generated_resources.h" |
176 #include "grit/locale_settings.h" | 177 #include "grit/locale_settings.h" |
177 #include "grit/theme_resources_standard.h" | 178 #include "grit/theme_resources_standard.h" |
178 #include "net/base/net_util.h" | 179 #include "net/base/net_util.h" |
179 #include "net/base/registry_controlled_domain.h" | 180 #include "net/base/registry_controlled_domain.h" |
180 #include "net/cookies/cookie_monster.h" | 181 #include "net/cookies/cookie_monster.h" |
181 #include "net/url_request/url_request_context.h" | 182 #include "net/url_request/url_request_context.h" |
183 #include "printing/printed_document.h" | |
182 #include "ui/base/animation/animation.h" | 184 #include "ui/base/animation/animation.h" |
183 #include "ui/base/l10n/l10n_util.h" | 185 #include "ui/base/l10n/l10n_util.h" |
184 #include "ui/gfx/point.h" | 186 #include "ui/gfx/point.h" |
185 #include "webkit/glue/web_intent_data.h" | 187 #include "webkit/glue/web_intent_data.h" |
186 #include "webkit/glue/web_intent_service_data.h" | 188 #include "webkit/glue/web_intent_service_data.h" |
187 #include "webkit/glue/webkit_glue.h" | 189 #include "webkit/glue/webkit_glue.h" |
188 #include "webkit/glue/window_open_disposition.h" | 190 #include "webkit/glue/window_open_disposition.h" |
189 #include "webkit/plugins/webplugininfo.h" | 191 #include "webkit/plugins/webplugininfo.h" |
190 | 192 |
191 #if defined(OS_WIN) | 193 #if defined(OS_WIN) |
(...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1609 GetActiveTabContents()->print_view_manager()->PrintNow(); | 1611 GetActiveTabContents()->print_view_manager()->PrintNow(); |
1610 } else { | 1612 } else { |
1611 GetActiveTabContents()->print_view_manager()->PrintPreviewNow(); | 1613 GetActiveTabContents()->print_view_manager()->PrintPreviewNow(); |
1612 } | 1614 } |
1613 } | 1615 } |
1614 | 1616 |
1615 void Browser::AdvancedPrint() { | 1617 void Browser::AdvancedPrint() { |
1616 GetActiveTabContents()->print_view_manager()->AdvancedPrintNow(); | 1618 GetActiveTabContents()->print_view_manager()->AdvancedPrintNow(); |
1617 } | 1619 } |
1618 | 1620 |
1621 void Browser::PrintToDelegate() { | |
Albert Bodenhamer
2012/06/15 18:41:24
Does this need to live in browser? If you pull Me
MAD
2012/06/19 14:24:10
Good point, will move it to a more sensible place.
MAD
2012/06/28 15:48:14
Actually, I would look the interface pointer to co
| |
1622 scoped_refptr<printing::PrintedDocument::Delegate> printed_document_delegate; | |
1623 #if defined(OS_WIN) | |
1624 class MetroPrintingDelegate : public printing::PrintedDocument::Delegate { | |
Albert Bodenhamer
2012/06/15 18:41:24
Pull this into its own .cc/.h
MAD
2012/06/19 14:24:10
Yep, will do...
MAD
2012/06/28 15:48:14
Done.
| |
1625 public: | |
1626 MetroPrintingDelegate() | |
1627 : metro_set_print_page_count_(NULL), | |
1628 metro_set_print_page_content_(NULL) { | |
1629 HMODULE metro_module = base::win::GetMetroModule(); | |
1630 if (metro_module != NULL) { | |
1631 metro_set_print_page_count_ = | |
1632 reinterpret_cast<MetroSetPrintPageCount>( | |
1633 ::GetProcAddress(metro_module, "MetroSetPrintPageCount")); | |
1634 metro_set_print_page_content_ = | |
1635 reinterpret_cast<MetroSetPrintPageContent>( | |
1636 ::GetProcAddress(metro_module, "MetroSetPrintPageContent")); | |
1637 } | |
1638 } | |
1639 virtual void SetPageCount(int page_count) { | |
1640 if (metro_set_print_page_count_) | |
1641 metro_set_print_page_count_(page_count); | |
1642 } | |
1643 | |
1644 virtual void SetPageContent(int page_number, | |
1645 void* content, | |
1646 size_t content_size) { | |
1647 if (metro_set_print_page_content_) | |
1648 metro_set_print_page_content_(page_number - 1, content, content_size); | |
1649 } | |
1650 private: | |
1651 typedef void (*MetroSetPrintPageCount)(INT); | |
1652 typedef void (*MetroSetPrintPageContent)(INT, VOID*, UINT32); | |
1653 MetroSetPrintPageCount metro_set_print_page_count_; | |
1654 MetroSetPrintPageContent metro_set_print_page_content_; | |
1655 }; | |
1656 printed_document_delegate = new MetroPrintingDelegate(); | |
1657 #endif // defined(OS_WIN) | |
1658 GetActiveTabContents()->print_view_manager()->PrintToDelegate( | |
1659 printed_document_delegate.get()); | |
1660 } | |
1661 | |
1619 void Browser::EmailPageLocation() { | 1662 void Browser::EmailPageLocation() { |
1620 content::RecordAction(UserMetricsAction("EmailPageLocation")); | 1663 content::RecordAction(UserMetricsAction("EmailPageLocation")); |
1621 WebContents* wc = GetActiveWebContents(); | 1664 WebContents* wc = GetActiveWebContents(); |
1622 DCHECK(wc); | 1665 DCHECK(wc); |
1623 | 1666 |
1624 std::string title = net::EscapeQueryParamValue( | 1667 std::string title = net::EscapeQueryParamValue( |
1625 UTF16ToUTF8(wc->GetTitle()), false); | 1668 UTF16ToUTF8(wc->GetTitle()), false); |
1626 std::string page_url = net::EscapeQueryParamValue(wc->GetURL().spec(), false); | 1669 std::string page_url = net::EscapeQueryParamValue(wc->GetURL().spec(), false); |
1627 std::string mailto = std::string("mailto:?subject=Fwd:%20") + | 1670 std::string mailto = std::string("mailto:?subject=Fwd:%20") + |
1628 title + "&body=%0A%0A" + page_url; | 1671 title + "&body=%0A%0A" + page_url; |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2509 case IDC_EXIT: Exit(); break; | 2552 case IDC_EXIT: Exit(); break; |
2510 | 2553 |
2511 // Page-related commands | 2554 // Page-related commands |
2512 case IDC_SAVE_PAGE: SavePage(); break; | 2555 case IDC_SAVE_PAGE: SavePage(); break; |
2513 case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break; | 2556 case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break; |
2514 case IDC_PIN_TO_START_SCREEN: PinCurrentPageToStartScreen(); break; | 2557 case IDC_PIN_TO_START_SCREEN: PinCurrentPageToStartScreen(); break; |
2515 case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(); break; | 2558 case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(); break; |
2516 case IDC_VIEW_SOURCE: ViewSelectedSource(); break; | 2559 case IDC_VIEW_SOURCE: ViewSelectedSource(); break; |
2517 case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break; | 2560 case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break; |
2518 case IDC_PRINT: Print(); break; | 2561 case IDC_PRINT: Print(); break; |
2562 case IDC_PRINT_TO_FILE : PrintToDelegate(); break; | |
2519 case IDC_ADVANCED_PRINT: AdvancedPrint(); break; | 2563 case IDC_ADVANCED_PRINT: AdvancedPrint(); break; |
2520 case IDC_CHROME_TO_MOBILE_PAGE: ShowChromeToMobileBubble(); break; | 2564 case IDC_CHROME_TO_MOBILE_PAGE: ShowChromeToMobileBubble(); break; |
2521 case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break; | 2565 case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break; |
2522 case IDC_ENCODING_UTF8: | 2566 case IDC_ENCODING_UTF8: |
2523 case IDC_ENCODING_UTF16LE: | 2567 case IDC_ENCODING_UTF16LE: |
2524 case IDC_ENCODING_ISO88591: | 2568 case IDC_ENCODING_ISO88591: |
2525 case IDC_ENCODING_WINDOWS1252: | 2569 case IDC_ENCODING_WINDOWS1252: |
2526 case IDC_ENCODING_GBK: | 2570 case IDC_ENCODING_GBK: |
2527 case IDC_ENCODING_GB18030: | 2571 case IDC_ENCODING_GB18030: |
2528 case IDC_ENCODING_BIG5HKSCS: | 2572 case IDC_ENCODING_BIG5HKSCS: |
(...skipping 1922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4451 printing::PrintPreviewTabController* controller = | 4495 printing::PrintPreviewTabController* controller = |
4452 printing::PrintPreviewTabController::GetInstance(); | 4496 printing::PrintPreviewTabController::GetInstance(); |
4453 if (controller && (controller->GetPrintPreviewForTab(tab_contents) || | 4497 if (controller && (controller->GetPrintPreviewForTab(tab_contents) || |
4454 controller->is_creating_print_preview_tab())) { | 4498 controller->is_creating_print_preview_tab())) { |
4455 advanced_print_enabled = true; | 4499 advanced_print_enabled = true; |
4456 } | 4500 } |
4457 } | 4501 } |
4458 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); | 4502 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); |
4459 command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT, | 4503 command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT, |
4460 advanced_print_enabled); | 4504 advanced_print_enabled); |
4505 command_updater_.UpdateCommandEnabled(IDC_PRINT_TO_FILE, print_enabled); | |
4461 } | 4506 } |
4462 | 4507 |
4463 void Browser::UpdateSaveAsState(int content_restrictions) { | 4508 void Browser::UpdateSaveAsState(int content_restrictions) { |
4464 bool enabled = !(content_restrictions & content::CONTENT_RESTRICTION_SAVE); | 4509 bool enabled = !(content_restrictions & content::CONTENT_RESTRICTION_SAVE); |
4465 PrefService* state = g_browser_process->local_state(); | 4510 PrefService* state = g_browser_process->local_state(); |
4466 if (state) | 4511 if (state) |
4467 enabled = enabled && state->GetBoolean(prefs::kAllowFileSelectionDialogs); | 4512 enabled = enabled && state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
4468 | 4513 |
4469 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, enabled); | 4514 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, enabled); |
4470 } | 4515 } |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5225 if (contents && !allow_js_access) { | 5270 if (contents && !allow_js_access) { |
5226 contents->web_contents()->GetController().LoadURL( | 5271 contents->web_contents()->GetController().LoadURL( |
5227 target_url, | 5272 target_url, |
5228 content::Referrer(), | 5273 content::Referrer(), |
5229 content::PAGE_TRANSITION_LINK, | 5274 content::PAGE_TRANSITION_LINK, |
5230 std::string()); // No extra headers. | 5275 std::string()); // No extra headers. |
5231 } | 5276 } |
5232 | 5277 |
5233 return contents != NULL; | 5278 return contents != NULL; |
5234 } | 5279 } |
OLD | NEW |