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

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: 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
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->sender_tab_id_) {
34 request_sender_->sender_tab_id_ = tab_id;
35 }
36
37 RequestSender::ScopedTabID::~ScopedTabID() {
38 DCHECK_EQ(tab_id_, request_sender_->sender_tab_id_);
39 request_sender_->sender_tab_id_ = previous_tab_id_;
40 }
41
42 RequestSender::RequestSender(Dispatcher* dispatcher)
43 : dispatcher_(dispatcher),
44 sender_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 10 matching lines...) Expand all
50 int RequestSender::GetNextRequestId() const { 65 int RequestSender::GetNextRequestId() const {
51 static int next_request_id = 0; 66 static int next_request_id = 0;
52 return next_request_id++; 67 return next_request_id++;
53 } 68 }
54 69
55 void RequestSender::StartRequest(Source* source, 70 void RequestSender::StartRequest(Source* source,
56 const std::string& name, 71 const std::string& name,
57 int request_id, 72 int request_id,
58 bool has_callback, 73 bool has_callback,
59 bool for_io_thread, 74 bool for_io_thread,
75 int source_tab_id,
60 base::ListValue* value_args) { 76 base::ListValue* value_args) {
61 ChromeV8Context* context = source->GetContext(); 77 ChromeV8Context* context = source->GetContext();
62 if (!context) 78 if (!context)
63 return; 79 return;
64 80
65 // Get the current RenderView so that we can send a routed IPC message from 81 // Get the current RenderView so that we can send a routed IPC message from
66 // the correct source. 82 // the correct source.
67 content::RenderView* renderview = context->GetRenderView(); 83 content::RenderView* renderview = context->GetRenderView();
68 if (!renderview) 84 if (!renderview)
69 return; 85 return;
(...skipping 13 matching lines...) Expand all
83 if (blink::WebFrame* webframe = context->web_frame()) 99 if (blink::WebFrame* webframe = context->web_frame())
84 source_url = webframe->document().url(); 100 source_url = webframe->document().url();
85 101
86 InsertRequest(request_id, new PendingRequest(name, source)); 102 InsertRequest(request_id, new PendingRequest(name, source));
87 103
88 ExtensionHostMsg_Request_Params params; 104 ExtensionHostMsg_Request_Params params;
89 params.name = name; 105 params.name = name;
90 params.arguments.Swap(value_args); 106 params.arguments.Swap(value_args);
91 params.extension_id = context->GetExtensionID(); 107 params.extension_id = context->GetExtensionID();
92 params.source_url = source_url; 108 params.source_url = source_url;
109 params.source_tab_id = source_tab_id;
not at google - send to devlin 2014/01/28 18:45:45 I was imagining the source_tab_id would be read fr
Lei Zhang 2014/01/28 22:52:27 Ah, yes. That is much simpler. Done.
93 params.request_id = request_id; 110 params.request_id = request_id;
94 params.has_callback = has_callback; 111 params.has_callback = has_callback;
95 params.user_gesture = 112 params.user_gesture =
96 blink::WebUserGestureIndicator::isProcessingUserGesture(); 113 blink::WebUserGestureIndicator::isProcessingUserGesture();
97 if (for_io_thread) { 114 if (for_io_thread) {
98 renderview->Send(new ExtensionHostMsg_RequestForIOThread( 115 renderview->Send(new ExtensionHostMsg_RequestForIOThread(
99 renderview->GetRoutingID(), params)); 116 renderview->GetRoutingID(), params));
100 } else { 117 } else {
101 renderview->Send(new ExtensionHostMsg_Request( 118 renderview->Send(new ExtensionHostMsg_Request(
102 renderview->GetRoutingID(), params)); 119 renderview->GetRoutingID(), params));
(...skipping 19 matching lines...) Expand all
122 for (PendingRequestMap::iterator it = pending_requests_.begin(); 139 for (PendingRequestMap::iterator it = pending_requests_.begin();
123 it != pending_requests_.end();) { 140 it != pending_requests_.end();) {
124 if (it->second->source == source) 141 if (it->second->source == source)
125 pending_requests_.erase(it++); 142 pending_requests_.erase(it++);
126 else 143 else
127 ++it; 144 ++it;
128 } 145 }
129 } 146 }
130 147
131 } // namespace extensions 148 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698