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_api.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... | |
37 #include "chrome/browser/ui/browser_commands.h" | 37 #include "chrome/browser/ui/browser_commands.h" |
38 #include "chrome/browser/ui/browser_finder.h" | 38 #include "chrome/browser/ui/browser_finder.h" |
39 #include "chrome/browser/ui/browser_iterator.h" | 39 #include "chrome/browser/ui/browser_iterator.h" |
40 #include "chrome/browser/ui/browser_navigator.h" | 40 #include "chrome/browser/ui/browser_navigator.h" |
41 #include "chrome/browser/ui/browser_tabstrip.h" | 41 #include "chrome/browser/ui/browser_tabstrip.h" |
42 #include "chrome/browser/ui/browser_window.h" | 42 #include "chrome/browser/ui/browser_window.h" |
43 #include "chrome/browser/ui/host_desktop.h" | 43 #include "chrome/browser/ui/host_desktop.h" |
44 #include "chrome/browser/ui/panels/panel_manager.h" | 44 #include "chrome/browser/ui/panels/panel_manager.h" |
45 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
46 #include "chrome/browser/ui/window_sizer/window_sizer.h" | 46 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
47 #include "chrome/browser/ui/zoom/zoom_controller.h" | |
47 #include "chrome/browser/web_applications/web_app.h" | 48 #include "chrome/browser/web_applications/web_app.h" |
48 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
49 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" | 50 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" |
50 #include "chrome/common/extensions/api/tabs.h" | 51 #include "chrome/common/extensions/api/tabs.h" |
51 #include "chrome/common/extensions/api/windows.h" | 52 #include "chrome/common/extensions/api/windows.h" |
52 #include "chrome/common/extensions/extension_constants.h" | 53 #include "chrome/common/extensions/extension_constants.h" |
53 #include "chrome/common/pref_names.h" | 54 #include "chrome/common/pref_names.h" |
54 #include "chrome/common/url_constants.h" | 55 #include "chrome/common/url_constants.h" |
55 #include "components/pref_registry/pref_registry_syncable.h" | 56 #include "components/pref_registry/pref_registry_syncable.h" |
56 #include "components/translate/core/browser/language_state.h" | 57 #include "components/translate/core/browser/language_state.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 template <typename T> | 157 template <typename T> |
157 void AssignOptionalValue(const scoped_ptr<T>& source, | 158 void AssignOptionalValue(const scoped_ptr<T>& source, |
158 scoped_ptr<T>& destination) { | 159 scoped_ptr<T>& destination) { |
159 if (source.get()) { | 160 if (source.get()) { |
160 destination.reset(new T(*source.get())); | 161 destination.reset(new T(*source.get())); |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 } // namespace | 165 } // namespace |
165 | 166 |
167 void ZoomModeToZoomSettings(ZoomMode zoom_mode, | |
168 api::tabs::ZoomSettings* zoom_settings) { | |
169 DCHECK(zoom_settings); | |
170 switch (zoom_mode) { | |
171 case kZoomModeDefault: | |
172 zoom_settings->mode = api::tabs::ZoomSettings::MODE_AUTOMATIC; | |
173 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_ORIGIN; | |
174 break; | |
175 case kZoomModeIsolated: | |
176 zoom_settings->mode = api::tabs::ZoomSettings::MODE_AUTOMATIC; | |
177 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_TAB; | |
178 break; | |
179 case kZoomModeManual: | |
180 zoom_settings->mode = api::tabs::ZoomSettings::MODE_MANUAL; | |
181 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_TAB; | |
182 break; | |
183 case kZoomModeDisabled: | |
184 zoom_settings->mode = api::tabs::ZoomSettings::MODE_DISABLED; | |
185 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_TAB; | |
186 break; | |
187 } | |
188 } | |
189 | |
166 // Windows --------------------------------------------------------------------- | 190 // Windows --------------------------------------------------------------------- |
167 | 191 |
168 bool WindowsGetFunction::RunSync() { | 192 bool WindowsGetFunction::RunSync() { |
169 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_)); | 193 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_)); |
170 EXTENSION_FUNCTION_VALIDATE(params.get()); | 194 EXTENSION_FUNCTION_VALIDATE(params.get()); |
171 | 195 |
172 bool populate_tabs = false; | 196 bool populate_tabs = false; |
173 if (params->get_info.get() && params->get_info->populate.get()) | 197 if (params->get_info.get() && params->get_info->populate.get()) |
174 populate_tabs = *params->get_info->populate; | 198 populate_tabs = *params->get_info->populate; |
175 | 199 |
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1413 int tab_id = *params->tab_id; | 1437 int tab_id = *params->tab_id; |
1414 | 1438 |
1415 Browser* browser = NULL; | 1439 Browser* browser = NULL; |
1416 if (!GetTabById(tab_id, | 1440 if (!GetTabById(tab_id, |
1417 GetProfile(), | 1441 GetProfile(), |
1418 include_incognito(), | 1442 include_incognito(), |
1419 &browser, | 1443 &browser, |
1420 NULL, | 1444 NULL, |
1421 &web_contents, | 1445 &web_contents, |
1422 NULL, | 1446 NULL, |
1423 &error_)) | 1447 &error_)) { |
1424 return false; | 1448 return false; |
1449 } | |
1425 } | 1450 } |
1426 | 1451 |
1427 if (web_contents->ShowingInterstitialPage()) { | 1452 if (web_contents->ShowingInterstitialPage()) { |
1428 // This does as same as Browser::ReloadInternal. | 1453 // This does as same as Browser::ReloadInternal. |
1429 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); | 1454 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); |
1430 OpenURLParams params(entry->GetURL(), Referrer(), CURRENT_TAB, | 1455 OpenURLParams params(entry->GetURL(), Referrer(), CURRENT_TAB, |
1431 content::PAGE_TRANSITION_RELOAD, false); | 1456 content::PAGE_TRANSITION_RELOAD, false); |
1432 GetCurrentBrowser()->OpenURL(params); | 1457 GetCurrentBrowser()->OpenURL(params); |
1433 } else if (bypass_cache) { | 1458 } else if (bypass_cache) { |
1434 web_contents->GetController().ReloadIgnoringCache(true); | 1459 web_contents->GetController().ReloadIgnoringCache(true); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1742 | 1767 |
1743 execute_tab_id_ = tab_id; | 1768 execute_tab_id_ = tab_id; |
1744 details_ = details.Pass(); | 1769 details_ = details.Pass(); |
1745 return true; | 1770 return true; |
1746 } | 1771 } |
1747 | 1772 |
1748 bool TabsInsertCSSFunction::ShouldInsertCSS() const { | 1773 bool TabsInsertCSSFunction::ShouldInsertCSS() const { |
1749 return true; | 1774 return true; |
1750 } | 1775 } |
1751 | 1776 |
1777 bool ZoomAPIFunction::GetWebContents(int* tab_id, | |
Devlin
2014/06/16 19:04:47
Why not content::WebContents* GetWebContents(int*
wjmaclean
2014/06/18 19:03:52
I inherited this code from Paul Meyer, and I suspe
| |
1778 content::WebContents** web_contents) { | |
1779 if (tab_id) { | |
1780 if (!GetTabById(*tab_id, | |
1781 GetProfile(), | |
1782 include_incognito(), | |
1783 NULL, | |
1784 NULL, | |
1785 web_contents, | |
1786 NULL, | |
1787 &error_)) { | |
1788 return false; | |
1789 } | |
1790 } else { | |
1791 Browser* browser = GetCurrentBrowser(); | |
1792 if (!browser) { | |
1793 error_ = keys::kNoCurrentWindowError; | |
Devlin
2014/06/16 19:04:47
It's odd that a function called GetWebContents als
wjmaclean
2014/06/18 19:03:52
I've mentioned in the .h file that this function m
| |
1794 return false; | |
1795 } | |
1796 if (!ExtensionTabUtil::GetDefaultTab(browser, web_contents, NULL)) { | |
1797 error_ = keys::kNoSelectedTabError; | |
1798 return false; | |
1799 } | |
1800 } | |
1801 return true; | |
1802 } | |
1803 | |
1804 bool TabsSetZoomFunction::RunAsync() { | |
1805 scoped_ptr<tabs::SetZoom::Params> params( | |
1806 tabs::SetZoom::Params::Create(*args_)); | |
1807 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
1808 | |
1809 WebContents* web_contents = NULL; | |
1810 if (!GetWebContents(params->tab_id.get(), &web_contents)) | |
1811 return false; | |
1812 if (web_contents->GetURL().SchemeIs(content::kChromeUIScheme)) { | |
Devlin
2014/06/16 19:04:47
WebContents::GetURL() is deprecated. See web_cont
wjmaclean
2014/06/18 19:03:52
Done.
| |
1813 error_ = keys::kCannotZoomChromePagesError; | |
Devlin
2014/06/16 19:04:47
This looks like it should probably be using Permis
Devlin
2014/06/17 19:10:20
Going back to this - I thought developers would ne
wjmaclean
2014/06/18 19:03:52
Possibly. It seems to mean that any extension want
| |
1814 return false; | |
1815 } | |
1816 | |
1817 ZoomController* zoom_controller = | |
1818 ZoomController::FromWebContents(web_contents); | |
1819 double zoom_level = content::ZoomFactorToZoomLevel(params->zoom_factor); | |
1820 | |
1821 if (!zoom_controller->SetZoomLevelByExtension(zoom_level, GetExtension())) { | |
1822 // Tried to zoom a tab in disabled mode. | |
1823 error_ = keys::kCannotZoomDisabledTabError; | |
1824 return false; | |
1825 } | |
1826 | |
1827 SendResponse(true); | |
1828 return true; | |
1829 } | |
1830 | |
1831 bool TabsGetZoomFunction::RunAsync() { | |
1832 scoped_ptr<tabs::GetZoom::Params> params( | |
1833 tabs::GetZoom::Params::Create(*args_)); | |
1834 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
1835 | |
1836 WebContents* web_contents = NULL; | |
1837 if (!GetWebContents(params->tab_id.get(), &web_contents)) { | |
1838 return false; | |
Devlin
2014/06/16 19:04:47
nit: no braces around single-line conditionals.
wjmaclean
2014/06/18 19:03:52
Done.
| |
1839 } | |
1840 | |
1841 double zoom_level = | |
1842 ZoomController::FromWebContents(web_contents)->GetZoomLevel(); | |
1843 double zoom_factor = content::ZoomLevelToZoomFactor(zoom_level); | |
1844 results_ = tabs::GetZoom::Results::Create(zoom_factor); | |
1845 SendResponse(true); | |
1846 return true; | |
1847 } | |
1848 | |
1849 bool TabsSetZoomSettingsFunction::RunAsync() { | |
1850 using api::tabs::ZoomSettings; | |
1851 | |
1852 scoped_ptr<tabs::SetZoomSettings::Params> params( | |
1853 tabs::SetZoomSettings::Params::Create(*args_)); | |
1854 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
1855 | |
1856 WebContents* web_contents = NULL; | |
1857 if (!GetWebContents(params->tab_id.get(), &web_contents)) | |
1858 return false; | |
1859 if (web_contents->GetURL().SchemeIs(content::kChromeUIScheme)) { | |
Devlin
2014/06/16 19:04:47
Same comments as above.
wjmaclean
2014/06/18 19:03:52
Done.
| |
1860 error_ = keys::kCannotChangeChromePageZoomSettingsError; | |
1861 return false; | |
1862 } | |
1863 ZoomController* zoom_controller = | |
Devlin
2014/06/16 19:04:47
nit: Move this down where it's used.
wjmaclean
2014/06/18 19:03:52
Done.
| |
1864 ZoomController::FromWebContents(web_contents); | |
1865 | |
1866 // "per-origin" scope is only available in "automatic" mode. | |
1867 if (params->zoom_settings.scope == ZoomSettings::SCOPE_PER_ORIGIN && | |
1868 params->zoom_settings.mode != ZoomSettings::MODE_AUTOMATIC && | |
1869 params->zoom_settings.mode != ZoomSettings::MODE_NONE) { | |
1870 error_ = keys::kPerOriginOnlyInAutomaticError; | |
1871 return false; | |
1872 } | |
1873 | |
1874 // Determine the correct internal zoom mode to set |web_contents| to from the | |
1875 // user-specified |zoom_settings|. | |
1876 ZoomMode zoom_mode = kZoomModeDefault; | |
1877 switch (params->zoom_settings.mode) { | |
1878 case ZoomSettings::MODE_NONE: | |
1879 case ZoomSettings::MODE_AUTOMATIC: | |
1880 switch (params->zoom_settings.scope) { | |
1881 case ZoomSettings::SCOPE_NONE: | |
1882 case ZoomSettings::SCOPE_PER_ORIGIN: | |
1883 zoom_mode = kZoomModeDefault; | |
1884 break; | |
1885 case ZoomSettings::SCOPE_PER_TAB: | |
1886 zoom_mode = kZoomModeIsolated; | |
1887 break; | |
Devlin
2014/06/16 19:04:47
nit: Remove trailing break.
wjmaclean
2014/06/18 19:03:52
Done.
| |
1888 } | |
1889 break; | |
1890 case ZoomSettings::MODE_MANUAL: | |
1891 zoom_mode = kZoomModeManual; | |
1892 break; | |
1893 case ZoomSettings::MODE_DISABLED: | |
1894 zoom_mode = kZoomModeDisabled; | |
1895 break; | |
Devlin
2014/06/16 19:04:47
nit: Remove trailing break.
wjmaclean
2014/06/18 19:03:52
Done.
| |
1896 } | |
1897 | |
1898 zoom_controller->SetZoomMode(zoom_mode); | |
1899 | |
1900 SendResponse(true); | |
1901 return true; | |
1902 } | |
1903 | |
1904 bool TabsGetZoomSettingsFunction::RunAsync() { | |
1905 scoped_ptr<tabs::GetZoomSettings::Params> params( | |
1906 tabs::GetZoomSettings::Params::Create(*args_)); | |
1907 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
1908 | |
1909 WebContents* web_contents = NULL; | |
1910 if (!GetWebContents(params->tab_id.get(), &web_contents)) | |
1911 return false; | |
1912 ZoomController* zoom_controller = | |
1913 ZoomController::FromWebContents(web_contents); | |
1914 | |
1915 ZoomMode zoom_mode = zoom_controller->zoom_mode(); | |
1916 api::tabs::ZoomSettings zoom_settings; | |
1917 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | |
1918 | |
1919 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | |
1920 SendResponse(true); | |
1921 return true; | |
1922 } | |
1923 | |
1752 } // namespace extensions | 1924 } // namespace extensions |
OLD | NEW |