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

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: 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"
11 #include "content/public/renderer/render_frame.h"
11 #include "content/public/renderer/render_view.h" 12 #include "content/public/renderer/render_view.h"
12 #include "extensions/common/error_utils.h" 13 #include "extensions/common/error_utils.h"
13 #include "extensions/common/extension_messages.h" 14 #include "extensions/common/extension_messages.h"
14 #include "extensions/common/manifest_constants.h" 15 #include "extensions/common/manifest_constants.h"
15 #include "extensions/common/permissions/permissions_data.h" 16 #include "extensions/common/permissions/permissions_data.h"
16 #include "extensions/renderer/injection_host.h" 17 #include "extensions/renderer/injection_host.h"
17 #include "extensions/renderer/script_context.h" 18 #include "extensions/renderer/script_context.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 19 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/web/WebDocument.h" 20 #include "third_party/WebKit/public/web/WebDocument.h"
20 #include "third_party/WebKit/public/web/WebFrame.h" 21 #include "third_party/WebKit/public/web/WebFrame.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 60 }
60 61
61 bool ProgrammaticScriptInjector::ShouldInjectCss( 62 bool ProgrammaticScriptInjector::ShouldInjectCss(
62 UserScript::RunLocation run_location) const { 63 UserScript::RunLocation run_location) const {
63 return GetRunLocation() == run_location && !params_->is_javascript; 64 return GetRunLocation() == run_location && !params_->is_javascript;
64 } 65 }
65 66
66 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( 67 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame(
67 const InjectionHost* injection_host, 68 const InjectionHost* injection_host,
68 blink::WebFrame* frame, 69 blink::WebFrame* frame,
69 int tab_id, 70 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 71 // It doesn't make sense to inject a script into a remote frame or a frame
72 // with a null document. 72 // with a null document.
73 if (frame->isWebRemoteFrame() || frame->document().isNull()) 73 if (frame->isWebRemoteFrame() || frame->document().isNull())
74 return PermissionsData::ACCESS_DENIED; 74 return PermissionsData::ACCESS_DENIED;
75 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 75 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
76 frame, frame->document().url(), params_->match_about_blank); 76 frame, frame->document().url(), params_->match_about_blank);
77 if (params_->is_web_view) { 77 if (params_->is_web_view) {
78 if (frame->parent()) { 78 if (frame->parent()) {
79 // This is a subframe inside <webview>, so allow it. 79 // This is a subframe inside <webview>, so allow it.
80 return PermissionsData::ACCESS_ALLOWED; 80 return PermissionsData::ACCESS_ALLOWED;
81 } 81 }
82 82
83 return effective_document_url == params_->webview_src 83 return effective_document_url == params_->webview_src
84 ? PermissionsData::ACCESS_ALLOWED 84 ? PermissionsData::ACCESS_ALLOWED
85 : PermissionsData::ACCESS_DENIED; 85 : PermissionsData::ACCESS_DENIED;
86 } 86 }
87 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS); 87 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS);
88 88
89 return injection_host->CanExecuteOnFrame( 89 return injection_host->CanExecuteOnFrame(
90 effective_document_url, top_url, tab_id, true /* is_declarative */); 90 effective_document_url,
91 content::RenderFrame::FromWebFrame(frame),
92 tab_id,
93 true /* is_declarative */);
91 } 94 }
92 95
93 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources( 96 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources(
94 UserScript::RunLocation run_location) const { 97 UserScript::RunLocation run_location) const {
95 DCHECK_EQ(GetRunLocation(), run_location); 98 DCHECK_EQ(GetRunLocation(), run_location);
96 DCHECK(params_->is_javascript); 99 DCHECK(params_->is_javascript);
97 100
98 return std::vector<blink::WebScriptSource>( 101 return std::vector<blink::WebScriptSource>(
99 1, 102 1,
100 blink::WebScriptSource( 103 blink::WebScriptSource(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 156
154 render_view_->Send(new ExtensionHostMsg_ExecuteCodeFinished( 157 render_view_->Send(new ExtensionHostMsg_ExecuteCodeFinished(
155 render_view_->GetRoutingID(), 158 render_view_->GetRoutingID(),
156 params_->request_id, 159 params_->request_id,
157 error, 160 error,
158 url_, 161 url_,
159 results_)); 162 results_));
160 } 163 }
161 164
162 } // namespace extensions 165 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/programmatic_script_injector.h ('k') | extensions/renderer/script_injection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698