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 <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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 blink::WebFrame* web_frame) | 27 blink::WebFrame* web_frame) |
28 : params_(new ExtensionMsg_ExecuteCode_Params(params)), | 28 : params_(new ExtensionMsg_ExecuteCode_Params(params)), |
29 web_frame_(web_frame), | 29 web_frame_(web_frame), |
30 results_(new base::ListValue()), | 30 results_(new base::ListValue()), |
31 finished_(false) { | 31 finished_(false) { |
32 } | 32 } |
33 | 33 |
34 ProgrammaticScriptInjector::~ProgrammaticScriptInjector() { | 34 ProgrammaticScriptInjector::~ProgrammaticScriptInjector() { |
35 } | 35 } |
36 | 36 |
| 37 extension_misc::InjectedScriptType |
| 38 ProgrammaticScriptInjector::script_type() const { |
| 39 return extension_misc::PROGRAMMATIC_SCRIPT; |
| 40 } |
| 41 |
37 bool ProgrammaticScriptInjector::ShouldExecuteInChildFrames() const { | 42 bool ProgrammaticScriptInjector::ShouldExecuteInChildFrames() const { |
38 return params_->all_frames; | 43 return params_->all_frames; |
39 } | 44 } |
40 | 45 |
41 bool ProgrammaticScriptInjector::ShouldExecuteInMainWorld() const { | 46 bool ProgrammaticScriptInjector::ShouldExecuteInMainWorld() const { |
42 return params_->in_main_world; | 47 return params_->in_main_world; |
43 } | 48 } |
44 | 49 |
45 bool ProgrammaticScriptInjector::IsUserGesture() const { | 50 bool ProgrammaticScriptInjector::IsUserGesture() const { |
46 return params_->user_gesture; | 51 return params_->user_gesture; |
47 } | 52 } |
48 | 53 |
49 bool ProgrammaticScriptInjector::ExpectsResults() const { | 54 bool ProgrammaticScriptInjector::ExpectsResults() const { |
50 return params_->wants_result; | 55 return params_->wants_result; |
51 } | 56 } |
52 | 57 |
53 bool ProgrammaticScriptInjector::ShouldInjectJs( | 58 bool ProgrammaticScriptInjector::ShouldInjectJs( |
54 UserScript::RunLocation run_location) const { | 59 UserScript::RunLocation run_location) const { |
55 return GetRunLocation() == run_location && params_->is_javascript; | 60 return GetRunLocation() == run_location && params_->is_javascript; |
56 } | 61 } |
57 | 62 |
58 bool ProgrammaticScriptInjector::ShouldInjectCss( | 63 bool ProgrammaticScriptInjector::ShouldInjectCss( |
59 UserScript::RunLocation run_location) const { | 64 UserScript::RunLocation run_location) const { |
60 return GetRunLocation() == run_location && !params_->is_javascript; | 65 return GetRunLocation() == run_location && !params_->is_javascript; |
61 } | 66 } |
62 | 67 |
63 ScriptInjector::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( | 68 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( |
64 const Extension* extension, | 69 const Extension* extension, |
65 blink::WebFrame* frame, | 70 blink::WebFrame* frame, |
66 int tab_id, | 71 int tab_id, |
67 const GURL& top_url) const { | 72 const GURL& top_url) const { |
68 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 73 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
69 frame, frame->document().url(), params_->match_about_blank); | 74 frame, frame->document().url(), params_->match_about_blank); |
70 if (params_->is_web_view) { | 75 if (params_->is_web_view) { |
71 return effective_document_url == params_->webview_src ? ALLOW_ACCESS | 76 return effective_document_url == params_->webview_src ? |
72 : DENY_ACCESS; | 77 PermissionsData::ALLOW_ACCESS : PermissionsData::DENY_ACCESS; |
73 } | 78 } |
74 | 79 |
75 if (!extension->permissions_data()->CanAccessPage(extension, | 80 return extension->permissions_data()->CanAccessPageWithUserConsent( |
76 effective_document_url, | 81 extension, |
77 top_url, | 82 effective_document_url, |
78 tab_id, | 83 top_url, |
79 -1, // no process ID. | 84 tab_id, |
80 NULL /* ignore error */)) { | 85 -1, // no process ID. |
81 return DENY_ACCESS; | 86 NULL /* ignore error */); |
82 } | |
83 | |
84 return extension->permissions_data()->RequiresActionForScriptExecution( | |
85 extension, tab_id, effective_document_url) | |
86 ? REQUEST_ACCESS | |
87 : ALLOW_ACCESS; | |
88 } | 87 } |
89 | 88 |
90 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources( | 89 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources( |
91 UserScript::RunLocation run_location) const { | 90 UserScript::RunLocation run_location) const { |
92 DCHECK_EQ(GetRunLocation(), run_location); | 91 DCHECK_EQ(GetRunLocation(), run_location); |
93 DCHECK(params_->is_javascript); | 92 DCHECK(params_->is_javascript); |
94 | 93 |
95 return std::vector<blink::WebScriptSource>( | 94 return std::vector<blink::WebScriptSource>( |
96 1, | 95 1, |
97 blink::WebScriptSource( | 96 blink::WebScriptSource( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 render_view->Send(new ExtensionHostMsg_ExecuteCodeFinished( | 141 render_view->Send(new ExtensionHostMsg_ExecuteCodeFinished( |
143 render_view->GetRoutingID(), | 142 render_view->GetRoutingID(), |
144 params_->request_id, | 143 params_->request_id, |
145 error, | 144 error, |
146 render_view->GetPageId(), | 145 render_view->GetPageId(), |
147 ScriptContext::GetDataSourceURLForFrame(web_frame_), | 146 ScriptContext::GetDataSourceURLForFrame(web_frame_), |
148 *results_)); | 147 *results_)); |
149 } | 148 } |
150 | 149 |
151 } // namespace extensions | 150 } // namespace extensions |
OLD | NEW |