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/extensions/api/tabs/tabs.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 23 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
24 #include "chrome/browser/extensions/extension_function_util.h" | 24 #include "chrome/browser/extensions/extension_function_util.h" |
25 #include "chrome/browser/extensions/extension_host.h" | 25 #include "chrome/browser/extensions/extension_host.h" |
26 #include "chrome/browser/extensions/extension_service.h" | 26 #include "chrome/browser/extensions/extension_service.h" |
27 #include "chrome/browser/extensions/extension_tab_helper.h" | 27 #include "chrome/browser/extensions/extension_tab_helper.h" |
28 #include "chrome/browser/extensions/extension_tab_util.h" | 28 #include "chrome/browser/extensions/extension_tab_util.h" |
29 #include "chrome/browser/extensions/extension_window_controller.h" | 29 #include "chrome/browser/extensions/extension_window_controller.h" |
30 #include "chrome/browser/extensions/extension_window_list.h" | 30 #include "chrome/browser/extensions/extension_window_list.h" |
31 #include "chrome/browser/extensions/script_executor.h" | 31 #include "chrome/browser/extensions/script_executor.h" |
32 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 32 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 33 #include "chrome/browser/prefs/pref_service.h" |
33 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
34 #include "chrome/browser/sessions/restore_tab_helper.h" | 35 #include "chrome/browser/sessions/restore_tab_helper.h" |
35 #include "chrome/browser/translate/translate_tab_helper.h" | 36 #include "chrome/browser/translate/translate_tab_helper.h" |
36 #include "chrome/browser/ui/browser.h" | 37 #include "chrome/browser/ui/browser.h" |
37 #include "chrome/browser/ui/browser_commands.h" | 38 #include "chrome/browser/ui/browser_commands.h" |
38 #include "chrome/browser/ui/browser_finder.h" | 39 #include "chrome/browser/ui/browser_finder.h" |
39 #include "chrome/browser/ui/browser_list.h" | 40 #include "chrome/browser/ui/browser_list.h" |
40 #include "chrome/browser/ui/browser_navigator.h" | 41 #include "chrome/browser/ui/browser_navigator.h" |
41 #include "chrome/browser/ui/browser_tabstrip.h" | 42 #include "chrome/browser/ui/browser_tabstrip.h" |
42 #include "chrome/browser/ui/browser_window.h" | 43 #include "chrome/browser/ui/browser_window.h" |
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1592 error_ = keys::kInternalVisibleTabCaptureError; | 1593 error_ = keys::kInternalVisibleTabCaptureError; |
1593 return false; | 1594 return false; |
1594 } | 1595 } |
1595 | 1596 |
1596 *tab_contents = chrome::GetActiveTabContents(browser); | 1597 *tab_contents = chrome::GetActiveTabContents(browser); |
1597 | 1598 |
1598 return true; | 1599 return true; |
1599 }; | 1600 }; |
1600 | 1601 |
1601 bool CaptureVisibleTabFunction::RunImpl() { | 1602 bool CaptureVisibleTabFunction::RunImpl() { |
| 1603 PrefService* service = profile()->GetPrefs(); |
| 1604 if (service->GetBoolean(prefs::kDisableScreenshots)) { |
| 1605 error_ = keys::kScreenshotsDisabled; |
| 1606 return false; |
| 1607 } |
| 1608 |
1602 WebContents* web_contents = NULL; | 1609 WebContents* web_contents = NULL; |
1603 TabContents* tab_contents = NULL; | 1610 TabContents* tab_contents = NULL; |
1604 if (!GetTabToCapture(&web_contents, &tab_contents)) | 1611 if (!GetTabToCapture(&web_contents, &tab_contents)) |
1605 return false; | 1612 return false; |
1606 | 1613 |
1607 image_format_ = FORMAT_JPEG; // Default format is JPEG. | 1614 image_format_ = FORMAT_JPEG; // Default format is JPEG. |
1608 image_quality_ = kDefaultQuality; // Default quality setting. | 1615 image_quality_ = kDefaultQuality; // Default quality setting. |
1609 | 1616 |
1610 if (HasOptionalArgument(1)) { | 1617 if (HasOptionalArgument(1)) { |
1611 DictionaryValue* options = NULL; | 1618 DictionaryValue* options = NULL; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 base::StringPiece stream_as_string( | 1756 base::StringPiece stream_as_string( |
1750 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); | 1757 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); |
1751 | 1758 |
1752 base::Base64Encode(stream_as_string, &base64_result); | 1759 base::Base64Encode(stream_as_string, &base64_result); |
1753 base64_result.insert(0, base::StringPrintf("data:%s;base64,", | 1760 base64_result.insert(0, base::StringPrintf("data:%s;base64,", |
1754 mime_type.c_str())); | 1761 mime_type.c_str())); |
1755 result_.reset(new StringValue(base64_result)); | 1762 result_.reset(new StringValue(base64_result)); |
1756 SendResponse(true); | 1763 SendResponse(true); |
1757 } | 1764 } |
1758 | 1765 |
| 1766 void CaptureVisibleTabFunction::RegisterUserPrefs(PrefService* service) { |
| 1767 service->RegisterBooleanPref(prefs::kDisableScreenshots, false, |
| 1768 PrefService::UNSYNCABLE_PREF); |
| 1769 } |
| 1770 |
1759 bool DetectTabLanguageFunction::RunImpl() { | 1771 bool DetectTabLanguageFunction::RunImpl() { |
1760 int tab_id = 0; | 1772 int tab_id = 0; |
1761 Browser* browser = NULL; | 1773 Browser* browser = NULL; |
1762 TabContents* contents = NULL; | 1774 TabContents* contents = NULL; |
1763 | 1775 |
1764 // If |tab_id| is specified, look for it. Otherwise default to selected tab | 1776 // If |tab_id| is specified, look for it. Otherwise default to selected tab |
1765 // in the current window. | 1777 // in the current window. |
1766 if (HasOptionalArgument(0)) { | 1778 if (HasOptionalArgument(0)) { |
1767 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 1779 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
1768 if (!GetTabById(tab_id, profile(), include_incognito(), | 1780 if (!GetTabById(tab_id, profile(), include_incognito(), |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1826 // called for every API call the extension made. | 1838 // called for every API call the extension made. |
1827 GotLanguage(language); | 1839 GotLanguage(language); |
1828 } | 1840 } |
1829 | 1841 |
1830 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1842 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
1831 result_.reset(Value::CreateStringValue(language.c_str())); | 1843 result_.reset(Value::CreateStringValue(language.c_str())); |
1832 SendResponse(true); | 1844 SendResponse(true); |
1833 | 1845 |
1834 Release(); // Balanced in Run() | 1846 Release(); // Balanced in Run() |
1835 } | 1847 } |
OLD | NEW |