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

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

Issue 9692017: An internal intents dispatcher useful for initiating an intent from the browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add CONTENT_EXPORT Created 8 years, 9 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 | « content/public/browser/web_intents_dispatcher.h ('k') | webkit/glue/web_intent_data.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 "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 "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"
(...skipping 13 matching lines...) Expand all
24 using WebKit::WebIntentRequest; 24 using WebKit::WebIntentRequest;
25 using WebKit::WebString; 25 using WebKit::WebString;
26 using WebKit::WebSerializedScriptValue; 26 using WebKit::WebSerializedScriptValue;
27 27
28 // This class encapsulates the API the Intent object will expose to Javascript. 28 // This class encapsulates the API the Intent object will expose to Javascript.
29 // It is made available to the Javascript runtime in the service page using 29 // It is made available to the Javascript runtime in the service page using
30 // NPAPI methods as with plugin/Javascript interaction objects and other 30 // NPAPI methods as with plugin/Javascript interaction objects and other
31 // browser-provided Javascript API objects on |window|. 31 // browser-provided Javascript API objects on |window|.
32 class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass { 32 class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
33 public: 33 public:
34 BoundDeliveredIntent(const string16& action, 34 BoundDeliveredIntent(const webkit_glue::WebIntentData& intent,
35 const string16& type,
36 const string16& data,
37 WebIntentsHost* parent, 35 WebIntentsHost* parent,
38 WebFrame* frame) { 36 WebFrame* frame) {
39 action_ = WebString(action).utf8(); 37 action_ = WebString(intent.action).utf8();
40 type_ = WebString(type).utf8(); 38 type_ = WebString(intent.type).utf8();
41 parent_ = parent; 39 parent_ = parent;
42 40
43 v8::HandleScope scope; 41 v8::HandleScope scope;
44 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext(); 42 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext();
45 v8::Context::Scope cscope(ctx); 43 v8::Context::Scope cscope(ctx);
46 WebSerializedScriptValue ssv = 44 v8::Local<v8::Value> data_obj;
47 WebSerializedScriptValue::fromString(WebString(data)); 45
48 // TODO(gbillock): use an exception handler instead? Need to 46 if (intent.data_type == webkit_glue::WebIntentData::SERIALIZED) {
49 // pass back error state to caller? This is a pretty unexpected 47 WebSerializedScriptValue ssv =
50 // internal error... 48 WebSerializedScriptValue::fromString(WebString(intent.data));
51 CHECK(!ssv.isNull()); 49 DCHECK(!ssv.isNull());
52 v8::Local<v8::Value> data_obj = 50 data_obj = v8::Local<v8::Value>::New(ssv.deserialize());
53 v8::Local<v8::Value>::New(ssv.deserialize()); 51 } else {
52 DCHECK(intent.data_type == webkit_glue::WebIntentData::UNSERIALIZED);
53 data_obj = v8::String::New(
54 reinterpret_cast<const uint16_t*>(intent.unserialized_data.data()),
55 static_cast<int>(intent.unserialized_data.length()));
56 }
54 57
55 data_val_.reset(new CppVariant); 58 data_val_.reset(new CppVariant);
56 WebBindings::toNPVariant(data_obj, frame->windowObject(), data_val_.get()); 59 WebBindings::toNPVariant(data_obj, frame->windowObject(), data_val_.get());
57 60
58 BindGetterCallback("action", base::Bind(&BoundDeliveredIntent::getAction, 61 BindGetterCallback("action", base::Bind(&BoundDeliveredIntent::getAction,
59 base::Unretained(this))); 62 base::Unretained(this)));
60 BindGetterCallback("type", base::Bind(&BoundDeliveredIntent::getType, 63 BindGetterCallback("type", base::Bind(&BoundDeliveredIntent::getType,
61 base::Unretained(this))); 64 base::Unretained(this)));
62 BindGetterCallback("data", base::Bind(&BoundDeliveredIntent::getData, 65 BindGetterCallback("data", base::Bind(&BoundDeliveredIntent::getData,
63 base::Unretained(this))); 66 base::Unretained(this)));
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 191 }
189 192
190 // We set the intent payload into all top-level frame window objects. This 193 // We set the intent payload into all top-level frame window objects. This
191 // should persist the data through redirects, and not deliver it to any 194 // should persist the data through redirects, and not deliver it to any
192 // sub-frames. TODO(gbillock): This policy needs to be fine-tuned and 195 // sub-frames. TODO(gbillock): This policy needs to be fine-tuned and
193 // documented. 196 // documented.
194 void WebIntentsHost::DidClearWindowObject(WebFrame* frame) { 197 void WebIntentsHost::DidClearWindowObject(WebFrame* frame) {
195 if (intent_.get() == NULL || frame->top() != frame) 198 if (intent_.get() == NULL || frame->top() != frame)
196 return; 199 return;
197 200
198 delivered_intent_.reset(new BoundDeliveredIntent( 201 delivered_intent_.reset(
199 intent_->action, intent_->type, intent_->data, this, frame)); 202 new BoundDeliveredIntent(*(intent_.get()), this, frame));
200 delivered_intent_->BindToJavascript(frame, "intent"); 203 delivered_intent_->BindToJavascript(frame, "intent");
201 } 204 }
OLDNEW
« no previous file with comments | « content/public/browser/web_intents_dispatcher.h ('k') | webkit/glue/web_intent_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698