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

Unified Diff: extensions/renderer/script_injection.cc

Issue 348313003: Create withheld permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/script_injection.cc
diff --git a/extensions/renderer/script_injection.cc b/extensions/renderer/script_injection.cc
index 3c77f9af5ed88fb3c7794bb2f3ee4c4be1cf3ab8..f28a89d8495ed5ac6d36270b4411783c7c89ba08 100644
--- a/extensions/renderer/script_injection.cc
+++ b/extensions/renderer/script_injection.cc
@@ -40,8 +40,8 @@ const int kInvalidRequestId = -1;
// The id of the next pending injection.
int64 g_next_pending_id = 0;
-bool ShouldDelayForPermission() {
- return FeatureSwitch::scripts_require_action()->IsEnabled();
+bool ShouldNotifyBrowserOfInjections() {
+ return !FeatureSwitch::scripts_require_action()->IsEnabled();
}
// Append all the child frames of |parent_frame| to |frames_vector|.
@@ -145,15 +145,13 @@ bool ScriptInjection::TryToInject(UserScript::RunLocation current_location,
switch (injector_->CanExecuteOnFrame(
extension, web_frame_, tab_id_, web_frame_->top()->document().url())) {
- case ScriptInjector::DENY_ACCESS:
+ case PermissionsData::ACCESS_DENIED:
NotifyWillNotInject(ScriptInjector::NOT_ALLOWED);
return true; // We're done.
- case ScriptInjector::REQUEST_ACCESS:
+ case PermissionsData::ACCESS_WITHHELD:
RequestPermission();
- if (ShouldDelayForPermission())
- return false; // Wait around for permission.
- // else fall through
- case ScriptInjector::ALLOW_ACCESS:
+ return false; // Wait around for permission.
+ case PermissionsData::ACCESS_ALLOWED:
Inject(extension, scripts_run_info);
return true; // We're done!
}
@@ -178,13 +176,14 @@ void ScriptInjection::RequestPermission() {
content::RenderView* render_view =
content::RenderView::FromWebView(web_frame()->top()->view());
- // If the feature to delay for permission isn't enabled, then just send an
+ // If we are just notifying the browser of the injection, then send an
// invalid request (which is treated like a notification).
- request_id_ =
- ShouldDelayForPermission() ? g_next_pending_id++ : kInvalidRequestId;
+ request_id_ = ShouldNotifyBrowserOfInjections() ? kInvalidRequestId
+ : g_next_pending_id++;
render_view->Send(new ExtensionHostMsg_RequestScriptInjectionPermission(
render_view->GetRoutingID(),
extension_id_,
+ injector_->script_type(),
render_view->GetPageId(),
request_id_));
}
@@ -201,6 +200,9 @@ void ScriptInjection::Inject(const Extension* extension,
DCHECK(scripts_run_info);
DCHECK(!complete_);
+ if (ShouldNotifyBrowserOfInjections())
+ RequestPermission();
+
std::vector<blink::WebFrame*> frame_vector;
frame_vector.push_back(web_frame_);
if (injector_->ShouldExecuteInChildFrames())
@@ -226,11 +228,11 @@ void ScriptInjection::Inject(const Extension* extension,
// extension might only have access to a subset of them.
// For child frames, we just skip ones the extension doesn't have access
// to and carry on.
- // Note: we don't consider REQUEST_ACCESS because there is nowhere to
+ // Note: we don't consider ACCESS_WITHHELD because there is nowhere to
// surface a request for a child frame.
// TODO(rdevlin.cronin): We should ask for permission somehow.
if (injector_->CanExecuteOnFrame(extension, frame, tab_id_, top_url) ==
- ScriptInjector::DENY_ACCESS) {
+ PermissionsData::ACCESS_DENIED) {
DCHECK(frame->parent());
continue;
}

Powered by Google App Engine
This is Rietveld 408576698