Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 1150683007: [Extensions] Use document url (not top url) for tab-specific permissions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 return false; 1268 return false;
1269 } 1269 }
1270 1270
1271 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so 1271 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so
1272 // we need to check host permissions before allowing them. 1272 // we need to check host permissions before allowing them.
1273 if (url.SchemeIs(url::kJavaScriptScheme)) { 1273 if (url.SchemeIs(url::kJavaScriptScheme)) {
1274 content::RenderProcessHost* process = web_contents_->GetRenderProcessHost(); 1274 content::RenderProcessHost* process = web_contents_->GetRenderProcessHost();
1275 if (!extension()->permissions_data()->CanAccessPage( 1275 if (!extension()->permissions_data()->CanAccessPage(
1276 extension(), 1276 extension(),
1277 web_contents_->GetURL(), 1277 web_contents_->GetURL(),
1278 web_contents_->GetURL(),
1279 tab_id, 1278 tab_id,
1280 process ? process->GetID() : -1, 1279 process ? process->GetID() : -1,
1281 &error_)) { 1280 &error_)) {
1282 return false; 1281 return false;
1283 } 1282 }
1284 1283
1285 TabHelper::FromWebContents(web_contents_)->script_executor()->ExecuteScript( 1284 TabHelper::FromWebContents(web_contents_)->script_executor()->ExecuteScript(
1286 HostID(HostID::EXTENSIONS, extension_id()), 1285 HostID(HostID::EXTENSIONS, extension_id()),
1287 ScriptExecutor::JAVASCRIPT, 1286 ScriptExecutor::JAVASCRIPT,
1288 url.GetContent(), 1287 url.GetContent(),
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 } 1791 }
1793 1792
1794 CHECK(contents); 1793 CHECK(contents);
1795 1794
1796 // NOTE: This can give the wrong answer due to race conditions, but it is OK, 1795 // NOTE: This can give the wrong answer due to race conditions, but it is OK,
1797 // we check again in the renderer. 1796 // we check again in the renderer.
1798 content::RenderProcessHost* process = contents->GetRenderProcessHost(); 1797 content::RenderProcessHost* process = contents->GetRenderProcessHost();
1799 if (!extension()->permissions_data()->CanAccessPage( 1798 if (!extension()->permissions_data()->CanAccessPage(
1800 extension(), 1799 extension(),
1801 contents->GetURL(), 1800 contents->GetURL(),
1802 contents->GetURL(),
1803 execute_tab_id_, 1801 execute_tab_id_,
1804 process ? process->GetID() : -1, 1802 process ? process->GetID() : -1,
1805 &error_)) { 1803 &error_)) {
1806 return false; 1804 return false;
1807 } 1805 }
1808 1806
1809 return true; 1807 return true;
1810 } 1808 }
1811 1809
1812 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { 1810 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 scoped_ptr<tabs::SetZoom::Params> params( 1878 scoped_ptr<tabs::SetZoom::Params> params(
1881 tabs::SetZoom::Params::Create(*args_)); 1879 tabs::SetZoom::Params::Create(*args_));
1882 EXTENSION_FUNCTION_VALIDATE(params); 1880 EXTENSION_FUNCTION_VALIDATE(params);
1883 1881
1884 int tab_id = params->tab_id ? *params->tab_id : -1; 1882 int tab_id = params->tab_id ? *params->tab_id : -1;
1885 WebContents* web_contents = GetWebContents(tab_id); 1883 WebContents* web_contents = GetWebContents(tab_id);
1886 if (!web_contents) 1884 if (!web_contents)
1887 return false; 1885 return false;
1888 1886
1889 GURL url(web_contents->GetVisibleURL()); 1887 GURL url(web_contents->GetVisibleURL());
1890 if (PermissionsData::IsRestrictedUrl(url, url, extension(), &error_)) 1888 if (PermissionsData::IsRestrictedUrl(url, extension(), &error_))
1891 return false; 1889 return false;
1892 1890
1893 ZoomController* zoom_controller = 1891 ZoomController* zoom_controller =
1894 ZoomController::FromWebContents(web_contents); 1892 ZoomController::FromWebContents(web_contents);
1895 double zoom_level = params->zoom_factor > 0 1893 double zoom_level = params->zoom_factor > 0
1896 ? content::ZoomFactorToZoomLevel(params->zoom_factor) 1894 ? content::ZoomFactorToZoomLevel(params->zoom_factor)
1897 : zoom_controller->GetDefaultZoomLevel(); 1895 : zoom_controller->GetDefaultZoomLevel();
1898 1896
1899 scoped_refptr<ExtensionZoomRequestClient> client( 1897 scoped_refptr<ExtensionZoomRequestClient> client(
1900 new ExtensionZoomRequestClient(extension())); 1898 new ExtensionZoomRequestClient(extension()));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 scoped_ptr<tabs::SetZoomSettings::Params> params( 1930 scoped_ptr<tabs::SetZoomSettings::Params> params(
1933 tabs::SetZoomSettings::Params::Create(*args_)); 1931 tabs::SetZoomSettings::Params::Create(*args_));
1934 EXTENSION_FUNCTION_VALIDATE(params); 1932 EXTENSION_FUNCTION_VALIDATE(params);
1935 1933
1936 int tab_id = params->tab_id ? *params->tab_id : -1; 1934 int tab_id = params->tab_id ? *params->tab_id : -1;
1937 WebContents* web_contents = GetWebContents(tab_id); 1935 WebContents* web_contents = GetWebContents(tab_id);
1938 if (!web_contents) 1936 if (!web_contents)
1939 return false; 1937 return false;
1940 1938
1941 GURL url(web_contents->GetVisibleURL()); 1939 GURL url(web_contents->GetVisibleURL());
1942 if (PermissionsData::IsRestrictedUrl(url, url, extension(), &error_)) 1940 if (PermissionsData::IsRestrictedUrl(url, extension(), &error_))
1943 return false; 1941 return false;
1944 1942
1945 // "per-origin" scope is only available in "automatic" mode. 1943 // "per-origin" scope is only available in "automatic" mode.
1946 if (params->zoom_settings.scope == tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN && 1944 if (params->zoom_settings.scope == tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN &&
1947 params->zoom_settings.mode != tabs::ZOOM_SETTINGS_MODE_AUTOMATIC && 1945 params->zoom_settings.mode != tabs::ZOOM_SETTINGS_MODE_AUTOMATIC &&
1948 params->zoom_settings.mode != tabs::ZOOM_SETTINGS_MODE_NONE) { 1946 params->zoom_settings.mode != tabs::ZOOM_SETTINGS_MODE_NONE) {
1949 error_ = keys::kPerOriginOnlyInAutomaticError; 1947 error_ = keys::kPerOriginOnlyInAutomaticError;
1950 return false; 1948 return false;
1951 } 1949 }
1952 1950
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); 1993 ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
1996 zoom_settings.default_zoom_factor.reset(new double( 1994 zoom_settings.default_zoom_factor.reset(new double(
1997 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); 1995 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel())));
1998 1996
1999 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); 1997 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings);
2000 SendResponse(true); 1998 SendResponse(true);
2001 return true; 1999 return true;
2002 } 2000 }
2003 2001
2004 } // namespace extensions 2002 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698