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

Side by Side Diff: extensions/renderer/request_sender.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
« no previous file with comments | « chrome/test/data/extensions/api_test/permissions/optional_retain_gesture/manifest.json ('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/request_sender.h" 5 #include "extensions/renderer/request_sender.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/renderer/extensions/dispatcher.h" 8 #include "chrome/renderer/extensions/dispatcher.h"
9 #include "content/public/renderer/render_view.h" 9 #include "content/public/renderer/render_view.h"
10 #include "extensions/common/extension_messages.h" 10 #include "extensions/common/extension_messages.h"
11 #include "extensions/renderer/script_context.h" 11 #include "extensions/renderer/script_context.h"
12 #include "third_party/WebKit/public/web/WebDocument.h" 12 #include "third_party/WebKit/public/web/WebDocument.h"
13 #include "third_party/WebKit/public/web/WebFrame.h" 13 #include "third_party/WebKit/public/web/WebFrame.h"
14 #include "third_party/WebKit/public/web/WebScopedUserGesture.h"
14 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
16 #include "third_party/WebKit/public/web/WebUserGestureToken.h"
15 17
16 namespace extensions { 18 namespace extensions {
17 19
18 // Contains info relevant to a pending API request. 20 // Contains info relevant to a pending API request.
19 struct PendingRequest { 21 struct PendingRequest {
20 public: 22 public:
21 PendingRequest(const std::string& name, RequestSender::Source* source) 23 PendingRequest(const std::string& name,
22 : name(name), source(source) {} 24 RequestSender::Source* source,
25 blink::WebUserGestureToken token)
26 : name(name), source(source), token(token) {}
23 27
24 std::string name; 28 std::string name;
25 RequestSender::Source* source; 29 RequestSender::Source* source;
30 blink::WebUserGestureToken token;
26 }; 31 };
27 32
28 RequestSender::ScopedTabID::ScopedTabID(RequestSender* request_sender, 33 RequestSender::ScopedTabID::ScopedTabID(RequestSender* request_sender,
29 int tab_id) 34 int tab_id)
30 : request_sender_(request_sender), 35 : request_sender_(request_sender),
31 tab_id_(tab_id), 36 tab_id_(tab_id),
32 previous_tab_id_(request_sender->source_tab_id_) { 37 previous_tab_id_(request_sender->source_tab_id_) {
33 request_sender_->source_tab_id_ = tab_id; 38 request_sender_->source_tab_id_ = tab_id;
34 } 39 }
35 40
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 93 }
89 94
90 // TODO(koz): See if we can make this a CHECK. 95 // TODO(koz): See if we can make this a CHECK.
91 if (!dispatcher_->CheckContextAccessToExtensionAPI(name, context)) 96 if (!dispatcher_->CheckContextAccessToExtensionAPI(name, context))
92 return; 97 return;
93 98
94 GURL source_url; 99 GURL source_url;
95 if (blink::WebFrame* webframe = context->web_frame()) 100 if (blink::WebFrame* webframe = context->web_frame())
96 source_url = webframe->document().url(); 101 source_url = webframe->document().url();
97 102
98 InsertRequest(request_id, new PendingRequest(name, source)); 103 InsertRequest(request_id, new PendingRequest(name, source,
104 blink::WebUserGestureIndicator::currentUserGestureToken()));
99 105
100 ExtensionHostMsg_Request_Params params; 106 ExtensionHostMsg_Request_Params params;
101 params.name = name; 107 params.name = name;
102 params.arguments.Swap(value_args); 108 params.arguments.Swap(value_args);
103 params.extension_id = context->GetExtensionID(); 109 params.extension_id = context->GetExtensionID();
104 params.source_url = source_url; 110 params.source_url = source_url;
105 params.source_tab_id = source_tab_id_; 111 params.source_tab_id = source_tab_id_;
106 params.request_id = request_id; 112 params.request_id = request_id;
107 params.has_callback = has_callback; 113 params.has_callback = has_callback;
108 params.user_gesture = 114 params.user_gesture =
(...skipping 11 matching lines...) Expand all
120 bool success, 126 bool success,
121 const base::ListValue& response, 127 const base::ListValue& response,
122 const std::string& error) { 128 const std::string& error) {
123 linked_ptr<PendingRequest> request = RemoveRequest(request_id); 129 linked_ptr<PendingRequest> request = RemoveRequest(request_id);
124 130
125 if (!request.get()) { 131 if (!request.get()) {
126 // This can happen if a context is destroyed while a request is in flight. 132 // This can happen if a context is destroyed while a request is in flight.
127 return; 133 return;
128 } 134 }
129 135
136 blink::WebScopedUserGesture gesture(request->token);
130 request->source->OnResponseReceived( 137 request->source->OnResponseReceived(
131 request->name, request_id, success, response, error); 138 request->name, request_id, success, response, error);
132 } 139 }
133 140
134 void RequestSender::InvalidateSource(Source* source) { 141 void RequestSender::InvalidateSource(Source* source) {
135 for (PendingRequestMap::iterator it = pending_requests_.begin(); 142 for (PendingRequestMap::iterator it = pending_requests_.begin();
136 it != pending_requests_.end();) { 143 it != pending_requests_.end();) {
137 if (it->second->source == source) 144 if (it->second->source == source)
138 pending_requests_.erase(it++); 145 pending_requests_.erase(it++);
139 else 146 else
140 ++it; 147 ++it;
141 } 148 }
142 } 149 }
143 150
144 } // namespace extensions 151 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/permissions/optional_retain_gesture/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698