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/tab_helper.h" | 27 #include "chrome/browser/extensions/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/script_executor.h" | 29 #include "chrome/browser/extensions/script_executor.h" |
30 #include "chrome/browser/extensions/window_controller.h" | 30 #include "chrome/browser/extensions/window_controller.h" |
31 #include "chrome/browser/extensions/window_controller_list.h" | 31 #include "chrome/browser/extensions/window_controller_list.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 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 error_ = keys::kInternalVisibleTabCaptureError; | 1578 error_ = keys::kInternalVisibleTabCaptureError; |
1578 return false; | 1579 return false; |
1579 } | 1580 } |
1580 | 1581 |
1581 *tab_contents = chrome::GetActiveTabContents(browser); | 1582 *tab_contents = chrome::GetActiveTabContents(browser); |
1582 | 1583 |
1583 return true; | 1584 return true; |
1584 }; | 1585 }; |
1585 | 1586 |
1586 bool CaptureVisibleTabFunction::RunImpl() { | 1587 bool CaptureVisibleTabFunction::RunImpl() { |
| 1588 PrefService* service = profile()->GetPrefs(); |
| 1589 if (service->GetBoolean(prefs::kDisableScreenshots)) { |
| 1590 error_ = keys::kScreenshotsDisabled; |
| 1591 return false; |
| 1592 } |
| 1593 |
1587 WebContents* web_contents = NULL; | 1594 WebContents* web_contents = NULL; |
1588 TabContents* tab_contents = NULL; | 1595 TabContents* tab_contents = NULL; |
1589 if (!GetTabToCapture(&web_contents, &tab_contents)) | 1596 if (!GetTabToCapture(&web_contents, &tab_contents)) |
1590 return false; | 1597 return false; |
1591 | 1598 |
1592 image_format_ = FORMAT_JPEG; // Default format is JPEG. | 1599 image_format_ = FORMAT_JPEG; // Default format is JPEG. |
1593 image_quality_ = kDefaultQuality; // Default quality setting. | 1600 image_quality_ = kDefaultQuality; // Default quality setting. |
1594 | 1601 |
1595 if (HasOptionalArgument(1)) { | 1602 if (HasOptionalArgument(1)) { |
1596 DictionaryValue* options = NULL; | 1603 DictionaryValue* options = NULL; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1734 base::StringPiece stream_as_string( | 1741 base::StringPiece stream_as_string( |
1735 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); | 1742 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); |
1736 | 1743 |
1737 base::Base64Encode(stream_as_string, &base64_result); | 1744 base::Base64Encode(stream_as_string, &base64_result); |
1738 base64_result.insert(0, base::StringPrintf("data:%s;base64,", | 1745 base64_result.insert(0, base::StringPrintf("data:%s;base64,", |
1739 mime_type.c_str())); | 1746 mime_type.c_str())); |
1740 SetResult(new StringValue(base64_result)); | 1747 SetResult(new StringValue(base64_result)); |
1741 SendResponse(true); | 1748 SendResponse(true); |
1742 } | 1749 } |
1743 | 1750 |
| 1751 void CaptureVisibleTabFunction::RegisterUserPrefs(PrefService* service) { |
| 1752 service->RegisterBooleanPref(prefs::kDisableScreenshots, false, |
| 1753 PrefService::UNSYNCABLE_PREF); |
| 1754 } |
| 1755 |
1744 bool DetectTabLanguageFunction::RunImpl() { | 1756 bool DetectTabLanguageFunction::RunImpl() { |
1745 int tab_id = 0; | 1757 int tab_id = 0; |
1746 Browser* browser = NULL; | 1758 Browser* browser = NULL; |
1747 TabContents* contents = NULL; | 1759 TabContents* contents = NULL; |
1748 | 1760 |
1749 // If |tab_id| is specified, look for it. Otherwise default to selected tab | 1761 // If |tab_id| is specified, look for it. Otherwise default to selected tab |
1750 // in the current window. | 1762 // in the current window. |
1751 if (HasOptionalArgument(0)) { | 1763 if (HasOptionalArgument(0)) { |
1752 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 1764 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
1753 if (!GetTabById(tab_id, profile(), include_incognito(), | 1765 if (!GetTabById(tab_id, profile(), include_incognito(), |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1811 // called for every API call the extension made. | 1823 // called for every API call the extension made. |
1812 GotLanguage(language); | 1824 GotLanguage(language); |
1813 } | 1825 } |
1814 | 1826 |
1815 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1827 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
1816 SetResult(Value::CreateStringValue(language.c_str())); | 1828 SetResult(Value::CreateStringValue(language.c_str())); |
1817 SendResponse(true); | 1829 SendResponse(true); |
1818 | 1830 |
1819 Release(); // Balanced in Run() | 1831 Release(); // Balanced in Run() |
1820 } | 1832 } |
OLD | NEW |