OLD | NEW |
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 <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "content/public/common/url_constants.h" | 11 #include "content/public/common/url_constants.h" |
12 #include "content/public/renderer/render_frame.h" | 12 #include "content/public/renderer/render_frame.h" |
13 #include "extensions/common/error_utils.h" | 13 #include "extensions/common/error_utils.h" |
14 #include "extensions/common/extension_messages.h" | 14 #include "extensions/common/extension_messages.h" |
15 #include "extensions/common/manifest_constants.h" | 15 #include "extensions/common/manifest_constants.h" |
16 #include "extensions/common/permissions/api_permission.h" | 16 #include "extensions/common/permissions/api_permission.h" |
17 #include "extensions/common/permissions/permissions_data.h" | 17 #include "extensions/common/permissions/permissions_data.h" |
18 #include "extensions/renderer/injection_host.h" | 18 #include "extensions/renderer/injection_host.h" |
19 #include "extensions/renderer/renderer_extension_registry.h" | 19 #include "extensions/renderer/renderer_extension_registry.h" |
20 #include "extensions/renderer/script_context.h" | 20 #include "extensions/renderer/script_context.h" |
| 21 #include "extensions/renderer/scripts_run_info.h" |
21 #include "third_party/WebKit/public/platform/WebString.h" | 22 #include "third_party/WebKit/public/platform/WebString.h" |
22 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
23 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
24 #include "third_party/WebKit/public/web/WebScriptSource.h" | 25 #include "third_party/WebKit/public/web/WebScriptSource.h" |
25 | 26 |
26 namespace extensions { | 27 namespace extensions { |
27 | 28 |
28 ProgrammaticScriptInjector::ProgrammaticScriptInjector( | 29 ProgrammaticScriptInjector::ProgrammaticScriptInjector( |
29 const ExtensionMsg_ExecuteCode_Params& params, | 30 const ExtensionMsg_ExecuteCode_Params& params, |
30 content::RenderFrame* render_frame) | 31 content::RenderFrame* render_frame) |
(...skipping 21 matching lines...) Expand all Loading... |
52 | 53 |
53 bool ProgrammaticScriptInjector::IsUserGesture() const { | 54 bool ProgrammaticScriptInjector::IsUserGesture() const { |
54 return params_->user_gesture; | 55 return params_->user_gesture; |
55 } | 56 } |
56 | 57 |
57 bool ProgrammaticScriptInjector::ExpectsResults() const { | 58 bool ProgrammaticScriptInjector::ExpectsResults() const { |
58 return params_->wants_result; | 59 return params_->wants_result; |
59 } | 60 } |
60 | 61 |
61 bool ProgrammaticScriptInjector::ShouldInjectJs( | 62 bool ProgrammaticScriptInjector::ShouldInjectJs( |
62 UserScript::RunLocation run_location) const { | 63 UserScript::RunLocation run_location, |
| 64 std::set<GURL> injected_scripts) const { |
63 return GetRunLocation() == run_location && params_->is_javascript; | 65 return GetRunLocation() == run_location && params_->is_javascript; |
64 } | 66 } |
65 | 67 |
66 bool ProgrammaticScriptInjector::ShouldInjectCss( | 68 bool ProgrammaticScriptInjector::ShouldInjectCss( |
67 UserScript::RunLocation run_location) const { | 69 UserScript::RunLocation run_location, |
| 70 std::set<GURL> injected_scripts) const { |
68 return GetRunLocation() == run_location && !params_->is_javascript; | 71 return GetRunLocation() == run_location && !params_->is_javascript; |
69 } | 72 } |
70 | 73 |
71 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( | 74 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( |
72 const InjectionHost* injection_host, | 75 const InjectionHost* injection_host, |
73 blink::WebLocalFrame* frame, | 76 blink::WebLocalFrame* frame, |
74 int tab_id) const { | 77 int tab_id) const { |
75 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 78 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
76 frame, frame->document().url(), params_->match_about_blank); | 79 frame, frame->document().url(), params_->match_about_blank); |
77 if (params_->is_web_view) { | 80 if (params_->is_web_view) { |
78 if (frame->parent()) { | 81 if (frame->parent()) { |
79 // This is a subframe inside <webview>, so allow it. | 82 // This is a subframe inside <webview>, so allow it. |
80 return PermissionsData::ACCESS_ALLOWED; | 83 return PermissionsData::ACCESS_ALLOWED; |
81 } | 84 } |
82 | 85 |
83 return effective_document_url == params_->webview_src | 86 return effective_document_url == params_->webview_src |
84 ? PermissionsData::ACCESS_ALLOWED | 87 ? PermissionsData::ACCESS_ALLOWED |
85 : PermissionsData::ACCESS_DENIED; | 88 : PermissionsData::ACCESS_DENIED; |
86 } | 89 } |
87 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS); | 90 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS); |
88 | 91 |
89 return injection_host->CanExecuteOnFrame( | 92 return injection_host->CanExecuteOnFrame( |
90 effective_document_url, | 93 effective_document_url, |
91 content::RenderFrame::FromWebFrame(frame), | 94 content::RenderFrame::FromWebFrame(frame), |
92 tab_id, | 95 tab_id, |
93 true /* is_declarative */); | 96 true /* is_declarative */); |
94 } | 97 } |
95 | 98 |
96 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources( | 99 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources( |
97 UserScript::RunLocation run_location) const { | 100 UserScript::RunLocation run_location, |
| 101 ScriptsRunInfo* scripts_run_info) const { |
98 DCHECK_EQ(GetRunLocation(), run_location); | 102 DCHECK_EQ(GetRunLocation(), run_location); |
99 DCHECK(params_->is_javascript); | 103 DCHECK(params_->is_javascript); |
100 | 104 |
101 return std::vector<blink::WebScriptSource>( | 105 return std::vector<blink::WebScriptSource>( |
102 1, | 106 1, |
103 blink::WebScriptSource( | 107 blink::WebScriptSource( |
104 blink::WebString::fromUTF8(params_->code), params_->file_url)); | 108 blink::WebString::fromUTF8(params_->code), params_->file_url)); |
105 } | 109 } |
106 | 110 |
107 std::vector<std::string> ProgrammaticScriptInjector::GetCssSources( | 111 std::vector<std::string> ProgrammaticScriptInjector::GetCssSources( |
108 UserScript::RunLocation run_location) const { | 112 UserScript::RunLocation run_location, |
| 113 ScriptsRunInfo* scripts_run_info) const { |
109 DCHECK_EQ(GetRunLocation(), run_location); | 114 DCHECK_EQ(GetRunLocation(), run_location); |
110 DCHECK(!params_->is_javascript); | 115 DCHECK(!params_->is_javascript); |
111 | 116 |
112 return std::vector<std::string>(1, params_->code); | 117 return std::vector<std::string>(1, params_->code); |
113 } | 118 } |
114 | 119 |
115 void ProgrammaticScriptInjector::GetRunInfo( | 120 void ProgrammaticScriptInjector::GetRunInfo( |
116 ScriptsRunInfo* scripts_run_info, | 121 ScriptsRunInfo* scripts_run_info, |
117 UserScript::RunLocation run_location) const { | 122 UserScript::RunLocation run_location) const { |
118 } | 123 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // frame deletions so nothing is left hanging). | 181 // frame deletions so nothing is left hanging). |
177 if (render_frame) { | 182 if (render_frame) { |
178 render_frame->Send( | 183 render_frame->Send( |
179 new ExtensionHostMsg_ExecuteCodeFinished( | 184 new ExtensionHostMsg_ExecuteCodeFinished( |
180 render_frame->GetRoutingID(), params_->request_id, | 185 render_frame->GetRoutingID(), params_->request_id, |
181 error, url_, results_)); | 186 error, url_, results_)); |
182 } | 187 } |
183 } | 188 } |
184 | 189 |
185 } // namespace extensions | 190 } // namespace extensions |
OLD | NEW |