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

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

Issue 1628423002: Add frameId to chrome.tabs.executeScript/insertCSS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permissiondata-remove-process_id
Patch Set: Nits + comments Created 4 years, 11 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 <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
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 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 } 1354 }
1354 1355
1355 TabHelper::FromWebContents(web_contents_) 1356 TabHelper::FromWebContents(web_contents_)
1356 ->script_executor() 1357 ->script_executor()
1357 ->ExecuteScript( 1358 ->ExecuteScript(
1358 HostID(HostID::EXTENSIONS, extension_id()), 1359 HostID(HostID::EXTENSIONS, extension_id()),
1359 ScriptExecutor::JAVASCRIPT, 1360 ScriptExecutor::JAVASCRIPT,
1360 net::UnescapeURLComponent(url.GetContent(), 1361 net::UnescapeURLComponent(url.GetContent(),
1361 net::UnescapeRule::URL_SPECIAL_CHARS | 1362 net::UnescapeRule::URL_SPECIAL_CHARS |
1362 net::UnescapeRule::SPACES), 1363 net::UnescapeRule::SPACES),
1363 ScriptExecutor::TOP_FRAME, ScriptExecutor::DONT_MATCH_ABOUT_BLANK, 1364 ScriptExecutor::SINGLE_FRAME, ExtensionApiFrameIdMap::kTopFrameId,
1364 UserScript::DOCUMENT_IDLE, ScriptExecutor::MAIN_WORLD, 1365 ScriptExecutor::DONT_MATCH_ABOUT_BLANK, UserScript::DOCUMENT_IDLE,
1365 ScriptExecutor::DEFAULT_PROCESS, GURL(), GURL(), user_gesture_, 1366 ScriptExecutor::MAIN_WORLD, ScriptExecutor::DEFAULT_PROCESS, GURL(),
1366 ScriptExecutor::NO_RESULT, 1367 GURL(), user_gesture_, ScriptExecutor::NO_RESULT,
1367 base::Bind(&TabsUpdateFunction::OnExecuteCodeFinished, this)); 1368 base::Bind(&TabsUpdateFunction::OnExecuteCodeFinished, this));
1368 1369
1369 *is_async = true; 1370 *is_async = true;
1370 return true; 1371 return true;
1371 } 1372 }
1372 1373
1373 web_contents_->GetController().LoadURL( 1374 web_contents_->GetController().LoadURL(
1374 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); 1375 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
1375 1376
1376 // The URL of a tab contents never actually changes to a JavaScript URL, so 1377 // The URL of a tab contents never actually changes to a JavaScript URL, so
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 NULL, 1855 NULL,
1855 NULL, 1856 NULL,
1856 &contents, 1857 &contents,
1857 NULL, 1858 NULL,
1858 &error_)) { 1859 &error_)) {
1859 return false; 1860 return false;
1860 } 1861 }
1861 1862
1862 CHECK(contents); 1863 CHECK(contents);
1863 1864
1865 int frame_id = details_->frame_id ? *details_->frame_id
1866 : ExtensionApiFrameIdMap::kTopFrameId;
1867 content::RenderFrameHost* rfh =
1868 ExtensionApiFrameIdMap::GetRenderFrameHostById(contents, frame_id);
1869 if (!rfh) {
1870 error_ = ErrorUtils::FormatErrorMessage(keys::kFrameNotFoundError,
1871 base::IntToString(frame_id),
1872 base::IntToString(execute_tab_id_));
1873 return false;
1874 }
1875
1876 // Content scripts declared in manifest.json can access frames at about:-URLs
1877 // if the extension has permission to access the frame's origin, so also allow
1878 // programmatic content scripts at about:-URLs for allowed origins.
1879 GURL effective_document_url(rfh->GetLastCommittedURL());
1880 bool is_about_url = effective_document_url.SchemeIs(url::kAboutScheme);
1881 if (is_about_url && details_->match_about_blank &&
1882 *details_->match_about_blank) {
1883 effective_document_url = GURL(rfh->GetLastCommittedOrigin().Serialize());
1884 }
1885
1886 if (!effective_document_url.is_valid()) {
1887 // Unknown URL, e.g. because no load was committed yet. Allow for now, the
1888 // renderer will check again and fail the injection if needed.
1889 return true;
1890 }
1891
1864 // NOTE: This can give the wrong answer due to race conditions, but it is OK, 1892 // NOTE: This can give the wrong answer due to race conditions, but it is OK,
1865 // we check again in the renderer. 1893 // we check again in the renderer.
1866 if (!extension()->permissions_data()->CanAccessPage( 1894 if (!extension()->permissions_data()->CanAccessPage(
1867 extension(), 1895 extension(), effective_document_url, execute_tab_id_, &error_)) {
1868 contents->GetURL(), 1896 if (is_about_url &&
1869 execute_tab_id_, 1897 extension()->permissions_data()->active_permissions().HasAPIPermission(
1870 &error_)) { 1898 APIPermission::kTab)) {
1899 error_ = ErrorUtils::FormatErrorMessage(
1900 manifest_errors::kCannotAccessAboutUrl,
1901 rfh->GetLastCommittedURL().spec(),
1902 rfh->GetLastCommittedOrigin().Serialize());
1903 }
1871 return false; 1904 return false;
1872 } 1905 }
1873 1906
1874 return true; 1907 return true;
1875 } 1908 }
1876 1909
1877 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { 1910 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() {
1878 Browser* browser = NULL; 1911 Browser* browser = NULL;
1879 content::WebContents* contents = NULL; 1912 content::WebContents* contents = NULL;
1880 1913
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
2060 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); 2093 ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
2061 zoom_settings.default_zoom_factor.reset(new double( 2094 zoom_settings.default_zoom_factor.reset(new double(
2062 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); 2095 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel())));
2063 2096
2064 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); 2097 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings);
2065 SendResponse(true); 2098 SendResponse(true);
2066 return true; 2099 return true;
2067 } 2100 }
2068 2101
2069 } // namespace extensions 2102 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698