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

Side by Side Diff: extensions/renderer/programmatic_script_injector.cc

Issue 885493007: Refactoring: de-couple Extensions from "script injection System" [render side] : 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 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/renderer/render_view.h" 10 #include "content/public/renderer/render_view.h"
11 #include "extensions/common/error_utils.h" 11 #include "extensions/common/error_utils.h"
12 #include "extensions/common/extension.h" 12 #include "extensions/common/extension.h"
Devlin 2015/02/11 00:00:48 Prune
Xi Han 2015/02/11 16:00:23 Done.
13 #include "extensions/common/extension_messages.h" 13 #include "extensions/common/extension_messages.h"
14 #include "extensions/common/manifest_constants.h" 14 #include "extensions/common/manifest_constants.h"
15 #include "extensions/common/permissions/permissions_data.h" 15 #include "extensions/common/permissions/permissions_data.h"
16 #include "extensions/renderer/script_context.h" 16 #include "extensions/renderer/script_context.h"
17 #include "third_party/WebKit/public/platform/WebString.h" 17 #include "third_party/WebKit/public/platform/WebString.h"
18 #include "third_party/WebKit/public/web/WebDocument.h" 18 #include "third_party/WebKit/public/web/WebDocument.h"
19 #include "third_party/WebKit/public/web/WebFrame.h" 19 #include "third_party/WebKit/public/web/WebFrame.h"
20 #include "third_party/WebKit/public/web/WebScriptSource.h" 20 #include "third_party/WebKit/public/web/WebScriptSource.h"
21 21
22 namespace extensions { 22 namespace extensions {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 UserScript::RunLocation run_location) const { 59 UserScript::RunLocation run_location) const {
60 return GetRunLocation() == run_location && params_->is_javascript; 60 return GetRunLocation() == run_location && params_->is_javascript;
61 } 61 }
62 62
63 bool ProgrammaticScriptInjector::ShouldInjectCss( 63 bool ProgrammaticScriptInjector::ShouldInjectCss(
64 UserScript::RunLocation run_location) const { 64 UserScript::RunLocation run_location) const {
65 return GetRunLocation() == run_location && !params_->is_javascript; 65 return GetRunLocation() == run_location && !params_->is_javascript;
66 } 66 }
67 67
68 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( 68 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame(
69 const Extension* extension, 69 const InjectionHost* injection_host,
70 blink::WebFrame* frame, 70 blink::WebFrame* frame,
71 int tab_id, 71 int tab_id,
72 const GURL& top_url) const { 72 const GURL& top_url) const {
73 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 73 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
74 frame, frame->document().url(), params_->match_about_blank); 74 frame, frame->document().url(), params_->match_about_blank);
75 if (params_->is_web_view) { 75 if (params_->is_web_view) {
76 if (frame->parent()) { 76 if (frame->parent()) {
77 // This is a subframe inside <webview>, so allow it. 77 // This is a subframe inside <webview>, so allow it.
78 return PermissionsData::ACCESS_ALLOWED; 78 return PermissionsData::ACCESS_ALLOWED;
79 } 79 }
80 80
81 return effective_document_url == params_->webview_src 81 return effective_document_url == params_->webview_src
82 ? PermissionsData::ACCESS_ALLOWED 82 ? PermissionsData::ACCESS_ALLOWED
83 : PermissionsData::ACCESS_DENIED; 83 : PermissionsData::ACCESS_DENIED;
84 } 84 }
85 85
86 return extension->permissions_data()->GetPageAccess(extension, 86 return injection_host->CanExecuteOnFrame(
87 effective_document_url, 87 effective_document_url, top_url, tab_id, true /* is_declarative */);
88 top_url,
89 tab_id,
90 -1, // no process ID.
91 NULL /* ignore error */);
92 } 88 }
93 89
94 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources( 90 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources(
95 UserScript::RunLocation run_location) const { 91 UserScript::RunLocation run_location) const {
96 DCHECK_EQ(GetRunLocation(), run_location); 92 DCHECK_EQ(GetRunLocation(), run_location);
97 DCHECK(params_->is_javascript); 93 DCHECK(params_->is_javascript);
98 94
99 return std::vector<blink::WebScriptSource>( 95 return std::vector<blink::WebScriptSource>(
100 1, 96 1,
101 blink::WebScriptSource( 97 blink::WebScriptSource(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 138
143 render_view_->Send(new ExtensionHostMsg_ExecuteCodeFinished( 139 render_view_->Send(new ExtensionHostMsg_ExecuteCodeFinished(
144 render_view_->GetRoutingID(), 140 render_view_->GetRoutingID(),
145 params_->request_id, 141 params_->request_id,
146 error, 142 error,
147 url_, 143 url_,
148 *results_)); 144 *results_));
149 } 145 }
150 146
151 } // namespace extensions 147 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698