| 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 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 *web_contents = chrome::GetActiveWebContents(browser); | 1633 *web_contents = chrome::GetActiveWebContents(browser); |
| 1634 if (*web_contents == NULL) { | 1634 if (*web_contents == NULL) { |
| 1635 error_ = keys::kInternalVisibleTabCaptureError; | 1635 error_ = keys::kInternalVisibleTabCaptureError; |
| 1636 return false; | 1636 return false; |
| 1637 } | 1637 } |
| 1638 | 1638 |
| 1639 return true; | 1639 return true; |
| 1640 }; | 1640 }; |
| 1641 | 1641 |
| 1642 bool CaptureVisibleTabFunction::RunImpl() { | 1642 bool CaptureVisibleTabFunction::RunImpl() { |
| 1643 PrefService* service = profile()->GetPrefs(); | 1643 PrefServiceBase* service = profile()->GetPrefs(); |
| 1644 if (service->GetBoolean(prefs::kDisableScreenshots)) { | 1644 if (service->GetBoolean(prefs::kDisableScreenshots)) { |
| 1645 error_ = keys::kScreenshotsDisabled; | 1645 error_ = keys::kScreenshotsDisabled; |
| 1646 return false; | 1646 return false; |
| 1647 } | 1647 } |
| 1648 | 1648 |
| 1649 WebContents* web_contents = NULL; | 1649 WebContents* web_contents = NULL; |
| 1650 if (!GetTabToCapture(&web_contents)) | 1650 if (!GetTabToCapture(&web_contents)) |
| 1651 return false; | 1651 return false; |
| 1652 | 1652 |
| 1653 image_format_ = FORMAT_JPEG; // Default format is JPEG. | 1653 image_format_ = FORMAT_JPEG; // Default format is JPEG. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1794 base::StringPiece stream_as_string( | 1794 base::StringPiece stream_as_string( |
| 1795 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); | 1795 reinterpret_cast<const char*>(vector_as_array(&data)), data.size()); |
| 1796 | 1796 |
| 1797 base::Base64Encode(stream_as_string, &base64_result); | 1797 base::Base64Encode(stream_as_string, &base64_result); |
| 1798 base64_result.insert(0, base::StringPrintf("data:%s;base64,", | 1798 base64_result.insert(0, base::StringPrintf("data:%s;base64,", |
| 1799 mime_type.c_str())); | 1799 mime_type.c_str())); |
| 1800 SetResult(new StringValue(base64_result)); | 1800 SetResult(new StringValue(base64_result)); |
| 1801 SendResponse(true); | 1801 SendResponse(true); |
| 1802 } | 1802 } |
| 1803 | 1803 |
| 1804 void CaptureVisibleTabFunction::RegisterUserPrefs(PrefService* service) { | 1804 void CaptureVisibleTabFunction::RegisterUserPrefs( |
| 1805 PrefServiceSyncable* service) { |
| 1805 service->RegisterBooleanPref(prefs::kDisableScreenshots, false, | 1806 service->RegisterBooleanPref(prefs::kDisableScreenshots, false, |
| 1806 PrefService::UNSYNCABLE_PREF); | 1807 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 1807 } | 1808 } |
| 1808 | 1809 |
| 1809 bool DetectTabLanguageFunction::RunImpl() { | 1810 bool DetectTabLanguageFunction::RunImpl() { |
| 1810 int tab_id = 0; | 1811 int tab_id = 0; |
| 1811 Browser* browser = NULL; | 1812 Browser* browser = NULL; |
| 1812 WebContents* contents = NULL; | 1813 WebContents* contents = NULL; |
| 1813 | 1814 |
| 1814 // If |tab_id| is specified, look for it. Otherwise default to selected tab | 1815 // If |tab_id| is specified, look for it. Otherwise default to selected tab |
| 1815 // in the current window. | 1816 // in the current window. |
| 1816 if (HasOptionalArgument(0)) { | 1817 if (HasOptionalArgument(0)) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 // called for every API call the extension made. | 1876 // called for every API call the extension made. |
| 1876 GotLanguage(language); | 1877 GotLanguage(language); |
| 1877 } | 1878 } |
| 1878 | 1879 |
| 1879 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1880 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
| 1880 SetResult(Value::CreateStringValue(language.c_str())); | 1881 SetResult(Value::CreateStringValue(language.c_str())); |
| 1881 SendResponse(true); | 1882 SendResponse(true); |
| 1882 | 1883 |
| 1883 Release(); // Balanced in Run() | 1884 Release(); // Balanced in Run() |
| 1884 } | 1885 } |
| OLD | NEW |