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

Side by Side Diff: extensions/renderer/programmatic_script_injector.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: Fix extension page content scripts 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/programmatic_script_injector.h" 5 #include "extensions/renderer/programmatic_script_injector.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "content/public/common/url_constants.h" 10 #include "content/public/common/url_constants.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 60
61 bool ProgrammaticScriptInjector::ShouldInjectCss( 61 bool ProgrammaticScriptInjector::ShouldInjectCss(
62 UserScript::RunLocation run_location) const { 62 UserScript::RunLocation run_location) const {
63 return GetRunLocation() == run_location && !params_->is_javascript; 63 return GetRunLocation() == run_location && !params_->is_javascript;
64 } 64 }
65 65
66 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( 66 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame(
67 const InjectionHost* injection_host, 67 const InjectionHost* injection_host,
68 blink::WebFrame* frame, 68 blink::WebFrame* frame,
69 int tab_id, 69 int tab_id) const {
70 const GURL& top_url) const {
71 // It doesn't make sense to inject a script into a remote frame or a frame 70 // It doesn't make sense to inject a script into a remote frame or a frame
72 // with a null document. 71 // with a null document.
73 if (frame->isWebRemoteFrame() || frame->document().isNull()) 72 if (frame->isWebRemoteFrame() || frame->document().isNull())
74 return PermissionsData::ACCESS_DENIED; 73 return PermissionsData::ACCESS_DENIED;
75 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 74 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
76 frame, frame->document().url(), params_->match_about_blank); 75 frame, frame->document().url(), params_->match_about_blank);
77 if (params_->is_web_view) { 76 if (params_->is_web_view) {
78 if (frame->parent()) { 77 if (frame->parent()) {
79 // This is a subframe inside <webview>, so allow it. 78 // This is a subframe inside <webview>, so allow it.
80 return PermissionsData::ACCESS_ALLOWED; 79 return PermissionsData::ACCESS_ALLOWED;
81 } 80 }
82 81
83 return effective_document_url == params_->webview_src 82 return effective_document_url == params_->webview_src
84 ? PermissionsData::ACCESS_ALLOWED 83 ? PermissionsData::ACCESS_ALLOWED
85 : PermissionsData::ACCESS_DENIED; 84 : PermissionsData::ACCESS_DENIED;
86 } 85 }
87 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS); 86 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS);
88 87
89 return injection_host->CanExecuteOnFrame( 88 return injection_host->CanExecuteOnFrame(
90 effective_document_url, top_url, tab_id, true /* is_declarative */); 89 effective_document_url, frame, tab_id, true /* is_declarative */);
91 } 90 }
92 91
93 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources( 92 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources(
94 UserScript::RunLocation run_location) const { 93 UserScript::RunLocation run_location) const {
95 DCHECK_EQ(GetRunLocation(), run_location); 94 DCHECK_EQ(GetRunLocation(), run_location);
96 DCHECK(params_->is_javascript); 95 DCHECK(params_->is_javascript);
97 96
98 return std::vector<blink::WebScriptSource>( 97 return std::vector<blink::WebScriptSource>(
99 1, 98 1,
100 blink::WebScriptSource( 99 blink::WebScriptSource(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 152
154 render_view_->Send(new ExtensionHostMsg_ExecuteCodeFinished( 153 render_view_->Send(new ExtensionHostMsg_ExecuteCodeFinished(
155 render_view_->GetRoutingID(), 154 render_view_->GetRoutingID(),
156 params_->request_id, 155 params_->request_id,
157 error, 156 error,
158 url_, 157 url_,
159 results_)); 158 results_));
160 } 159 }
161 160
162 } // namespace extensions 161 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698