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

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

Issue 8934011: Rename IntentsHost -> WebIntentsDispatcher and IntentsDispatcher -> WebIntentsHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head Created 9 years 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 | « content/renderer/web_intents_host.h ('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 (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/intents_dispatcher.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 "content/common/intents_messages.h" 9 #include "content/common/intents_messages.h"
10 #include "content/renderer/render_view_impl.h" 10 #include "content/renderer/render_view_impl.h"
11 #include "ipc/ipc_message.h" 11 #include "ipc/ipc_message.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h "
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.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" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
17 #include "v8/include/v8.h" 17 #include "v8/include/v8.h"
18 #include "webkit/glue/cpp_bound_class.h" 18 #include "webkit/glue/cpp_bound_class.h"
19 19
20 using WebKit::WebCString; 20 using WebKit::WebCString;
21 using WebKit::WebString; 21 using WebKit::WebString;
22 22
23 // This class encapsulates the API the Intent object will expose to Javascript. 23 // 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 24 // It is made available to the Javascript runtime in the service page using
25 // NPAPI methods as with plugin/Javascript interaction objects and other 25 // NPAPI methods as with plugin/Javascript interaction objects and other
26 // browser-provided Javascript API objects on |window|. 26 // browser-provided Javascript API objects on |window|.
27 class IntentsDispatcher::BoundDeliveredIntent : public CppBoundClass { 27 class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
28 public: 28 public:
29 BoundDeliveredIntent(const string16& action, 29 BoundDeliveredIntent(const string16& action,
30 const string16& type, 30 const string16& type,
31 const string16& data, 31 const string16& data,
32 IntentsDispatcher* parent, 32 WebIntentsHost* parent,
33 WebKit::WebFrame* frame) { 33 WebKit::WebFrame* frame) {
34 action_ = WebString(action).utf8(); 34 action_ = WebString(action).utf8();
35 type_ = WebString(type).utf8(); 35 type_ = WebString(type).utf8();
36 parent_ = parent; 36 parent_ = parent;
37 37
38 v8::HandleScope scope; 38 v8::HandleScope scope;
39 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext(); 39 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext();
40 v8::Context::Scope cscope(ctx); 40 v8::Context::Scope cscope(ctx);
41 WebKit::WebSerializedScriptValue ssv = 41 WebKit::WebSerializedScriptValue ssv =
42 WebKit::WebSerializedScriptValue::fromString(WebString(data)); 42 WebKit::WebSerializedScriptValue::fromString(WebString(data));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 result->Set(*data_val_.get()); 117 result->Set(*data_val_.get());
118 } 118 }
119 119
120 private: 120 private:
121 // Intent data suitable for surfacing to Javascript callers. 121 // Intent data suitable for surfacing to Javascript callers.
122 WebCString action_; 122 WebCString action_;
123 WebCString type_; 123 WebCString type_;
124 scoped_ptr<CppVariant> data_val_; 124 scoped_ptr<CppVariant> data_val_;
125 125
126 // The dispatcher object, for forwarding postResult/postFailure calls. 126 // The dispatcher object, for forwarding postResult/postFailure calls.
127 IntentsDispatcher* parent_; 127 WebIntentsHost* parent_;
128 }; 128 };
129 129
130 IntentsDispatcher::IntentsDispatcher(RenderViewImpl* render_view) 130 WebIntentsHost::WebIntentsHost(RenderViewImpl* render_view)
131 : content::RenderViewObserver(render_view) { 131 : content::RenderViewObserver(render_view) {
132 } 132 }
133 133
134 IntentsDispatcher::~IntentsDispatcher() {} 134 WebIntentsHost::~WebIntentsHost() {}
135 135
136 bool IntentsDispatcher::OnMessageReceived(const IPC::Message& message) { 136 bool WebIntentsHost::OnMessageReceived(const IPC::Message& message) {
137 bool handled = true; 137 bool handled = true;
138 IPC_BEGIN_MESSAGE_MAP(IntentsDispatcher, message) 138 IPC_BEGIN_MESSAGE_MAP(WebIntentsHost, message)
139 IPC_MESSAGE_HANDLER(IntentsMsg_SetWebIntentData, OnSetIntent) 139 IPC_MESSAGE_HANDLER(IntentsMsg_SetWebIntentData, OnSetIntent)
140 IPC_MESSAGE_HANDLER(IntentsMsg_WebIntentReply, OnWebIntentReply); 140 IPC_MESSAGE_HANDLER(IntentsMsg_WebIntentReply, OnWebIntentReply);
141 IPC_MESSAGE_UNHANDLED(handled = false) 141 IPC_MESSAGE_UNHANDLED(handled = false)
142 IPC_END_MESSAGE_MAP() 142 IPC_END_MESSAGE_MAP()
143 return handled; 143 return handled;
144 } 144 }
145 145
146 void IntentsDispatcher::OnSetIntent(const webkit_glue::WebIntentData& intent) { 146 void WebIntentsHost::OnSetIntent(const webkit_glue::WebIntentData& intent) {
147 intent_.reset(new webkit_glue::WebIntentData(intent)); 147 intent_.reset(new webkit_glue::WebIntentData(intent));
148 } 148 }
149 149
150 void IntentsDispatcher::OnWebIntentReply( 150 void WebIntentsHost::OnWebIntentReply(
151 webkit_glue::WebIntentReplyType reply_type, 151 webkit_glue::WebIntentReplyType reply_type,
152 const WebKit::WebString& data, 152 const WebKit::WebString& data,
153 int intent_id) { 153 int intent_id) {
154 154
155 if (reply_type == webkit_glue::WEB_INTENT_REPLY_SUCCESS) { 155 if (reply_type == webkit_glue::WEB_INTENT_REPLY_SUCCESS) {
156 render_view()->GetWebView()->mainFrame()->handleIntentResult( 156 render_view()->GetWebView()->mainFrame()->handleIntentResult(
157 intent_id, data); 157 intent_id, data);
158 } else { 158 } else {
159 render_view()->GetWebView()->mainFrame()->handleIntentFailure( 159 render_view()->GetWebView()->mainFrame()->handleIntentFailure(
160 intent_id, data); 160 intent_id, data);
161 } 161 }
162 } 162 }
163 163
164 void IntentsDispatcher::OnResult(const WebKit::WebString& data) { 164 void WebIntentsHost::OnResult(const WebKit::WebString& data) {
165 Send(new IntentsHostMsg_WebIntentReply( 165 Send(new IntentsHostMsg_WebIntentReply(
166 routing_id(), webkit_glue::WEB_INTENT_REPLY_SUCCESS, data)); 166 routing_id(), webkit_glue::WEB_INTENT_REPLY_SUCCESS, data));
167 } 167 }
168 168
169 void IntentsDispatcher::OnFailure(const WebKit::WebString& data) { 169 void WebIntentsHost::OnFailure(const WebKit::WebString& data) {
170 Send(new IntentsHostMsg_WebIntentReply( 170 Send(new IntentsHostMsg_WebIntentReply(
171 routing_id(), webkit_glue::WEB_INTENT_REPLY_FAILURE, data)); 171 routing_id(), webkit_glue::WEB_INTENT_REPLY_FAILURE, data));
172 } 172 }
173 173
174 // We set the intent payload into all top-level frame window objects. This 174 // 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 175 // 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 176 // sub-frames. TODO(gbillock): This policy needs to be fine-tuned and
177 // documented. 177 // documented.
178 void IntentsDispatcher::DidClearWindowObject(WebKit::WebFrame* frame) { 178 void WebIntentsHost::DidClearWindowObject(WebKit::WebFrame* frame) {
179 if (intent_.get() == NULL || frame->top() != frame) 179 if (intent_.get() == NULL || frame->top() != frame)
180 return; 180 return;
181 181
182 delivered_intent_.reset(new BoundDeliveredIntent( 182 delivered_intent_.reset(new BoundDeliveredIntent(
183 intent_->action, intent_->type, intent_->data, this, frame)); 183 intent_->action, intent_->type, intent_->data, this, frame));
184 delivered_intent_->BindToJavascript(frame, "intent"); 184 delivered_intent_->BindToJavascript(frame, "intent");
185 } 185 }
OLDNEW
« no previous file with comments | « content/renderer/web_intents_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698