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

Unified Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 952473002: Add frameId to executeScript/insertCSS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a few nits (review up to comment 16) Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/tabs/tabs_api.cc
diff --git a/chrome/browser/extensions/api/tabs/tabs_api.cc b/chrome/browser/extensions/api/tabs/tabs_api.cc
index 4816da7e0687d8ce20a9b3f0af4717c47edc2252..491c111ffbfd671975587347615174e652aadc91 100644
--- a/chrome/browser/extensions/api/tabs/tabs_api.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_api.cc
@@ -59,6 +59,7 @@
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
@@ -913,7 +914,7 @@ bool TabsQueryFunction::RunSync() {
continue;
if (!url_patterns.is_empty() &&
- !url_patterns.MatchesURL(web_contents->GetURL()))
+ !url_patterns.MatchesURL(web_contents->GetLastCommittedURL()))
continue;
if (loading_status_set && loading != web_contents->IsLoading())
@@ -1232,8 +1233,8 @@ bool TabsUpdateFunction::UpdateURL(const std::string &url_string,
content::RenderProcessHost* process = web_contents_->GetRenderProcessHost();
if (!extension()->permissions_data()->CanAccessPage(
extension(),
- web_contents_->GetURL(),
- web_contents_->GetURL(),
+ web_contents_->GetLastCommittedURL(),
+ web_contents_->GetLastCommittedURL(),
tab_id,
process ? process->GetID() : -1,
&error_)) {
@@ -1244,7 +1245,8 @@ bool TabsUpdateFunction::UpdateURL(const std::string &url_string,
extension_id(),
ScriptExecutor::JAVASCRIPT,
url.GetContent(),
- ScriptExecutor::TOP_FRAME,
+ ScriptExecutor::SINGLE_FRAME,
+ 0, // Top-level frame
ScriptExecutor::DONT_MATCH_ABOUT_BLANK,
UserScript::DOCUMENT_IDLE,
ScriptExecutor::MAIN_WORLD,
@@ -1265,7 +1267,7 @@ bool TabsUpdateFunction::UpdateURL(const std::string &url_string,
// The URL of a tab contents never actually changes to a JavaScript URL, so
// this check only makes sense in other cases.
if (!url.SchemeIs(url::kJavaScriptScheme))
- DCHECK_EQ(url.spec(), web_contents_->GetURL().spec());
+ DCHECK_EQ(url.spec(), web_contents_->GetLastCommittedURL().spec());
return true;
}
@@ -1756,10 +1758,31 @@ bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage() {
// NOTE: This can give the wrong answer due to race conditions, but it is OK,
// we check again in the renderer.
content::RenderProcessHost* process = contents->GetRenderProcessHost();
+ content::RenderFrameHost* rfh = nullptr;
+ int frame_id = details_->frame_id ? *details_->frame_id : 0;
+ if (process && frame_id > 0) {
+ // TODO(robwu): This method will not work with OOPI, because the frames
+ // in a tab may be hosted within different processes (crbug.com/432875).
+ rfh = content::RenderFrameHost::FromID(process->GetID(), frame_id);
+ if (!rfh) {
+ error_ = ErrorUtils::FormatErrorMessage(
+ keys::kFrameNotFoundError, base::IntToString(frame_id),
+ base::IntToString(execute_tab_id_));
+ return false;
+ }
+ }
+ GURL document_url = rfh ?
+ rfh->GetLastCommittedURL() : contents->GetLastCommittedURL();
+ if (document_url.SchemeIs(url::kAboutScheme)) {
+ // Whether access is allowed depends on the frame's effective origin
+ // (see ScriptContext::GetEffectiveDocumentURL). Let the renderer decide
+ // whether to execute the script.
+ return true;
+ }
if (!extension()->permissions_data()->CanAccessPage(
extension(),
- contents->GetURL(),
- contents->GetURL(),
+ document_url,
+ contents->GetLastCommittedURL(),
execute_tab_id_,
process ? process->GetID() : -1,
&error_)) {
« no previous file with comments | « chrome/browser/chromeos/accessibility/accessibility_manager.cc ('k') | chrome/browser/extensions/api/tabs/tabs_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698