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

Side by Side Diff: content/renderer/web_intents_host.cc

Issue 9186021: Update chromium code to use WebIntentRequest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/renderer/web_intents_host.h" 5 #include "content/renderer/web_intents_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/stl_util.h"
9 #include "content/common/intents_messages.h" 10 #include "content/common/intents_messages.h"
10 #include "content/renderer/render_view_impl.h" 11 #include "content/renderer/render_view_impl.h"
11 #include "ipc/ipc_message.h" 12 #include "ipc/ipc_message.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h "
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
17 #include "v8/include/v8.h" 19 #include "v8/include/v8.h"
18 #include "webkit/glue/cpp_bound_class.h" 20 #include "webkit/glue/cpp_bound_class.h"
19 21
20 using WebKit::WebCString; 22 using WebKit::WebCString;
21 using WebKit::WebString; 23 using WebKit::WebString;
22 24
23 // This class encapsulates the API the Intent object will expose to Javascript. 25 // This class encapsulates the API the Intent object will expose to Javascript.
24 // It is made available to the Javascript runtime in the service page using 26 // It is made available to the Javascript runtime in the service page using
25 // NPAPI methods as with plugin/Javascript interaction objects and other 27 // NPAPI methods as with plugin/Javascript interaction objects and other
26 // browser-provided Javascript API objects on |window|. 28 // browser-provided Javascript API objects on |window|.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // Intent data suitable for surfacing to Javascript callers. 123 // Intent data suitable for surfacing to Javascript callers.
122 WebCString action_; 124 WebCString action_;
123 WebCString type_; 125 WebCString type_;
124 scoped_ptr<CppVariant> data_val_; 126 scoped_ptr<CppVariant> data_val_;
125 127
126 // The dispatcher object, for forwarding postResult/postFailure calls. 128 // The dispatcher object, for forwarding postResult/postFailure calls.
127 WebIntentsHost* parent_; 129 WebIntentsHost* parent_;
128 }; 130 };
129 131
130 WebIntentsHost::WebIntentsHost(RenderViewImpl* render_view) 132 WebIntentsHost::WebIntentsHost(RenderViewImpl* render_view)
131 : content::RenderViewObserver(render_view) { 133 : content::RenderViewObserver(render_view),
134 id_counter_(0) {
132 } 135 }
133 136
134 WebIntentsHost::~WebIntentsHost() {} 137 WebIntentsHost::~WebIntentsHost() {
138 STLDeleteContainerPairSecondPointers(intent_requests_.begin(),
139 intent_requests_.end());
140 }
141
142 int WebIntentsHost::RegisterWebIntent(
143 WebKit::WebIntentRequest* request) {
144 int id = id_counter_++;
145 intent_requests_[id] = request;
146 return id;
147 }
135 148
136 bool WebIntentsHost::OnMessageReceived(const IPC::Message& message) { 149 bool WebIntentsHost::OnMessageReceived(const IPC::Message& message) {
137 bool handled = true; 150 bool handled = true;
138 IPC_BEGIN_MESSAGE_MAP(WebIntentsHost, message) 151 IPC_BEGIN_MESSAGE_MAP(WebIntentsHost, message)
139 IPC_MESSAGE_HANDLER(IntentsMsg_SetWebIntentData, OnSetIntent) 152 IPC_MESSAGE_HANDLER(IntentsMsg_SetWebIntentData, OnSetIntent)
140 IPC_MESSAGE_HANDLER(IntentsMsg_WebIntentReply, OnWebIntentReply); 153 IPC_MESSAGE_HANDLER(IntentsMsg_WebIntentReply, OnWebIntentReply);
141 IPC_MESSAGE_UNHANDLED(handled = false) 154 IPC_MESSAGE_UNHANDLED(handled = false)
142 IPC_END_MESSAGE_MAP() 155 IPC_END_MESSAGE_MAP()
143 return handled; 156 return handled;
144 } 157 }
145 158
146 void WebIntentsHost::OnSetIntent(const webkit_glue::WebIntentData& intent) { 159 void WebIntentsHost::OnSetIntent(const webkit_glue::WebIntentData& intent) {
147 intent_.reset(new webkit_glue::WebIntentData(intent)); 160 intent_.reset(new webkit_glue::WebIntentData(intent));
148 } 161 }
149 162
150 void WebIntentsHost::OnWebIntentReply( 163 void WebIntentsHost::OnWebIntentReply(
151 webkit_glue::WebIntentReplyType reply_type, 164 webkit_glue::WebIntentReplyType reply_type,
152 const WebKit::WebString& data, 165 const WebKit::WebString& data,
153 int intent_id) { 166 int intent_id) {
167 std::map<int, WebKit::WebIntentRequest*>::iterator request =
168 intent_requests_.find(intent_id);
169 if (request == intent_requests_.end())
170 return;
171 WebKit::WebIntentRequest* intent_request = request->second;
172 intent_requests_.erase(request);
154 173
155 if (reply_type == webkit_glue::WEB_INTENT_REPLY_SUCCESS) { 174 if (reply_type == webkit_glue::WEB_INTENT_REPLY_SUCCESS) {
156 render_view()->GetWebView()->mainFrame()->handleIntentResult( 175 intent_request->postResult(data);
157 intent_id, data);
158 } else { 176 } else {
159 render_view()->GetWebView()->mainFrame()->handleIntentFailure( 177 intent_request->postFailure(data);
160 intent_id, data);
161 } 178 }
162 } 179 }
163 180
164 void WebIntentsHost::OnResult(const WebKit::WebString& data) { 181 void WebIntentsHost::OnResult(const WebKit::WebString& data) {
165 Send(new IntentsHostMsg_WebIntentReply( 182 Send(new IntentsHostMsg_WebIntentReply(
166 routing_id(), webkit_glue::WEB_INTENT_REPLY_SUCCESS, data)); 183 routing_id(), webkit_glue::WEB_INTENT_REPLY_SUCCESS, data));
167 } 184 }
168 185
169 void WebIntentsHost::OnFailure(const WebKit::WebString& data) { 186 void WebIntentsHost::OnFailure(const WebKit::WebString& data) {
170 Send(new IntentsHostMsg_WebIntentReply( 187 Send(new IntentsHostMsg_WebIntentReply(
171 routing_id(), webkit_glue::WEB_INTENT_REPLY_FAILURE, data)); 188 routing_id(), webkit_glue::WEB_INTENT_REPLY_FAILURE, data));
172 } 189 }
173 190
174 // We set the intent payload into all top-level frame window objects. This 191 // We set the intent payload into all top-level frame window objects. This
175 // should persist the data through redirects, and not deliver it to any 192 // should persist the data through redirects, and not deliver it to any
176 // sub-frames. TODO(gbillock): This policy needs to be fine-tuned and 193 // sub-frames. TODO(gbillock): This policy needs to be fine-tuned and
177 // documented. 194 // documented.
178 void WebIntentsHost::DidClearWindowObject(WebKit::WebFrame* frame) { 195 void WebIntentsHost::DidClearWindowObject(WebKit::WebFrame* frame) {
179 if (intent_.get() == NULL || frame->top() != frame) 196 if (intent_.get() == NULL || frame->top() != frame)
180 return; 197 return;
181 198
182 delivered_intent_.reset(new BoundDeliveredIntent( 199 delivered_intent_.reset(new BoundDeliveredIntent(
183 intent_->action, intent_->type, intent_->data, this, frame)); 200 intent_->action, intent_->type, intent_->data, this, frame));
184 delivered_intent_->BindToJavascript(frame, "intent"); 201 delivered_intent_->BindToJavascript(frame, "intent");
185 } 202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698