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/extensions/extension_file_util.h" | 54 #include "chrome/common/extensions/extension_file_util.h" |
54 #include "chrome/common/pref_names.h" | 55 #include "chrome/common/pref_names.h" |
55 #include "chrome/common/url_constants.h" | 56 #include "chrome/common/url_constants.h" |
56 #include "components/translate/core/common/language_detection_details.h" | 57 #include "components/translate/core/common/language_detection_details.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 new_window = chrome::FindTabbedBrowser(profile, false, | 209 new_window = chrome::FindTabbedBrowser(profile, false, |
209 params.host_desktop_type); | 210 params.host_desktop_type); |
210 | 211 |
211 if (!new_window) | 212 if (!new_window) |
212 new_window = new Browser(params); | 213 new_window = new Browser(params); |
213 return new_window; | 214 return new_window; |
214 } | 215 } |
215 | 216 |
216 } // namespace | 217 } // namespace |
217 | 218 |
| 219 void ZoomModeToZoomSettings(ZoomMode zoom_mode, |
| 220 api::tabs::ZoomSettings* zoom_settings) { |
| 221 DCHECK(zoom_settings); |
| 222 switch (zoom_mode) { |
| 223 case kZoomModeDefault: |
| 224 zoom_settings->mode = api::tabs::ZoomSettings::MODE_AUTOMATIC; |
| 225 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_ORIGIN; |
| 226 break; |
| 227 case kZoomModeIsolated: |
| 228 zoom_settings->mode = api::tabs::ZoomSettings::MODE_AUTOMATIC; |
| 229 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_TAB; |
| 230 break; |
| 231 case kZoomModeManual: |
| 232 zoom_settings->mode = api::tabs::ZoomSettings::MODE_MANUAL; |
| 233 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_TAB; |
| 234 break; |
| 235 case kZoomModeDisabled: |
| 236 zoom_settings->mode = api::tabs::ZoomSettings::MODE_DISABLED; |
| 237 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_TAB; |
| 238 break; |
| 239 } |
| 240 } |
| 241 |
218 // Windows --------------------------------------------------------------------- | 242 // Windows --------------------------------------------------------------------- |
219 | 243 |
220 bool WindowsGetFunction::RunImpl() { | 244 bool WindowsGetFunction::RunImpl() { |
221 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_)); | 245 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_)); |
222 EXTENSION_FUNCTION_VALIDATE(params.get()); | 246 EXTENSION_FUNCTION_VALIDATE(params.get()); |
223 | 247 |
224 bool populate_tabs = false; | 248 bool populate_tabs = false; |
225 if (params->get_info.get() && params->get_info->populate.get()) | 249 if (params->get_info.get() && params->get_info->populate.get()) |
226 populate_tabs = *params->get_info->populate; | 250 populate_tabs = *params->get_info->populate; |
227 | 251 |
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 int tab_id = *params->tab_id; | 1613 int tab_id = *params->tab_id; |
1590 | 1614 |
1591 Browser* browser = NULL; | 1615 Browser* browser = NULL; |
1592 if (!GetTabById(tab_id, | 1616 if (!GetTabById(tab_id, |
1593 GetProfile(), | 1617 GetProfile(), |
1594 include_incognito(), | 1618 include_incognito(), |
1595 &browser, | 1619 &browser, |
1596 NULL, | 1620 NULL, |
1597 &web_contents, | 1621 &web_contents, |
1598 NULL, | 1622 NULL, |
1599 &error_)) | 1623 &error_)) { |
1600 return false; | 1624 return false; |
| 1625 } |
1601 } | 1626 } |
1602 | 1627 |
1603 if (web_contents->ShowingInterstitialPage()) { | 1628 if (web_contents->ShowingInterstitialPage()) { |
1604 // This does as same as Browser::ReloadInternal. | 1629 // This does as same as Browser::ReloadInternal. |
1605 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); | 1630 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); |
1606 OpenURLParams params(entry->GetURL(), Referrer(), CURRENT_TAB, | 1631 OpenURLParams params(entry->GetURL(), Referrer(), CURRENT_TAB, |
1607 content::PAGE_TRANSITION_RELOAD, false); | 1632 content::PAGE_TRANSITION_RELOAD, false); |
1608 GetCurrentBrowser()->OpenURL(params); | 1633 GetCurrentBrowser()->OpenURL(params); |
1609 } else if (bypass_cache) { | 1634 } else if (bypass_cache) { |
1610 web_contents->GetController().ReloadIgnoringCache(true); | 1635 web_contents->GetController().ReloadIgnoringCache(true); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1914 | 1939 |
1915 execute_tab_id_ = tab_id; | 1940 execute_tab_id_ = tab_id; |
1916 details_ = details.Pass(); | 1941 details_ = details.Pass(); |
1917 return true; | 1942 return true; |
1918 } | 1943 } |
1919 | 1944 |
1920 bool TabsInsertCSSFunction::ShouldInsertCSS() const { | 1945 bool TabsInsertCSSFunction::ShouldInsertCSS() const { |
1921 return true; | 1946 return true; |
1922 } | 1947 } |
1923 | 1948 |
| 1949 bool ZoomAPIFunction::GetWebContents(int* tab_id, |
| 1950 content::WebContents** web_contents) { |
| 1951 if (tab_id) { |
| 1952 if (!GetTabById(*tab_id, |
| 1953 GetProfile(), |
| 1954 include_incognito(), |
| 1955 NULL, |
| 1956 NULL, |
| 1957 web_contents, |
| 1958 NULL, |
| 1959 &error_)) { |
| 1960 return false; |
| 1961 } |
| 1962 } else { |
| 1963 Browser* browser = GetCurrentBrowser(); |
| 1964 if (!browser) { |
| 1965 error_ = keys::kNoCurrentWindowError; |
| 1966 return false; |
| 1967 } |
| 1968 if (!ExtensionTabUtil::GetDefaultTab(browser, web_contents, NULL)) { |
| 1969 error_ = keys::kNoSelectedTabError; |
| 1970 return false; |
| 1971 } |
| 1972 } |
| 1973 return true; |
| 1974 } |
| 1975 |
| 1976 bool TabsSetZoomFunction::RunImpl() { |
| 1977 scoped_ptr<tabs::SetZoom::Params> params( |
| 1978 tabs::SetZoom::Params::Create(*args_)); |
| 1979 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1980 |
| 1981 WebContents* web_contents = NULL; |
| 1982 if (!GetWebContents(params->tab_id.get(), &web_contents)) |
| 1983 return false; |
| 1984 if (web_contents->GetURL().SchemeIs(content::kChromeUIScheme)) { |
| 1985 error_ = keys::kCannotZoomChromePagesError; |
| 1986 return false; |
| 1987 } |
| 1988 |
| 1989 ZoomController* zoom_controller = |
| 1990 ZoomController::FromWebContents(web_contents); |
| 1991 double zoom_level = content::ZoomFactorToZoomLevel(params->zoom_factor); |
| 1992 |
| 1993 if (!zoom_controller->SetZoomLevelByExtension(zoom_level, GetExtension())) { |
| 1994 // Tried to zoom a tab in disabled mode. |
| 1995 error_ = keys::kCannotZoomDisabledTabError; |
| 1996 return false; |
| 1997 } |
| 1998 |
| 1999 return true; |
| 2000 } |
| 2001 |
| 2002 bool TabsGetZoomFunction::RunImpl() { |
| 2003 scoped_ptr<tabs::GetZoom::Params> params( |
| 2004 tabs::GetZoom::Params::Create(*args_)); |
| 2005 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 2006 |
| 2007 WebContents* web_contents = NULL; |
| 2008 if (!GetWebContents(params->tab_id.get(), &web_contents)) { |
| 2009 return false; |
| 2010 } |
| 2011 |
| 2012 double zoom_level = web_contents->GetZoomLevel(); |
| 2013 double zoom_factor = content::ZoomLevelToZoomFactor(zoom_level); |
| 2014 results_ = tabs::GetZoom::Results::Create(zoom_factor); |
| 2015 SendResponse(true); |
| 2016 return true; |
| 2017 } |
| 2018 |
| 2019 bool TabsSetZoomSettingsFunction::RunImpl() { |
| 2020 using api::tabs::ZoomSettings; |
| 2021 |
| 2022 scoped_ptr<tabs::SetZoomSettings::Params> params( |
| 2023 tabs::SetZoomSettings::Params::Create(*args_)); |
| 2024 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 2025 |
| 2026 WebContents* web_contents = NULL; |
| 2027 if (!GetWebContents(params->tab_id.get(), &web_contents)) |
| 2028 return false; |
| 2029 if (web_contents->GetURL().SchemeIs(content::kChromeUIScheme)) { |
| 2030 error_ = keys::kCannotChangeChromePageZoomSettingsError; |
| 2031 return false; |
| 2032 } |
| 2033 ZoomController* zoom_controller = |
| 2034 ZoomController::FromWebContents(web_contents); |
| 2035 |
| 2036 // "per-origin" scope is only available in "automatic" mode. |
| 2037 if (params->zoom_settings.scope == ZoomSettings::SCOPE_PER_ORIGIN && |
| 2038 params->zoom_settings.mode != ZoomSettings::MODE_AUTOMATIC && |
| 2039 params->zoom_settings.mode != ZoomSettings::MODE_NONE) { |
| 2040 error_ = keys::kPerOriginOnlyInAutomaticError; |
| 2041 return false; |
| 2042 } |
| 2043 |
| 2044 // Determine the correct internal zoom mode to set |web_contents| to from the |
| 2045 // user-specified |zoom_settings|. |
| 2046 ZoomMode zoom_mode = kZoomModeDefault; |
| 2047 switch (params->zoom_settings.mode) { |
| 2048 case ZoomSettings::MODE_NONE: |
| 2049 case ZoomSettings::MODE_AUTOMATIC: |
| 2050 switch (params->zoom_settings.scope) { |
| 2051 case ZoomSettings::SCOPE_NONE: |
| 2052 case ZoomSettings::SCOPE_PER_ORIGIN: |
| 2053 zoom_mode = kZoomModeDefault; |
| 2054 break; |
| 2055 case ZoomSettings::SCOPE_PER_TAB: |
| 2056 zoom_mode = kZoomModeIsolated; |
| 2057 break; |
| 2058 } |
| 2059 break; |
| 2060 case ZoomSettings::MODE_MANUAL: |
| 2061 zoom_mode = kZoomModeManual; |
| 2062 break; |
| 2063 case ZoomSettings::MODE_DISABLED: |
| 2064 zoom_mode = kZoomModeDisabled; |
| 2065 break; |
| 2066 } |
| 2067 |
| 2068 zoom_controller->SetZoomMode(zoom_mode); |
| 2069 |
| 2070 SendResponse(true); |
| 2071 return true; |
| 2072 } |
| 2073 |
| 2074 bool TabsGetZoomSettingsFunction::RunImpl() { |
| 2075 scoped_ptr<tabs::GetZoomSettings::Params> params( |
| 2076 tabs::GetZoomSettings::Params::Create(*args_)); |
| 2077 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 2078 |
| 2079 WebContents* web_contents = NULL; |
| 2080 if (!GetWebContents(params->tab_id.get(), &web_contents)) |
| 2081 return false; |
| 2082 ZoomController* zoom_controller = |
| 2083 ZoomController::FromWebContents(web_contents); |
| 2084 |
| 2085 ZoomMode zoom_mode = zoom_controller->zoom_mode(); |
| 2086 api::tabs::ZoomSettings zoom_settings; |
| 2087 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
| 2088 |
| 2089 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
| 2090 SendResponse(true); |
| 2091 return true; |
| 2092 } |
| 2093 |
1924 } // namespace extensions | 2094 } // namespace extensions |
OLD | NEW |