| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 #include "components/ui/zoom/zoom_controller.h" | 64 #include "components/ui/zoom/zoom_controller.h" |
| 65 #include "content/public/browser/navigation_controller.h" | 65 #include "content/public/browser/navigation_controller.h" |
| 66 #include "content/public/browser/navigation_entry.h" | 66 #include "content/public/browser/navigation_entry.h" |
| 67 #include "content/public/browser/notification_details.h" | 67 #include "content/public/browser/notification_details.h" |
| 68 #include "content/public/browser/notification_source.h" | 68 #include "content/public/browser/notification_source.h" |
| 69 #include "content/public/browser/render_frame_host.h" | 69 #include "content/public/browser/render_frame_host.h" |
| 70 #include "content/public/browser/render_widget_host_view.h" | 70 #include "content/public/browser/render_widget_host_view.h" |
| 71 #include "content/public/browser/web_contents.h" | 71 #include "content/public/browser/web_contents.h" |
| 72 #include "content/public/common/url_constants.h" | 72 #include "content/public/common/url_constants.h" |
| 73 #include "extensions/browser/app_window/app_window.h" | 73 #include "extensions/browser/app_window/app_window.h" |
| 74 #include "extensions/browser/extension_api_frame_id_map.h" |
| 74 #include "extensions/browser/extension_function_dispatcher.h" | 75 #include "extensions/browser/extension_function_dispatcher.h" |
| 75 #include "extensions/browser/extension_function_util.h" | 76 #include "extensions/browser/extension_function_util.h" |
| 76 #include "extensions/browser/extension_host.h" | 77 #include "extensions/browser/extension_host.h" |
| 77 #include "extensions/browser/extension_zoom_request_client.h" | 78 #include "extensions/browser/extension_zoom_request_client.h" |
| 78 #include "extensions/browser/file_reader.h" | 79 #include "extensions/browser/file_reader.h" |
| 79 #include "extensions/browser/script_executor.h" | 80 #include "extensions/browser/script_executor.h" |
| 80 #include "extensions/common/api/extension_types.h" | 81 #include "extensions/common/api/extension_types.h" |
| 81 #include "extensions/common/constants.h" | 82 #include "extensions/common/constants.h" |
| 82 #include "extensions/common/error_utils.h" | 83 #include "extensions/common/error_utils.h" |
| 83 #include "extensions/common/extension.h" | 84 #include "extensions/common/extension.h" |
| (...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1352 } | 1353 } |
| 1353 | 1354 |
| 1354 TabHelper::FromWebContents(web_contents_) | 1355 TabHelper::FromWebContents(web_contents_) |
| 1355 ->script_executor() | 1356 ->script_executor() |
| 1356 ->ExecuteScript( | 1357 ->ExecuteScript( |
| 1357 HostID(HostID::EXTENSIONS, extension_id()), | 1358 HostID(HostID::EXTENSIONS, extension_id()), |
| 1358 ScriptExecutor::JAVASCRIPT, | 1359 ScriptExecutor::JAVASCRIPT, |
| 1359 net::UnescapeURLComponent(url.GetContent(), | 1360 net::UnescapeURLComponent(url.GetContent(), |
| 1360 net::UnescapeRule::URL_SPECIAL_CHARS | | 1361 net::UnescapeRule::URL_SPECIAL_CHARS | |
| 1361 net::UnescapeRule::SPACES), | 1362 net::UnescapeRule::SPACES), |
| 1362 ScriptExecutor::TOP_FRAME, ScriptExecutor::DONT_MATCH_ABOUT_BLANK, | 1363 ScriptExecutor::SINGLE_FRAME, ExtensionApiFrameIdMap::kTopFrameId, |
| 1363 UserScript::DOCUMENT_IDLE, ScriptExecutor::MAIN_WORLD, | 1364 ScriptExecutor::DONT_MATCH_ABOUT_BLANK, UserScript::DOCUMENT_IDLE, |
| 1364 ScriptExecutor::DEFAULT_PROCESS, GURL(), GURL(), user_gesture_, | 1365 ScriptExecutor::MAIN_WORLD, ScriptExecutor::DEFAULT_PROCESS, GURL(), |
| 1365 ScriptExecutor::NO_RESULT, | 1366 GURL(), user_gesture_, ScriptExecutor::NO_RESULT, |
| 1366 base::Bind(&TabsUpdateFunction::OnExecuteCodeFinished, this)); | 1367 base::Bind(&TabsUpdateFunction::OnExecuteCodeFinished, this)); |
| 1367 | 1368 |
| 1368 *is_async = true; | 1369 *is_async = true; |
| 1369 return true; | 1370 return true; |
| 1370 } | 1371 } |
| 1371 | 1372 |
| 1372 web_contents_->GetController().LoadURL( | 1373 web_contents_->GetController().LoadURL( |
| 1373 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 1374 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 1374 | 1375 |
| 1375 // The URL of a tab contents never actually changes to a JavaScript URL, so | 1376 // The URL of a tab contents never actually changes to a JavaScript URL, so |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1891 NULL, | 1892 NULL, |
| 1892 NULL, | 1893 NULL, |
| 1893 &contents, | 1894 &contents, |
| 1894 NULL, | 1895 NULL, |
| 1895 &error_)) { | 1896 &error_)) { |
| 1896 return false; | 1897 return false; |
| 1897 } | 1898 } |
| 1898 | 1899 |
| 1899 CHECK(contents); | 1900 CHECK(contents); |
| 1900 | 1901 |
| 1902 int frame_id = details_->frame_id ? *details_->frame_id |
| 1903 : ExtensionApiFrameIdMap::kTopFrameId; |
| 1904 content::RenderFrameHost* rfh = |
| 1905 ExtensionApiFrameIdMap::GetRenderFrameHostById(contents, frame_id); |
| 1906 if (!rfh) { |
| 1907 error_ = ErrorUtils::FormatErrorMessage(keys::kFrameNotFoundError, |
| 1908 base::IntToString(frame_id), |
| 1909 base::IntToString(execute_tab_id_)); |
| 1910 return false; |
| 1911 } |
| 1912 |
| 1913 // Content scripts declared in manifest.json can access frames at about:-URLs |
| 1914 // if the extension has permission to access the frame's origin, so also allow |
| 1915 // programmatic content scripts at about:-URLs for allowed origins. |
| 1916 GURL effective_document_url(rfh->GetLastCommittedURL()); |
| 1917 bool is_about_url = effective_document_url.SchemeIs(url::kAboutScheme); |
| 1918 if (is_about_url && details_->match_about_blank && |
| 1919 *details_->match_about_blank) { |
| 1920 effective_document_url = GURL(rfh->GetLastCommittedOrigin().Serialize()); |
| 1921 } |
| 1922 |
| 1923 if (!effective_document_url.is_valid()) { |
| 1924 // Unknown URL, e.g. because no load was committed yet. Allow for now, the |
| 1925 // renderer will check again and fail the injection if needed. |
| 1926 return true; |
| 1927 } |
| 1928 |
| 1901 // NOTE: This can give the wrong answer due to race conditions, but it is OK, | 1929 // NOTE: This can give the wrong answer due to race conditions, but it is OK, |
| 1902 // we check again in the renderer. | 1930 // we check again in the renderer. |
| 1903 if (!extension()->permissions_data()->CanAccessPage( | 1931 if (!extension()->permissions_data()->CanAccessPage( |
| 1904 extension(), | 1932 extension(), effective_document_url, execute_tab_id_, &error_)) { |
| 1905 contents->GetURL(), | 1933 if (is_about_url && |
| 1906 execute_tab_id_, | 1934 extension()->permissions_data()->active_permissions().HasAPIPermission( |
| 1907 &error_)) { | 1935 APIPermission::kTab)) { |
| 1936 error_ = ErrorUtils::FormatErrorMessage( |
| 1937 manifest_errors::kCannotAccessAboutUrl, |
| 1938 rfh->GetLastCommittedURL().spec(), |
| 1939 rfh->GetLastCommittedOrigin().Serialize()); |
| 1940 } |
| 1908 return false; | 1941 return false; |
| 1909 } | 1942 } |
| 1910 | 1943 |
| 1911 return true; | 1944 return true; |
| 1912 } | 1945 } |
| 1913 | 1946 |
| 1914 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { | 1947 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { |
| 1915 Browser* browser = NULL; | 1948 Browser* browser = NULL; |
| 1916 content::WebContents* contents = NULL; | 1949 content::WebContents* contents = NULL; |
| 1917 | 1950 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2097 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 2130 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
| 2098 zoom_settings.default_zoom_factor.reset(new double( | 2131 zoom_settings.default_zoom_factor.reset(new double( |
| 2099 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); | 2132 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); |
| 2100 | 2133 |
| 2101 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 2134 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
| 2102 SendResponse(true); | 2135 SendResponse(true); |
| 2103 return true; | 2136 return true; |
| 2104 } | 2137 } |
| 2105 | 2138 |
| 2106 } // namespace extensions | 2139 } // namespace extensions |
| OLD | NEW |