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/extensions/extension_l10n_util.h" | 55 #include "chrome/common/extensions/extension_l10n_util.h" |
55 #include "chrome/common/extensions/message_bundle.h" | 56 #include "chrome/common/extensions/message_bundle.h" |
56 #include "chrome/common/pref_names.h" | 57 #include "chrome/common/pref_names.h" |
57 #include "chrome/common/url_constants.h" | 58 #include "chrome/common/url_constants.h" |
58 #include "components/translate/core/common/language_detection_details.h" | 59 #include "components/translate/core/common/language_detection_details.h" |
59 #include "components/user_prefs/pref_registry_syncable.h" | 60 #include "components/user_prefs/pref_registry_syncable.h" |
60 #include "content/public/browser/navigation_controller.h" | 61 #include "content/public/browser/navigation_controller.h" |
61 #include "content/public/browser/navigation_entry.h" | 62 #include "content/public/browser/navigation_entry.h" |
62 #include "content/public/browser/notification_details.h" | 63 #include "content/public/browser/notification_details.h" |
64 #include "content/public/browser/notification_service.h" | |
not at google - send to devlin
2014/04/11 15:04:25
no longer needed
paulmeyer
2014/04/11 19:09:49
Done.
| |
63 #include "content/public/browser/notification_source.h" | 65 #include "content/public/browser/notification_source.h" |
64 #include "content/public/browser/render_process_host.h" | 66 #include "content/public/browser/render_process_host.h" |
65 #include "content/public/browser/render_view_host.h" | 67 #include "content/public/browser/render_view_host.h" |
66 #include "content/public/browser/render_widget_host_view.h" | 68 #include "content/public/browser/render_widget_host_view.h" |
67 #include "content/public/browser/web_contents.h" | 69 #include "content/public/browser/web_contents.h" |
68 #include "content/public/browser/web_contents_view.h" | 70 #include "content/public/browser/web_contents_view.h" |
69 #include "content/public/common/url_constants.h" | 71 #include "content/public/common/url_constants.h" |
70 #include "extensions/browser/extension_function_dispatcher.h" | 72 #include "extensions/browser/extension_function_dispatcher.h" |
71 #include "extensions/browser/extension_function_util.h" | 73 #include "extensions/browser/extension_function_util.h" |
72 #include "extensions/browser/extension_host.h" | 74 #include "extensions/browser/extension_host.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 new_window = chrome::FindTabbedBrowser(profile, false, | 210 new_window = chrome::FindTabbedBrowser(profile, false, |
209 params.host_desktop_type); | 211 params.host_desktop_type); |
210 | 212 |
211 if (!new_window) | 213 if (!new_window) |
212 new_window = new Browser(params); | 214 new_window = new Browser(params); |
213 return new_window; | 215 return new_window; |
214 } | 216 } |
215 | 217 |
216 } // namespace | 218 } // namespace |
217 | 219 |
220 void ZoomModeToZoomSettings(content::ZoomMode zoom_mode, | |
221 api::tabs::ZoomSettings* zoom_settings) { | |
222 DCHECK(zoom_settings); | |
223 switch (zoom_mode) { | |
224 case content::kZoomModeDefault: | |
225 zoom_settings->mode = api::tabs::ZoomSettings::MODE_AUTOMATIC; | |
226 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_ORIGIN; | |
227 break; | |
not at google - send to devlin
2014/04/11 15:04:25
let's just return an api::tabs::ZoomSettings (or a
paulmeyer
2014/04/11 19:09:49
Yeah, it is disallow-copy, and being scoped_ptr is
| |
228 case content::kZoomModeIsolated: | |
229 zoom_settings->mode = api::tabs::ZoomSettings::MODE_AUTOMATIC; | |
230 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_TAB; | |
231 break; | |
232 case content::kZoomModeManual: | |
233 zoom_settings->mode = api::tabs::ZoomSettings::MODE_MANUAL; | |
234 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_TAB; | |
235 break; | |
236 case content::kZoomModeDisabled: | |
237 zoom_settings->mode = api::tabs::ZoomSettings::MODE_DISABLED; | |
238 zoom_settings->scope = api::tabs::ZoomSettings::SCOPE_PER_TAB; | |
239 break; | |
240 } | |
241 } | |
242 | |
218 // Windows --------------------------------------------------------------------- | 243 // Windows --------------------------------------------------------------------- |
219 | 244 |
220 bool WindowsGetFunction::RunImpl() { | 245 bool WindowsGetFunction::RunImpl() { |
221 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_)); | 246 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_)); |
222 EXTENSION_FUNCTION_VALIDATE(params.get()); | 247 EXTENSION_FUNCTION_VALIDATE(params.get()); |
223 | 248 |
224 bool populate_tabs = false; | 249 bool populate_tabs = false; |
225 if (params->get_info.get() && params->get_info->populate.get()) | 250 if (params->get_info.get() && params->get_info->populate.get()) |
226 populate_tabs = *params->get_info->populate; | 251 populate_tabs = *params->get_info->populate; |
227 | 252 |
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1589 int tab_id = *params->tab_id; | 1614 int tab_id = *params->tab_id; |
1590 | 1615 |
1591 Browser* browser = NULL; | 1616 Browser* browser = NULL; |
1592 if (!GetTabById(tab_id, | 1617 if (!GetTabById(tab_id, |
1593 GetProfile(), | 1618 GetProfile(), |
1594 include_incognito(), | 1619 include_incognito(), |
1595 &browser, | 1620 &browser, |
1596 NULL, | 1621 NULL, |
1597 &web_contents, | 1622 &web_contents, |
1598 NULL, | 1623 NULL, |
1599 &error_)) | 1624 &error_)) { |
1600 return false; | 1625 return false; |
1626 } | |
1601 } | 1627 } |
1602 | 1628 |
1603 if (web_contents->ShowingInterstitialPage()) { | 1629 if (web_contents->ShowingInterstitialPage()) { |
1604 // This does as same as Browser::ReloadInternal. | 1630 // This does as same as Browser::ReloadInternal. |
1605 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); | 1631 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); |
1606 OpenURLParams params(entry->GetURL(), Referrer(), CURRENT_TAB, | 1632 OpenURLParams params(entry->GetURL(), Referrer(), CURRENT_TAB, |
1607 content::PAGE_TRANSITION_RELOAD, false); | 1633 content::PAGE_TRANSITION_RELOAD, false); |
1608 GetCurrentBrowser()->OpenURL(params); | 1634 GetCurrentBrowser()->OpenURL(params); |
1609 } else if (bypass_cache) { | 1635 } else if (bypass_cache) { |
1610 web_contents->GetController().ReloadIgnoringCache(true); | 1636 web_contents->GetController().ReloadIgnoringCache(true); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1910 | 1936 |
1911 execute_tab_id_ = tab_id; | 1937 execute_tab_id_ = tab_id; |
1912 details_ = details.Pass(); | 1938 details_ = details.Pass(); |
1913 return true; | 1939 return true; |
1914 } | 1940 } |
1915 | 1941 |
1916 bool TabsInsertCSSFunction::ShouldInsertCSS() const { | 1942 bool TabsInsertCSSFunction::ShouldInsertCSS() const { |
1917 return true; | 1943 return true; |
1918 } | 1944 } |
1919 | 1945 |
1946 bool ZoomAPIFunction::GetWebContents(int* tab_id, | |
1947 content::WebContents** web_contents) { | |
1948 if (tab_id) { | |
1949 if (!GetTabById(*tab_id, | |
1950 GetProfile(), | |
1951 include_incognito(), | |
1952 NULL, | |
1953 NULL, | |
1954 web_contents, | |
1955 NULL, | |
1956 &error_)) { | |
1957 return false; | |
1958 } | |
1959 } else { | |
1960 Browser* browser = GetCurrentBrowser(); | |
1961 if (!browser) { | |
1962 error_ = keys::kNoCurrentWindowError; | |
1963 return false; | |
1964 } | |
1965 if (!ExtensionTabUtil::GetDefaultTab(browser, web_contents, NULL)) { | |
1966 error_ = keys::kNoCurrentTabError; | |
not at google - send to devlin
2014/04/11 15:04:25
as discussed, you could re-use the "no selected ta
paulmeyer
2014/04/11 19:09:49
Done.
| |
1967 return false; | |
1968 } | |
1969 } | |
1970 return true; | |
1971 } | |
1972 | |
1973 bool TabsSetZoomFunction::RunImpl() { | |
1974 scoped_ptr<tabs::SetZoom::Params> params( | |
1975 tabs::SetZoom::Params::Create(*args_)); | |
1976 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
1977 | |
1978 WebContents* web_contents = NULL; | |
1979 if (!GetWebContents(params->tab_id.get(), &web_contents)) { | |
1980 return false; | |
1981 } else if (web_contents->GetURL().SchemeIs(content::kChromeUIScheme)) { | |
not at google - send to devlin
2014/04/11 15:04:25
no else after return
paulmeyer
2014/04/11 19:09:49
Done.
| |
1982 error_ = keys::kCannotZoomChromePagesError; | |
not at google - send to devlin
2014/04/11 15:04:25
you should be able to reuse some sort of generic "
paulmeyer
2014/04/11 19:09:49
There aren't any existing errors that general, tho
not at google - send to devlin
2014/04/11 20:37:02
Ok, looks like we do have a precedent here in mani
| |
1983 return false; | |
1984 } | |
1985 | |
1986 ZoomController* zoom_controller = | |
1987 ZoomController::FromWebContents(web_contents); | |
1988 double zoom_level = content::ZoomFactorToZoomLevel(params->zoom_factor); | |
1989 | |
1990 // Attempt to set the zoom level with a callback. | |
not at google - send to devlin
2014/04/11 15:04:25
comment doesn't add much
paulmeyer
2014/04/11 19:09:49
Done.
| |
1991 scoped_refptr<TabsSetZoomFunction> this_ref = this; | |
1992 if (!zoom_controller->SetZoomLevelByExtension( | |
1993 zoom_level, | |
1994 GetExtension(), | |
1995 base::Bind(&TabsSetZoomFunction::SendResponse, this_ref, true))) { | |
1996 // Tried to zoom a tab in disabled mode. | |
1997 error_ = keys::kCannotZoomDisabledTabError; | |
1998 return false; | |
1999 } | |
2000 | |
2001 return true; | |
2002 } | |
2003 | |
2004 bool TabsGetZoomFunction::RunImpl() { | |
2005 scoped_ptr<tabs::GetZoom::Params> params( | |
2006 tabs::GetZoom::Params::Create(*args_)); | |
2007 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
2008 | |
2009 WebContents* web_contents = NULL; | |
2010 if (!GetWebContents(params->tab_id.get(), &web_contents)) { | |
2011 return false; | |
2012 } | |
2013 | |
2014 double zoom_level = web_contents->GetZoomLevel(); | |
2015 double zoom_factor = content::ZoomLevelToZoomFactor(zoom_level); | |
2016 results_ = tabs::GetZoom::Results::Create(zoom_factor); | |
2017 SendResponse(true); | |
2018 return true; | |
2019 } | |
2020 | |
2021 bool TabsSetZoomSettingsFunction::RunImpl() { | |
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 } else if (web_contents->GetURL().SchemeIs(content::kChromeUIScheme)) { | |
not at google - send to devlin
2014/04/11 15:04:25
no else after return
paulmeyer
2014/04/11 19:09:49
Done.
| |
2030 error_ = keys::kCannotChangeChromePageZoomSettingsError; | |
not at google - send to devlin
2014/04/11 15:04:25
same comment re chrome:// url
paulmeyer
2014/04/11 19:09:49
See above.
On 2014/04/11 15:04:25, kalman wrote:
| |
2031 return false; | |
2032 } | |
2033 | |
2034 // "per-origin" scope is only available in "automatic" mode. | |
2035 if (params->zoom_settings.scope == | |
2036 api::tabs::ZoomSettings::SCOPE_PER_ORIGIN && | |
not at google - send to devlin
2014/04/11 15:04:25
hm is this the indentation that "git cl format" gi
paulmeyer
2014/04/11 19:09:49
Done. This does clean it up a lot.
| |
2037 params->zoom_settings.mode != api::tabs::ZoomSettings::MODE_AUTOMATIC && | |
2038 params->zoom_settings.mode != api::tabs::ZoomSettings::MODE_NONE) { | |
2039 error_ = keys::kPerOriginOnlyInAutomaticError; | |
2040 return false; | |
2041 } | |
2042 | |
2043 // Determine the correct internal zoom mode to set |web_contents| to from the | |
2044 // user-specified |zoom_settings|. | |
2045 content::ZoomMode zoom_mode = content::kZoomModeDefault; | |
2046 switch (params->zoom_settings.mode) { | |
2047 case api::tabs::ZoomSettings::MODE_NONE: | |
2048 case api::tabs::ZoomSettings::MODE_AUTOMATIC: | |
2049 switch (params->zoom_settings.scope) { | |
2050 case api::tabs::ZoomSettings::SCOPE_NONE: | |
2051 case api::tabs::ZoomSettings::SCOPE_PER_ORIGIN: | |
2052 zoom_mode = content::kZoomModeDefault; | |
2053 break; | |
2054 case api::tabs::ZoomSettings::SCOPE_PER_TAB: | |
2055 zoom_mode = content::kZoomModeIsolated; | |
2056 break; | |
2057 } | |
2058 break; | |
2059 case api::tabs::ZoomSettings::MODE_MANUAL: | |
2060 zoom_mode = content::kZoomModeManual; | |
2061 break; | |
2062 case api::tabs::ZoomSettings::MODE_DISABLED: | |
2063 zoom_mode = content::kZoomModeDisabled; | |
2064 break; | |
2065 } | |
2066 | |
2067 web_contents->SetZoomMode(zoom_mode); | |
2068 | |
2069 SendResponse(true); | |
2070 return true; | |
2071 } | |
2072 | |
2073 bool TabsGetZoomSettingsFunction::RunImpl() { | |
2074 scoped_ptr<tabs::GetZoomSettings::Params> params( | |
2075 tabs::GetZoomSettings::Params::Create(*args_)); | |
2076 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
2077 | |
2078 WebContents* web_contents = NULL; | |
2079 if (!GetWebContents(params->tab_id.get(), &web_contents)) { | |
2080 return false; | |
2081 } | |
2082 | |
2083 content::ZoomMode zoom_mode = web_contents->GetZoomMode(); | |
2084 api::tabs::ZoomSettings zoom_settings; | |
not at google - send to devlin
2014/04/11 15:04:25
ZoomSettings zoom_settings = ZoomModeToZoomSetting
paulmeyer
2014/04/11 19:09:49
Done. I personally like separating lines when poss
| |
2085 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | |
2086 | |
2087 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | |
2088 SendResponse(true); | |
2089 return true; | |
2090 } | |
2091 | |
1920 } // namespace extensions | 2092 } // namespace extensions |
OLD | NEW |