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

Side by Side Diff: extensions/browser/extension_function_dispatcher.cc

Issue 227413008: Add the feature to retain the user gesture in the extension callback (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
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/browser/extension_function_dispatcher.h" 5 #include "extensions/browser/extension_function_dispatcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_string_value_serializer.h" 8 #include "base/json/json_string_value_serializer.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 if (process) 85 if (process)
86 base::KillProcess(process, content::RESULT_CODE_KILLED_BAD_MESSAGE, false); 86 base::KillProcess(process, content::RESULT_CODE_KILLED_BAD_MESSAGE, false);
87 } 87 }
88 88
89 void CommonResponseCallback(IPC::Sender* ipc_sender, 89 void CommonResponseCallback(IPC::Sender* ipc_sender,
90 int routing_id, 90 int routing_id,
91 base::ProcessHandle peer_process, 91 base::ProcessHandle peer_process,
92 int request_id, 92 int request_id,
93 ExtensionFunction::ResponseType type, 93 ExtensionFunction::ResponseType type,
94 const base::ListValue& results, 94 const base::ListValue& results,
95 const std::string& error) { 95 const std::string& error,
96 const bool user_gesture) {
96 DCHECK(ipc_sender); 97 DCHECK(ipc_sender);
97 98
98 if (type == ExtensionFunction::BAD_MESSAGE) { 99 if (type == ExtensionFunction::BAD_MESSAGE) {
99 // The renderer has done validation before sending extension api requests. 100 // The renderer has done validation before sending extension api requests.
100 // Therefore, we should never receive a request that is invalid in a way 101 // Therefore, we should never receive a request that is invalid in a way
101 // that JSON validation in the renderer should have caught. It could be an 102 // that JSON validation in the renderer should have caught. It could be an
102 // attacker trying to exploit the browser, so we crash the renderer instead. 103 // attacker trying to exploit the browser, so we crash the renderer instead.
103 LOG(ERROR) << 104 LOG(ERROR) <<
104 "Terminating renderer because of malformed extension message."; 105 "Terminating renderer because of malformed extension message.";
105 if (content::RenderProcessHost::run_renderer_in_process()) { 106 if (content::RenderProcessHost::run_renderer_in_process()) {
106 // In single process mode it is better if we don't suicide but just crash. 107 // In single process mode it is better if we don't suicide but just crash.
107 CHECK(false); 108 CHECK(false);
108 } else { 109 } else {
109 KillBadMessageSender(peer_process); 110 KillBadMessageSender(peer_process);
110 } 111 }
111 112
112 return; 113 return;
113 } 114 }
114 115
115 ipc_sender->Send(new ExtensionMsg_Response( 116 ipc_sender->Send(new ExtensionMsg_Response(
116 routing_id, request_id, type == ExtensionFunction::SUCCEEDED, results, 117 routing_id, request_id, type == ExtensionFunction::SUCCEEDED, results,
117 error)); 118 error, user_gesture));
118 } 119 }
119 120
120 void IOThreadResponseCallback( 121 void IOThreadResponseCallback(
121 const base::WeakPtr<ExtensionMessageFilter>& ipc_sender, 122 const base::WeakPtr<ExtensionMessageFilter>& ipc_sender,
122 int routing_id, 123 int routing_id,
123 int request_id, 124 int request_id,
124 ExtensionFunction::ResponseType type, 125 ExtensionFunction::ResponseType type,
125 const base::ListValue& results, 126 const base::ListValue& results,
126 const std::string& error) { 127 const std::string& error,
128 const bool user_gesture) {
127 if (!ipc_sender.get()) 129 if (!ipc_sender.get())
128 return; 130 return;
129 131
130 CommonResponseCallback(ipc_sender.get(), 132 CommonResponseCallback(ipc_sender.get(),
131 routing_id, 133 routing_id,
132 ipc_sender->PeerHandle(), 134 ipc_sender->PeerHandle(),
133 request_id, 135 request_id,
134 type, 136 type,
135 results, 137 results,
136 error); 138 error,
139 user_gesture);
137 } 140 }
138 141
139 } // namespace 142 } // namespace
140 143
141 class ExtensionFunctionDispatcher::UIThreadResponseCallbackWrapper 144 class ExtensionFunctionDispatcher::UIThreadResponseCallbackWrapper
142 : public content::WebContentsObserver { 145 : public content::WebContentsObserver {
143 public: 146 public:
144 UIThreadResponseCallbackWrapper( 147 UIThreadResponseCallbackWrapper(
145 const base::WeakPtr<ExtensionFunctionDispatcher>& dispatcher, 148 const base::WeakPtr<ExtensionFunctionDispatcher>& dispatcher,
146 RenderViewHost* render_view_host) 149 RenderViewHost* render_view_host)
(...skipping 26 matching lines...) Expand all
173 return base::Bind( 176 return base::Bind(
174 &UIThreadResponseCallbackWrapper::OnExtensionFunctionCompleted, 177 &UIThreadResponseCallbackWrapper::OnExtensionFunctionCompleted,
175 weak_ptr_factory_.GetWeakPtr(), 178 weak_ptr_factory_.GetWeakPtr(),
176 request_id); 179 request_id);
177 } 180 }
178 181
179 private: 182 private:
180 void OnExtensionFunctionCompleted(int request_id, 183 void OnExtensionFunctionCompleted(int request_id,
181 ExtensionFunction::ResponseType type, 184 ExtensionFunction::ResponseType type,
182 const base::ListValue& results, 185 const base::ListValue& results,
183 const std::string& error) { 186 const std::string& error,
187 const bool user_gesture) {
184 CommonResponseCallback( 188 CommonResponseCallback(
185 render_view_host_, render_view_host_->GetRoutingID(), 189 render_view_host_, render_view_host_->GetRoutingID(),
186 render_view_host_->GetProcess()->GetHandle(), request_id, type, 190 render_view_host_->GetProcess()->GetHandle(), request_id, type,
187 results, error); 191 results, error, user_gesture);
188 } 192 }
189 193
190 base::WeakPtr<ExtensionFunctionDispatcher> dispatcher_; 194 base::WeakPtr<ExtensionFunctionDispatcher> dispatcher_;
191 content::RenderViewHost* render_view_host_; 195 content::RenderViewHost* render_view_host_;
192 base::WeakPtrFactory<UIThreadResponseCallbackWrapper> weak_ptr_factory_; 196 base::WeakPtrFactory<UIThreadResponseCallbackWrapper> weak_ptr_factory_;
193 197
194 DISALLOW_COPY_AND_ASSIGN(UIThreadResponseCallbackWrapper); 198 DISALLOW_COPY_AND_ASSIGN(UIThreadResponseCallbackWrapper);
195 }; 199 };
196 200
197 WindowController* 201 WindowController*
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 function->set_source_tab_id(params.source_tab_id); 503 function->set_source_tab_id(params.source_tab_id);
500 504
501 return function; 505 return function;
502 } 506 }
503 507
504 // static 508 // static
505 void ExtensionFunctionDispatcher::SendAccessDenied( 509 void ExtensionFunctionDispatcher::SendAccessDenied(
506 const ExtensionFunction::ResponseCallback& callback) { 510 const ExtensionFunction::ResponseCallback& callback) {
507 base::ListValue empty_list; 511 base::ListValue empty_list;
508 callback.Run(ExtensionFunction::FAILED, empty_list, 512 callback.Run(ExtensionFunction::FAILED, empty_list,
509 "Access to extension API denied."); 513 "Access to extension API denied.", false);
510 } 514 }
511 515
512 } // namespace extensions 516 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698