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