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

Side by Side Diff: chrome/renderer/extensions/request_sender.cc

Issue 145463002: Extensions: Send the tab id to platform apps. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix null pointer deref Created 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/extensions/request_sender.h ('k') | extensions/browser/extension_function.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/request_sender.h" 5 #include "chrome/renderer/extensions/request_sender.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/common/extensions/extension_messages.h" 8 #include "chrome/common/extensions/extension_messages.h"
9 #include "chrome/renderer/extensions/chrome_v8_context.h" 9 #include "chrome/renderer/extensions/chrome_v8_context.h"
10 #include "chrome/renderer/extensions/dispatcher.h" 10 #include "chrome/renderer/extensions/dispatcher.h"
11 #include "content/public/renderer/render_view.h" 11 #include "content/public/renderer/render_view.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/WebUserGestureIndicator.h" 14 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
15 15
16 namespace extensions { 16 namespace extensions {
17 17
18 // Contains info relevant to a pending API request. 18 // Contains info relevant to a pending API request.
19 struct PendingRequest { 19 struct PendingRequest {
20 public : 20 public :
21 PendingRequest(const std::string& name, RequestSender::Source* source) 21 PendingRequest(const std::string& name, RequestSender::Source* source)
22 : name(name), source(source) { 22 : name(name), source(source) {
23 } 23 }
24 24
25 std::string name; 25 std::string name;
26 RequestSender::Source* source; 26 RequestSender::Source* source;
27 }; 27 };
28 28
29 RequestSender::RequestSender(Dispatcher* dispatcher) : dispatcher_(dispatcher) { 29 RequestSender::ScopedTabID::ScopedTabID(RequestSender* request_sender,
30 int tab_id)
31 : request_sender_(request_sender),
32 tab_id_(tab_id),
33 previous_tab_id_(request_sender->source_tab_id_) {
34 request_sender_->source_tab_id_ = tab_id;
35 }
36
37 RequestSender::ScopedTabID::~ScopedTabID() {
38 DCHECK_EQ(tab_id_, request_sender_->source_tab_id_);
39 request_sender_->source_tab_id_ = previous_tab_id_;
40 }
41
42 RequestSender::RequestSender(Dispatcher* dispatcher)
43 : dispatcher_(dispatcher),
44 source_tab_id_(-1) {
30 } 45 }
31 46
32 RequestSender::~RequestSender() { 47 RequestSender::~RequestSender() {
33 } 48 }
34 49
35 void RequestSender::InsertRequest(int request_id, 50 void RequestSender::InsertRequest(int request_id,
36 PendingRequest* pending_request) { 51 PendingRequest* pending_request) {
37 DCHECK_EQ(0u, pending_requests_.count(request_id)); 52 DCHECK_EQ(0u, pending_requests_.count(request_id));
38 pending_requests_[request_id].reset(pending_request); 53 pending_requests_[request_id].reset(pending_request);
39 } 54 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 if (blink::WebFrame* webframe = context->web_frame()) 98 if (blink::WebFrame* webframe = context->web_frame())
84 source_url = webframe->document().url(); 99 source_url = webframe->document().url();
85 100
86 InsertRequest(request_id, new PendingRequest(name, source)); 101 InsertRequest(request_id, new PendingRequest(name, source));
87 102
88 ExtensionHostMsg_Request_Params params; 103 ExtensionHostMsg_Request_Params params;
89 params.name = name; 104 params.name = name;
90 params.arguments.Swap(value_args); 105 params.arguments.Swap(value_args);
91 params.extension_id = context->GetExtensionID(); 106 params.extension_id = context->GetExtensionID();
92 params.source_url = source_url; 107 params.source_url = source_url;
108 params.source_tab_id = source_tab_id_;
93 params.request_id = request_id; 109 params.request_id = request_id;
94 params.has_callback = has_callback; 110 params.has_callback = has_callback;
95 params.user_gesture = 111 params.user_gesture =
96 blink::WebUserGestureIndicator::isProcessingUserGesture(); 112 blink::WebUserGestureIndicator::isProcessingUserGesture();
97 if (for_io_thread) { 113 if (for_io_thread) {
98 renderview->Send(new ExtensionHostMsg_RequestForIOThread( 114 renderview->Send(new ExtensionHostMsg_RequestForIOThread(
99 renderview->GetRoutingID(), params)); 115 renderview->GetRoutingID(), params));
100 } else { 116 } else {
101 renderview->Send(new ExtensionHostMsg_Request( 117 renderview->Send(new ExtensionHostMsg_Request(
102 renderview->GetRoutingID(), params)); 118 renderview->GetRoutingID(), params));
(...skipping 19 matching lines...) Expand all
122 for (PendingRequestMap::iterator it = pending_requests_.begin(); 138 for (PendingRequestMap::iterator it = pending_requests_.begin();
123 it != pending_requests_.end();) { 139 it != pending_requests_.end();) {
124 if (it->second->source == source) 140 if (it->second->source == source)
125 pending_requests_.erase(it++); 141 pending_requests_.erase(it++);
126 else 142 else
127 ++it; 143 ++it;
128 } 144 }
129 } 145 }
130 146
131 } // namespace extensions 147 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/request_sender.h ('k') | extensions/browser/extension_function.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698