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

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

Issue 945743003: Improve error message for failing code insertion on about:-URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add origin to error message 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
« no previous file with comments | « extensions/renderer/programmatic_script_injector.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/renderer/render_view.h" 11 #include "content/public/renderer/render_view.h"
11 #include "extensions/common/error_utils.h" 12 #include "extensions/common/error_utils.h"
12 #include "extensions/common/extension_messages.h" 13 #include "extensions/common/extension_messages.h"
13 #include "extensions/common/manifest_constants.h" 14 #include "extensions/common/manifest_constants.h"
14 #include "extensions/common/permissions/permissions_data.h" 15 #include "extensions/common/permissions/permissions_data.h"
15 #include "extensions/renderer/injection_host.h" 16 #include "extensions/renderer/injection_host.h"
16 #include "extensions/renderer/script_context.h" 17 #include "extensions/renderer/script_context.h"
17 #include "third_party/WebKit/public/platform/WebString.h" 18 #include "third_party/WebKit/public/platform/WebString.h"
18 #include "third_party/WebKit/public/web/WebDocument.h" 19 #include "third_party/WebKit/public/web/WebDocument.h"
19 #include "third_party/WebKit/public/web/WebFrame.h" 20 #include "third_party/WebKit/public/web/WebFrame.h"
20 #include "third_party/WebKit/public/web/WebScriptSource.h" 21 #include "third_party/WebKit/public/web/WebScriptSource.h"
21 22
22 namespace extensions { 23 namespace extensions {
23 24
24 ProgrammaticScriptInjector::ProgrammaticScriptInjector( 25 ProgrammaticScriptInjector::ProgrammaticScriptInjector(
25 const ExtensionMsg_ExecuteCode_Params& params, 26 const ExtensionMsg_ExecuteCode_Params& params,
26 blink::WebFrame* web_frame) 27 blink::WebFrame* web_frame)
27 : params_(new ExtensionMsg_ExecuteCode_Params(params)), 28 : params_(new ExtensionMsg_ExecuteCode_Params(params)),
28 url_(ScriptContext::GetDataSourceURLForFrame(web_frame)), 29 url_(ScriptContext::GetDataSourceURLForFrame(web_frame)),
29 render_view_(content::RenderView::FromWebView(web_frame->view())), 30 render_view_(content::RenderView::FromWebView(web_frame->view())),
30 results_(new base::ListValue()), 31 results_(new base::ListValue()),
31 finished_(false) { 32 finished_(false) {
33 effective_url_ = ScriptContext::GetEffectiveDocumentURL(
34 web_frame, url_, params.match_about_blank);
32 } 35 }
33 36
34 ProgrammaticScriptInjector::~ProgrammaticScriptInjector() { 37 ProgrammaticScriptInjector::~ProgrammaticScriptInjector() {
35 } 38 }
36 39
37 UserScript::InjectionType ProgrammaticScriptInjector::script_type() 40 UserScript::InjectionType ProgrammaticScriptInjector::script_type()
38 const { 41 const {
39 return UserScript::PROGRAMMATIC_SCRIPT; 42 return UserScript::PROGRAMMATIC_SCRIPT;
40 } 43 }
41 44
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 ScriptsRunInfo* scripts_run_info, 114 ScriptsRunInfo* scripts_run_info,
112 UserScript::RunLocation run_location) { 115 UserScript::RunLocation run_location) {
113 results_ = execution_results.Pass(); 116 results_ = execution_results.Pass();
114 Finish(std::string()); 117 Finish(std::string());
115 } 118 }
116 119
117 void ProgrammaticScriptInjector::OnWillNotInject(InjectFailureReason reason) { 120 void ProgrammaticScriptInjector::OnWillNotInject(InjectFailureReason reason) {
118 std::string error; 121 std::string error;
119 switch (reason) { 122 switch (reason) {
120 case NOT_ALLOWED: 123 case NOT_ALLOWED:
121 error = ErrorUtils::FormatErrorMessage(manifest_errors::kCannotAccessPage, 124 if (url_.SchemeIs(url::kAboutScheme)) {
122 url_.spec()); 125 error = ErrorUtils::FormatErrorMessage(
126 manifest_errors::kCannotAccessAboutUrl, url_.spec(),
127 effective_url_.GetOrigin().spec());
128 } else {
129 error = ErrorUtils::FormatErrorMessage(
130 manifest_errors::kCannotAccessPage, url_.spec());
131 }
123 break; 132 break;
124 case EXTENSION_REMOVED: // no special error here. 133 case EXTENSION_REMOVED: // no special error here.
125 case WONT_INJECT: 134 case WONT_INJECT:
126 break; 135 break;
127 } 136 }
128 Finish(error); 137 Finish(error);
129 } 138 }
130 139
131 UserScript::RunLocation ProgrammaticScriptInjector::GetRunLocation() const { 140 UserScript::RunLocation ProgrammaticScriptInjector::GetRunLocation() const {
132 return static_cast<UserScript::RunLocation>(params_->run_at); 141 return static_cast<UserScript::RunLocation>(params_->run_at);
133 } 142 }
134 143
135 void ProgrammaticScriptInjector::Finish(const std::string& error) { 144 void ProgrammaticScriptInjector::Finish(const std::string& error) {
136 DCHECK(!finished_); 145 DCHECK(!finished_);
137 finished_ = true; 146 finished_ = true;
138 147
139 render_view_->Send(new ExtensionHostMsg_ExecuteCodeFinished( 148 render_view_->Send(new ExtensionHostMsg_ExecuteCodeFinished(
140 render_view_->GetRoutingID(), 149 render_view_->GetRoutingID(),
141 params_->request_id, 150 params_->request_id,
142 error, 151 error,
143 url_, 152 url_,
144 *results_)); 153 *results_));
145 } 154 }
146 155
147 } // namespace extensions 156 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/programmatic_script_injector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698